| 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 r
ights reserved. | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010, 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } | 58 } |
| 59 | 59 |
| 60 const FormAssociatedElement::List& HTMLFormControlsCollection::formControlElemen
ts() const | 60 const FormAssociatedElement::List& HTMLFormControlsCollection::formControlElemen
ts() const |
| 61 { | 61 { |
| 62 ASSERT(isHTMLFormElement(ownerNode()) || isHTMLFieldSetElement(ownerNode()))
; | 62 ASSERT(isHTMLFormElement(ownerNode()) || isHTMLFieldSetElement(ownerNode()))
; |
| 63 if (isHTMLFormElement(ownerNode())) | 63 if (isHTMLFormElement(ownerNode())) |
| 64 return toHTMLFormElement(ownerNode()).associatedElements(); | 64 return toHTMLFormElement(ownerNode()).associatedElements(); |
| 65 return toHTMLFieldSetElement(ownerNode()).associatedElements(); | 65 return toHTMLFieldSetElement(ownerNode()).associatedElements(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement> >& HTMLFormControlsC
ollection::formImageElements() const | 68 const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>>& HTMLFormControlsCo
llection::formImageElements() const |
| 69 { | 69 { |
| 70 return toHTMLFormElement(ownerNode()).imageElements(); | 70 return toHTMLFormElement(ownerNode()).imageElements(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 static unsigned findFormAssociatedElement(const FormAssociatedElement::List& ass
ociatedElements, Element* element) | 73 static unsigned findFormAssociatedElement(const FormAssociatedElement::List& ass
ociatedElements, Element* element) |
| 74 { | 74 { |
| 75 unsigned i = 0; | 75 unsigned i = 0; |
| 76 for (; i < associatedElements.size(); ++i) { | 76 for (; i < associatedElements.size(); ++i) { |
| 77 FormAssociatedElement* associatedElement = associatedElements[i]; | 77 FormAssociatedElement* associatedElement = associatedElements[i]; |
| 78 if (associatedElement->isEnumeratable() && toHTMLElement(associatedEleme
nt) == element) | 78 if (associatedElement->isEnumeratable() && toHTMLElement(associatedEleme
nt) == element) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 93 offset = findFormAssociatedElement(associatedElements, previous) + 1; | 93 offset = findFormAssociatedElement(associatedElements, previous) + 1; |
| 94 | 94 |
| 95 for (unsigned i = offset; i < associatedElements.size(); ++i) { | 95 for (unsigned i = offset; i < associatedElements.size(); ++i) { |
| 96 FormAssociatedElement* associatedElement = associatedElements[i]; | 96 FormAssociatedElement* associatedElement = associatedElements[i]; |
| 97 if (associatedElement->isEnumeratable()) { | 97 if (associatedElement->isEnumeratable()) { |
| 98 m_cachedElement = toHTMLElement(associatedElement); | 98 m_cachedElement = toHTMLElement(associatedElement); |
| 99 m_cachedElementOffsetInArray = i; | 99 m_cachedElementOffsetInArray = i; |
| 100 return m_cachedElement; | 100 return m_cachedElement; |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 return 0; | 103 return nullptr; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void HTMLFormControlsCollection::invalidateCache(Document* oldDocument) const | 106 void HTMLFormControlsCollection::invalidateCache(Document* oldDocument) const |
| 107 { | 107 { |
| 108 HTMLCollection::invalidateCache(oldDocument); | 108 HTMLCollection::invalidateCache(oldDocument); |
| 109 m_cachedElement = nullptr; | 109 m_cachedElement = nullptr; |
| 110 m_cachedElementOffsetInArray = 0; | 110 m_cachedElementOffsetInArray = 0; |
| 111 } | 111 } |
| 112 | 112 |
| 113 static HTMLElement* firstNamedItem(const FormAssociatedElement::List& elementsAr
ray, | 113 static HTMLElement* firstNamedItem(const FormAssociatedElement::List& elementsAr
ray, |
| 114 const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement> >* imageElements
Array, const QualifiedName& attrName, const String& name) | 114 const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>>* imageElementsA
rray, const QualifiedName& attrName, const String& name) |
| 115 { | 115 { |
| 116 ASSERT(attrName == idAttr || attrName == nameAttr); | 116 ASSERT(attrName == idAttr || attrName == nameAttr); |
| 117 | 117 |
| 118 for (unsigned i = 0; i < elementsArray.size(); ++i) { | 118 for (unsigned i = 0; i < elementsArray.size(); ++i) { |
| 119 HTMLElement* element = toHTMLElement(elementsArray[i]); | 119 HTMLElement* element = toHTMLElement(elementsArray[i]); |
| 120 if (elementsArray[i]->isEnumeratable() && element->fastGetAttribute(attr
Name) == name) | 120 if (elementsArray[i]->isEnumeratable() && element->fastGetAttribute(attr
Name) == name) |
| 121 return element; | 121 return element; |
| 122 } | 122 } |
| 123 | 123 |
| 124 if (!imageElementsArray) | 124 if (!imageElementsArray) |
| 125 return 0; | 125 return nullptr; |
| 126 | 126 |
| 127 for (unsigned i = 0; i < imageElementsArray->size(); ++i) { | 127 for (unsigned i = 0; i < imageElementsArray->size(); ++i) { |
| 128 HTMLImageElement* element = (*imageElementsArray)[i]; | 128 HTMLImageElement* element = (*imageElementsArray)[i]; |
| 129 if (element->fastGetAttribute(attrName) == name) { | 129 if (element->fastGetAttribute(attrName) == name) { |
| 130 UseCounter::count(element->document(), UseCounter::FormNameAccessFor
ImageElement); | 130 UseCounter::count(element->document(), UseCounter::FormNameAccessFor
ImageElement); |
| 131 return element; | 131 return element; |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 | 134 |
| 135 return 0; | 135 return nullptr; |
| 136 } | 136 } |
| 137 | 137 |
| 138 HTMLElement* HTMLFormControlsCollection::namedItem(const AtomicString& name) con
st | 138 HTMLElement* HTMLFormControlsCollection::namedItem(const AtomicString& name) con
st |
| 139 { | 139 { |
| 140 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/namedit
em.asp | 140 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/namedit
em.asp |
| 141 // This method first searches for an object with a matching id | 141 // This method first searches for an object with a matching id |
| 142 // attribute. If a match is not found, the method then searches for an | 142 // attribute. If a match is not found, the method then searches for an |
| 143 // object with a matching name attribute, but only on those elements | 143 // object with a matching name attribute, but only on those elements |
| 144 // that are allowed a name attribute. | 144 // that are allowed a name attribute. |
| 145 const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement> >* imagesElement
s = isHTMLFieldSetElement(ownerNode()) ? 0 : &formImageElements(); | 145 const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>>* imagesElements
= isHTMLFieldSetElement(ownerNode()) ? 0 : &formImageElements(); |
| 146 if (HTMLElement* item = firstNamedItem(formControlElements(), imagesElements
, idAttr, name)) | 146 if (HTMLElement* item = firstNamedItem(formControlElements(), imagesElements
, idAttr, name)) |
| 147 return item; | 147 return item; |
| 148 | 148 |
| 149 return firstNamedItem(formControlElements(), imagesElements, nameAttr, name)
; | 149 return firstNamedItem(formControlElements(), imagesElements, nameAttr, name)
; |
| 150 } | 150 } |
| 151 | 151 |
| 152 void HTMLFormControlsCollection::updateIdNameCache() const | 152 void HTMLFormControlsCollection::updateIdNameCache() const |
| 153 { | 153 { |
| 154 if (hasValidIdNameCache()) | 154 if (hasValidIdNameCache()) |
| 155 return; | 155 return; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 170 foundInputElements.add(idAttrVal.impl()); | 170 foundInputElements.add(idAttrVal.impl()); |
| 171 } | 171 } |
| 172 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { | 172 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { |
| 173 cache->addElementWithName(nameAttrVal, element); | 173 cache->addElementWithName(nameAttrVal, element); |
| 174 foundInputElements.add(nameAttrVal.impl()); | 174 foundInputElements.add(nameAttrVal.impl()); |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 if (isHTMLFormElement(ownerNode())) { | 179 if (isHTMLFormElement(ownerNode())) { |
| 180 const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement> >& imageElem
entsArray = formImageElements(); | 180 const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>>& imageEleme
ntsArray = formImageElements(); |
| 181 for (unsigned i = 0; i < imageElementsArray.size(); ++i) { | 181 for (unsigned i = 0; i < imageElementsArray.size(); ++i) { |
| 182 HTMLImageElement* element = imageElementsArray[i]; | 182 HTMLImageElement* element = imageElementsArray[i]; |
| 183 const AtomicString& idAttrVal = element->getIdAttribute(); | 183 const AtomicString& idAttrVal = element->getIdAttribute(); |
| 184 const AtomicString& nameAttrVal = element->getNameAttribute(); | 184 const AtomicString& nameAttrVal = element->getNameAttribute(); |
| 185 if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.i
mpl())) | 185 if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.i
mpl())) |
| 186 cache->addElementWithId(idAttrVal, element); | 186 cache->addElementWithId(idAttrVal, element); |
| 187 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInpu
tElements.contains(nameAttrVal.impl())) | 187 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInpu
tElements.contains(nameAttrVal.impl())) |
| 188 cache->addElementWithName(nameAttrVal, element); | 188 cache->addElementWithName(nameAttrVal, element); |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Set the named item cache last as traversing the tree may cause cache inva
lidation. | 192 // Set the named item cache last as traversing the tree may cause cache inva
lidation. |
| 193 setNamedItemCache(cache.release()); | 193 setNamedItemCache(cache.release()); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void HTMLFormControlsCollection::namedGetter(const AtomicString& name, RadioNode
ListOrElement& returnValue) | 196 void HTMLFormControlsCollection::namedGetter(const AtomicString& name, RadioNode
ListOrElement& returnValue) |
| 197 { | 197 { |
| 198 WillBeHeapVector<RefPtrWillBeMember<Element> > namedItems; | 198 WillBeHeapVector<RefPtrWillBeMember<Element>> namedItems; |
| 199 this->namedItems(name, namedItems); | 199 this->namedItems(name, namedItems); |
| 200 | 200 |
| 201 if (namedItems.isEmpty()) | 201 if (namedItems.isEmpty()) |
| 202 return; | 202 return; |
| 203 | 203 |
| 204 if (namedItems.size() == 1) { | 204 if (namedItems.size() == 1) { |
| 205 returnValue.setElement(namedItems.at(0)); | 205 returnValue.setElement(namedItems.at(0)); |
| 206 return; | 206 return; |
| 207 } | 207 } |
| 208 | 208 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 | 238 |
| 239 void HTMLFormControlsCollection::trace(Visitor* visitor) | 239 void HTMLFormControlsCollection::trace(Visitor* visitor) |
| 240 { | 240 { |
| 241 visitor->trace(m_cachedElement); | 241 visitor->trace(m_cachedElement); |
| 242 HTMLCollection::trace(visitor); | 242 HTMLCollection::trace(visitor); |
| 243 } | 243 } |
| 244 | 244 |
| 245 } | 245 } |
| OLD | NEW |