From e2bc606eeb89305ce31004264f718c80df1b1fb7 Mon Sep 17 00:00:00 2001 From: Bastiaan van der Plaat Date: Fri, 19 Jan 2024 18:53:05 +0100 Subject: [PATCH] LibWeb: Add MouseEvent JavaScript constructor --- .../expected/UIEvents/custom-mouse-event.txt | 4 ++++ .../input/UIEvents/custom-mouse-event.html | 22 +++++++++++++++++++ .../Libraries/LibWeb/UIEvents/MouseEvent.cpp | 5 +++++ .../Libraries/LibWeb/UIEvents/MouseEvent.h | 1 + .../Libraries/LibWeb/UIEvents/MouseEvent.idl | 2 +- 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/UIEvents/custom-mouse-event.txt create mode 100644 Tests/LibWeb/Text/input/UIEvents/custom-mouse-event.html diff --git a/Tests/LibWeb/Text/expected/UIEvents/custom-mouse-event.txt b/Tests/LibWeb/Text/expected/UIEvents/custom-mouse-event.txt new file mode 100644 index 0000000000..139787de3f --- /dev/null +++ b/Tests/LibWeb/Text/expected/UIEvents/custom-mouse-event.txt @@ -0,0 +1,4 @@ +1. 10 +2. true +3. true +4. true diff --git a/Tests/LibWeb/Text/input/UIEvents/custom-mouse-event.html b/Tests/LibWeb/Text/input/UIEvents/custom-mouse-event.html new file mode 100644 index 0000000000..52962c867d --- /dev/null +++ b/Tests/LibWeb/Text/input/UIEvents/custom-mouse-event.html @@ -0,0 +1,22 @@ + + diff --git a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp index 79add6e12e..d796712579 100644 --- a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp +++ b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.cpp @@ -113,6 +113,11 @@ JS::NonnullGCPtr MouseEvent::create(JS::Realm& realm, FlyString cons return realm.heap().allocate(realm, realm, event_name, event_init, page_x, page_y, offset_x, offset_y); } +WebIDL::ExceptionOr> MouseEvent::construct_impl(JS::Realm& realm, FlyString const& event_name, MouseEventInit const& event_init) +{ + return create(realm, event_name, event_init); +} + WebIDL::ExceptionOr> MouseEvent::create_from_platform_event(JS::Realm& realm, FlyString const& event_name, CSSPixelPoint screen, CSSPixelPoint page, CSSPixelPoint client, CSSPixelPoint offset, Optional movement, unsigned button, unsigned buttons, unsigned modifiers) { MouseEventInit event_init {}; diff --git a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h index 813e909ddf..a27d85ffe2 100644 --- a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h +++ b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.h @@ -31,6 +31,7 @@ class MouseEvent : public UIEvent { public: [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&, FlyString const& event_name, MouseEventInit const& = {}, double page_x = 0, double page_y = 0, double offset_x = 0, double offset_y = 0); static WebIDL::ExceptionOr> create_from_platform_event(JS::Realm&, FlyString const& event_name, CSSPixelPoint screen, CSSPixelPoint page, CSSPixelPoint client, CSSPixelPoint offset, Optional movement, unsigned button, unsigned buttons, unsigned modifiers); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, FlyString const& event_name, MouseEventInit const&); virtual ~MouseEvent() override; diff --git a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.idl b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.idl index 31c4af90ce..7134d33244 100644 --- a/Userland/Libraries/LibWeb/UIEvents/MouseEvent.idl +++ b/Userland/Libraries/LibWeb/UIEvents/MouseEvent.idl @@ -3,7 +3,7 @@ // https://w3c.github.io/uievents/#mouseevent [Exposed=Window] interface MouseEvent : UIEvent { - // FIXME: constructor(DOMString type, optional MouseEventInit eventInitDict = {}); + constructor(DOMString type, optional MouseEventInit eventInitDict = {}); // https://drafts.csswg.org/cssom-view/#extensions-to-the-mouseevent-interface readonly attribute double screenX;