Skip to content

Truly independent web browser

LibWeb: Expose legacy mouse target accessors

Andreas Klingc10c79cf3db8
diff --git a/Libraries/LibWeb/UIEvents/MouseEvent.cpp b/Libraries/LibWeb/UIEvents/MouseEvent.cpp
index c54dc01d16c..69f42535043 100644
--- a/Libraries/LibWeb/UIEvents/MouseEvent.cpp
+++ b/Libraries/LibWeb/UIEvents/MouseEvent.cpp
@@ -7,6 +7,7 @@
#include <LibGC/Heap.h>
#include <LibWeb/Bindings/MouseEvent.h>
+#include <LibWeb/DOM/Node.h>
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/HTML/WindowProxy.h>
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
@@ -19,6 +20,19 @@ namespace Web::UIEvents {
GC_DEFINE_ALLOCATOR(MouseEvent);
+// INTEROP: The legacy mouse endpoints use the current dispatch targets, reversing direction for exit events.
+GC::Ptr<DOM::Node> MouseEvent::from_element() const
+{
+ auto endpoint = type().is_one_of(EventNames::mouseout, EventNames::mouseleave) ? target() : related_target();
+ return as_if<DOM::Node>(endpoint.ptr());
+}
+
+GC::Ptr<DOM::Node> MouseEvent::to_element() const
+{
+ auto endpoint = type().is_one_of(EventNames::mouseout, EventNames::mouseleave) ? related_target() : target();
+ return as_if<DOM::Node>(endpoint.ptr());
+}
+
MouseEvent::MouseEvent(FlyString const& event_name, MouseEventOptions const& options, double page_x, double page_y, double offset_x, double offset_y, HighResolutionTime::DOMHighResTimeStamp time_stamp)
: UIEvent(event_name, time_stamp)
, m_screen_x(options.screen_x)
diff --git a/Libraries/LibWeb/UIEvents/MouseEvent.h b/Libraries/LibWeb/UIEvents/MouseEvent.h
index d1fd1abf9c7..ebeb88b168a 100644
--- a/Libraries/LibWeb/UIEvents/MouseEvent.h
+++ b/Libraries/LibWeb/UIEvents/MouseEvent.h
@@ -116,6 +116,9 @@ public:
i16 button() const { return m_button; }
u16 buttons() const { return m_buttons; }
+ virtual GC::Ptr<DOM::Node> from_element() const;
+ virtual GC::Ptr<DOM::Node> to_element() const;
+
bool get_modifier_state(Utf16FlyString const& key_arg) const;
virtual u32 which() const override { return m_button + 1; }
diff --git a/Libraries/LibWeb/UIEvents/MouseEvent.idl b/Libraries/LibWeb/UIEvents/MouseEvent.idl
index de335a40142..9e721001d9f 100644
--- a/Libraries/LibWeb/UIEvents/MouseEvent.idl
+++ b/Libraries/LibWeb/UIEvents/MouseEvent.idl
@@ -29,6 +29,9 @@ interface MouseEvent : UIEvent {
[DirectGetter] readonly attribute EventTarget? relatedTarget;
+ readonly attribute Node? fromElement;
+ readonly attribute Node? toElement;
+
boolean getModifierState([FlyString] DOMString keyArg);
// https://w3c.github.io/uievents/#dom-mouseevent-initmouseevent
diff --git a/Libraries/LibWeb/UIEvents/PointerEvent.h b/Libraries/LibWeb/UIEvents/PointerEvent.h
index e367baa09b0..2014a06bc97 100644
--- a/Libraries/LibWeb/UIEvents/PointerEvent.h
+++ b/Libraries/LibWeb/UIEvents/PointerEvent.h
@@ -82,6 +82,13 @@ public:
double offset_x() const override;
double offset_y() const override;
+ // https://w3c.github.io/pointerevents/#attributes-and-default-actions
+ // Many user agents expose non-standard attributes fromElement and toElement in MouseEvents to support legacy content.
+ // We encourage those user agents to set the values of those (inherited) attributes in PointerEvents to null to
+ // transition authors to the use of standardized alternates (target and relatedTarget).
+ virtual GC::Ptr<DOM::Node> from_element() const override { return nullptr; }
+ virtual GC::Ptr<DOM::Node> to_element() const override { return nullptr; }
+
WebIDL::Long pointer_id() const { return m_pointer_id; }
double width() const { return m_width; }
double height() const { return m_height; }
diff --git a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
index 7e66cbdba1e..14b0f5417c0 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
+++ b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
@@ -2,22 +2,21 @@ Harness status: OK
Found 16 tests
-1 Pass
+15 Pass
1 Fail
-14 Optional Feature Unsupported
Pass Main-frame attribute test.
Fail Inner-frame attribute test.
-Optional Feature Unsupported Main-frame mouse pointerover.fromElement value is null
-Optional Feature Unsupported Main-frame mouse pointerover.toElement value is null
-Optional Feature Unsupported Main-frame mouse pointerenter.fromElement value is null
-Optional Feature Unsupported Main-frame mouse pointerenter.toElement value is null
-Optional Feature Unsupported Main-frame mouse pointermove.fromElement value is null
-Optional Feature Unsupported Main-frame mouse pointermove.toElement value is null
-Optional Feature Unsupported Main-frame mouse pointerdown.fromElement value is null
-Optional Feature Unsupported Main-frame mouse pointerdown.toElement value is null
-Optional Feature Unsupported Main-frame mouse pointerup.fromElement value is null
-Optional Feature Unsupported Main-frame mouse pointerup.toElement value is null
-Optional Feature Unsupported Main-frame mouse pointerout.fromElement value is null
-Optional Feature Unsupported Main-frame mouse pointerout.toElement value is null
-Optional Feature Unsupported Main-frame mouse pointerleave.fromElement value is null
-Optional Feature Unsupported Main-frame mouse pointerleave.toElement value is null
\ No newline at end of file
+Pass Main-frame mouse pointerover.fromElement value is null
+Pass Main-frame mouse pointerover.toElement value is null
+Pass Main-frame mouse pointerenter.fromElement value is null
+Pass Main-frame mouse pointerenter.toElement value is null
+Pass Main-frame mouse pointermove.fromElement value is null
+Pass Main-frame mouse pointermove.toElement value is null
+Pass Main-frame mouse pointerdown.fromElement value is null
+Pass Main-frame mouse pointerdown.toElement value is null
+Pass Main-frame mouse pointerup.fromElement value is null
+Pass Main-frame mouse pointerup.toElement value is null
+Pass Main-frame mouse pointerout.fromElement value is null
+Pass Main-frame mouse pointerout.toElement value is null
+Pass Main-frame mouse pointerleave.fromElement value is null
+Pass Main-frame mouse pointerleave.toElement value is null
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
index 7e66cbdba1e..14b0f5417c0 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
+++ b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
@@ -2,22 +2,21 @@ Harness status: OK
Found 16 tests
-1 Pass
+15 Pass
1 Fail
-14 Optional Feature Unsupported
Pass Main-frame attribute test.
Fail Inner-frame attribute test.
-Optional Feature Unsupported Main-frame mouse pointerover.fromElement value is null
-Optional Feature Unsupported Main-frame mouse pointerover.toElement value is null
-Optional Feature Unsupported Main-frame mouse pointerenter.fromElement value is null
-Optional Feature Unsupported Main-frame mouse pointerenter.toElement value is null
-Optional Feature Unsupported Main-frame mouse pointermove.fromElement value is null
-Optional Feature Unsupported Main-frame mouse pointermove.toElement value is null
-Optional Feature Unsupported Main-frame mouse pointerdown.fromElement value is null
-Optional Feature Unsupported Main-frame mouse pointerdown.toElement value is null
-Optional Feature Unsupported Main-frame mouse pointerup.fromElement value is null
-Optional Feature Unsupported Main-frame mouse pointerup.toElement value is null
-Optional Feature Unsupported Main-frame mouse pointerout.fromElement value is null
-Optional Feature Unsupported Main-frame mouse pointerout.toElement value is null
-Optional Feature Unsupported Main-frame mouse pointerleave.fromElement value is null
-Optional Feature Unsupported Main-frame mouse pointerleave.toElement value is null
\ No newline at end of file
+Pass Main-frame mouse pointerover.fromElement value is null
+Pass Main-frame mouse pointerover.toElement value is null
+Pass Main-frame mouse pointerenter.fromElement value is null
+Pass Main-frame mouse pointerenter.toElement value is null
+Pass Main-frame mouse pointermove.fromElement value is null
+Pass Main-frame mouse pointermove.toElement value is null
+Pass Main-frame mouse pointerdown.fromElement value is null
+Pass Main-frame mouse pointerdown.toElement value is null
+Pass Main-frame mouse pointerup.fromElement value is null
+Pass Main-frame mouse pointerup.toElement value is null
+Pass Main-frame mouse pointerout.fromElement value is null
+Pass Main-frame mouse pointerout.toElement value is null
+Pass Main-frame mouse pointerleave.fromElement value is null
+Pass Main-frame mouse pointerleave.toElement value is null
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
index 371324ed478..425e08a2f03 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
+++ b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
@@ -2,22 +2,21 @@ Harness status: OK
Found 16 tests
-1 Pass
+15 Pass
1 Fail
-14 Optional Feature Unsupported
Pass Main-frame attribute test.
Fail Inner-frame attribute test.
-Optional Feature Unsupported Main-frame pen pointerover.fromElement value is null
-Optional Feature Unsupported Main-frame pen pointerover.toElement value is null
-Optional Feature Unsupported Main-frame pen pointerenter.fromElement value is null
-Optional Feature Unsupported Main-frame pen pointerenter.toElement value is null
-Optional Feature Unsupported Main-frame pen pointermove.fromElement value is null
-Optional Feature Unsupported Main-frame pen pointermove.toElement value is null
-Optional Feature Unsupported Main-frame pen pointerdown.fromElement value is null
-Optional Feature Unsupported Main-frame pen pointerdown.toElement value is null
-Optional Feature Unsupported Main-frame pen pointerup.fromElement value is null
-Optional Feature Unsupported Main-frame pen pointerup.toElement value is null
-Optional Feature Unsupported Main-frame pen pointerout.fromElement value is null
-Optional Feature Unsupported Main-frame pen pointerout.toElement value is null
-Optional Feature Unsupported Main-frame pen pointerleave.fromElement value is null
-Optional Feature Unsupported Main-frame pen pointerleave.toElement value is null
\ No newline at end of file
+Pass Main-frame pen pointerover.fromElement value is null
+Pass Main-frame pen pointerover.toElement value is null
+Pass Main-frame pen pointerenter.fromElement value is null
+Pass Main-frame pen pointerenter.toElement value is null
+Pass Main-frame pen pointermove.fromElement value is null
+Pass Main-frame pen pointermove.toElement value is null
+Pass Main-frame pen pointerdown.fromElement value is null
+Pass Main-frame pen pointerdown.toElement value is null
+Pass Main-frame pen pointerup.fromElement value is null
+Pass Main-frame pen pointerup.toElement value is null
+Pass Main-frame pen pointerout.fromElement value is null
+Pass Main-frame pen pointerout.toElement value is null
+Pass Main-frame pen pointerleave.fromElement value is null
+Pass Main-frame pen pointerleave.toElement value is null
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
index 371324ed478..425e08a2f03 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
+++ b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
@@ -2,22 +2,21 @@ Harness status: OK
Found 16 tests
-1 Pass
+15 Pass
1 Fail
-14 Optional Feature Unsupported
Pass Main-frame attribute test.
Fail Inner-frame attribute test.
-Optional Feature Unsupported Main-frame pen pointerover.fromElement value is null
-Optional Feature Unsupported Main-frame pen pointerover.toElement value is null
-Optional Feature Unsupported Main-frame pen pointerenter.fromElement value is null
-Optional Feature Unsupported Main-frame pen pointerenter.toElement value is null
-Optional Feature Unsupported Main-frame pen pointermove.fromElement value is null
-Optional Feature Unsupported Main-frame pen pointermove.toElement value is null
-Optional Feature Unsupported Main-frame pen pointerdown.fromElement value is null
-Optional Feature Unsupported Main-frame pen pointerdown.toElement value is null
-Optional Feature Unsupported Main-frame pen pointerup.fromElement value is null
-Optional Feature Unsupported Main-frame pen pointerup.toElement value is null
-Optional Feature Unsupported Main-frame pen pointerout.fromElement value is null
-Optional Feature Unsupported Main-frame pen pointerout.toElement value is null
-Optional Feature Unsupported Main-frame pen pointerleave.fromElement value is null
-Optional Feature Unsupported Main-frame pen pointerleave.toElement value is null
\ No newline at end of file
+Pass Main-frame pen pointerover.fromElement value is null
+Pass Main-frame pen pointerover.toElement value is null
+Pass Main-frame pen pointerenter.fromElement value is null
+Pass Main-frame pen pointerenter.toElement value is null
+Pass Main-frame pen pointermove.fromElement value is null
+Pass Main-frame pen pointermove.toElement value is null
+Pass Main-frame pen pointerdown.fromElement value is null
+Pass Main-frame pen pointerdown.toElement value is null
+Pass Main-frame pen pointerup.fromElement value is null
+Pass Main-frame pen pointerup.toElement value is null
+Pass Main-frame pen pointerout.fromElement value is null
+Pass Main-frame pen pointerout.toElement value is null
+Pass Main-frame pen pointerleave.fromElement value is null
+Pass Main-frame pen pointerleave.toElement value is null
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
index 88104e90741..ec724277f80 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
+++ b/Tests/LibWeb/Text/expected/wpt-import/pointerevents/[email protected]
@@ -2,22 +2,21 @@ Harness status: OK
Found 16 tests
-1 Pass
+15 Pass
1 Fail
-14 Optional Feature Unsupported
Pass Main-frame attribute test.
Fail Inner-frame attribute test.
-Optional Feature Unsupported Main-frame touch pointerover.fromElement value is null
-Optional Feature Unsupported Main-frame touch pointerover.toElement value is null
-Optional Feature Unsupported Main-frame touch pointerenter.fromElement value is null
-Optional Feature Unsupported Main-frame touch pointerenter.toElement value is null
-Optional Feature Unsupported Main-frame touch pointerdown.fromElement value is null
-Optional Feature Unsupported Main-frame touch pointerdown.toElement value is null
-Optional Feature Unsupported Main-frame touch pointermove.fromElement value is null
-Optional Feature Unsupported Main-frame touch pointermove.toElement value is null
-Optional Feature Unsupported Main-frame touch pointerup.fromElement value is null
-Optional Feature Unsupported Main-frame touch pointerup.toElement value is null
-Optional Feature Unsupported Main-frame touch pointerout.fromElement value is null
-Optional Feature Unsupported Main-frame touch pointerout.toElement value is null
-Optional Feature Unsupported Main-frame touch pointerleave.fromElement value is null
-Optional Feature Unsupported Main-frame touch pointerleave.toElement value is null
\ No newline at end of file
+Pass Main-frame touch pointerover.fromElement value is null
+Pass Main-frame touch pointerover.toElement value is null
+Pass Main-frame touch pointerenter.fromElement value is null
+Pass Main-frame touch pointerenter.toElement value is null
+Pass Main-frame touch pointerdown.fromElement value is null
+Pass Main-frame touch pointerdown.toElement value is null
+Pass Main-frame touch pointermove.fromElement value is null
+Pass Main-frame touch pointermove.toElement value is null
+Pass Main-frame touch pointerup.fromElement value is null
+Pass Main-frame touch pointerup.toElement value is null
+Pass Main-frame touch pointerout.fromElement value is null
+Pass Main-frame touch pointerout.toElement value is null
+Pass Main-frame touch pointerleave.fromElement value is null
+Pass Main-frame touch pointerleave.toElement value is null
\ No newline at end of file