Title: [219568] trunk
Revision
219568
Author
cdu...@apple.com
Date
2017-07-17 12:14:12 -0700 (Mon, 17 Jul 2017)

Log Message

click event does not dispatch to parent when child target stops hit testing after mousedown
https://bugs.webkit.org/show_bug.cgi?id=174564
<rdar://problem/33340234>

Reviewed by Simon Fraser.

Source/WebCore:

As per [1], if the mouse down node and the mouse release node differ, then we are supposed to
fire the click event at their common ancestor, if such node exists. This patch implements this
logic. This also aligns our behavior with Blink.

[1] https://w3c.github.io/uievents/#events-mouseevent-event-order

Test: fast/events/mouse-click-different-mouseDown-mouseUp-nodes.html

* page/EventHandler.cpp:
(WebCore::targetNodeForClickEvent):

LayoutTests:

Add layout test coverage.

* fast/events/mouse-click-different-mouseDown-mouseUp-nodes-expected.txt: Added.
* fast/events/mouse-click-different-mouseDown-mouseUp-nodes.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (219567 => 219568)


--- trunk/LayoutTests/ChangeLog	2017-07-17 19:10:06 UTC (rev 219567)
+++ trunk/LayoutTests/ChangeLog	2017-07-17 19:14:12 UTC (rev 219568)
@@ -1,3 +1,16 @@
+2017-07-17  Chris Dumez  <cdu...@apple.com>
+
+        click event does not dispatch to parent when child target stops hit testing after mousedown
+        https://bugs.webkit.org/show_bug.cgi?id=174564
+        <rdar://problem/33340234>
+
+        Reviewed by Simon Fraser.
+
+        Add layout test coverage.
+
+        * fast/events/mouse-click-different-mouseDown-mouseUp-nodes-expected.txt: Added.
+        * fast/events/mouse-click-different-mouseDown-mouseUp-nodes.html: Added.
+
 2017-07-17  Antoine Quint  <grao...@apple.com>
 
         REGRESSION: order of AirPlay and volume controls is inconsistent between <audio> and <video>

Added: trunk/LayoutTests/fast/events/mouse-click-different-mouseDown-mouseUp-nodes-expected.txt (0 => 219568)


--- trunk/LayoutTests/fast/events/mouse-click-different-mouseDown-mouseUp-nodes-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/mouse-click-different-mouseDown-mouseUp-nodes-expected.txt	2017-07-17 19:14:12 UTC (rev 219568)
@@ -0,0 +1,11 @@
+Tests that the click event is fired at the common ancestor if the mouseDown / mouseUp nodes differ.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS parentGotClickEvent is true
+PASS childGotClickEvent is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/events/mouse-click-different-mouseDown-mouseUp-nodes.html (0 => 219568)


--- trunk/LayoutTests/fast/events/mouse-click-different-mouseDown-mouseUp-nodes.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/mouse-click-different-mouseDown-mouseUp-nodes.html	2017-07-17 19:14:12 UTC (rev 219568)
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<style>
+    div {
+        position: absolute;
+        top: 0;
+        left: 0;
+        width: 100%;
+        height: 100%;
+    }
+
+    .button {
+        background-color: blue;
+    }
+
+    .icon {
+        background-color: black;
+    }
+
+    .button:active .icon {
+        transform: scale(0.25);
+    }
+</style>
+</head>
+<body>
+<div id="parentDiv" class="button" _onclick_="alert('clicked')">
+    <div id="childDiv" class="icon"></div>
+</div>
+<script>
+description("Tests that the click event is fired at the common ancestor if the mouseDown / mouseUp nodes differ.");
+jsTestIsAsync = true;
+
+parentGotClickEvent = false;
+childGotClickEvent = false;
+
+document.getElementById("parentDiv")._onclick_ = function() {
+    parentGotClickEvent = true;
+};
+
+document.getElementById("childDiv")._onclick_ = function() {
+    childGotClickEvent = true;
+};
+
+_onload_ = function() {
+    if (window.eventSender) {
+        eventSender.mouseMoveTo(10, 300);
+        eventSender.mouseDown();
+        eventSender.mouseUp();    
+    }
+
+    setTimeout(function() {
+        shouldBeTrue("parentGotClickEvent");
+        shouldBeFalse("childGotClickEvent");
+        finishJSTest();
+    }, 0);
+}
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/ios/TestExpectations (219567 => 219568)


--- trunk/LayoutTests/platform/ios/TestExpectations	2017-07-17 19:10:06 UTC (rev 219567)
+++ trunk/LayoutTests/platform/ios/TestExpectations	2017-07-17 19:14:12 UTC (rev 219568)
@@ -387,6 +387,7 @@
 fast/forms/range/range-drag-when-toggled-disabled.html [ Skip ]
 fast/media/video-element-in-details-collapse.html [ Skip ]
 fast/frames/user-gesture-timestamp-propagation.html [ Failure ]
+fast/events/mouse-click-different-mouseDown-mouseUp-nodes.html [ Skip ]
 
 # The file-wrapper part of <attachment> is not yet working on iOS
 fast/attachment/attachment-type-attribute.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (219567 => 219568)


--- trunk/Source/WebCore/ChangeLog	2017-07-17 19:10:06 UTC (rev 219567)
+++ trunk/Source/WebCore/ChangeLog	2017-07-17 19:14:12 UTC (rev 219568)
@@ -1,3 +1,22 @@
+2017-07-17  Chris Dumez  <cdu...@apple.com>
+
+        click event does not dispatch to parent when child target stops hit testing after mousedown
+        https://bugs.webkit.org/show_bug.cgi?id=174564
+        <rdar://problem/33340234>
+
+        Reviewed by Simon Fraser.
+
+        As per [1], if the mouse down node and the mouse release node differ, then we are supposed to
+        fire the click event at their common ancestor, if such node exists. This patch implements this
+        logic. This also aligns our behavior with Blink.
+
+        [1] https://w3c.github.io/uievents/#events-mouseevent-event-order
+
+        Test: fast/events/mouse-click-different-mouseDown-mouseUp-nodes.html
+
+        * page/EventHandler.cpp:
+        (WebCore::targetNodeForClickEvent):
+
 2017-07-17  Brady Eidson  <beid...@apple.com>
 
         WKHTTPCookieStore observing only works on the default cookie store.

Modified: trunk/Source/WebCore/page/EventHandler.cpp (219567 => 219568)


--- trunk/Source/WebCore/page/EventHandler.cpp	2017-07-17 19:10:06 UTC (rev 219567)
+++ trunk/Source/WebCore/page/EventHandler.cpp	2017-07-17 19:14:12 UTC (rev 219568)
@@ -70,6 +70,7 @@
 #include "PlatformKeyboardEvent.h"
 #include "PlatformWheelEvent.h"
 #include "PluginDocument.h"
+#include "Range.h"
 #include "RenderFrameSet.h"
 #include "RenderLayer.h"
 #include "RenderListBox.h"
@@ -1999,6 +2000,12 @@
     if (mousePressNode == mouseReleaseNode)
         return mouseReleaseNode;
 
+    // If mousePressNode and mouseReleaseNode differ, we should fire the event at their common ancestor if there is one.
+    if (&mousePressNode->document() == &mouseReleaseNode->document()) {
+        if (auto* commonAncestor = Range::commonAncestorContainer(mousePressNode, mouseReleaseNode))
+            return commonAncestor;
+    }
+
     Element* mouseReleaseShadowHost = mouseReleaseNode->shadowHost();
     if (mouseReleaseShadowHost && mouseReleaseShadowHost == mousePressNode->shadowHost()) {
         // We want to dispatch the click to the shadow tree host element to give listeners the illusion that the
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to