- Revision
- 121027
- Author
- [email protected]
- Date
- 2012-06-22 09:00:48 -0700 (Fri, 22 Jun 2012)
Log Message
[Shadow] parentTreeScope() of nested shadow DOM subtree returns document().
https://bugs.webkit.org/show_bug.cgi?id=89172
Patch by Takashi Sakamoto <[email protected]> on 2012-06-22
Reviewed by Hajime Morita.
Source/WebCore:
Added setParentTreeScope to set parent treescope of shadow root to be
host's treescope in ElementShadow::addShadowRoot.
Test: fast/dom/shadow/parent-tree-scope-in-shadow.html
* dom/ElementShadow.cpp:
(WebCore::ElementShadow::addShadowRoot):
Added setParentTreeScope.
* testing/Internals.cpp:
(WebCore::Internals::parentTreeScope):
Newly added. This method returns a parent tree scope's root node of
a given node, because a tree scope's root node is either document node
or shadow root node and both nodes derive from TreeScope. So root nodes
are treated as TreeScope.
* testing/Internals.h:
(Internals):
* testing/Internals.idl:
Added parentTreeScope.
LayoutTests:
* fast/dom/shadow/parent-tree-scope-in-shadow-expected.txt: Added.
* fast/dom/shadow/parent-tree-scope-in-shadow.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (121026 => 121027)
--- trunk/LayoutTests/ChangeLog 2012-06-22 15:20:50 UTC (rev 121026)
+++ trunk/LayoutTests/ChangeLog 2012-06-22 16:00:48 UTC (rev 121027)
@@ -1,3 +1,13 @@
+2012-06-22 Takashi Sakamoto <[email protected]>
+
+ [Shadow] parentTreeScope() of nested shadow DOM subtree returns document().
+ https://bugs.webkit.org/show_bug.cgi?id=89172
+
+ Reviewed by Hajime Morita.
+
+ * fast/dom/shadow/parent-tree-scope-in-shadow-expected.txt: Added.
+ * fast/dom/shadow/parent-tree-scope-in-shadow.html: Added.
+
2012-06-22 Tony Chang <[email protected]>
-webkit-flex-flow shouldn't be an enumerable property of the computed style
Added: trunk/LayoutTests/fast/dom/shadow/parent-tree-scope-in-shadow-expected.txt (0 => 121027)
--- trunk/LayoutTests/fast/dom/shadow/parent-tree-scope-in-shadow-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/parent-tree-scope-in-shadow-expected.txt 2012-06-22 16:00:48 UTC (rev 121027)
@@ -0,0 +1,15 @@
+Creating shadow dom subtrees from top to bottom.
+PASS internals.parentTreeScope(shadow1) is document
+PASS internals.parentTreeScope(shadow2) is shadow1
+PASS internals.parentTreeScope(shadow3) is shadow2
+Creating multiple shadow dom subtrees.
+PASS internals.parentTreeScope(shadow2) is shadow1
+PASS internals.parentTreeScope(shadow3) is shadow1
+Creating multiple shadow dom subtrees from bottom to top.
+PASS internals.parentTreeScope(shadow1) is document
+PASS internals.parentTreeScope(shadow2) is shadow1
+PASS internals.parentTreeScope(shadow3) is shadow2
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/shadow/parent-tree-scope-in-shadow.html (0 => 121027)
--- trunk/LayoutTests/fast/dom/shadow/parent-tree-scope-in-shadow.html (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/parent-tree-scope-in-shadow.html 2012-06-22 16:00:48 UTC (rev 121027)
@@ -0,0 +1,66 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<div id="test"></div>
+
+<script>
+ var div = document.createElement("div");
+ document.body.appendChild(div);
+
+ debug("Creating shadow dom subtrees from top to bottom.");
+ var shadow1 = new WebKitShadowRoot(div);
+ shadow1.innerHTML = "<div id='E'>/div>";
+ var e = shadow1.getElementById("E");
+ var shadow2 = new WebKitShadowRoot(e);
+ shadow2.innerHTML = "<div id='F'></div>";
+ var f = shadow2.getElementById("F");
+ var shadow3 = new WebKitShadowRoot(f);
+ shadow3.innerHTML = "<div id='G'></div>";
+
+ shouldBe("internals.parentTreeScope(shadow1)", "document");
+ shouldBe("internals.parentTreeScope(shadow2)", "shadow1");
+ shouldBe("internals.parentTreeScope(shadow3)", "shadow2");
+
+ document.body.removeChild(div);
+
+ debug("Creating multiple shadow dom subtrees.");
+ div = document.createElement("div");
+ document.body.appendChild(div);
+ shadow1 = new WebKitShadowRoot(div);
+ shadow1.innerHTML = "<div id='H'></div>";
+
+ var h = shadow1.getElementById("H");
+ shadow2 = new WebKitShadowRoot(h);
+ shadow2.innerHTML = "<div>shadow2</div>";
+ shadow3 = new WebKitShadowRoot(h);
+ shadow3.innerHTML = "<div>shadow3</div>";
+ shouldBe("internals.parentTreeScope(shadow2)", "shadow1");
+ shouldBe("internals.parentTreeScope(shadow3)", "shadow1");
+
+ document.body.removeChild(div);
+
+ debug("Creating multiple shadow dom subtrees from bottom to top.");
+ f = document.createElement("div");
+ shadow3 = new WebKitShadowRoot(f);
+ shadow3.innerHTML = "<div id='G'></div>";
+ e = document.createElement("div");
+ shadow2 = new WebKitShadowRoot(e);
+ shadow2.appendChild(f);
+ div = document.createElement("div");
+ shadow1 = new WebKitShadowRoot(div);
+ shadow1.appendChild(e);
+ document.body.appendChild(div);
+
+ shouldBe("internals.parentTreeScope(shadow1)", "document");
+ shouldBe("internals.parentTreeScope(shadow2)", "shadow1");
+ shouldBe("internals.parentTreeScope(shadow3)", "shadow2");
+
+ document.body.removeChild(div);
+</script>
+ <script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (121026 => 121027)
--- trunk/Source/WebCore/ChangeLog 2012-06-22 15:20:50 UTC (rev 121026)
+++ trunk/Source/WebCore/ChangeLog 2012-06-22 16:00:48 UTC (rev 121027)
@@ -1,3 +1,29 @@
+2012-06-22 Takashi Sakamoto <[email protected]>
+
+ [Shadow] parentTreeScope() of nested shadow DOM subtree returns document().
+ https://bugs.webkit.org/show_bug.cgi?id=89172
+
+ Reviewed by Hajime Morita.
+
+ Added setParentTreeScope to set parent treescope of shadow root to be
+ host's treescope in ElementShadow::addShadowRoot.
+
+ Test: fast/dom/shadow/parent-tree-scope-in-shadow.html
+
+ * dom/ElementShadow.cpp:
+ (WebCore::ElementShadow::addShadowRoot):
+ Added setParentTreeScope.
+ * testing/Internals.cpp:
+ (WebCore::Internals::parentTreeScope):
+ Newly added. This method returns a parent tree scope's root node of
+ a given node, because a tree scope's root node is either document node
+ or shadow root node and both nodes derive from TreeScope. So root nodes
+ are treated as TreeScope.
+ * testing/Internals.h:
+ (Internals):
+ * testing/Internals.idl:
+ Added parentTreeScope.
+
2012-06-22 Tony Chang <[email protected]>
-webkit-flex-flow shouldn't be an enumerable property of the computed style
Modified: trunk/Source/WebCore/dom/ElementShadow.cpp (121026 => 121027)
--- trunk/Source/WebCore/dom/ElementShadow.cpp 2012-06-22 15:20:50 UTC (rev 121026)
+++ trunk/Source/WebCore/dom/ElementShadow.cpp 2012-06-22 16:00:48 UTC (rev 121027)
@@ -74,6 +74,7 @@
return;
shadowRoot->setHost(shadowHost);
+ shadowRoot->setParentTreeScope(shadowHost->treeScope());
m_shadowRoots.push(shadowRoot.get());
invalidateDistribution(shadowHost);
ChildNodeInsertionNotifier(shadowHost).notify(shadowRoot.get());
Modified: trunk/Source/WebCore/testing/Internals.cpp (121026 => 121027)
--- trunk/Source/WebCore/testing/Internals.cpp 2012-06-22 15:20:50 UTC (rev 121026)
+++ trunk/Source/WebCore/testing/Internals.cpp 2012-06-22 16:00:48 UTC (rev 121027)
@@ -206,6 +206,16 @@
return node->treeScope()->rootNode();
}
+Node* Internals::parentTreeScope(Node* node, ExceptionCode& ec)
+{
+ if (!node) {
+ ec = INVALID_ACCESS_ERR;
+ return 0;
+ }
+ const TreeScope* parentTreeScope = node->treeScope()->parentTreeScope();
+ return parentTreeScope ? parentTreeScope->rootNode() : 0;
+}
+
bool Internals::attached(Node* node, ExceptionCode& ec)
{
if (!node) {
Modified: trunk/Source/WebCore/testing/Internals.h (121026 => 121027)
--- trunk/Source/WebCore/testing/Internals.h 2012-06-22 15:20:50 UTC (rev 121026)
+++ trunk/Source/WebCore/testing/Internals.h 2012-06-22 16:00:48 UTC (rev 121027)
@@ -84,6 +84,7 @@
Element* getElementByIdInShadowRoot(Node* shadowRoot, const String& id, ExceptionCode&);
bool isValidContentSelect(Element* insertionPoint, ExceptionCode&);
Node* treeScopeRootNode(Node*, ExceptionCode&);
+ Node* parentTreeScope(Node*, ExceptionCode&);
bool attached(Node*, ExceptionCode&);
Modified: trunk/Source/WebCore/testing/Internals.idl (121026 => 121027)
--- trunk/Source/WebCore/testing/Internals.idl 2012-06-22 15:20:50 UTC (rev 121026)
+++ trunk/Source/WebCore/testing/Internals.idl 2012-06-22 16:00:48 UTC (rev 121027)
@@ -55,6 +55,7 @@
Element getElementByIdInShadowRoot(in Node shadowRoot, in DOMString id) raises(DOMException);
boolean isValidContentSelect(in Element contentElement) raises(DOMException);
Node treeScopeRootNode(in Node node) raises (DOMException);
+ Node parentTreeScope(in Node node) raises (DOMException);
Node nextSiblingByWalker(in Node node) raises(DOMException);
Node firstChildByWalker(in Node node) raises(DOMException);