DisallowUserAgentShadowContent moves out of non-UA shadow roots
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Jul 2017 02:10:42 +0000 (02:10 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Jul 2017 02:10:42 +0000 (02:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=165647

Patch by Ali Juma <ajuma@chromium.org> on 2017-07-16
Reviewed by Ryosuke Niwa.

Source/WebCore:

Make rect-based hit-testing include nodes in non-UA shadow trees when the
HitTestRequest has type DisallowUserAgentShadowContent.

Test: fast/dom/nodesFromRect/nodesFromRect-shadow.html

* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::addNodeToRectBasedTestResult):
* testing/Internals.cpp:
(WebCore::Internals::nodesFromRect):
* testing/Internals.h:

LayoutTests:

* fast/dom/nodesFromRect/nodesFromRect-shadow-expected.txt: Added.
* fast/dom/nodesFromRect/nodesFromRect-shadow.html: Added.
* fast/dom/nodesFromRect/resources/nodesFromRect.js:
(check):
(checkShadowContent):
(nodesFromRectAsString):

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

LayoutTests/ChangeLog
LayoutTests/fast/dom/nodesFromRect/nodesFromRect-shadow-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/nodesFromRect/nodesFromRect-shadow.html [new file with mode: 0644]
LayoutTests/fast/dom/nodesFromRect/resources/nodesFromRect.js
Source/WebCore/ChangeLog
Source/WebCore/rendering/HitTestResult.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h

index c98b9a3..314eabb 100644 (file)
@@ -1,3 +1,17 @@
+2017-07-16  Ali Juma  <ajuma@chromium.org>
+
+        DisallowUserAgentShadowContent moves out of non-UA shadow roots
+        https://bugs.webkit.org/show_bug.cgi?id=165647
+
+        Reviewed by Ryosuke Niwa.
+
+        * fast/dom/nodesFromRect/nodesFromRect-shadow-expected.txt: Added.
+        * fast/dom/nodesFromRect/nodesFromRect-shadow.html: Added.
+        * fast/dom/nodesFromRect/resources/nodesFromRect.js:
+        (check):
+        (checkShadowContent):
+        (nodesFromRectAsString):
+
 2017-07-16  Antoine Quint  <graouts@apple.com>
 
         Clicking edges of media control buttons changes visual state of button (pressed) but doesn't execute action
diff --git a/LayoutTests/fast/dom/nodesFromRect/nodesFromRect-shadow-expected.txt b/LayoutTests/fast/dom/nodesFromRect/nodesFromRect-shadow-expected.txt
new file mode 100644 (file)
index 0000000..c2aea1e
--- /dev/null
@@ -0,0 +1,7 @@
+PASS All correct nodes found for rect
+PASS All correct nodes found for rect
+PASS All correct nodes found for rect
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/nodesFromRect/nodesFromRect-shadow.html b/LayoutTests/fast/dom/nodesFromRect/nodesFromRect-shadow.html
new file mode 100644 (file)
index 0000000..2251221
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script src="../../../resources/js-test-pre.js"></script>
+    <script src="resources/nodesFromRect.js"></script>
+    <style>
+        .box {
+            width: 30px;
+            height: 30px;
+            padding: 0px;
+        }
+     </style>
+</head>
+<body id="body">
+    <div id="d1" class="box"></div>
+
+    <div id="d2" class="box"></div>
+
+    <div id="shadowHost" class="box"></div>
+
+    <div id="console"></div>
+
+    <script>
+        checkRect(10, 45, 15, 30, "DIV#shadowHost, DIV#d2, BODY#body");
+
+        var host = document.getElementById("shadowHost");
+        var shadow = host.attachShadow({mode: 'closed'});
+        shadow.innerHTML="<content>text</content>";
+
+        checkRect(10, 45, 15, 30, "'text', CONTENT, DIV#shadowHost, DIV#d2, BODY#body");
+
+        shadow.innerHTML="<slot></slot>";
+        host.innerHTML="<inner-host></inner-host>";
+        var innerHost = host.querySelector("inner-host");
+        var innerShadow = innerHost.attachShadow({mode: 'closed'});
+        innerShadow.innerHTML = "<content>text</content>";
+
+        checkRect(10, 45, 15, 30, "'text', CONTENT, INNER-HOST, DIV#shadowHost, DIV#d2, BODY#body");
+    </script>
+    <script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
+
index ffa9ee4..dc3d138 100644 (file)
@@ -42,7 +42,7 @@ function check(x, y, topPadding, rightPadding, bottomPadding, leftPadding, list,
   if (!doc)
     doc = document;
 
-  var nodes = internals.nodesFromRect(doc, x, y, topPadding, rightPadding, bottomPadding, leftPadding, true /* ignoreClipping */, false /* allow shadow content */, false /* allow child-frame content */);
+  var nodes = internals.nodesFromRect(doc, x, y, topPadding, rightPadding, bottomPadding, leftPadding, true /* ignoreClipping */, false /* allow user-agent shadow content */, false /* allow child-frame content */);
   if (!nodes)
     return;
 
@@ -78,7 +78,7 @@ function checkShadowContent(x, y, topPadding, rightPadding, bottomPadding, leftP
   if (!doc)
     doc = document;
 
-  var nodes = internals.nodesFromRect(doc, x, y, topPadding, rightPadding, bottomPadding, leftPadding, true /* ignoreClipping */, true /* allowShadowContent */, false /* allow child-frame content */);
+  var nodes = internals.nodesFromRect(doc, x, y, topPadding, rightPadding, bottomPadding, leftPadding, true /* ignoreClipping */, true /* allowUserAgentShadowContent */, false /* allow child-frame content */);
   if (!nodes)
     return;
 
@@ -145,7 +145,7 @@ function checkPoint(left, top, expectedNodeString, doc)
 
 function nodesFromRectAsString(doc, x, y, topPadding, rightPadding, bottomPadding, leftPadding)
 {
-    var nodes = internals.nodesFromRect(doc, x, y, topPadding, rightPadding, bottomPadding, leftPadding, true /* ignoreClipping */, false /* allow shadow content */, true /* allow child-frame content */);
+    var nodes = internals.nodesFromRect(doc, x, y, topPadding, rightPadding, bottomPadding, leftPadding, true /* ignoreClipping */, false /* allow user-agent shadow content */, true /* allow child-frame content */);
     if (!nodes)
         return "";
 
index b74a793..51f0904 100644 (file)
@@ -1,3 +1,21 @@
+2017-07-16  Ali Juma  <ajuma@chromium.org>
+
+        DisallowUserAgentShadowContent moves out of non-UA shadow roots
+        https://bugs.webkit.org/show_bug.cgi?id=165647
+
+        Reviewed by Ryosuke Niwa.
+
+        Make rect-based hit-testing include nodes in non-UA shadow trees when the
+        HitTestRequest has type DisallowUserAgentShadowContent.
+
+        Test: fast/dom/nodesFromRect/nodesFromRect-shadow.html
+
+        * rendering/HitTestResult.cpp:
+        (WebCore::HitTestResult::addNodeToRectBasedTestResult):
+        * testing/Internals.cpp:
+        (WebCore::Internals::nodesFromRect):
+        * testing/Internals.h:
+
 2017-07-16  Antoine Quint  <graouts@apple.com>
 
         Clicking edges of media control buttons changes visual state of button (pressed) but doesn't execute action
index 7f7c139..edb6c1b 100644 (file)
@@ -667,8 +667,7 @@ bool HitTestResult::addNodeToRectBasedTestResult(Node* node, const HitTestReques
     if (!node)
         return true;
 
-    // FIXME: This moves out of a author shadow tree.
-    if (request.disallowsUserAgentShadowContent())
+    if (request.disallowsUserAgentShadowContent() && node->isInUserAgentShadowTree())
         node = node->document().ancestorNodeInThisScope(node);
 
     mutableRectBasedTestResult().add(node);
@@ -688,8 +687,7 @@ bool HitTestResult::addNodeToRectBasedTestResult(Node* node, const HitTestReques
     if (!node)
         return true;
 
-    // FIXME: This moves out of a author shadow tree.
-    if (request.disallowsUserAgentShadowContent())
+    if (request.disallowsUserAgentShadowContent() && node->isInUserAgentShadowTree())
         node = node->document().ancestorNodeInThisScope(node);
 
     mutableRectBasedTestResult().add(node);
index 4b00ee2..4fb91cc 100644 (file)
@@ -1835,7 +1835,7 @@ ExceptionOr<Ref<DOMRectList>> Internals::passiveTouchEventListenerRects()
 // contextDocument(), with the exception of a few tests that pass a
 // different document, and could just make the call through another Internals
 // instance instead.
-ExceptionOr<RefPtr<NodeList>> Internals::nodesFromRect(Document& document, int centerX, int centerY, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent) const
+ExceptionOr<RefPtr<NodeList>> Internals::nodesFromRect(Document& document, int centerX, int centerY, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowUserAgentShadowContent, bool allowChildFrameContent) const
 {
     if (!document.frame() || !document.frame()->view())
         return Exception { INVALID_ACCESS_ERR };
@@ -1854,7 +1854,7 @@ ExceptionOr<RefPtr<NodeList>> Internals::nodesFromRect(Document& document, int c
     HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active;
     if (ignoreClipping)
         hitType |= HitTestRequest::IgnoreClipping;
-    if (!allowShadowContent)
+    if (!allowUserAgentShadowContent)
         hitType |= HitTestRequest::DisallowUserAgentShadowContent;
     if (allowChildFrameContent)
         hitType |= HitTestRequest::AllowChildFrameContent;
index 5be2199..e68aad6 100644 (file)
@@ -249,7 +249,7 @@ public:
     ExceptionOr<Ref<DOMRectList>> touchEventRectsForEvent(const String&);
     ExceptionOr<Ref<DOMRectList>> passiveTouchEventListenerRects();
 
-    ExceptionOr<RefPtr<NodeList>> nodesFromRect(Document&, int x, int y, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowShadowContent, bool allowChildFrameContent) const;
+    ExceptionOr<RefPtr<NodeList>> nodesFromRect(Document&, int x, int y, unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding, bool ignoreClipping, bool allowUserAgentShadowContent, bool allowChildFrameContent) const;
 
     String parserMetaData(JSC::JSValue = JSC::JSValue::JSUndefined);