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

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

Issue 251633002: Add support for DocumentFragment.getElementById() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix createElement() calls Created 6 years, 8 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/ContainerNode.h ('k') | Source/core/dom/Document.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/ContainerNode.cpp
diff --git a/Source/core/dom/ContainerNode.cpp b/Source/core/dom/ContainerNode.cpp
index 5448f4b2d046c0ee1e834fc7469b3fd78305cebb..ab5e75245a2c86ae7ddab1f895429df81a84ec1f 100644
--- a/Source/core/dom/ContainerNode.cpp
+++ b/Source/core/dom/ContainerNode.cpp
@@ -1167,6 +1167,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))
+ 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)
{
« no previous file with comments | « Source/core/dom/ContainerNode.h ('k') | Source/core/dom/Document.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698