CompositeShadowTreeWalker should use InsertionPoint::hasDistribution() instead of...
authorhayato@chromium.org <hayato@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Jun 2012 23:05:59 +0000 (23:05 +0000)
committerhayato@chromium.org <hayato@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Jun 2012 23:05:59 +0000 (23:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=89177

Reviewed by Dimitri Glazkov.

Source/WebCore:

Prevents ComposedShadowTreeWalker from escaping out of an
insertion point (which has distributed nodes) from a non-used
fallback element in the insertion point.  Such a fallback element
should be treated as in an orphaned subtree.

ComposedShadowTreeParentWalker will be also fixed in a follow-up patch.

Test: fast/dom/shadow/composed-shadow-tree-walker.html

* dom/ComposedShadowTreeWalker.cpp:
(WebCore::ComposedShadowTreeWalker::traverseNodeEscapingFallbackContents):

LayoutTests:

* fast/dom/shadow/composed-shadow-tree-walker-expected.txt:
* fast/dom/shadow/composed-shadow-tree-walker.html:

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

LayoutTests/ChangeLog
LayoutTests/fast/dom/shadow/composed-shadow-tree-walker-expected.txt
LayoutTests/fast/dom/shadow/composed-shadow-tree-walker.html
Source/WebCore/ChangeLog
Source/WebCore/dom/ComposedShadowTreeWalker.cpp

index 2184252..edaccc8 100644 (file)
@@ -1,3 +1,13 @@
+2012-06-28  Hayato Ito  <hayato@chromium.org>
+
+        CompositeShadowTreeWalker should use InsertionPoint::hasDistribution() instead of InsertionPoint::isActive().
+        https://bugs.webkit.org/show_bug.cgi?id=89177
+
+        Reviewed by Dimitri Glazkov.
+
+        * fast/dom/shadow/composed-shadow-tree-walker-expected.txt:
+        * fast/dom/shadow/composed-shadow-tree-walker.html:
+
 2012-06-28  Gregg Tavares  <gman@google.com>
 
         Add support for DEPTH_STENCIL to WEBGL_depth_texture
index b5fe9e5..5fe303a 100644 (file)
@@ -87,7 +87,7 @@ DIV    id=f1
 DIV     id=b
 DIV     id=a
 
-Fallback elements should not be used if  element selects any elements.
+Fallback elements should not be used if a content element selects an element.
 Composed Shadow Tree:
 DIV     id=a
        DIV      id=b
@@ -102,6 +102,21 @@ DIV         id=c
 DIV     id=b
 DIV     id=a
 
+Test for traversal, starting with a fallback element which is not used.
+Composed Shadow Tree:
+DIV     id=f1
+       DIV      id=f2
+
+Traverse in forward.
+DIV     id=f1
+DIV     id=f2
+Traverse in backward.
+DIV     id=f2
+DIV     id=f1
+
+Next node of [DIV       id=f1] is [DIV  id=f2]
+Next node of [DIV       id=f2] is [(null)]
+
 Test for Nested ShadowRoots.
 Composed Shadow Tree:
 DIV     id=a
index 3e035eb..44a32fd 100644 (file)
@@ -15,6 +15,8 @@ if (window.testRunner)
 
 function dumpNode(node)
 {
+    if (!node)
+        return '(null)'
     var output = node.nodeName + "\t";
     if (node.id)
         output += ' id=' + node.id;
@@ -78,6 +80,11 @@ function showComposedShadowTree(node)
     debug('');
 }
 
+function showNextNode(node) {
+    var next = internals.nextNodeByWalker(node);
+    debug('Next node of [' + dumpNode(node) + '] is [' + dumpNode(next) + ']');
+}
+
 function testComposedShadowTree(node)
 {
     var sandbox = document.getElementById('sandbox');
@@ -129,15 +136,21 @@ testComposedShadowTree(
                                          createDOM('div', {'id': 'f2'}))),
               createDOM('div', {'id': 'c'})));
 
-debug('Fallback elements should not be used if <content> element selects any elements.');
+debug('Fallback elements should not be used if a content element selects an element.');
 testComposedShadowTree(
     createDOM('div', {'id': 'a'},
               createShadowRoot(createDOM('div', {'id': 'b'}),
                                createDOM('content', {'select': '#c'},
-                                         createDOM('div', {'id': 'f1'}),
-                                         createDOM('div', {'id': 'f2'}))),
+                                         createDOM('div', {'id': 'f1'},
+                                                   createDOM('div', {'id': 'f2'})))),
               createDOM('div', {'id': 'c'})));
 
+debug('Test for traversal, starting with a fallback element which is not used.');
+showComposedShadowTree(getNodeInShadowTreeStack('a/f1'));
+showNextNode(getNodeInShadowTreeStack('a/f1'));
+showNextNode(getNodeInShadowTreeStack('a/f2'));
+debug('');
+
 debug('Test for Nested ShadowRoots.');
 testComposedShadowTree(
     createDOM('div', {'id': 'a'},
index 2fac9f3..96bab0a 100644 (file)
@@ -1,3 +1,22 @@
+2012-06-28  Hayato Ito  <hayato@chromium.org>
+
+        CompositeShadowTreeWalker should use InsertionPoint::hasDistribution() instead of InsertionPoint::isActive().
+        https://bugs.webkit.org/show_bug.cgi?id=89177
+
+        Reviewed by Dimitri Glazkov.
+
+        Prevents ComposedShadowTreeWalker from escaping out of an
+        insertion point (which has distributed nodes) from a non-used
+        fallback element in the insertion point.  Such a fallback element
+        should be treated as in an orphaned subtree.
+
+        ComposedShadowTreeParentWalker will be also fixed in a follow-up patch.
+
+        Test: fast/dom/shadow/composed-shadow-tree-walker.html
+
+        * dom/ComposedShadowTreeWalker.cpp:
+        (WebCore::ComposedShadowTreeWalker::traverseNodeEscapingFallbackContents):
+
 2012-06-27  Ryosuke Niwa  <rniwa@webkit.org>
 
         Cleanup HTMLFormCollection
index a48345a..7faaf8a 100644 (file)
@@ -188,9 +188,11 @@ Node* ComposedShadowTreeWalker::escapeFallbackContentElement(const Node* node, T
 Node* ComposedShadowTreeWalker::traverseNodeEscapingFallbackContents(const Node* node) const
 {
     ASSERT(node);
-    if (isActiveInsertionPoint(node))
-        return traverseParent(node);
-    return const_cast<Node*>(node);
+    if (!isInsertionPoint(node))
+        return const_cast<Node*>(node);
+    const InsertionPoint* insertionPoint = toInsertionPoint(node);
+    return insertionPoint->hasDistribution() ? 0 :
+        insertionPoint->isActive() ? traverseParent(node) : const_cast<Node*>(node);
 }
 
 void ComposedShadowTreeWalker::parent()