Index: Source/core/dom/ContainerNode.cpp |
diff --git a/Source/core/dom/ContainerNode.cpp b/Source/core/dom/ContainerNode.cpp |
index f355f618b05a5d2abd7d3807fca55973c52daf0d..f4be545c83d489d59034f896d7663954a12dc620 100644 |
--- a/Source/core/dom/ContainerNode.cpp |
+++ b/Source/core/dom/ContainerNode.cpp |
@@ -1162,6 +1162,26 @@ PassRefPtr<RadioNodeList> ContainerNode::radioNodeList(const AtomicString& name, |
return ensureRareData().ensureNodeLists().addCache<RadioNodeList>(*this, type, name); |
} |
+Element* ContainerNode::getElementById(const AtomicString& id) const |
+{ |
+ if (isInTreeScope()) { |
+ // Fast path if we are in a tree scope: call getElementById() on tree scope |
+ // and check if the matching element is in our subtree. |
+ Element* element = treeScope().getElementById(id); |
+ if (!element) |
+ return 0; |
+ if (element->isDescendantOf(this)) |
arv (Not doing code reviews)
2014/04/25 15:28:59
Can this ever be false?
Inactive
2014/04/25 15:31:30
Yes, just because there is an element in the Docum
arv (Not doing code reviews)
2014/04/25 15:37:42
I see. The SVGSVGElement makes this != tree scope.
|
+ return element; |
+ } |
+ |
+ // Fall back to traversing our subtree. In case of duplicate ids, the first element found will be returned. |
+ for (Element* element = ElementTraversal::firstWithin(*this); element; element = ElementTraversal::next(*element, this)) { |
+ if (element->getIdAttribute() == id) |
+ return element; |
+ } |
+ return 0; |
+} |
+ |
#ifndef NDEBUG |
bool childAttachedAllowedWhenAttachingChildren(ContainerNode* node) |
{ |