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

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

Issue 342283005: Make collection caching code more consistent (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Stop including NodeListsNodeData.h in ContainerNode.h Created 6 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 unified diff | Download patch | Annotate | Revision Log
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, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All rights reserved.
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 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 else if (renderStyle()->affectedByHover()) 1079 else if (renderStyle()->affectedByHover())
1080 setNeedsStyleRecalc(LocalStyleChange); 1080 setNeedsStyleRecalc(LocalStyleChange);
1081 } 1081 }
1082 1082
1083 if (renderer()->style()->hasAppearance()) 1083 if (renderer()->style()->hasAppearance())
1084 RenderTheme::theme().stateChanged(renderer(), HoverControlState); 1084 RenderTheme::theme().stateChanged(renderer(), HoverControlState);
1085 } 1085 }
1086 1086
1087 PassRefPtrWillBeRawPtr<HTMLCollection> ContainerNode::children() 1087 PassRefPtrWillBeRawPtr<HTMLCollection> ContainerNode::children()
1088 { 1088 {
1089 return ensureRareData().ensureNodeLists().addCache<HTMLCollection>(*this, No deChildren); 1089 return ensureCachedCollection<HTMLCollection>(NodeChildren);
1090 } 1090 }
1091 1091
1092 unsigned ContainerNode::countChildren() const 1092 unsigned ContainerNode::countChildren() const
1093 { 1093 {
1094 unsigned count = 0; 1094 unsigned count = 0;
1095 Node *n; 1095 Node *n;
1096 for (n = firstChild(); n; n = n->nextSibling()) 1096 for (n = firstChild(); n; n = n->nextSibling())
1097 count++; 1097 count++;
1098 return count; 1098 return count;
1099 } 1099 }
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange); 1314 elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange);
1315 } 1315 }
1316 } 1316 }
1317 1317
1318 PassRefPtrWillBeRawPtr<TagCollection> ContainerNode::getElementsByTagName(const AtomicString& localName) 1318 PassRefPtrWillBeRawPtr<TagCollection> ContainerNode::getElementsByTagName(const AtomicString& localName)
1319 { 1319 {
1320 if (localName.isNull()) 1320 if (localName.isNull())
1321 return nullptr; 1321 return nullptr;
1322 1322
1323 if (document().isHTMLDocument()) 1323 if (document().isHTMLDocument())
1324 return ensureRareData().ensureNodeLists().addCache<HTMLTagCollection>(*t his, HTMLTagCollectionType, localName); 1324 return ensureCachedCollection<HTMLTagCollection>(HTMLTagCollectionType, localName);
1325 return ensureRareData().ensureNodeLists().addCache<TagCollection>(*this, Tag CollectionType, localName); 1325 return ensureCachedCollection<TagCollection>(TagCollectionType, localName);
1326 } 1326 }
1327 1327
1328 PassRefPtrWillBeRawPtr<TagCollection> ContainerNode::getElementsByTagNameNS(cons t AtomicString& namespaceURI, const AtomicString& localName) 1328 PassRefPtrWillBeRawPtr<TagCollection> ContainerNode::getElementsByTagNameNS(cons t AtomicString& namespaceURI, const AtomicString& localName)
1329 { 1329 {
1330 if (localName.isNull()) 1330 if (localName.isNull())
1331 return nullptr; 1331 return nullptr;
1332 1332
1333 if (namespaceURI == starAtom) 1333 if (namespaceURI == starAtom)
1334 return getElementsByTagName(localName); 1334 return getElementsByTagName(localName);
1335 1335
1336 return ensureRareData().ensureNodeLists().addCache(*this, namespaceURI.isEmp ty() ? nullAtom : namespaceURI, localName); 1336 return ensureCachedCollection<TagCollection>(TagCollectionType, namespaceURI .isEmpty() ? nullAtom : namespaceURI, localName);
1337 } 1337 }
1338 1338
1339 // Takes an AtomicString in argument because it is common for elements to share the same name attribute. 1339 // Takes an AtomicString in argument because it is common for elements to share the same name attribute.
1340 // Therefore, the NameNodeList factory function expects an AtomicString type. 1340 // Therefore, the NameNodeList factory function expects an AtomicString type.
1341 PassRefPtrWillBeRawPtr<NameNodeList> ContainerNode::getElementsByName(const Atom icString& elementName) 1341 PassRefPtrWillBeRawPtr<NameNodeList> ContainerNode::getElementsByName(const Atom icString& elementName)
1342 { 1342 {
1343 return ensureRareData().ensureNodeLists().addCache<NameNodeList>(*this, Name NodeListType, elementName); 1343 return ensureCachedCollection<NameNodeList>(NameNodeListType, elementName);
1344 } 1344 }
1345 1345
1346 // Takes an AtomicString in argument because it is common for elements to share the same set of class names. 1346 // Takes an AtomicString in argument because it is common for elements to share the same set of class names.
1347 // Therefore, the ClassNodeList factory function expects an AtomicString type. 1347 // Therefore, the ClassNodeList factory function expects an AtomicString type.
1348 PassRefPtrWillBeRawPtr<ClassCollection> ContainerNode::getElementsByClassName(co nst AtomicString& classNames) 1348 PassRefPtrWillBeRawPtr<ClassCollection> ContainerNode::getElementsByClassName(co nst AtomicString& classNames)
1349 { 1349 {
1350 return ensureRareData().ensureNodeLists().addCache<ClassCollection>(*this, C lassCollectionType, classNames); 1350 return ensureCachedCollection<ClassCollection>(ClassCollectionType, classNam es);
1351 } 1351 }
1352 1352
1353 PassRefPtrWillBeRawPtr<RadioNodeList> ContainerNode::radioNodeList(const AtomicS tring& name, bool onlyMatchImgElements) 1353 PassRefPtrWillBeRawPtr<RadioNodeList> ContainerNode::radioNodeList(const AtomicS tring& name, bool onlyMatchImgElements)
1354 { 1354 {
1355 ASSERT(isHTMLFormElement(this) || isHTMLFieldSetElement(this)); 1355 ASSERT(isHTMLFormElement(this) || isHTMLFieldSetElement(this));
1356 CollectionType type = onlyMatchImgElements ? RadioImgNodeListType : RadioNod eListType; 1356 CollectionType type = onlyMatchImgElements ? RadioImgNodeListType : RadioNod eListType;
1357 return ensureRareData().ensureNodeLists().addCache<RadioNodeList>(*this, typ e, name); 1357 return ensureCachedCollection<RadioNodeList>(type, name);
1358 } 1358 }
1359 1359
1360 Element* ContainerNode::getElementById(const AtomicString& id) const 1360 Element* ContainerNode::getElementById(const AtomicString& id) const
1361 { 1361 {
1362 if (isInTreeScope()) { 1362 if (isInTreeScope()) {
1363 // Fast path if we are in a tree scope: call getElementById() on tree sc ope 1363 // Fast path if we are in a tree scope: call getElementById() on tree sc ope
1364 // and check if the matching element is in our subtree. 1364 // and check if the matching element is in our subtree.
1365 Element* element = treeScope().getElementById(id); 1365 Element* element = treeScope().getElementById(id);
1366 if (!element) 1366 if (!element)
1367 return 0; 1367 return 0;
1368 if (element->isDescendantOf(this)) 1368 if (element->isDescendantOf(this))
1369 return element; 1369 return element;
1370 } 1370 }
1371 1371
1372 // Fall back to traversing our subtree. In case of duplicate ids, the first element found will be returned. 1372 // Fall back to traversing our subtree. In case of duplicate ids, the first element found will be returned.
1373 for (Element* element = ElementTraversal::firstWithin(*this); element; eleme nt = ElementTraversal::next(*element, this)) { 1373 for (Element* element = ElementTraversal::firstWithin(*this); element; eleme nt = ElementTraversal::next(*element, this)) {
1374 if (element->getIdAttribute() == id) 1374 if (element->getIdAttribute() == id)
1375 return element; 1375 return element;
1376 } 1376 }
1377 return 0; 1377 return 0;
1378 } 1378 }
1379 1379
1380 NodeListsNodeData& ContainerNode::ensureNodeLists()
1381 {
1382 return ensureRareData().ensureNodeLists();
1383 }
1384
1380 #if ENABLE(ASSERT) 1385 #if ENABLE(ASSERT)
1381 bool childAttachedAllowedWhenAttachingChildren(ContainerNode* node) 1386 bool childAttachedAllowedWhenAttachingChildren(ContainerNode* node)
1382 { 1387 {
1383 if (node->isShadowRoot()) 1388 if (node->isShadowRoot())
1384 return true; 1389 return true;
1385 1390
1386 if (node->isInsertionPoint()) 1391 if (node->isInsertionPoint())
1387 return true; 1392 return true;
1388 1393
1389 if (node->isElementNode() && toElement(node)->shadow()) 1394 if (node->isElementNode() && toElement(node)->shadow())
1390 return true; 1395 return true;
1391 1396
1392 return false; 1397 return false;
1393 } 1398 }
1394 #endif 1399 #endif
1395 1400
1396 } // namespace blink 1401 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698