Title: [253790] trunk
Revision
253790
Author
[email protected]
Date
2019-12-19 14:48:54 -0800 (Thu, 19 Dec 2019)

Log Message

Make ShadowRoot.delegateFocus work in iOS
https://bugs.webkit.org/show_bug.cgi?id=202875

Reviewed by Wenson Hsieh.

Source/WebCore:

This patch fixes the bug that a shadow tree doesn't recieve focus delegation even if the shadow host
had delegateFocus flag set unless the shadow host itself is focusable beacuse Frame's
nodeRespondingToClickEvents and friends would return false on the shadow host.

Test: fast/shadow-dom/delegates-focus-by-activation.html

* page/ios/FrameIOS.mm:
(WebCore::nodeIsMouseFocusable): Added the logic to handle shadow hosts whose shadow root has
delegates focus flag set.
(WebCore::nodeWillRespondToMouseEvents): Extracted out of approximateNodeAtViewportLocationLegacy.
(WebCore::Frame::approximateNodeAtViewportLocationLegacy):
(WebCore::ancestorRespondingToClickEventsNodeQualifier):

LayoutTests:

Added a regression test.

* fast/shadow-dom/delegates-focus-by-activation-expected.txt: Added.
* fast/shadow-dom/delegates-focus-by-activation.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (253789 => 253790)


--- trunk/LayoutTests/ChangeLog	2019-12-19 22:17:13 UTC (rev 253789)
+++ trunk/LayoutTests/ChangeLog	2019-12-19 22:48:54 UTC (rev 253790)
@@ -1,3 +1,15 @@
+2019-12-19  Ryosuke Niwa  <[email protected]>
+
+        Make ShadowRoot.delegateFocus work in iOS
+        https://bugs.webkit.org/show_bug.cgi?id=202875
+
+        Reviewed by Wenson Hsieh.
+
+        Added a regression test.
+
+        * fast/shadow-dom/delegates-focus-by-activation-expected.txt: Added.
+        * fast/shadow-dom/delegates-focus-by-activation.html: Added.
+
 2019-12-19  Chris Dumez  <[email protected]>
 
         Unreviewed, unskip fast/workers/worker-cloneport.html on iOS.

Added: trunk/LayoutTests/fast/shadow-dom/delegates-focus-by-activation-expected.txt (0 => 253790)


--- trunk/LayoutTests/fast/shadow-dom/delegates-focus-by-activation-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/delegates-focus-by-activation-expected.txt	2019-12-19 22:48:54 UTC (rev 253790)
@@ -0,0 +1,5 @@
+Test passes if you see a single 100px by 100px green box below.
+
+document.activeElement: PASS
+host.activeElement: PASS
+

Added: trunk/LayoutTests/fast/shadow-dom/delegates-focus-by-activation.html (0 => 253790)


--- trunk/LayoutTests/fast/shadow-dom/delegates-focus-by-activation.html	                        (rev 0)
+++ trunk/LayoutTests/fast/shadow-dom/delegates-focus-by-activation.html	2019-12-19 22:48:54 UTC (rev 253790)
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
+</head>
+<body>
+<p>Test passes if you see a single 100px by 100px green box below.</p>
+<style>
+* { outline: none; }
+div { width: 100px; height: 100px; background: gray; }
+div:focus { background: red; }
+div:focus-within { color: green; }
+</style>
+<script src=""
+<script>
+
+const host = document.createElement('div');
+document.body.appendChild(host);
+
+const shadowRoot = host.attachShadow({mode: 'closed', delegatesFocus: true});
+shadowRoot.innerHTML = `
+<style>
+:host { position: relative; }
+div { position: absolute; width: 100px; height: 100px; left: 0px; top: 0px; }
+div:focus { background: green; }
+</style>
+<div id="target" tabindex="0"></div>
+<div>Click here</div>`;
+
+async function runTest() {
+    testRunner.dumpAsText();
+
+    await UIHelper.activateElement(host);
+    await UIHelper.ensurePresentationUpdate();
+    await new Promise(requestAnimationFrame);
+
+    const pre = document.body.appendChild(document.createElement('pre'));
+    log = (text) => pre.textContent += text + '\n';
+
+    log('document.activeElement: ' + (document.activeElement == host ? 'PASS' : 'FAIL'));
+    log('host.activeElement: ' + (shadowRoot.activeElement == shadowRoot.getElementById('target') ? 'PASS' : 'FAIL'));
+}
+
+if (window.testRunner)
+    UIHelper.wait(runTest());
+
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (253789 => 253790)


--- trunk/Source/WebCore/ChangeLog	2019-12-19 22:17:13 UTC (rev 253789)
+++ trunk/Source/WebCore/ChangeLog	2019-12-19 22:48:54 UTC (rev 253790)
@@ -1,3 +1,23 @@
+2019-12-19  Ryosuke Niwa  <[email protected]>
+
+        Make ShadowRoot.delegateFocus work in iOS
+        https://bugs.webkit.org/show_bug.cgi?id=202875
+
+        Reviewed by Wenson Hsieh.
+
+        This patch fixes the bug that a shadow tree doesn't recieve focus delegation even if the shadow host
+        had delegateFocus flag set unless the shadow host itself is focusable beacuse Frame's
+        nodeRespondingToClickEvents and friends would return false on the shadow host.
+
+        Test: fast/shadow-dom/delegates-focus-by-activation.html
+
+        * page/ios/FrameIOS.mm:
+        (WebCore::nodeIsMouseFocusable): Added the logic to handle shadow hosts whose shadow root has
+        delegates focus flag set.
+        (WebCore::nodeWillRespondToMouseEvents): Extracted out of approximateNodeAtViewportLocationLegacy.
+        (WebCore::Frame::approximateNodeAtViewportLocationLegacy):
+        (WebCore::ancestorRespondingToClickEventsNodeQualifier):
+
 2019-12-19  Kate Cheney  <[email protected]>
 
         Activate the SQLite database as an on-by-default feature

Modified: trunk/Source/WebCore/page/ios/FrameIOS.mm (253789 => 253790)


--- trunk/Source/WebCore/page/ios/FrameIOS.mm	2019-12-19 22:17:13 UTC (rev 253789)
+++ trunk/Source/WebCore/page/ios/FrameIOS.mm	2019-12-19 22:48:54 UTC (rev 253790)
@@ -29,6 +29,7 @@
 
 #import "CSSAnimationController.h"
 #import "CommonVM.h"
+#import "ComposedTreeIterator.h"
 #import "DOMWindow.h"
 #import "Document.h"
 #import "DocumentMarkerController.h"
@@ -383,6 +384,32 @@
     return hitTestResult.innerNode();
 }
 
+static bool nodeIsMouseFocusable(Node& node)
+{
+    if (!is<Element>(node))
+        return false;
+
+    auto& element = downcast<Element>(node);
+    if (element.isMouseFocusable())
+        return true;
+
+    if (auto shadowRoot = makeRefPtr(element.shadowRoot())) {
+        if (shadowRoot->delegatesFocus()) {
+            for (auto& node : composedTreeDescendants(element)) {
+                if (is<Element>(node) && downcast<Element>(node).isMouseFocusable())
+                    return true;
+            }
+        }
+    }
+
+    return false;
+}
+
+static bool nodeWillRespondToMouseEvents(Node& node)
+{
+    return node.willRespondToMouseClickEvents() || node.willRespondToMouseMoveEvents() || nodeIsMouseFocusable(node);
+}
+
 Node* Frame::approximateNodeAtViewportLocationLegacy(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation)
 {
     // This function is only used for UIWebView.
@@ -420,7 +447,7 @@
                 pointerCursorStillValid = false;
             }
 
-            if (node->willRespondToMouseClickEvents() || node->willRespondToMouseMoveEvents() || (is<Element>(*node) && downcast<Element>(*node).isMouseFocusable())) {
+            if (nodeWillRespondToMouseEvents(*node)) {
                 // If we're at the body or higher, use the pointer cursor node (which may be null).
                 if (bodyHasBeenReached)
                     node = pointerCursorNode;
@@ -455,7 +482,7 @@
             return nullptr;
 
         for (; node && node != terminationNode; node = node->parentInComposedTree()) {
-            if (node->willRespondToMouseClickEvents() || node->willRespondToMouseMoveEvents() || (is<Element>(*node) && downcast<Element>(*node).isMouseFocusable())) {
+            if (nodeWillRespondToMouseEvents(*node)) {
                 // 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.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to