Skip to content

Commit 5dafb3e

Browse files
aprotyasmnutt
authored andcommitted
pointerevent_movementxy.html?mouse WPT is failing
https://bugs.webkit.org/show_bug.cgi?id=258780 rdar://111635046 Reviewed by Wenson Hsieh. Currently, we are failing the pointerevent_movementxy.html?mouse WPT variant with the error "FAIL mouse pointerevent attributes assert_equals: movementX should be 0 for event other than pointermove. expected 0 but got 20". We fail this assertion because events that are not of the pointermove type have non-zero movementX/Y values. We address said issue in this commit by: - Making sure that any event which isn't of type (mouse/pointer/touch)move does not have non-zero movementX/movementY fields. - Hardening against accidentally assigning movementX/movementY fields outside of initialization, by making said fields private. - Adjusting the expected result for the now passing WPT. This commit also introduces some additional state into the WebCore::Event class, through which we can consult if the Event was constructed using an EventInit dictionary. We need this information because the attribute values assigned from the EventInit dictionary receive priority over other rules dictating the Event attribute. * LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerevent_movementxy_mouse-expected.txt: * Source/WebCore/dom/Event.cpp: * Source/WebCore/dom/Event.h: (WebCore::Event::isConstructedFromInitializer const): * Source/WebCore/dom/MouseRelatedEvent.cpp: (WebCore::isMoveEventType): (WebCore::MouseRelatedEvent::init): * Source/WebCore/dom/MouseRelatedEvent.h: Canonical link: https://commits.webkit.org/265730@main
1 parent 3342e7d commit 5dafb3e

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
Pointer Events movementX/Y attribute test
22

3-
Follow the test instructions with mouse. If you don't have the device skip it.
4-
53
Test Description: This test checks the movementX/Y properties of pointer events.
64
Press down on the black square.
75
Move your pointer slowly along a straight line to the red square.
@@ -10,5 +8,5 @@ Test passes if the proper behavior of the events is observed.
108

119

1210

13-
FAIL mouse pointerevent attributes assert_equals: movementX should be 0 for event other than pointermove. expected 0 but got 20
11+
PASS mouse pointerevent attributes
1412

Source/WebCore/dom/Event.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Event::Event(const AtomString& eventType, const EventInit& initializer, IsTruste
8484
initializer.composed ? IsComposed::Yes : IsComposed::No }
8585
{
8686
ASSERT(!eventType.isNull());
87+
m_isConstructedFromInitializer = true;
8788
}
8889

8990
Event::~Event() = default;

Source/WebCore/dom/Event.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ class Event : public ScriptWrappable, public RefCounted<Event> {
160160

161161
virtual void receivedTarget() { }
162162

163+
bool isConstructedFromInitializer() const { return m_isConstructedFromInitializer; }
164+
163165
private:
164166
explicit Event(MonotonicTime createTime, const AtomString& type, IsTrusted, CanBubble, IsCancelable, IsComposed);
165167

@@ -181,6 +183,10 @@ class Event : public ScriptWrappable, public RefCounted<Event> {
181183

182184
unsigned m_eventPhase : 2;
183185

186+
// We consult this flag since the EventInit dictionary takes priority in initializing event attribute values.
187+
// See step 4 of https://dom.spec.whatwg.org/#inner-event-creation-steps
188+
unsigned m_isConstructedFromInitializer : 1 { false };
189+
184190
AtomString m_type;
185191

186192
RefPtr<EventTarget> m_currentTarget;

Source/WebCore/dom/MouseRelatedEvent.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ MouseRelatedEvent::MouseRelatedEvent(const AtomString& eventType, const MouseRel
6464
init(false, IntPoint(0, 0));
6565
}
6666

67+
static inline bool isMoveEventType(const AtomString& eventType)
68+
{
69+
auto& eventNames = WebCore::eventNames();
70+
return eventType == eventNames.mousemoveEvent
71+
|| eventType == eventNames.pointermoveEvent
72+
|| eventType == eventNames.touchmoveEvent;
73+
}
74+
6775
void MouseRelatedEvent::init(bool isSimulated, const IntPoint& windowLocation)
6876
{
6977
if (!isSimulated) {
@@ -76,6 +84,11 @@ void MouseRelatedEvent::init(bool isSimulated, const IntPoint& windowLocation)
7684
}
7785

7886
initCoordinates();
87+
88+
if (!isConstructedFromInitializer() && !isMoveEventType(type())) {
89+
m_movementX = 0;
90+
m_movementY = 0;
91+
}
7992
}
8093

8194
void MouseRelatedEvent::initCoordinates()

Source/WebCore/dom/MouseRelatedEvent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ class MouseRelatedEvent : public UIEventWithKeyState {
9696
// Expose these so MouseEvent::initMouseEvent can set them.
9797
IntPoint m_screenLocation;
9898
LayoutPoint m_clientLocation;
99-
double m_movementX { 0 };
100-
double m_movementY { 0 };
10199

102100
private:
103101
void init(bool isSimulated, const IntPoint&);
104102

103+
double m_movementX { 0 };
104+
double m_movementY { 0 };
105105
LayoutPoint m_pageLocation;
106106
LayoutPoint m_layerLocation;
107107
LayoutPoint m_offsetLocation;

0 commit comments

Comments
 (0)