Title: [245699] trunk
Revision
245699
Author
[email protected]
Date
2019-05-23 11:13:56 -0700 (Thu, 23 May 2019)

Log Message

[Pointer Events] Compatibility mouse events can only be prevented while the pointer is pressed
https://bugs.webkit.org/show_bug.cgi?id=198178

Patch by Antoine Quint <[email protected]> on 2019-05-23
Reviewed by Dean Jackson.

Source/WebCore:

Test: pointerevents/mouse/compatibility-mouse-events-prevention-mouse-released.html

The Pointer Events spec, in https://www.w3.org/TR/pointerevents/#compatibility-mapping-with-mouse-events, says that "Mouse events
can only be prevented when the pointer is down. Hovering pointers (e.g. a mouse with no buttons pressed) cannot have their mouse
events prevented." We now track whether the pointer is pressed and clear the preventsCompatibilityMouseEvents when the pointer is
moved and it is not pressed.

* page/PointerCaptureController.cpp:
(WebCore::PointerCaptureController::pointerEventWasDispatched):
* page/PointerCaptureController.h:

LayoutTests:

Add a test that listens "mousemove" events and checks it is not dispatched after preventDefault() is called when handling
 "pointerdown" but it is dispatched after releasing the mouse pointer and moving it again.

* pointerevents/mouse/compatibility-mouse-events-prevention-mouse-released-expected.txt: Added.
* pointerevents/mouse/compatibility-mouse-events-prevention-mouse-released.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (245698 => 245699)


--- trunk/LayoutTests/ChangeLog	2019-05-23 18:08:01 UTC (rev 245698)
+++ trunk/LayoutTests/ChangeLog	2019-05-23 18:13:56 UTC (rev 245699)
@@ -1,5 +1,18 @@
 2019-05-23  Antoine Quint  <[email protected]>
 
+        [Pointer Events] Compatibility mouse events can only be prevented while the pointer is pressed
+        https://bugs.webkit.org/show_bug.cgi?id=198178
+
+        Reviewed by Dean Jackson.
+
+        Add a test that listens "mousemove" events and checks it is not dispatched after preventDefault() is called when handling
+         "pointerdown" but it is dispatched after releasing the mouse pointer and moving it again.
+
+        * pointerevents/mouse/compatibility-mouse-events-prevention-mouse-released-expected.txt: Added.
+        * pointerevents/mouse/compatibility-mouse-events-prevention-mouse-released.html: Added.
+
+2019-05-23  Antoine Quint  <[email protected]>
+
         [Pointer Events] The mouseover, mouseout, mouseenter, and mouseleave events should not be prevented while the pointer is down
         https://bugs.webkit.org/show_bug.cgi?id=198177
 

Added: trunk/LayoutTests/pointerevents/mouse/compatibility-mouse-events-prevention-mouse-released-expected.txt (0 => 245699)


--- trunk/LayoutTests/pointerevents/mouse/compatibility-mouse-events-prevention-mouse-released-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/pointerevents/mouse/compatibility-mouse-events-prevention-mouse-released-expected.txt	2019-05-23 18:13:56 UTC (rev 245699)
@@ -0,0 +1,3 @@
+
+PASS Testing that calling preventDefault() when handling a "pointerdown" event only blocks events while the mouse pointer is pressed. 
+

Added: trunk/LayoutTests/pointerevents/mouse/compatibility-mouse-events-prevention-mouse-released.html (0 => 245699)


--- trunk/LayoutTests/pointerevents/mouse/compatibility-mouse-events-prevention-mouse-released.html	                        (rev 0)
+++ trunk/LayoutTests/pointerevents/mouse/compatibility-mouse-events-prevention-mouse-released.html	2019-05-23 18:13:56 UTC (rev 245699)
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset=utf-8>
+</head>
+<body>
+<script src=""
+<script src=""
+<script src=""
+<script>
+
+'use strict';
+
+target_test((target, test) => {
+    // First, let's make sure we call preventDefault() the first time we get a pointerdown event.
+    target.addEventListener("pointerdown", event => event.preventDefault(), { once: true });
+
+    // Press the mouse while over the element.
+    eventSender.mouseMoveTo(50, 50);
+    eventSender.mouseDown();
+
+    let obtainedMouseMove = false;
+    target.addEventListener("mousemove", event => obtainedMouseMove = true, { once: true });
+    eventSender.mouseMoveTo(60, 60);
+    assert_false(obtainedMouseMove, "The mousemove event is not fired after calling preventDefault() while handling the pointerdown event.");
+
+    // Release the mouse.
+    eventSender.mouseUp();
+
+    // Now, without the mouse pressed, move the pointer over the element again. This should not prevent the mousemove event anymore since
+    // the mouse pointer is not pressed.
+    eventSender.mouseMoveTo(50, 50);
+    assert_true(obtainedMouseMove, "The mousemove event is fired after releasing the mouse.");
+
+    test.done();
+}, `Testing that calling preventDefault() when handling a "pointerdown" event only blocks events while the mouse pointer is pressed.`);
+
+</script>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (245698 => 245699)


--- trunk/Source/WebCore/ChangeLog	2019-05-23 18:08:01 UTC (rev 245698)
+++ trunk/Source/WebCore/ChangeLog	2019-05-23 18:13:56 UTC (rev 245699)
@@ -1,5 +1,23 @@
 2019-05-23  Antoine Quint  <[email protected]>
 
+        [Pointer Events] Compatibility mouse events can only be prevented while the pointer is pressed
+        https://bugs.webkit.org/show_bug.cgi?id=198178
+
+        Reviewed by Dean Jackson.
+
+        Test: pointerevents/mouse/compatibility-mouse-events-prevention-mouse-released.html
+
+        The Pointer Events spec, in https://www.w3.org/TR/pointerevents/#compatibility-mapping-with-mouse-events, says that "Mouse events
+        can only be prevented when the pointer is down. Hovering pointers (e.g. a mouse with no buttons pressed) cannot have their mouse
+        events prevented." We now track whether the pointer is pressed and clear the preventsCompatibilityMouseEvents when the pointer is
+        moved and it is not pressed.
+
+        * page/PointerCaptureController.cpp:
+        (WebCore::PointerCaptureController::pointerEventWasDispatched):
+        * page/PointerCaptureController.h:
+
+2019-05-23  Antoine Quint  <[email protected]>
+
         [Pointer Events] The mouseover, mouseout, mouseenter, and mouseleave events should not be prevented while the pointer is down
         https://bugs.webkit.org/show_bug.cgi?id=198177
 

Modified: trunk/Source/WebCore/page/PointerCaptureController.cpp (245698 => 245699)


--- trunk/Source/WebCore/page/PointerCaptureController.cpp	2019-05-23 18:08:01 UTC (rev 245698)
+++ trunk/Source/WebCore/page/PointerCaptureController.cpp	2019-05-23 18:13:56 UTC (rev 245699)
@@ -264,13 +264,22 @@
         // override for the pointerId of the pointerup or pointercancel event that was just dispatched, and then run Process Pending
         // Pointer Capture steps to fire lostpointercapture if necessary.
         // https://w3c.github.io/pointerevents/#implicit-release-of-pointer-capture
-        if (event.type() == eventNames().pointerupEvent)
+        if (event.type() == eventNames().pointerupEvent) {
             capturingData.pendingTargetOverride = nullptr;
+            capturingData.pointerIsPressed = false;
+        }
 
+        // If a mouse pointer has moved while it isn't pressed, make sure we reset the preventsCompatibilityMouseEvents flag since
+        // we could otherwise prevent compatibility mouse events while those are only supposed to be prevented while the pointer is pressed.
+        if (event.type() == eventNames().pointermoveEvent && capturingData.pointerType == PointerEvent::mousePointerType() && !capturingData.pointerIsPressed)
+            capturingData.preventsCompatibilityMouseEvents = false;
+
         // If the pointer event dispatched was pointerdown and the event was canceled, then set the PREVENT MOUSE EVENT flag for this pointerType.
         // https://www.w3.org/TR/pointerevents/#mapping-for-devices-that-support-hover
-        if (event.type() == eventNames().pointerdownEvent)
+        if (event.type() == eventNames().pointerdownEvent) {
             capturingData.preventsCompatibilityMouseEvents = event.defaultPrevented();
+            capturingData.pointerIsPressed = true;
+        }
     }
 
     processPendingPointerCapture(event);

Modified: trunk/Source/WebCore/page/PointerCaptureController.h (245698 => 245699)


--- trunk/Source/WebCore/page/PointerCaptureController.h	2019-05-23 18:08:01 UTC (rev 245698)
+++ trunk/Source/WebCore/page/PointerCaptureController.h	2019-05-23 18:13:56 UTC (rev 245699)
@@ -66,6 +66,7 @@
         bool cancelled { false };
         bool isPrimary { false };
         bool preventsCompatibilityMouseEvents { false };
+        bool pointerIsPressed { false };
     };
 
     void pointerEventWillBeDispatched(const PointerEvent&, EventTarget*);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to