Click and touch event listeners on the body don't work
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Nov 2018 03:33:30 +0000 (03:33 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Nov 2018 03:33:30 +0000 (03:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=191392
<rdar://problem/5844416>

Reviewed by Simon Fraser.

Source/WebCore:

Remove the old quirk of ignoring onclick handlers on the body and beyond.

Test: fast/events/click-handler-on-body-simple.html

* page/ios/FrameIOS.mm:
(WebCore::Frame::nodeRespondingToClickEvents):

LayoutTests:

* fast/events/click-handler-on-body-simple-expected.txt: Added.
* fast/events/click-handler-on-body-simple.html: Added.
* fast/events/touch/touch-handler-on-body-simple-expected.txt: Added.
* fast/events/touch/touch-handler-on-body-simple.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237978 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/events/click-handler-on-body-simple-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/click-handler-on-body-simple.html [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/touch-handler-on-body-simple-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/touch-handler-on-body-simple.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/ios/FrameIOS.mm

index a4f9ca5..0fd8f51 100644 (file)
@@ -1,3 +1,16 @@
+2018-11-07  Zalan Bujtas  <zalan@apple.com>
+
+        Click and touch event listeners on the body don't work
+        https://bugs.webkit.org/show_bug.cgi?id=191392
+        <rdar://problem/5844416>
+
+        Reviewed by Simon Fraser.
+
+        * fast/events/click-handler-on-body-simple-expected.txt: Added.
+        * fast/events/click-handler-on-body-simple.html: Added.
+        * fast/events/touch/touch-handler-on-body-simple-expected.txt: Added.
+        * fast/events/touch/touch-handler-on-body-simple.html: Added.
+
 2018-11-07  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Add an editing command for creating and inserting child lists
diff --git a/LayoutTests/fast/events/click-handler-on-body-simple-expected.txt b/LayoutTests/fast/events/click-handler-on-body-simple-expected.txt
new file mode 100644 (file)
index 0000000..75d544a
--- /dev/null
@@ -0,0 +1 @@
+clicked
diff --git a/LayoutTests/fast/events/click-handler-on-body-simple.html b/LayoutTests/fast/events/click-handler-on-body-simple.html
new file mode 100644 (file)
index 0000000..fe73026
--- /dev/null
@@ -0,0 +1,37 @@
+<html>
+<head>
+<script src="../../resources/ui-helper.js"></script>
+<style>
+div {
+    width: 400px;
+    height: 400px;
+}
+</style>
+<script>
+async function test() {
+    if (!window.testRunner || !testRunner.runUIScript)
+        return;
+
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+
+    document.body.addEventListener("click", function( event ) {
+        result.innerHTML = "clicked";
+    }, false);
+
+    let element = document.getElementById("clickme");
+    let rect = element.getBoundingClientRect();
+    let x = rect.left + rect.width / 2;
+    let y = rect.top + rect.height / 2;
+
+    await UIHelper.activateAt(x, y);
+
+    testRunner.notifyDone();
+}
+</script>
+</head>
+<body onload="test()">
+<div id=clickme></div>
+<pre id=result></pre>
+</body>
+</html>
diff --git a/LayoutTests/fast/events/touch/ios/touch-handler-on-body-simple-expected.txt b/LayoutTests/fast/events/touch/ios/touch-handler-on-body-simple-expected.txt
new file mode 100644 (file)
index 0000000..3d2f6c9
--- /dev/null
@@ -0,0 +1 @@
+tapped
diff --git a/LayoutTests/fast/events/touch/ios/touch-handler-on-body-simple.html b/LayoutTests/fast/events/touch/ios/touch-handler-on-body-simple.html
new file mode 100644 (file)
index 0000000..a95bb4d
--- /dev/null
@@ -0,0 +1,37 @@
+<html>
+<head>
+<script src="../../../../resources/basic-gestures.js"></script>
+<style>
+div {
+    width: 400px;
+    height: 400px;
+}
+</style>
+<script>
+async function test() {
+    if (!window.testRunner || !testRunner.runUIScript)
+        return;
+
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+
+    document.body.addEventListener("touchstart", function( event ) {
+        result.innerHTML = "tapped";
+    }, false);
+
+    let element = document.getElementById("tapthis");
+    let rect = element.getBoundingClientRect();
+    let x = rect.left + rect.width / 2;
+    let y = rect.top + rect.height / 2;
+
+       await tapAtPoint(x, y);
+
+    testRunner.notifyDone();
+}
+</script>
+</head>
+<body onload="test()">
+<div id=tapthis></div>
+<pre id=result></pre>
+</body>
+</html>
index 4ac537b..92d5215 100644 (file)
@@ -1,3 +1,18 @@
+2018-11-07  Zalan Bujtas  <zalan@apple.com>
+
+        Click and touch event listeners on the body don't work
+        https://bugs.webkit.org/show_bug.cgi?id=191392
+        <rdar://problem/5844416>
+
+        Reviewed by Simon Fraser.
+
+        Remove the old quirk of ignoring onclick handlers on the body and beyond.
+
+        Test: fast/events/click-handler-on-body-simple.html
+
+        * page/ios/FrameIOS.mm:
+        (WebCore::Frame::nodeRespondingToClickEvents):
+
 2018-11-07  Brent Fulgham  <bfulgham@apple.com>
 
         [Windows][DirectX] Update canvas code to pass more tests
index 06e15dc..695a321 100644 (file)
@@ -390,9 +390,6 @@ Node* Frame::deepestNodeAtLocation(const FloatPoint& viewportLocation)
 Node* Frame::nodeRespondingToClickEvents(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation, SecurityOrigin* securityOrigin)
 {
     auto&& ancestorRespondingToClickEvents = [securityOrigin](const HitTestResult& hitTestResult, Node* terminationNode, IntRect* nodeBounds) -> Node* {
-        bool bodyHasBeenReached = false;
-        bool pointerCursorStillValid = true;
-
         if (nodeBounds)
             *nodeBounds = IntRect();
 
@@ -400,35 +397,8 @@ Node* Frame::nodeRespondingToClickEvents(const FloatPoint& viewportLocation, Flo
         if (!node || (securityOrigin && !securityOrigin->isSameOriginAs(node->document().securityOrigin())))
             return nullptr;
 
-        Node* pointerCursorNode = nullptr;
         for (; node && node != terminationNode; node = node->parentInComposedTree()) {
-            // We only accept pointer nodes before reaching the body tag.
-            if (node->hasTagName(HTMLNames::bodyTag)) {
-#if USE(UIKIT_EDITING)
-                // Make sure we cover the case of an empty editable body.
-                if (!pointerCursorNode && node->isContentEditable())
-                    pointerCursorNode = node;
-#endif
-                bodyHasBeenReached = true;
-                pointerCursorStillValid = false;
-            }
-
-            // If we already have a pointer, and we reach a table, don't accept it.
-            if (pointerCursorNode && (node->hasTagName(HTMLNames::tableTag) || node->hasTagName(HTMLNames::tbodyTag)))
-                pointerCursorStillValid = false;
-
-            // If we haven't reached the body, and we are still paying attention to pointer cursors, and the node has a pointer cursor...
-            if (pointerCursorStillValid && node->renderStyle() && node->renderStyle()->cursor() == CursorType::Pointer)
-                pointerCursorNode = node;
-            // We want the lowest unbroken chain of pointer cursors.
-            else if (pointerCursorNode)
-                pointerCursorStillValid = false;
-
             if (node->willRespondToMouseClickEvents() || node->willRespondToMouseMoveEvents() || (is<Element>(*node) && downcast<Element>(*node).isMouseFocusable())) {
-                // If we're at the body or higher, use the pointer cursor node (which may be null).
-                if (bodyHasBeenReached)
-                    node = pointerCursorNode;
-
                 // If we are interested about the frame, use it.
                 if (nodeBounds) {
                     // This is a check to see whether this node is an area element. The only way this can happen is if this is the first check.