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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 case ChildNodeListType: | 262 case ChildNodeListType: |
263 case NameNodeListType: | 263 case NameNodeListType: |
264 case RadioNodeListType: | 264 case RadioNodeListType: |
265 case RadioImgNodeListType: | 265 case RadioImgNodeListType: |
266 case LabelsNodeListType: | 266 case LabelsNodeListType: |
267 ASSERT_NOT_REACHED(); | 267 ASSERT_NOT_REACHED(); |
268 } | 268 } |
269 return false; | 269 return false; |
270 } | 270 } |
271 | 271 |
| 272 template <> inline bool isMatchingElement(const ClassCollection& collection, con
st Element& element) |
| 273 { |
| 274 return collection.elementMatches(element); |
| 275 } |
| 276 |
| 277 template <> inline bool isMatchingElement(const HTMLTagCollection& collection, c
onst Element& element) |
| 278 { |
| 279 return collection.elementMatches(element); |
| 280 } |
| 281 |
272 template <> inline bool isMatchingElement(const LiveNodeList& nodeList, const El
ement& element) | 282 template <> inline bool isMatchingElement(const LiveNodeList& nodeList, const El
ement& element) |
273 { | 283 { |
274 return nodeList.nodeMatches(element); | 284 return nodeList.nodeMatches(element); |
275 } | 285 } |
276 | 286 |
277 static Node* previousNode(const Node& base, const Node& previous, bool onlyInclu
deDirectChildren) | 287 static Node* previousNode(const Node& base, const Node& previous, bool onlyInclu
deDirectChildren) |
278 { | 288 { |
279 return onlyIncludeDirectChildren ? previous.previousSibling() : NodeTraversa
l::previous(previous, &base); | 289 return onlyIncludeDirectChildren ? previous.previousSibling() : NodeTraversa
l::previous(previous, &base); |
280 } | 290 } |
281 | 291 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 { | 451 { |
442 Element* next = ¤t; | 452 Element* next = ¤t; |
443 do { | 453 do { |
444 next = ElementTraversal::nextSkippingChildren(*next, &root); | 454 next = ElementTraversal::nextSkippingChildren(*next, &root); |
445 } while (next && !isMatchingElement(nodeList, *next)); | 455 } while (next && !isMatchingElement(nodeList, *next)); |
446 return next; | 456 return next; |
447 } | 457 } |
448 | 458 |
449 Element* HTMLCollection::traverseToFirstElement(const ContainerNode& root) const | 459 Element* HTMLCollection::traverseToFirstElement(const ContainerNode& root) const |
450 { | 460 { |
451 if (overridesItemAfter()) | 461 switch (type()) { |
452 return virtualItemAfter(0); | 462 case HTMLTagCollectionType: |
453 if (shouldOnlyIncludeDirectChildren()) | 463 return firstMatchingElement(static_cast<const HTMLTagCollection&>(*this)
, root); |
454 return firstMatchingChildElement(*this, root); | 464 case ClassCollectionType: |
455 return firstMatchingElement(*this, root); | 465 return firstMatchingElement(static_cast<const ClassCollection&>(*this),
root); |
| 466 default: |
| 467 if (overridesItemAfter()) |
| 468 return virtualItemAfter(0); |
| 469 if (shouldOnlyIncludeDirectChildren()) |
| 470 return firstMatchingChildElement(*this, root); |
| 471 return firstMatchingElement(*this, root); |
| 472 } |
456 } | 473 } |
457 | 474 |
458 inline Element* HTMLCollection::traverseNextElement(Element& previous, const Con
tainerNode& root) const | 475 inline Element* HTMLCollection::traverseNextElement(Element& previous, const Con
tainerNode& root) const |
459 { | 476 { |
460 if (overridesItemAfter()) | 477 if (overridesItemAfter()) |
461 return virtualItemAfter(&previous); | 478 return virtualItemAfter(&previous); |
462 if (shouldOnlyIncludeDirectChildren()) | 479 if (shouldOnlyIncludeDirectChildren()) |
463 return nextMatchingChildElement(*this, previous, root); | 480 return nextMatchingChildElement(*this, previous, root); |
464 return nextMatchingElement(*this, previous, root); | 481 return nextMatchingElement(*this, previous, root); |
465 } | 482 } |
466 | 483 |
467 Element* HTMLCollection::traverseForwardToOffset(unsigned offset, Element& curre
ntElement, unsigned& currentOffset, const ContainerNode& root) const | 484 Element* HTMLCollection::traverseForwardToOffset(unsigned offset, Element& curre
ntElement, unsigned& currentOffset, const ContainerNode& root) const |
468 { | 485 { |
469 ASSERT(currentOffset < offset); | 486 ASSERT(currentOffset < offset); |
470 if (overridesItemAfter()) { | 487 switch (type()) { |
471 Element* next = ¤tElement; | 488 case HTMLTagCollectionType: |
472 while ((next = virtualItemAfter(next))) { | 489 return traverseMatchingElementsForwardToOffset(static_cast<const HTMLTag
Collection&>(*this), offset, currentElement, currentOffset, root); |
473 if (++currentOffset == offset) | 490 case ClassCollectionType: |
474 return next; | 491 return traverseMatchingElementsForwardToOffset(static_cast<const ClassCo
llection&>(*this), offset, currentElement, currentOffset, root); |
| 492 default: |
| 493 if (overridesItemAfter()) { |
| 494 Element* next = ¤tElement; |
| 495 while ((next = virtualItemAfter(next))) { |
| 496 if (++currentOffset == offset) |
| 497 return next; |
| 498 } |
| 499 return 0; |
475 } | 500 } |
476 return 0; | 501 if (shouldOnlyIncludeDirectChildren()) { |
| 502 Element* next = ¤tElement; |
| 503 while ((next = nextMatchingChildElement(*this, *next, root))) { |
| 504 if (++currentOffset == offset) |
| 505 return next; |
| 506 } |
| 507 return 0; |
| 508 } |
| 509 return traverseMatchingElementsForwardToOffset(*this, offset, currentEle
ment, currentOffset, root); |
477 } | 510 } |
478 if (shouldOnlyIncludeDirectChildren()) { | |
479 Element* next = ¤tElement; | |
480 while ((next = nextMatchingChildElement(*this, *next, root))) { | |
481 if (++currentOffset == offset) | |
482 return next; | |
483 } | |
484 return 0; | |
485 } | |
486 return traverseMatchingElementsForwardToOffset(*this, offset, currentElement
, currentOffset, root); | |
487 } | 511 } |
488 | 512 |
489 Element* HTMLCollection::namedItem(const AtomicString& name) const | 513 Element* HTMLCollection::namedItem(const AtomicString& name) const |
490 { | 514 { |
491 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/namedit
em.asp | 515 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/namedit
em.asp |
492 // This method first searches for an object with a matching id | 516 // This method first searches for an object with a matching id |
493 // attribute. If a match is not found, the method then searches for an | 517 // attribute. If a match is not found, the method then searches for an |
494 // object with a matching name attribute, but only on those elements | 518 // object with a matching name attribute, but only on those elements |
495 // that are allowed a name attribute. | 519 // that are allowed a name attribute. |
496 | 520 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 | 580 |
557 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element*
element) | 581 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element*
element) |
558 { | 582 { |
559 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->v
alue; | 583 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->v
alue; |
560 if (!vector) | 584 if (!vector) |
561 vector = adoptPtr(new Vector<Element*>); | 585 vector = adoptPtr(new Vector<Element*>); |
562 vector->append(element); | 586 vector->append(element); |
563 } | 587 } |
564 | 588 |
565 } // namespace WebCore | 589 } // namespace WebCore |
OLD | NEW |