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

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

Issue 148323008: Update HTMLCollection's named property getter to behave according to spec (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Take feedback into consideation 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
« no previous file with comments | « Source/core/html/HTMLCollection.h ('k') | Source/core/html/HTMLCollection.idl » ('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 * 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 * 6 *
6 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
9 * 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.
10 * 11 *
11 * This library is distributed in the hope that it will be useful, 12 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 15 * Library General Public License for more details.
(...skipping 10 matching lines...) Expand all
25 26
26 #include "HTMLNames.h" 27 #include "HTMLNames.h"
27 #include "core/dom/ClassCollection.h" 28 #include "core/dom/ClassCollection.h"
28 #include "core/dom/ElementTraversal.h" 29 #include "core/dom/ElementTraversal.h"
29 #include "core/dom/NodeList.h" 30 #include "core/dom/NodeList.h"
30 #include "core/dom/NodeRareData.h" 31 #include "core/dom/NodeRareData.h"
31 #include "core/dom/NodeTraversal.h" 32 #include "core/dom/NodeTraversal.h"
32 #include "core/html/HTMLElement.h" 33 #include "core/html/HTMLElement.h"
33 #include "core/html/HTMLObjectElement.h" 34 #include "core/html/HTMLObjectElement.h"
34 #include "core/html/HTMLOptionElement.h" 35 #include "core/html/HTMLOptionElement.h"
36 #include "wtf/HashSet.h"
35 37
36 namespace WebCore { 38 namespace WebCore {
37 39
38 using namespace HTMLNames; 40 using namespace HTMLNames;
39 41
40 static bool shouldOnlyIncludeDirectChildren(CollectionType type) 42 static bool shouldOnlyIncludeDirectChildren(CollectionType type)
41 { 43 {
42 switch (type) { 44 switch (type) {
43 case ClassCollectionType: 45 case ClassCollectionType:
44 case TagCollectionType: 46 case TagCollectionType:
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 if (idResults && !idResults->isEmpty()) 482 if (idResults && !idResults->isEmpty())
481 return idResults->first(); 483 return idResults->first();
482 484
483 Vector<Element*>* nameResults = nameCache(name); 485 Vector<Element*>* nameResults = nameCache(name);
484 if (nameResults && !nameResults->isEmpty()) 486 if (nameResults && !nameResults->isEmpty())
485 return nameResults->first(); 487 return nameResults->first();
486 488
487 return 0; 489 return 0;
488 } 490 }
489 491
492 bool HTMLCollection::namedPropertyQuery(const AtomicString& name, ExceptionState &)
493 {
494 return namedItem(name);
495 }
496
497 void HTMLCollection::supportedPropertyNames(Vector<String>& names)
498 {
499 // As per the specification (http://dom.spec.whatwg.org/#htmlcollection):
500 // The supported property names are the values from the list returned by the se steps:
501 // 1. Let result be an empty list.
502 // 2. For each element represented by the collection, in tree order, run the se substeps:
503 // 1. If element is in the HTML namespace and has a name attribute whose v alue is neither the empty string
504 // nor is in result, append element's name attribute value to result.
505 // 2. If element has an ID which is neither the empty string nor is in res ult, append element's ID to result.
506 // 3. Return result.
507 HashSet<AtomicString> existingNames;
508 ContainerNode& root = rootNode();
509 for (Element* element = traverseToFirstElement(root); element; element = tra verseNextElement(*element, root)) {
510 if (element->isHTMLElement()) {
511 const AtomicString& nameAttribute = element->getNameAttribute();
512 if (!nameAttribute.isEmpty()) {
513 HashSet<AtomicString>::AddResult addResult = existingNames.add(n ameAttribute);
514 if (addResult.isNewEntry)
515 names.append(nameAttribute);
516 }
517 }
518 const AtomicString& idAttribute = element->getIdAttribute();
519 if (!idAttribute.isEmpty()) {
520 HashSet<AtomicString>::AddResult addResult = existingNames.add(idAtt ribute);
521 if (addResult.isNewEntry)
522 names.append(idAttribute);
523 }
524 }
525 }
526
527 void HTMLCollection::namedPropertyEnumerator(Vector<String>& names, ExceptionSta te&)
528 {
529 return supportedPropertyNames(names);
530 }
531
490 void HTMLCollection::updateNameCache() const 532 void HTMLCollection::updateNameCache() const
491 { 533 {
492 if (hasNameCache()) 534 if (hasNameCache())
493 return; 535 return;
494 536
495 ContainerNode& root = rootNode(); 537 ContainerNode& root = rootNode();
496 for (Element* element = traverseToFirstElement(root); element; element = tra verseNextElement(*element, root)) { 538 for (Element* element = traverseToFirstElement(root); element; element = tra verseNextElement(*element, root)) {
497 const AtomicString& idAttrVal = element->getIdAttribute(); 539 const AtomicString& idAttrVal = element->getIdAttribute();
498 if (!idAttrVal.isEmpty()) 540 if (!idAttrVal.isEmpty())
499 appendIdCache(idAttrVal, element); 541 appendIdCache(idAttrVal, element);
(...skipping 27 matching lines...) Expand all
527 569
528 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element* element) 570 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element* element)
529 { 571 {
530 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->v alue; 572 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->v alue;
531 if (!vector) 573 if (!vector)
532 vector = adoptPtr(new Vector<Element*>); 574 vector = adoptPtr(new Vector<Element*>);
533 vector->append(element); 575 vector->append(element);
534 } 576 }
535 577
536 } // namespace WebCore 578 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/HTMLCollection.h ('k') | Source/core/html/HTMLCollection.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698