OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009, 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009, 2011, 2012 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 29 matching lines...) Expand all Loading... |
40 HTMLAllCollection::HTMLAllCollection(ContainerNode& node) | 40 HTMLAllCollection::HTMLAllCollection(ContainerNode& node) |
41 : HTMLCollection(node, DocAll, DoesNotOverrideItemAfter) {} | 41 : HTMLCollection(node, DocAll, DoesNotOverrideItemAfter) {} |
42 | 42 |
43 HTMLAllCollection::~HTMLAllCollection() {} | 43 HTMLAllCollection::~HTMLAllCollection() {} |
44 | 44 |
45 Element* HTMLAllCollection::namedItemWithIndex(const AtomicString& name, | 45 Element* HTMLAllCollection::namedItemWithIndex(const AtomicString& name, |
46 unsigned index) const { | 46 unsigned index) const { |
47 updateIdNameCache(); | 47 updateIdNameCache(); |
48 | 48 |
49 const NamedItemCache& cache = namedItemCache(); | 49 const NamedItemCache& cache = namedItemCache(); |
50 if (HeapVector<Member<Element>>* elements = cache.getElementsById(name)) { | 50 if (const auto* elements = cache.getElementsById(name)) { |
51 if (index < elements->size()) | 51 if (index < elements->size()) |
52 return elements->at(index); | 52 return elements->at(index); |
53 index -= elements->size(); | 53 index -= elements->size(); |
54 } | 54 } |
55 | 55 |
56 if (HeapVector<Member<Element>>* elements = cache.getElementsByName(name)) { | 56 if (const auto* elements = cache.getElementsByName(name)) { |
57 if (index < elements->size()) | 57 if (index < elements->size()) |
58 return elements->at(index); | 58 return elements->at(index); |
59 } | 59 } |
60 | 60 |
61 return 0; | 61 return nullptr; |
62 } | 62 } |
63 | 63 |
64 void HTMLAllCollection::namedGetter(const AtomicString& name, | 64 void HTMLAllCollection::namedGetter(const AtomicString& name, |
65 NodeListOrElement& returnValue) { | 65 NodeListOrElement& returnValue) { |
66 HeapVector<Member<Element>> namedItems; | 66 HeapVector<Member<Element>> namedItems; |
67 this->namedItems(name, namedItems); | 67 this->namedItems(name, namedItems); |
68 | 68 |
69 if (!namedItems.size()) | 69 if (!namedItems.size()) |
70 return; | 70 return; |
71 | 71 |
72 if (namedItems.size() == 1) { | 72 if (namedItems.size() == 1) { |
73 returnValue.setElement(namedItems.at(0)); | 73 returnValue.setElement(namedItems.at(0)); |
74 return; | 74 return; |
75 } | 75 } |
76 | 76 |
77 // FIXME: HTML5 specification says this should be a HTMLCollection. | 77 // FIXME: HTML5 specification says this should be a HTMLCollection. |
78 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-inte
rfaces.html#htmlallcollection | 78 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-inte
rfaces.html#htmlallcollection |
79 returnValue.setNodeList(StaticElementList::adopt(namedItems)); | 79 returnValue.setNodeList(StaticElementList::adopt(namedItems)); |
80 } | 80 } |
81 | 81 |
82 } // namespace blink | 82 } // namespace blink |
OLD | NEW |