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

Side by Side Diff: Source/core/dom/ContainerNode.cpp

Issue 251633002: Add support for DocumentFragment.getElementById() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add comment 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/ContainerNode.h ('k') | Source/core/dom/Document.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 return ensureRareData().ensureNodeLists().addCache<ClassCollection>(*this, C lassCollectionType, classNames); 1155 return ensureRareData().ensureNodeLists().addCache<ClassCollection>(*this, C lassCollectionType, classNames);
1156 } 1156 }
1157 1157
1158 PassRefPtr<RadioNodeList> ContainerNode::radioNodeList(const AtomicString& name, bool onlyMatchImgElements) 1158 PassRefPtr<RadioNodeList> ContainerNode::radioNodeList(const AtomicString& name, bool onlyMatchImgElements)
1159 { 1159 {
1160 ASSERT(isHTMLFormElement(this) || isHTMLFieldSetElement(this)); 1160 ASSERT(isHTMLFormElement(this) || isHTMLFieldSetElement(this));
1161 CollectionType type = onlyMatchImgElements ? RadioImgNodeListType : RadioNod eListType; 1161 CollectionType type = onlyMatchImgElements ? RadioImgNodeListType : RadioNod eListType;
1162 return ensureRareData().ensureNodeLists().addCache<RadioNodeList>(*this, typ e, name); 1162 return ensureRareData().ensureNodeLists().addCache<RadioNodeList>(*this, typ e, name);
1163 } 1163 }
1164 1164
1165 Element* ContainerNode::getElementById(const AtomicString& id) const
1166 {
1167 if (inDocument()) {
arv (Not doing code reviews) 2014/04/25 13:36:19 I don't think this is required. It should be suffi
Inactive 2014/04/25 14:41:20 Yes, this is not strictly required. I thought it w
Inactive 2014/04/25 15:13:40 I think I should be using isInTreeScope() instead
1168 // Fast path if we are in a document: call getElementById() on document
1169 // and check if the matching element is in our subtree.
1170 Element* element = treeScope().getElementById(id);
1171 if (!element)
Inactive 2014/04/25 14:41:20 i.e. Early return here is now possible as we know
arv (Not doing code reviews) 2014/04/25 15:04:04 I was thinking of the case where we are in a disco
1172 return 0;
1173 if (element->isDescendantOf(this))
1174 return element;
1175 }
1176
1177 // Fall back to traversing our subtree. In case of duplicate ids, the first element found will be returned.
1178 for (Element* element = ElementTraversal::firstWithin(*this); element; eleme nt = ElementTraversal::next(*element, this)) {
1179 if (element->getIdAttribute() == id)
1180 return element;
1181 }
1182 return 0;
1183 }
1184
1165 #ifndef NDEBUG 1185 #ifndef NDEBUG
1166 bool childAttachedAllowedWhenAttachingChildren(ContainerNode* node) 1186 bool childAttachedAllowedWhenAttachingChildren(ContainerNode* node)
1167 { 1187 {
1168 if (node->isShadowRoot()) 1188 if (node->isShadowRoot())
1169 return true; 1189 return true;
1170 1190
1171 if (node->isInsertionPoint()) 1191 if (node->isInsertionPoint())
1172 return true; 1192 return true;
1173 1193
1174 if (node->isElementNode() && toElement(node)->shadow()) 1194 if (node->isElementNode() && toElement(node)->shadow())
1175 return true; 1195 return true;
1176 1196
1177 return false; 1197 return false;
1178 } 1198 }
1179 #endif 1199 #endif
1180 1200
1181 } // namespace WebCore 1201 } // namespace WebCore
OLDNEW
« 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