| 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, 2010, 2011, 2012 Apple Inc. All | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010, 2011, 2012 Apple Inc. All |
| 5 * rights reserved. | 5 * rights reserved. |
| 6 * Copyright (C) 2014 Samsung Electronics. All rights reserved. | 6 * Copyright (C) 2014 Samsung Electronics. All rights reserved. |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 HTMLCollection::invalidateCache(oldDocument); | 101 HTMLCollection::invalidateCache(oldDocument); |
| 102 m_cachedElement = nullptr; | 102 m_cachedElement = nullptr; |
| 103 m_cachedElementOffsetInArray = 0; | 103 m_cachedElementOffsetInArray = 0; |
| 104 } | 104 } |
| 105 | 105 |
| 106 static HTMLElement* firstNamedItem(const ListedElement::List& elementsArray, | 106 static HTMLElement* firstNamedItem(const ListedElement::List& elementsArray, |
| 107 const QualifiedName& attrName, | 107 const QualifiedName& attrName, |
| 108 const String& name) { | 108 const String& name) { |
| 109 DCHECK(attrName == idAttr || attrName == nameAttr); | 109 DCHECK(attrName == idAttr || attrName == nameAttr); |
| 110 | 110 |
| 111 for (unsigned i = 0; i < elementsArray.size(); ++i) { | 111 for (const auto& listedElement : elementsArray) { |
| 112 HTMLElement* element = toHTMLElement(elementsArray[i]); | 112 HTMLElement* element = toHTMLElement(listedElement); |
| 113 if (elementsArray[i]->isEnumeratable() && | 113 if (listedElement->isEnumeratable() && |
| 114 element->fastGetAttribute(attrName) == name) | 114 element->fastGetAttribute(attrName) == name) |
| 115 return element; | 115 return element; |
| 116 } | 116 } |
| 117 return nullptr; | 117 return nullptr; |
| 118 } | 118 } |
| 119 | 119 |
| 120 HTMLElement* HTMLFormControlsCollection::namedItem( | 120 HTMLElement* HTMLFormControlsCollection::namedItem( |
| 121 const AtomicString& name) const { | 121 const AtomicString& name) const { |
| 122 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/nameditem
.asp | 122 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/nameditem
.asp |
| 123 // This method first searches for an object with a matching id | 123 // This method first searches for an object with a matching id |
| 124 // attribute. If a match is not found, the method then searches for an | 124 // attribute. If a match is not found, the method then searches for an |
| 125 // object with a matching name attribute, but only on those elements | 125 // object with a matching name attribute, but only on those elements |
| 126 // that are allowed a name attribute. | 126 // that are allowed a name attribute. |
| 127 if (HTMLElement* item = firstNamedItem(listedElements(), idAttr, name)) | 127 if (HTMLElement* item = firstNamedItem(listedElements(), idAttr, name)) |
| 128 return item; | 128 return item; |
| 129 return firstNamedItem(listedElements(), nameAttr, name); | 129 return firstNamedItem(listedElements(), nameAttr, name); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void HTMLFormControlsCollection::updateIdNameCache() const { | 132 void HTMLFormControlsCollection::updateIdNameCache() const { |
| 133 if (hasValidIdNameCache()) | 133 if (hasValidIdNameCache()) |
| 134 return; | 134 return; |
| 135 | 135 |
| 136 NamedItemCache* cache = NamedItemCache::create(); | 136 NamedItemCache* cache = NamedItemCache::create(); |
| 137 HashSet<StringImpl*> foundInputElements; | 137 HashSet<StringImpl*> foundInputElements; |
| 138 | 138 |
| 139 const ListedElement::List& elementsArray = listedElements(); | 139 for (const auto& listedElement : listedElements()) { |
| 140 | |
| 141 for (unsigned i = 0; i < elementsArray.size(); ++i) { | |
| 142 ListedElement* listedElement = elementsArray[i]; | |
| 143 if (listedElement->isEnumeratable()) { | 140 if (listedElement->isEnumeratable()) { |
| 144 HTMLElement* element = toHTMLElement(listedElement); | 141 HTMLElement* element = toHTMLElement(listedElement); |
| 145 const AtomicString& idAttrVal = element->getIdAttribute(); | 142 const AtomicString& idAttrVal = element->getIdAttribute(); |
| 146 const AtomicString& nameAttrVal = element->getNameAttribute(); | 143 const AtomicString& nameAttrVal = element->getNameAttribute(); |
| 147 if (!idAttrVal.isEmpty()) { | 144 if (!idAttrVal.isEmpty()) { |
| 148 cache->addElementWithId(idAttrVal, element); | 145 cache->addElementWithId(idAttrVal, element); |
| 149 foundInputElements.add(idAttrVal.impl()); | 146 foundInputElements.add(idAttrVal.impl()); |
| 150 } | 147 } |
| 151 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { | 148 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { |
| 152 cache->addElementWithName(nameAttrVal, element); | 149 cache->addElementWithName(nameAttrVal, element); |
| 153 foundInputElements.add(nameAttrVal.impl()); | 150 foundInputElements.add(nameAttrVal.impl()); |
| 154 } | 151 } |
| 155 } | 152 } |
| 156 } | 153 } |
| 157 | 154 |
| 158 // HTMLFormControlsCollection doesn't support named getter for IMG | 155 // HTMLFormControlsCollection doesn't support named getter for IMG |
| 159 // elements. However we still need to handle IMG elements here because | 156 // elements. However we still need to handle IMG elements here because |
| 160 // HTMLFormElement named getter relies on this. | 157 // HTMLFormElement named getter relies on this. |
| 161 const HeapVector<Member<HTMLImageElement>>& imageElementsArray = | 158 for (const auto& element : formImageElements()) { |
| 162 formImageElements(); | |
| 163 for (unsigned i = 0; i < imageElementsArray.size(); ++i) { | |
| 164 HTMLImageElement* element = imageElementsArray[i]; | |
| 165 const AtomicString& idAttrVal = element->getIdAttribute(); | 159 const AtomicString& idAttrVal = element->getIdAttribute(); |
| 166 const AtomicString& nameAttrVal = element->getNameAttribute(); | 160 const AtomicString& nameAttrVal = element->getNameAttribute(); |
| 167 if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.impl())) | 161 if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.impl())) |
| 168 cache->addElementWithId(idAttrVal, element); | 162 cache->addElementWithId(idAttrVal, element); |
| 169 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && | 163 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && |
| 170 !foundInputElements.contains(nameAttrVal.impl())) | 164 !foundInputElements.contains(nameAttrVal.impl())) |
| 171 cache->addElementWithName(nameAttrVal, element); | 165 cache->addElementWithName(nameAttrVal, element); |
| 172 } | 166 } |
| 173 | 167 |
| 174 // Set the named item cache last as traversing the tree may cause cache | 168 // Set the named item cache last as traversing the tree may cause cache |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 } | 218 } |
| 225 } | 219 } |
| 226 } | 220 } |
| 227 | 221 |
| 228 DEFINE_TRACE(HTMLFormControlsCollection) { | 222 DEFINE_TRACE(HTMLFormControlsCollection) { |
| 229 visitor->trace(m_cachedElement); | 223 visitor->trace(m_cachedElement); |
| 230 HTMLCollection::trace(visitor); | 224 HTMLCollection::trace(visitor); |
| 231 } | 225 } |
| 232 | 226 |
| 233 } // namespace blink | 227 } // namespace blink |
| OLD | NEW |