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

Side by Side Diff: Source/core/html/HTMLCollection.cpp

Issue 158563004: Make HTMLAllCollection named property getter behave more according to spec (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix linking error Created 6 years, 10 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 * 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 * Copyright (C) 2014 Samsung Electronics. All rights reserved. 5 * Copyright (C) 2014 Samsung Electronics. 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 12 matching lines...) Expand all
23 23
24 #include "config.h" 24 #include "config.h"
25 #include "core/html/HTMLCollection.h" 25 #include "core/html/HTMLCollection.h"
26 26
27 #include "HTMLNames.h" 27 #include "HTMLNames.h"
28 #include "core/dom/ClassCollection.h" 28 #include "core/dom/ClassCollection.h"
29 #include "core/dom/ElementTraversal.h" 29 #include "core/dom/ElementTraversal.h"
30 #include "core/dom/NodeList.h" 30 #include "core/dom/NodeList.h"
31 #include "core/dom/NodeRareData.h" 31 #include "core/dom/NodeRareData.h"
32 #include "core/dom/NodeTraversal.h" 32 #include "core/dom/NodeTraversal.h"
33 #include "core/html/HTMLAllCollection.h"
33 #include "core/html/HTMLElement.h" 34 #include "core/html/HTMLElement.h"
34 #include "core/html/HTMLObjectElement.h" 35 #include "core/html/HTMLObjectElement.h"
35 #include "core/html/HTMLOptionElement.h" 36 #include "core/html/HTMLOptionElement.h"
36 #include "wtf/HashSet.h" 37 #include "wtf/HashSet.h"
37 38
38 namespace WebCore { 39 namespace WebCore {
39 40
40 using namespace HTMLNames; 41 using namespace HTMLNames;
41 42
42 static bool shouldTypeOnlyIncludeDirectChildren(CollectionType type) 43 static bool shouldTypeOnlyIncludeDirectChildren(CollectionType type)
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 { 379 {
379 return traverseMatchingElementsForwardToOffset(*this, offset, currentNode, c urrentOffset, root); 380 return traverseMatchingElementsForwardToOffset(*this, offset, currentNode, c urrentOffset, root);
380 } 381 }
381 382
382 Element* HTMLCollection::virtualItemAfter(Element*) const 383 Element* HTMLCollection::virtualItemAfter(Element*) const
383 { 384 {
384 ASSERT_NOT_REACHED(); 385 ASSERT_NOT_REACHED();
385 return 0; 386 return 0;
386 } 387 }
387 388
388 static inline bool nameShouldBeVisibleInDocumentAll(const HTMLElement& element)
389 {
390 // The document.all collection returns only certain types of elements by nam e,
391 // although it returns any type of element by id.
392 return element.hasLocalName(appletTag)
393 || element.hasLocalName(embedTag)
394 || element.hasLocalName(formTag)
395 || element.hasLocalName(imgTag)
396 || element.hasLocalName(inputTag)
397 || element.hasLocalName(objectTag)
398 || element.hasLocalName(selectTag);
399 }
400
401 inline Element* firstMatchingChildElement(const HTMLCollection& nodeList, const ContainerNode& root) 389 inline Element* firstMatchingChildElement(const HTMLCollection& nodeList, const ContainerNode& root)
402 { 390 {
403 Element* element = ElementTraversal::firstWithin(root); 391 Element* element = ElementTraversal::firstWithin(root);
404 while (element && !isMatchingElement(nodeList, *element)) 392 while (element && !isMatchingElement(nodeList, *element))
405 element = ElementTraversal::nextSkippingChildren(*element, &root); 393 element = ElementTraversal::nextSkippingChildren(*element, &root);
406 return element; 394 return element;
407 } 395 }
408 396
409 inline Element* nextMatchingChildElement(const HTMLCollection& nodeList, Element & current, const ContainerNode& root) 397 inline Element* nextMatchingChildElement(const HTMLCollection& nodeList, Element & current, const ContainerNode& root)
410 { 398 {
(...skipping 13 matching lines...) Expand all
424 return firstMatchingElement(static_cast<const ClassCollection&>(*this), root); 412 return firstMatchingElement(static_cast<const ClassCollection&>(*this), root);
425 default: 413 default:
426 if (overridesItemAfter()) 414 if (overridesItemAfter())
427 return virtualItemAfter(0); 415 return virtualItemAfter(0);
428 if (shouldOnlyIncludeDirectChildren()) 416 if (shouldOnlyIncludeDirectChildren())
429 return firstMatchingChildElement(*this, root); 417 return firstMatchingChildElement(*this, root);
430 return firstMatchingElement(*this, root); 418 return firstMatchingElement(*this, root);
431 } 419 }
432 } 420 }
433 421
434 inline Element* HTMLCollection::traverseNextElement(Element& previous, const Con tainerNode& root) const 422 Element* HTMLCollection::traverseNextElement(Element& previous, const ContainerN ode& root) const
435 { 423 {
436 if (overridesItemAfter()) 424 if (overridesItemAfter())
437 return virtualItemAfter(&previous); 425 return virtualItemAfter(&previous);
438 if (shouldOnlyIncludeDirectChildren()) 426 if (shouldOnlyIncludeDirectChildren())
439 return nextMatchingChildElement(*this, previous, root); 427 return nextMatchingChildElement(*this, previous, root);
440 return nextMatchingElement(*this, previous, root); 428 return nextMatchingElement(*this, previous, root);
441 } 429 }
442 430
443 Element* HTMLCollection::traverseForwardToOffset(unsigned offset, Element& curre ntElement, unsigned& currentOffset, const ContainerNode& root) const 431 Element* HTMLCollection::traverseForwardToOffset(unsigned offset, Element& curre ntElement, unsigned& currentOffset, const ContainerNode& root) const
444 { 432 {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 return; 523 return;
536 524
537 ContainerNode& root = rootNode(); 525 ContainerNode& root = rootNode();
538 for (Element* element = traverseToFirstElement(root); element; element = tra verseNextElement(*element, root)) { 526 for (Element* element = traverseToFirstElement(root); element; element = tra verseNextElement(*element, root)) {
539 const AtomicString& idAttrVal = element->getIdAttribute(); 527 const AtomicString& idAttrVal = element->getIdAttribute();
540 if (!idAttrVal.isEmpty()) 528 if (!idAttrVal.isEmpty())
541 appendIdCache(idAttrVal, element); 529 appendIdCache(idAttrVal, element);
542 if (!element->isHTMLElement()) 530 if (!element->isHTMLElement())
543 continue; 531 continue;
544 const AtomicString& nameAttrVal = element->getNameAttribute(); 532 const AtomicString& nameAttrVal = element->getNameAttribute();
545 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (type() != Doc All || nameShouldBeVisibleInDocumentAll(toHTMLElement(*element)))) 533 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (type() != Doc All || HTMLAllCollection::elementNameShouldBeVisible(toHTMLElement(*element))))
546 appendNameCache(nameAttrVal, element); 534 appendNameCache(nameAttrVal, element);
547 } 535 }
548 536
549 setHasNameCache(); 537 setHasNameCache();
550 } 538 }
551 539
552 void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Element> >& result) const 540 void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Element> >& result) const
553 { 541 {
554 ASSERT(result.isEmpty()); 542 ASSERT(result.isEmpty());
555 if (name.isEmpty()) 543 if (name.isEmpty())
(...skipping 13 matching lines...) Expand all
569 557
570 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element* element) 558 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element* element)
571 { 559 {
572 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->v alue; 560 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->v alue;
573 if (!vector) 561 if (!vector)
574 vector = adoptPtr(new Vector<Element*>); 562 vector = adoptPtr(new Vector<Element*>);
575 vector->append(element); 563 vector->append(element);
576 } 564 }
577 565
578 } // namespace WebCore 566 } // namespace WebCore
OLDNEW
« Source/core/html/HTMLAllCollection.cpp ('K') | « Source/core/html/HTMLCollection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698