Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(760)

Unified Diff: Source/core/dom/Node.cpp

Issue 21123005: Node.contains should return true for nodes in Shadow DOM. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make contains-something condition clearer. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/core/dom/Node.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Node.cpp
diff --git a/Source/core/dom/Node.cpp b/Source/core/dom/Node.cpp
index 896dccdae1f847adbcffd2618210de034eeee7fb..fff0087d3c837c40a840209858a827b61ef651e8 100644
--- a/Source/core/dom/Node.cpp
+++ b/Source/core/dom/Node.cpp
@@ -982,10 +982,28 @@ bool Node::contains(const Node* node) const
bool Node::containsIncludingShadowDOM(const Node* node) const
{
- for (; node; node = node->parentOrShadowHostNode()) {
- if (node == this)
- return true;
+ if (!node)
+ return false;
+
+ if (this == node)
+ return true;
+
+ if (document() != node->document())
+ return false;
+
+ if (inDocument() != node->inDocument())
+ return false;
+
+ bool hasChildren = isContainerNode() && toContainerNode(this)->hasChildNodes();
+ bool hasShadow = isElementNode() && toElement(this)->shadow();
+ if (!hasChildren && !hasShadow)
+ return false;
+
+ for (; node; node = node->shadowHost()) {
+ if (treeScope() == node->treeScope())
+ return contains(node);
}
+
return false;
}
« no previous file with comments | « Source/core/dom/Node.h ('k') | Source/core/dom/Node.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698