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 * 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 Loading... | |
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 Loading... | |
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 // The supported property names are the values from the list returned by the se steps: | |
haraken
2014/02/06 02:47:41
You can add a spec link:
http://dom.spec.whatwg.or
Inactive
2014/02/06 02:55:39
Will do.
Inactive
2014/02/06 03:03:29
Done.
| |
500 // 1. Let result be an empty list. | |
501 // 2. For each element represented by the collection, in tree order, run the se substeps: | |
502 // 1. If element is in the HTML namespace and has a name attribute whose v alue is neither the empty string | |
503 // nor is in result, append element's name attribute value to result. | |
504 // 2. If element has an ID which is neither the empty string nor is in res ult, append element's ID to result. | |
505 // 3. Return result. | |
506 HashSet<AtomicString> existingNames; | |
507 ContainerNode& root = rootNode(); | |
508 for (Element* element = traverseToFirstElement(root); element; element = tra verseNextElement(*element, root)) { | |
509 if (element->isHTMLElement()) { | |
510 const AtomicString& nameAttribute = element->getNameAttribute(); | |
511 if (!nameAttribute.isEmpty() && (type() != DocAll || nameShouldBeVis ibleInDocumentAll(toHTMLElement(*element)))) { | |
haraken
2014/02/06 02:47:41
I'm just curious: Where is this condition speced?
Inactive
2014/02/06 02:55:39
Right, this is spec'd at:
http://www.whatwg.org/sp
Inactive
2014/02/06 03:01:24
Oops, the HTMLAllCollection spec says "with the id
Inactive
2014/02/06 03:03:29
Done.
| |
512 HashSet<AtomicString>::AddResult addResult = existingNames.add(n ameAttribute); | |
513 if (addResult.isNewEntry) | |
514 names.append(nameAttribute); | |
515 } | |
516 } | |
517 const AtomicString& idAttribute = element->getIdAttribute(); | |
518 if (!idAttribute.isEmpty()) { | |
519 HashSet<AtomicString>::AddResult addResult = existingNames.add(idAtt ribute); | |
520 if (addResult.isNewEntry) | |
521 names.append(idAttribute); | |
522 } | |
523 } | |
524 } | |
525 | |
526 void HTMLCollection::namedPropertyEnumerator(Vector<String>& names, ExceptionSta te&) | |
527 { | |
528 return supportedPropertyNames(names); | |
529 } | |
530 | |
490 void HTMLCollection::updateNameCache() const | 531 void HTMLCollection::updateNameCache() const |
491 { | 532 { |
492 if (hasNameCache()) | 533 if (hasNameCache()) |
493 return; | 534 return; |
494 | 535 |
495 ContainerNode& root = rootNode(); | 536 ContainerNode& root = rootNode(); |
496 for (Element* element = traverseToFirstElement(root); element; element = tra verseNextElement(*element, root)) { | 537 for (Element* element = traverseToFirstElement(root); element; element = tra verseNextElement(*element, root)) { |
497 const AtomicString& idAttrVal = element->getIdAttribute(); | 538 const AtomicString& idAttrVal = element->getIdAttribute(); |
498 if (!idAttrVal.isEmpty()) | 539 if (!idAttrVal.isEmpty()) |
499 appendIdCache(idAttrVal, element); | 540 appendIdCache(idAttrVal, element); |
(...skipping 27 matching lines...) Expand all Loading... | |
527 | 568 |
528 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element* element) | 569 void HTMLCollection::append(NodeCacheMap& map, const AtomicString& key, Element* element) |
529 { | 570 { |
530 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->v alue; | 571 OwnPtr<Vector<Element*> >& vector = map.add(key.impl(), nullptr).iterator->v alue; |
531 if (!vector) | 572 if (!vector) |
532 vector = adoptPtr(new Vector<Element*>); | 573 vector = adoptPtr(new Vector<Element*>); |
533 vector->append(element); | 574 vector->append(element); |
534 } | 575 } |
535 | 576 |
536 } // namespace WebCore | 577 } // namespace WebCore |
OLD | NEW |