| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 PassRefPtr<HTMLFormControlsCollection> HTMLFormControlsCollection::create(Contai
nerNode& ownerNode, CollectionType) | 50 PassRefPtr<HTMLFormControlsCollection> HTMLFormControlsCollection::create(Contai
nerNode& ownerNode, CollectionType) |
| 51 { | 51 { |
| 52 return adoptRef(new HTMLFormControlsCollection(ownerNode)); | 52 return adoptRef(new HTMLFormControlsCollection(ownerNode)); |
| 53 } | 53 } |
| 54 | 54 |
| 55 HTMLFormControlsCollection::~HTMLFormControlsCollection() | 55 HTMLFormControlsCollection::~HTMLFormControlsCollection() |
| 56 { | 56 { |
| 57 } | 57 } |
| 58 | 58 |
| 59 const Vector<FormAssociatedElement*>& HTMLFormControlsCollection::formControlEle
ments() 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 Vector<HTMLImageElement*>& HTMLFormControlsCollection::formImageElements()
const | 67 const Vector<HTMLImageElement*>& HTMLFormControlsCollection::formImageElements()
const |
| 68 { | 68 { |
| 69 return toHTMLFormElement(ownerNode()).imageElements(); | 69 return toHTMLFormElement(ownerNode()).imageElements(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 static unsigned findFormAssociatedElement(const Vector<FormAssociatedElement*>&
associatedElements, 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) |
| 78 break; | 78 break; |
| 79 } | 79 } |
| 80 return i; | 80 return i; |
| 81 } | 81 } |
| 82 | 82 |
| 83 Element* HTMLFormControlsCollection::virtualItemAfter(Element* previous) const | 83 Element* HTMLFormControlsCollection::virtualItemAfter(Element* previous) const |
| 84 { | 84 { |
| 85 const Vector<FormAssociatedElement*>& associatedElements = formControlElemen
ts(); | 85 const FormAssociatedElement::List& associatedElements = formControlElements(
); |
| 86 unsigned offset; | 86 unsigned offset; |
| 87 if (!previous) | 87 if (!previous) |
| 88 offset = 0; | 88 offset = 0; |
| 89 else if (m_cachedElement == previous) | 89 else if (m_cachedElement == previous) |
| 90 offset = m_cachedElementOffsetInArray + 1; | 90 offset = m_cachedElementOffsetInArray + 1; |
| 91 else | 91 else |
| 92 offset = findFormAssociatedElement(associatedElements, previous) + 1; | 92 offset = findFormAssociatedElement(associatedElements, previous) + 1; |
| 93 | 93 |
| 94 for (unsigned i = offset; i < associatedElements.size(); ++i) { | 94 for (unsigned i = offset; i < associatedElements.size(); ++i) { |
| 95 FormAssociatedElement* associatedElement = associatedElements[i]; | 95 FormAssociatedElement* associatedElement = associatedElements[i]; |
| 96 if (associatedElement->isEnumeratable()) { | 96 if (associatedElement->isEnumeratable()) { |
| 97 m_cachedElement = toHTMLElement(associatedElement); | 97 m_cachedElement = toHTMLElement(associatedElement); |
| 98 m_cachedElementOffsetInArray = i; | 98 m_cachedElementOffsetInArray = i; |
| 99 return m_cachedElement; | 99 return m_cachedElement; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 return 0; | 102 return 0; |
| 103 } | 103 } |
| 104 | 104 |
| 105 void HTMLFormControlsCollection::invalidateCache(Document* oldDocument) const | 105 void HTMLFormControlsCollection::invalidateCache(Document* oldDocument) const |
| 106 { | 106 { |
| 107 HTMLCollection::invalidateCache(oldDocument); | 107 HTMLCollection::invalidateCache(oldDocument); |
| 108 m_cachedElement = 0; | 108 m_cachedElement = 0; |
| 109 m_cachedElementOffsetInArray = 0; | 109 m_cachedElementOffsetInArray = 0; |
| 110 } | 110 } |
| 111 | 111 |
| 112 static HTMLElement* firstNamedItem(const Vector<FormAssociatedElement*>& element
sArray, | 112 static HTMLElement* firstNamedItem(const FormAssociatedElement::List& elementsAr
ray, |
| 113 const Vector<HTMLImageElement*>* imageElementsArray, const QualifiedName& at
trName, const String& name) | 113 const Vector<HTMLImageElement*>* imageElementsArray, const QualifiedName& at
trName, const String& name) |
| 114 { | 114 { |
| 115 ASSERT(attrName == idAttr || attrName == nameAttr); | 115 ASSERT(attrName == idAttr || attrName == nameAttr); |
| 116 | 116 |
| 117 for (unsigned i = 0; i < elementsArray.size(); ++i) { | 117 for (unsigned i = 0; i < elementsArray.size(); ++i) { |
| 118 HTMLElement* element = toHTMLElement(elementsArray[i]); | 118 HTMLElement* element = toHTMLElement(elementsArray[i]); |
| 119 if (elementsArray[i]->isEnumeratable() && element->fastGetAttribute(attr
Name) == name) | 119 if (elementsArray[i]->isEnumeratable() && element->fastGetAttribute(attr
Name) == name) |
| 120 return element; | 120 return element; |
| 121 } | 121 } |
| 122 | 122 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 149 } | 149 } |
| 150 | 150 |
| 151 void HTMLFormControlsCollection::updateIdNameCache() const | 151 void HTMLFormControlsCollection::updateIdNameCache() const |
| 152 { | 152 { |
| 153 if (hasValidIdNameCache()) | 153 if (hasValidIdNameCache()) |
| 154 return; | 154 return; |
| 155 | 155 |
| 156 OwnPtr<NamedItemCache> cache = NamedItemCache::create(); | 156 OwnPtr<NamedItemCache> cache = NamedItemCache::create(); |
| 157 HashSet<StringImpl*> foundInputElements; | 157 HashSet<StringImpl*> foundInputElements; |
| 158 | 158 |
| 159 const Vector<FormAssociatedElement*>& elementsArray = formControlElements(); | 159 const FormAssociatedElement::List& elementsArray = formControlElements(); |
| 160 | 160 |
| 161 for (unsigned i = 0; i < elementsArray.size(); ++i) { | 161 for (unsigned i = 0; i < elementsArray.size(); ++i) { |
| 162 FormAssociatedElement* associatedElement = elementsArray[i]; | 162 FormAssociatedElement* associatedElement = elementsArray[i]; |
| 163 if (associatedElement->isEnumeratable()) { | 163 if (associatedElement->isEnumeratable()) { |
| 164 HTMLElement* element = toHTMLElement(associatedElement); | 164 HTMLElement* element = toHTMLElement(associatedElement); |
| 165 const AtomicString& idAttrVal = element->getIdAttribute(); | 165 const AtomicString& idAttrVal = element->getIdAttribute(); |
| 166 const AtomicString& nameAttrVal = element->getNameAttribute(); | 166 const AtomicString& nameAttrVal = element->getNameAttribute(); |
| 167 if (!idAttrVal.isEmpty()) { | 167 if (!idAttrVal.isEmpty()) { |
| 168 cache->addElementWithId(idAttrVal, element); | 168 cache->addElementWithId(idAttrVal, element); |
| 169 foundInputElements.add(idAttrVal.impl()); | 169 foundInputElements.add(idAttrVal.impl()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 const AtomicString& nameAttribute = element->getNameAttribute(); | 231 const AtomicString& nameAttribute = element->getNameAttribute(); |
| 232 if (!nameAttribute.isEmpty()) { | 232 if (!nameAttribute.isEmpty()) { |
| 233 HashSet<AtomicString>::AddResult addResult = existingNames.add(nameA
ttribute); | 233 HashSet<AtomicString>::AddResult addResult = existingNames.add(nameA
ttribute); |
| 234 if (addResult.isNewEntry) | 234 if (addResult.isNewEntry) |
| 235 names.append(nameAttribute); | 235 names.append(nameAttribute); |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 | 239 |
| 240 } | 240 } |
| OLD | NEW |