diff options
author | Andreas Kling <kling@serenityos.org> | 2022-02-25 20:45:19 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-25 20:45:19 +0100 |
commit | fbee0490a3db6ed9a87c2f8cc2e5565f1de1fc1b (patch) | |
tree | 37c3d9f4a928b04b8d7666f4c5d3221a99564ba0 /Userland/Libraries/LibWeb/HTML | |
parent | c25d653c313ff6fefd55df2388096ac15846c24c (diff) | |
download | serenity-fbee0490a3db6ed9a87c2f8cc2e5565f1de1fc1b.zip |
LibWeb: Improve HTMLElement.click()
This API now follows the spec a bit more closely, with regards to the
event being dispatched. There are still FIXME's but this is already an
improvement.
2% progression on ACID3. :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLElement.cpp | 33 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLElement.h | 2 |
2 files changed, 34 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index 68fe0fde74..b116fd20c9 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -390,6 +390,37 @@ void HTMLElement::focus() m_locked_for_focus = false; } +// https://html.spec.whatwg.org/multipage/webappapis.html#fire-a-synthetic-pointer-event +bool HTMLElement::fire_a_synthetic_pointer_event(FlyString const& type, DOM::Element& target, bool not_trusted) +{ + // 1. Let event be the result of creating an event using PointerEvent. + // 2. Initialize event's type attribute to e. + // FIXME: Actually create a PointerEvent! + auto event = DOM::Event::create(type); + + // 3. Initialize event's bubbles and cancelable attributes to true. + event->set_bubbles(true); + event->set_cancelable(true); + + // 4. Set event's composed flag. + event->set_composed(true); + + // 5. If the not trusted flag is set, initialize event's isTrusted attribute to false. + if (not_trusted) { + event->set_is_trusted(false); + } + + // FIXME: 6. Initialize event's ctrlKey, shiftKey, altKey, and metaKey attributes according to the current state + // of the key input device, if any (false for any keys that are not available). + + // FIXME: 7. Initialize event's view attribute to target's node document's Window object, if any, and null otherwise. + + // FIXME: 8. event's getModifierState() method is to return values appropriately describing the current state of the key input device. + + // 9. Return the result of dispatching event at target. + return target.dispatch_event(move(event)); +} + // https://html.spec.whatwg.org/multipage/interaction.html#dom-click void HTMLElement::click() { @@ -403,7 +434,7 @@ void HTMLElement::click() m_click_in_progress = true; // FIXME: 4. Fire a synthetic pointer event named click at this element, with the not trusted flag set. - dispatch_event(DOM::Event::create("click")); + fire_a_synthetic_pointer_event(HTML::EventNames::click, *this, true); // 5. Unset this element's click in progress flag. m_click_in_progress = false; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.h b/Userland/Libraries/LibWeb/HTML/HTMLElement.h index 0110ff7a88..9e925b2b59 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.h @@ -44,6 +44,8 @@ public: void click(); + bool fire_a_synthetic_pointer_event(FlyString const& type, DOM::Element& target, bool not_trusted); + protected: virtual void parse_attribute(const FlyString& name, const String& value) override; |