| OLD | NEW |
| 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 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r
ights reserved. | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r
ights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 case SelectedOptions: | 58 case SelectedOptions: |
| 59 case DataListOptions: | 59 case DataListOptions: |
| 60 case WindowNamedItems: | 60 case WindowNamedItems: |
| 61 case FormControls: | 61 case FormControls: |
| 62 return false; | 62 return false; |
| 63 case NodeChildren: | 63 case NodeChildren: |
| 64 case TRCells: | 64 case TRCells: |
| 65 case TSectionRows: | 65 case TSectionRows: |
| 66 case TableTBodies: | 66 case TableTBodies: |
| 67 return true; | 67 return true; |
| 68 case ChildNodeListType: | |
| 69 case NameNodeListType: | 68 case NameNodeListType: |
| 70 case RadioNodeListType: | 69 case RadioNodeListType: |
| 71 case RadioImgNodeListType: | 70 case RadioImgNodeListType: |
| 72 case LabelsNodeListType: | 71 case LabelsNodeListType: |
| 73 break; | 72 break; |
| 74 } | 73 } |
| 75 ASSERT_NOT_REACHED(); | 74 ASSERT_NOT_REACHED(); |
| 76 return false; | 75 return false; |
| 77 } | 76 } |
| 78 | 77 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 97 case NodeChildren: | 96 case NodeChildren: |
| 98 case TableTBodies: | 97 case TableTBodies: |
| 99 case TSectionRows: | 98 case TSectionRows: |
| 100 case TableRows: | 99 case TableRows: |
| 101 case TRCells: | 100 case TRCells: |
| 102 case SelectOptions: | 101 case SelectOptions: |
| 103 case SelectedOptions: | 102 case SelectedOptions: |
| 104 case DataListOptions: | 103 case DataListOptions: |
| 105 case MapAreas: | 104 case MapAreas: |
| 106 return NodeListIsRootedAtNode; | 105 return NodeListIsRootedAtNode; |
| 107 case ChildNodeListType: | |
| 108 case NameNodeListType: | 106 case NameNodeListType: |
| 109 case RadioNodeListType: | 107 case RadioNodeListType: |
| 110 case RadioImgNodeListType: | 108 case RadioImgNodeListType: |
| 111 case LabelsNodeListType: | 109 case LabelsNodeListType: |
| 112 break; | 110 break; |
| 113 } | 111 } |
| 114 ASSERT_NOT_REACHED(); | 112 ASSERT_NOT_REACHED(); |
| 115 return NodeListIsRootedAtNode; | 113 return NodeListIsRootedAtNode; |
| 116 } | 114 } |
| 117 | 115 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 143 case DocLinks: | 141 case DocLinks: |
| 144 return InvalidateOnHRefAttrChange; | 142 return InvalidateOnHRefAttrChange; |
| 145 case WindowNamedItems: | 143 case WindowNamedItems: |
| 146 return InvalidateOnIdNameAttrChange; | 144 return InvalidateOnIdNameAttrChange; |
| 147 case DocumentNamedItems: | 145 case DocumentNamedItems: |
| 148 return InvalidateOnIdNameAttrChange; | 146 return InvalidateOnIdNameAttrChange; |
| 149 case FormControls: | 147 case FormControls: |
| 150 return InvalidateForFormControls; | 148 return InvalidateForFormControls; |
| 151 case ClassCollectionType: | 149 case ClassCollectionType: |
| 152 return InvalidateOnClassAttrChange; | 150 return InvalidateOnClassAttrChange; |
| 153 case ChildNodeListType: | |
| 154 case NameNodeListType: | 151 case NameNodeListType: |
| 155 case RadioNodeListType: | 152 case RadioNodeListType: |
| 156 case RadioImgNodeListType: | 153 case RadioImgNodeListType: |
| 157 case LabelsNodeListType: | 154 case LabelsNodeListType: |
| 158 break; | 155 break; |
| 159 } | 156 } |
| 160 ASSERT_NOT_REACHED(); | 157 ASSERT_NOT_REACHED(); |
| 161 return DoNotInvalidateOnAttributeChanges; | 158 return DoNotInvalidateOnAttributeChanges; |
| 162 } | 159 } |
| 163 | 160 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 return element.hasLocalName(aTag) && element.fastHasAttribute(nameAttr); | 249 return element.hasLocalName(aTag) && element.fastHasAttribute(nameAttr); |
| 253 case ClassCollectionType: | 250 case ClassCollectionType: |
| 254 case TagCollectionType: | 251 case TagCollectionType: |
| 255 case HTMLTagCollectionType: | 252 case HTMLTagCollectionType: |
| 256 case DocAll: | 253 case DocAll: |
| 257 case NodeChildren: | 254 case NodeChildren: |
| 258 case FormControls: | 255 case FormControls: |
| 259 case DocumentNamedItems: | 256 case DocumentNamedItems: |
| 260 case TableRows: | 257 case TableRows: |
| 261 case WindowNamedItems: | 258 case WindowNamedItems: |
| 262 case ChildNodeListType: | |
| 263 case NameNodeListType: | 259 case NameNodeListType: |
| 264 case RadioNodeListType: | 260 case RadioNodeListType: |
| 265 case RadioImgNodeListType: | 261 case RadioImgNodeListType: |
| 266 case LabelsNodeListType: | 262 case LabelsNodeListType: |
| 267 ASSERT_NOT_REACHED(); | 263 ASSERT_NOT_REACHED(); |
| 268 } | 264 } |
| 269 return false; | 265 return false; |
| 270 } | 266 } |
| 271 | 267 |
| 272 template <> inline bool isMatchingElement(const ClassCollection& collection, con
st Element& element) | 268 template <> inline bool isMatchingElement(const ClassCollection& collection, con
st Element& element) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 bool onlyIncludeDirectChildren = collection.shouldOnlyIncludeDirectChildren(
); | 304 bool onlyIncludeDirectChildren = collection.shouldOnlyIncludeDirectChildren(
); |
| 309 Node& rootNode = collection.rootNode(); | 305 Node& rootNode = collection.rootNode(); |
| 310 for (; current; current = previousNode(rootNode, *current, onlyIncludeDirect
Children)) { | 306 for (; current; current = previousNode(rootNode, *current, onlyIncludeDirect
Children)) { |
| 311 if (current->isElementNode() && isMatchingElement(collection, toElement(
*current))) | 307 if (current->isElementNode() && isMatchingElement(collection, toElement(
*current))) |
| 312 return toElement(current); | 308 return toElement(current); |
| 313 } | 309 } |
| 314 return 0; | 310 return 0; |
| 315 } | 311 } |
| 316 | 312 |
| 317 template <typename Collection> | 313 template <typename Collection> |
| 318 Element* LiveNodeListBase::itemBefore(const Collection& collection, const Node*
previous) | 314 Element* LiveNodeListBase::itemBefore(const Collection& collection, const Elemen
t* previous) |
| 319 { | 315 { |
| 320 Node* current; | 316 Node* current; |
| 321 if (LIKELY(!!previous)) // Without this LIKELY, length() and item() can be 1
0% slower. | 317 if (LIKELY(!!previous)) // Without this LIKELY, length() and item() can be 1
0% slower. |
| 322 current = previousNode(collection.rootNode(), *previous, collection.shou
ldOnlyIncludeDirectChildren()); | 318 current = previousNode(collection.rootNode(), *previous, collection.shou
ldOnlyIncludeDirectChildren()); |
| 323 else | 319 else |
| 324 current = lastNode(collection.rootNode(), collection.shouldOnlyIncludeDi
rectChildren()); | 320 current = lastNode(collection.rootNode(), collection.shouldOnlyIncludeDi
rectChildren()); |
| 325 | 321 |
| 326 return iterateForPreviousNode(collection, current); | 322 return iterateForPreviousNode(collection, current); |
| 327 } | 323 } |
| 328 | 324 |
| 329 Node* LiveNodeList::itemBefore(const Node* previous) const | 325 Element* LiveNodeList::itemBefore(const Element* previous) const |
| 330 { | 326 { |
| 331 if (type() == ChildNodeListType) | |
| 332 return LIKELY(!!previous) ? previous->previousSibling() : rootNode().las
tChild(); | |
| 333 return LiveNodeListBase::itemBefore(*this, previous); | 327 return LiveNodeListBase::itemBefore(*this, previous); |
| 334 } | 328 } |
| 335 | 329 |
| 336 Element* HTMLCollection::itemBefore(const Node* previous) const | 330 Element* HTMLCollection::itemBefore(const Element* previous) const |
| 337 { | 331 { |
| 338 return LiveNodeListBase::itemBefore(*this, previous); | 332 return LiveNodeListBase::itemBefore(*this, previous); |
| 339 } | 333 } |
| 340 | 334 |
| 341 template <class NodeListType> | 335 template <class NodeListType> |
| 342 inline Element* firstMatchingElement(const NodeListType& nodeList, const Contain
erNode& root) | 336 inline Element* firstMatchingElement(const NodeListType& nodeList, const Contain
erNode& root) |
| 343 { | 337 { |
| 344 Element* element = ElementTraversal::firstWithin(root); | 338 Element* element = ElementTraversal::firstWithin(root); |
| 345 while (element && !isMatchingElement(nodeList, *element)) | 339 while (element && !isMatchingElement(nodeList, *element)) |
| 346 element = ElementTraversal::next(*element, &root); | 340 element = ElementTraversal::next(*element, &root); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 362 { | 356 { |
| 363 ASSERT(currentOffset < offset); | 357 ASSERT(currentOffset < offset); |
| 364 Element* next = ¤tElement; | 358 Element* next = ¤tElement; |
| 365 while ((next = nextMatchingElement(nodeList, *next, root))) { | 359 while ((next = nextMatchingElement(nodeList, *next, root))) { |
| 366 if (++currentOffset == offset) | 360 if (++currentOffset == offset) |
| 367 return next; | 361 return next; |
| 368 } | 362 } |
| 369 return 0; | 363 return 0; |
| 370 } | 364 } |
| 371 | 365 |
| 372 static inline Node* traverseSiblingsForwardToOffset(unsigned offset, Node& curre
ntNode, unsigned& currentOffset) | |
| 373 { | |
| 374 ASSERT(currentOffset < offset); | |
| 375 Node* next = ¤tNode; | |
| 376 while ((next = next->nextSibling())) { | |
| 377 if (++currentOffset == offset) | |
| 378 return next; | |
| 379 } | |
| 380 return 0; | |
| 381 } | |
| 382 | |
| 383 // FIXME: This should be in LiveNodeList.cpp but it needs to stay here until fir
stMatchingElement() | 366 // FIXME: This should be in LiveNodeList.cpp but it needs to stay here until fir
stMatchingElement() |
| 384 // and others are moved to a separate header. | 367 // and others are moved to a separate header. |
| 385 Node* LiveNodeList::traverseToFirstElement(const ContainerNode& root) const | 368 Element* LiveNodeList::traverseToFirstElement(const ContainerNode& root) const |
| 386 { | 369 { |
| 387 ASSERT(isLiveNodeListType(type())); | 370 return firstMatchingElement(*this, root); |
| 388 switch (type()) { | |
| 389 case ChildNodeListType: | |
| 390 return root.firstChild(); | |
| 391 default: | |
| 392 return firstMatchingElement(static_cast<const LiveNodeList&>(*this), roo
t); | |
| 393 } | |
| 394 } | 371 } |
| 395 | 372 |
| 396 // FIXME: This should be in LiveNodeList.cpp but it needs to stay here until tra
verseMatchingElementsForwardToOffset() | 373 // FIXME: This should be in LiveNodeList.cpp but it needs to stay here until tra
verseMatchingElementsForwardToOffset() |
| 397 // and others are moved to a separate header. | 374 // and others are moved to a separate header. |
| 398 Node* LiveNodeList::traverseForwardToOffset(unsigned offset, Node& currentNode,
unsigned& currentOffset, const ContainerNode& root) const | 375 Element* LiveNodeList::traverseForwardToOffset(unsigned offset, Element& current
Node, unsigned& currentOffset, const ContainerNode& root) const |
| 399 { | 376 { |
| 400 switch (type()) { | 377 return traverseMatchingElementsForwardToOffset(*this, offset, currentNode, c
urrentOffset, root); |
| 401 case ChildNodeListType: | |
| 402 return traverseSiblingsForwardToOffset(offset, currentNode, currentOffse
t); | |
| 403 default: | |
| 404 return traverseMatchingElementsForwardToOffset(*this, offset, toElement(
currentNode), currentOffset, root); | |
| 405 } | |
| 406 } | 378 } |
| 407 | 379 |
| 408 Element* HTMLCollection::virtualItemAfter(Element*) const | 380 Element* HTMLCollection::virtualItemAfter(Element*) const |
| 409 { | 381 { |
| 410 ASSERT_NOT_REACHED(); | 382 ASSERT_NOT_REACHED(); |
| 411 return 0; | 383 return 0; |
| 412 } | 384 } |
| 413 | 385 |
| 414 static inline bool nameShouldBeVisibleInDocumentAll(const HTMLElement& element) | 386 static inline bool nameShouldBeVisibleInDocumentAll(const HTMLElement& element) |
| 415 { | 387 { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 | 552 |
| 581 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element*
element) | 553 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element*
element) |
| 582 { | 554 { |
| 583 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->v
alue; | 555 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->v
alue; |
| 584 if (!vector) | 556 if (!vector) |
| 585 vector = adoptPtr(new Vector<Element*>); | 557 vector = adoptPtr(new Vector<Element*>); |
| 586 vector->append(element); | 558 vector->append(element); |
| 587 } | 559 } |
| 588 | 560 |
| 589 } // namespace WebCore | 561 } // namespace WebCore |
| OLD | NEW |