| 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 28 matching lines...) Expand all Loading... |
| 39 // calculation every time if anything has changed. | 39 // calculation every time if anything has changed. |
| 40 | 40 |
| 41 HTMLFormControlsCollection::HTMLFormControlsCollection(ContainerNode& ownerNode) | 41 HTMLFormControlsCollection::HTMLFormControlsCollection(ContainerNode& ownerNode) |
| 42 : HTMLCollection(ownerNode, FormControls, OverridesItemAfter) | 42 : HTMLCollection(ownerNode, FormControls, OverridesItemAfter) |
| 43 , m_cachedElement(nullptr) | 43 , m_cachedElement(nullptr) |
| 44 , m_cachedElementOffsetInArray(0) | 44 , m_cachedElementOffsetInArray(0) |
| 45 { | 45 { |
| 46 ASSERT(isHTMLFormElement(ownerNode) || isHTMLFieldSetElement(ownerNode)); | 46 ASSERT(isHTMLFormElement(ownerNode) || isHTMLFieldSetElement(ownerNode)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 PassRefPtrWillBeRawPtr<HTMLFormControlsCollection> HTMLFormControlsCollection::c
reate(ContainerNode& ownerNode, CollectionType type) | 49 RawPtr<HTMLFormControlsCollection> HTMLFormControlsCollection::create(ContainerN
ode& ownerNode, CollectionType type) |
| 50 { | 50 { |
| 51 ASSERT_UNUSED(type, type == FormControls); | 51 ASSERT_UNUSED(type, type == FormControls); |
| 52 return adoptRefWillBeNoop(new HTMLFormControlsCollection(ownerNode)); | 52 return new HTMLFormControlsCollection(ownerNode); |
| 53 } | 53 } |
| 54 | 54 |
| 55 HTMLFormControlsCollection::~HTMLFormControlsCollection() | 55 HTMLFormControlsCollection::~HTMLFormControlsCollection() |
| 56 { | 56 { |
| 57 } | 57 } |
| 58 | 58 |
| 59 const FormAssociatedElement::List& HTMLFormControlsCollection::formControlElemen
ts() const | 59 const FormAssociatedElement::List& HTMLFormControlsCollection::formControlElemen
ts() const |
| 60 { | 60 { |
| 61 ASSERT(isHTMLFormElement(ownerNode()) || isHTMLFieldSetElement(ownerNode()))
; | 61 ASSERT(isHTMLFormElement(ownerNode()) || isHTMLFieldSetElement(ownerNode()))
; |
| 62 if (isHTMLFormElement(ownerNode())) | 62 if (isHTMLFormElement(ownerNode())) |
| 63 return toHTMLFormElement(ownerNode()).associatedElements(); | 63 return toHTMLFormElement(ownerNode()).associatedElements(); |
| 64 return toHTMLFieldSetElement(ownerNode()).associatedElements(); | 64 return toHTMLFieldSetElement(ownerNode()).associatedElements(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>>& HTMLFormControlsCo
llection::formImageElements() const | 67 const HeapVector<Member<HTMLImageElement>>& HTMLFormControlsCollection::formImag
eElements() const |
| 68 { | 68 { |
| 69 return toHTMLFormElement(ownerNode()).imageElements(); | 69 return toHTMLFormElement(ownerNode()).imageElements(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 static unsigned findFormAssociatedElement(const FormAssociatedElement::List& ass
ociatedElements, Element* element) | 72 static unsigned findFormAssociatedElement(const FormAssociatedElement::List& ass
ociatedElements, Element* element) |
| 73 { | 73 { |
| 74 unsigned i = 0; | 74 unsigned i = 0; |
| 75 for (; i < associatedElements.size(); ++i) { | 75 for (; i < associatedElements.size(); ++i) { |
| 76 FormAssociatedElement* associatedElement = associatedElements[i]; | 76 FormAssociatedElement* associatedElement = associatedElements[i]; |
| 77 if (associatedElement->isEnumeratable() && toHTMLElement(associatedEleme
nt) == element) | 77 if (associatedElement->isEnumeratable() && toHTMLElement(associatedEleme
nt) == element) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 if (HTMLElement* item = firstNamedItem(formControlElements(), idAttr, name)) | 131 if (HTMLElement* item = firstNamedItem(formControlElements(), idAttr, name)) |
| 132 return item; | 132 return item; |
| 133 return firstNamedItem(formControlElements(), nameAttr, name); | 133 return firstNamedItem(formControlElements(), nameAttr, name); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void HTMLFormControlsCollection::updateIdNameCache() const | 136 void HTMLFormControlsCollection::updateIdNameCache() const |
| 137 { | 137 { |
| 138 if (hasValidIdNameCache()) | 138 if (hasValidIdNameCache()) |
| 139 return; | 139 return; |
| 140 | 140 |
| 141 OwnPtrWillBeRawPtr<NamedItemCache> cache = NamedItemCache::create(); | 141 RawPtr<NamedItemCache> cache = NamedItemCache::create(); |
| 142 HashSet<StringImpl*> foundInputElements; | 142 HashSet<StringImpl*> foundInputElements; |
| 143 | 143 |
| 144 const FormAssociatedElement::List& elementsArray = formControlElements(); | 144 const FormAssociatedElement::List& elementsArray = formControlElements(); |
| 145 | 145 |
| 146 for (unsigned i = 0; i < elementsArray.size(); ++i) { | 146 for (unsigned i = 0; i < elementsArray.size(); ++i) { |
| 147 FormAssociatedElement* associatedElement = elementsArray[i]; | 147 FormAssociatedElement* associatedElement = elementsArray[i]; |
| 148 if (associatedElement->isEnumeratable()) { | 148 if (associatedElement->isEnumeratable()) { |
| 149 HTMLElement* element = toHTMLElement(associatedElement); | 149 HTMLElement* element = toHTMLElement(associatedElement); |
| 150 const AtomicString& idAttrVal = element->getIdAttribute(); | 150 const AtomicString& idAttrVal = element->getIdAttribute(); |
| 151 const AtomicString& nameAttrVal = element->getNameAttribute(); | 151 const AtomicString& nameAttrVal = element->getNameAttribute(); |
| 152 if (!idAttrVal.isEmpty()) { | 152 if (!idAttrVal.isEmpty()) { |
| 153 cache->addElementWithId(idAttrVal, element); | 153 cache->addElementWithId(idAttrVal, element); |
| 154 foundInputElements.add(idAttrVal.impl()); | 154 foundInputElements.add(idAttrVal.impl()); |
| 155 } | 155 } |
| 156 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { | 156 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { |
| 157 cache->addElementWithName(nameAttrVal, element); | 157 cache->addElementWithName(nameAttrVal, element); |
| 158 foundInputElements.add(nameAttrVal.impl()); | 158 foundInputElements.add(nameAttrVal.impl()); |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 if (isHTMLFormElement(ownerNode())) { | 163 if (isHTMLFormElement(ownerNode())) { |
| 164 // HTMLFormControlsCollection doesn't support named getter for IMG | 164 // HTMLFormControlsCollection doesn't support named getter for IMG |
| 165 // elements. However we still need to handle IMG elements here because | 165 // elements. However we still need to handle IMG elements here because |
| 166 // HTMLFormElement named getter relies on this. | 166 // HTMLFormElement named getter relies on this. |
| 167 const WillBeHeapVector<RawPtrWillBeMember<HTMLImageElement>>& imageEleme
ntsArray = formImageElements(); | 167 const HeapVector<Member<HTMLImageElement>>& imageElementsArray = formIma
geElements(); |
| 168 for (unsigned i = 0; i < imageElementsArray.size(); ++i) { | 168 for (unsigned i = 0; i < imageElementsArray.size(); ++i) { |
| 169 HTMLImageElement* element = imageElementsArray[i]; | 169 HTMLImageElement* element = imageElementsArray[i]; |
| 170 const AtomicString& idAttrVal = element->getIdAttribute(); | 170 const AtomicString& idAttrVal = element->getIdAttribute(); |
| 171 const AtomicString& nameAttrVal = element->getNameAttribute(); | 171 const AtomicString& nameAttrVal = element->getNameAttribute(); |
| 172 if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.i
mpl())) | 172 if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.i
mpl())) |
| 173 cache->addElementWithId(idAttrVal, element); | 173 cache->addElementWithId(idAttrVal, element); |
| 174 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInpu
tElements.contains(nameAttrVal.impl())) | 174 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInpu
tElements.contains(nameAttrVal.impl())) |
| 175 cache->addElementWithName(nameAttrVal, element); | 175 cache->addElementWithName(nameAttrVal, element); |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Set the named item cache last as traversing the tree may cause cache inva
lidation. | 179 // Set the named item cache last as traversing the tree may cause cache inva
lidation. |
| 180 setNamedItemCache(cache.release()); | 180 setNamedItemCache(cache.release()); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void HTMLFormControlsCollection::namedGetter(const AtomicString& name, RadioNode
ListOrElement& returnValue) | 183 void HTMLFormControlsCollection::namedGetter(const AtomicString& name, RadioNode
ListOrElement& returnValue) |
| 184 { | 184 { |
| 185 WillBeHeapVector<RefPtrWillBeMember<Element>> namedItems; | 185 HeapVector<Member<Element>> namedItems; |
| 186 this->namedItems(name, namedItems); | 186 this->namedItems(name, namedItems); |
| 187 | 187 |
| 188 if (namedItems.isEmpty()) | 188 if (namedItems.isEmpty()) |
| 189 return; | 189 return; |
| 190 | 190 |
| 191 if (namedItems.size() == 1) { | 191 if (namedItems.size() == 1) { |
| 192 if (!isHTMLImageElement(*namedItems[0])) | 192 if (!isHTMLImageElement(*namedItems[0])) |
| 193 returnValue.setElement(namedItems.at(0)); | 193 returnValue.setElement(namedItems.at(0)); |
| 194 return; | 194 return; |
| 195 } | 195 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 | 230 |
| 231 DEFINE_TRACE(HTMLFormControlsCollection) | 231 DEFINE_TRACE(HTMLFormControlsCollection) |
| 232 { | 232 { |
| 233 visitor->trace(m_cachedElement); | 233 visitor->trace(m_cachedElement); |
| 234 HTMLCollection::trace(visitor); | 234 HTMLCollection::trace(visitor); |
| 235 } | 235 } |
| 236 | 236 |
| 237 } // namespace blink | 237 } // namespace blink |
| OLD | NEW |