Title: [123407] trunk
Revision
123407
Author
[email protected]
Date
2012-07-23 17:12:13 -0700 (Mon, 23 Jul 2012)

Log Message

A FocusScope for a distributed node should not be its TreeScope.
https://bugs.webkit.org/show_bug.cgi?id=91829

Reviewed by Dimitri Glazkov.

Source/WebCore:

Current implementation of FocusScope::focusScopeOf(Node*) returns
the given node's treeScope().  That does not apply if the node is
a distributed node.  We should calculate a FocusScope for a
distributed node by traversing ancestor nodes in Composed Shadow
Tree.

Test: fast/dom/shadow/focus-navigation-with-distributed-nodes.html

* page/FocusController.cpp:
(WebCore::FocusScope::focusScopeOf):

LayoutTests:

* fast/dom/shadow/focus-navigation-with-distributed-nodes-expected.txt: Added.
* fast/dom/shadow/focus-navigation-with-distributed-nodes.html: Added.
* fast/dom/shadow/resources/shadow-dom.js:
(shouldNavigateFocus):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (123406 => 123407)


--- trunk/LayoutTests/ChangeLog	2012-07-24 00:06:23 UTC (rev 123406)
+++ trunk/LayoutTests/ChangeLog	2012-07-24 00:12:13 UTC (rev 123407)
@@ -1,3 +1,15 @@
+2012-07-23  Hayato Ito  <[email protected]>
+
+        A FocusScope for a distributed node should not be its TreeScope.
+        https://bugs.webkit.org/show_bug.cgi?id=91829
+
+        Reviewed by Dimitri Glazkov.
+
+        * fast/dom/shadow/focus-navigation-with-distributed-nodes-expected.txt: Added.
+        * fast/dom/shadow/focus-navigation-with-distributed-nodes.html: Added.
+        * fast/dom/shadow/resources/shadow-dom.js:
+        (shouldNavigateFocus):
+
 2012-07-23  Douglas Stockwell  <[email protected]>
 
         Null-pointer crash when parsing border-image

Added: trunk/LayoutTests/fast/dom/shadow/focus-navigation-with-distributed-nodes-expected.txt (0 => 123407)


--- trunk/LayoutTests/fast/dom/shadow/focus-navigation-with-distributed-nodes-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/focus-navigation-with-distributed-nodes-expected.txt	2012-07-24 00:12:13 UTC (rev 123407)
@@ -0,0 +1,35 @@
+This tests that pressing Tab key should traverse into shadow DOM subtrees, and pressing Shift-Tab should reverse the order.
+
+
+
+Should move from input-1 to shadowhost in forward
+PASS
+Should move from shadowhost to distributed-node-1 in forward
+PASS
+Should move from distributed-node-1 to shadowhost/input-2 in forward
+PASS
+Should move from shadowhost/input-2 to distributed-node-2 in forward
+PASS
+Should move from distributed-node-2 to input-3 in forward
+PASS
+Should move from input-3 to distributed-node-2 in backward
+PASS
+Should move from distributed-node-2 to shadowhost/input-2 in backward
+PASS
+Should move from shadowhost/input-2 to distributed-node-1 in backward
+PASS
+Should move from distributed-node-1 to shadowhost in backward
+PASS
+Should move from shadowhost to input-1 in backward
+PASS
+details/summary elements use Shadow DOM and distributed nodes internally.
+Should move from input-1 to summary-1 in forward
+PASS
+Should move from summary-1 to input-2 in forward
+PASS
+Should move from input-2 to summary-1 in backward
+PASS
+Should move from summary-1 to input-1 in backward
+PASS
+Test finished.
+

Added: trunk/LayoutTests/fast/dom/shadow/focus-navigation-with-distributed-nodes.html (0 => 123407)


--- trunk/LayoutTests/fast/dom/shadow/focus-navigation-with-distributed-nodes.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/focus-navigation-with-distributed-nodes.html	2012-07-24 00:12:13 UTC (rev 123407)
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<p>This tests that pressing Tab key should traverse into shadow DOM subtrees, and pressing Shift-Tab should reverse the order.</p>
+<div id="sandbox"></div>
+<pre id="console"></pre>
+<script>
+
+function testWithDistributedNodes()
+{
+    var sandbox = document.getElementById('sandbox');
+    sandbox.innerHTML = '';
+    sandbox.appendChild(
+        createDOM('div', {'id': 'top-div'},
+                  createDOM('input', {'id': 'input-1', 'tabindex': 1}),
+                  createDOM('div', {'id': 'shadowhost', 'tabindex': 1},
+                            createShadowRoot(
+                                createDOM('content', {'select': '#distributed-node-1'}),
+                                createDOM('input', {'id': 'input-2', 'tabindex': 1}),
+                                createDOM('content', {'select': '#distributed-node-2'})),
+                            createDOM('input', {'id': 'distributed-node-2', 'tabindex': 1}),
+                            createDOM('input', {'id': 'distributed-node-1', 'tabindex': 1})),
+                  createDOM('input', {'id': 'input-3', 'tabindex': 1})));
+    sandbox.offsetLeft;
+
+    var elementsInFocusNavigationOrder = ['input-1', 'shadowhost', 'distributed-node-1', 'shadowhost/input-2', 'distributed-node-2', 'input-3'];
+    testFocusNavigationFowrad(elementsInFocusNavigationOrder);
+    elementsInFocusNavigationOrder.reverse()
+    testFocusNavigationBackward(elementsInFocusNavigationOrder)
+}
+
+function testDetailsSummary()
+{
+    debug('details/summary elements use Shadow DOM and distributed nodes internally.')
+    var sandbox = document.getElementById('sandbox');
+    sandbox.innerHTML = '';
+    sandbox.appendChild(
+        createDOM('div', {'id': 'top-div'},
+                  createDOM('input', {'id': 'input-1'}),
+                  createDOM('details', {'id': 'details-1'},
+                            createDOM('summary', {'id': 'summary-1'})),
+                  createDOM('input', {'id': 'input-2'})));
+    sandbox.offsetLeft;
+
+    var elementsInFocusNavigationOrder = ['input-1', 'summary-1', 'input-2'];
+    testFocusNavigationFowrad(elementsInFocusNavigationOrder);
+    elementsInFocusNavigationOrder.reverse()
+    testFocusNavigationBackward(elementsInFocusNavigationOrder);
+}
+
+
+function test() {
+    if (window.testRunner)
+        testRunner.dumpAsText();
+
+    if (!window.eventSender) {
+        testFailed('');
+        return;
+    }
+
+    testWithDistributedNodes()
+    testDetailsSummary();
+
+    debug('Test finished.');
+}
+
+test();
+
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/fast/dom/shadow/resources/shadow-dom.js (123406 => 123407)


--- trunk/LayoutTests/fast/dom/shadow/resources/shadow-dom.js	2012-07-24 00:06:23 UTC (rev 123406)
+++ trunk/LayoutTests/fast/dom/shadow/resources/shadow-dom.js	2012-07-24 00:12:13 UTC (rev 123407)
@@ -124,6 +124,10 @@
       return;
     }
     fromElement.focus();
+    if (!isInnermostActiveElement(from)) {
+        debug('FAIL: Can not be focused: '+ from);
+        return;
+    }
     if (direction == 'forward')
         navigateFocusForward();
     else

Modified: trunk/Source/WebCore/ChangeLog (123406 => 123407)


--- trunk/Source/WebCore/ChangeLog	2012-07-24 00:06:23 UTC (rev 123406)
+++ trunk/Source/WebCore/ChangeLog	2012-07-24 00:12:13 UTC (rev 123407)
@@ -1,3 +1,21 @@
+2012-07-23  Hayato Ito  <[email protected]>
+
+        A FocusScope for a distributed node should not be its TreeScope.
+        https://bugs.webkit.org/show_bug.cgi?id=91829
+
+        Reviewed by Dimitri Glazkov.
+
+        Current implementation of FocusScope::focusScopeOf(Node*) returns
+        the given node's treeScope().  That does not apply if the node is
+        a distributed node.  We should calculate a FocusScope for a
+        distributed node by traversing ancestor nodes in Composed Shadow
+        Tree.
+
+        Test: fast/dom/shadow/focus-navigation-with-distributed-nodes.html
+
+        * page/FocusController.cpp:
+        (WebCore::FocusScope::focusScopeOf):
+
 2012-07-23  Douglas Stockwell  <[email protected]>
 
         Null-pointer crash when parsing border-image

Modified: trunk/Source/WebCore/page/FocusController.cpp (123406 => 123407)


--- trunk/Source/WebCore/page/FocusController.cpp	2012-07-24 00:06:23 UTC (rev 123406)
+++ trunk/Source/WebCore/page/FocusController.cpp	2012-07-24 00:12:13 UTC (rev 123407)
@@ -119,10 +119,15 @@
 FocusScope FocusScope::focusScopeOf(Node* node)
 {
     ASSERT(node);
-    TreeScope* scope = node->treeScope();
-    if (scope->rootNode()->isShadowRoot())
-        return FocusScope(toShadowRoot(scope->rootNode())->owner()->youngestShadowRoot());
-    return FocusScope(scope);
+    ComposedShadowTreeWalker walker(node, ComposedShadowTreeWalker::DoNotCrossUpperBoundary);
+    Node* root = node;
+    while (walker.get()) {
+        root = walker.get();
+        walker.parent();
+    }
+    // The result is not always a ShadowRoot nor a DocumentNode since
+    // a starting node is in an orphaned tree in composed shadow tree.
+    return FocusScope(root->treeScope());
 }
 
 FocusScope FocusScope::focusScopeOwnedByShadowHost(Node* node)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to