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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 HTMLFormControlsCollection* HTMLFormControlsCollection::create( | 48 HTMLFormControlsCollection* HTMLFormControlsCollection::create( |
49 ContainerNode& ownerNode, | 49 ContainerNode& ownerNode, |
50 CollectionType type) { | 50 CollectionType type) { |
51 DCHECK_EQ(type, FormControls); | 51 DCHECK_EQ(type, FormControls); |
52 return new HTMLFormControlsCollection(ownerNode); | 52 return new HTMLFormControlsCollection(ownerNode); |
53 } | 53 } |
54 | 54 |
55 HTMLFormControlsCollection::~HTMLFormControlsCollection() {} | 55 HTMLFormControlsCollection::~HTMLFormControlsCollection() {} |
56 | 56 |
57 const FormAssociatedElement::List& | 57 const ListedElement::List& HTMLFormControlsCollection::listedElements() const { |
58 HTMLFormControlsCollection::formControlElements() const { | 58 return toHTMLFormElement(ownerNode()).listedElements(); |
59 return toHTMLFormElement(ownerNode()).associatedElements(); | |
60 } | 59 } |
61 | 60 |
62 const HeapVector<Member<HTMLImageElement>>& | 61 const HeapVector<Member<HTMLImageElement>>& |
63 HTMLFormControlsCollection::formImageElements() const { | 62 HTMLFormControlsCollection::formImageElements() const { |
64 return toHTMLFormElement(ownerNode()).imageElements(); | 63 return toHTMLFormElement(ownerNode()).imageElements(); |
65 } | 64 } |
66 | 65 |
67 static unsigned findFormAssociatedElement( | 66 static unsigned findListedElement(const ListedElement::List& listedElements, |
68 const FormAssociatedElement::List& associatedElements, | 67 Element* element) { |
69 Element* element) { | |
70 unsigned i = 0; | 68 unsigned i = 0; |
71 for (; i < associatedElements.size(); ++i) { | 69 for (; i < listedElements.size(); ++i) { |
72 FormAssociatedElement* associatedElement = associatedElements[i]; | 70 ListedElement* listedElement = listedElements[i]; |
73 if (associatedElement->isEnumeratable() && | 71 if (listedElement->isEnumeratable() && |
74 toHTMLElement(associatedElement) == element) | 72 toHTMLElement(listedElement) == element) |
75 break; | 73 break; |
76 } | 74 } |
77 return i; | 75 return i; |
78 } | 76 } |
79 | 77 |
80 HTMLElement* HTMLFormControlsCollection::virtualItemAfter( | 78 HTMLElement* HTMLFormControlsCollection::virtualItemAfter( |
81 Element* previous) const { | 79 Element* previous) const { |
82 const FormAssociatedElement::List& associatedElements = formControlElements(); | 80 const ListedElement::List& listedElements = this->listedElements(); |
83 unsigned offset; | 81 unsigned offset; |
84 if (!previous) | 82 if (!previous) |
85 offset = 0; | 83 offset = 0; |
86 else if (m_cachedElement == previous) | 84 else if (m_cachedElement == previous) |
87 offset = m_cachedElementOffsetInArray + 1; | 85 offset = m_cachedElementOffsetInArray + 1; |
88 else | 86 else |
89 offset = findFormAssociatedElement(associatedElements, previous) + 1; | 87 offset = findListedElement(listedElements, previous) + 1; |
90 | 88 |
91 for (unsigned i = offset; i < associatedElements.size(); ++i) { | 89 for (unsigned i = offset; i < listedElements.size(); ++i) { |
92 FormAssociatedElement* associatedElement = associatedElements[i]; | 90 ListedElement* listedElement = listedElements[i]; |
93 if (associatedElement->isEnumeratable()) { | 91 if (listedElement->isEnumeratable()) { |
94 m_cachedElement = toHTMLElement(associatedElement); | 92 m_cachedElement = toHTMLElement(listedElement); |
95 m_cachedElementOffsetInArray = i; | 93 m_cachedElementOffsetInArray = i; |
96 return m_cachedElement; | 94 return m_cachedElement; |
97 } | 95 } |
98 } | 96 } |
99 return nullptr; | 97 return nullptr; |
100 } | 98 } |
101 | 99 |
102 void HTMLFormControlsCollection::invalidateCache(Document* oldDocument) const { | 100 void HTMLFormControlsCollection::invalidateCache(Document* oldDocument) const { |
103 HTMLCollection::invalidateCache(oldDocument); | 101 HTMLCollection::invalidateCache(oldDocument); |
104 m_cachedElement = nullptr; | 102 m_cachedElement = nullptr; |
105 m_cachedElementOffsetInArray = 0; | 103 m_cachedElementOffsetInArray = 0; |
106 } | 104 } |
107 | 105 |
108 static HTMLElement* firstNamedItem( | 106 static HTMLElement* firstNamedItem(const ListedElement::List& elementsArray, |
109 const FormAssociatedElement::List& elementsArray, | 107 const QualifiedName& attrName, |
110 const QualifiedName& attrName, | 108 const String& name) { |
111 const String& name) { | |
112 DCHECK(attrName == idAttr || attrName == nameAttr); | 109 DCHECK(attrName == idAttr || attrName == nameAttr); |
113 | 110 |
114 for (unsigned i = 0; i < elementsArray.size(); ++i) { | 111 for (unsigned i = 0; i < elementsArray.size(); ++i) { |
115 HTMLElement* element = toHTMLElement(elementsArray[i]); | 112 HTMLElement* element = toHTMLElement(elementsArray[i]); |
116 if (elementsArray[i]->isEnumeratable() && | 113 if (elementsArray[i]->isEnumeratable() && |
117 element->fastGetAttribute(attrName) == name) | 114 element->fastGetAttribute(attrName) == name) |
118 return element; | 115 return element; |
119 } | 116 } |
120 return nullptr; | 117 return nullptr; |
121 } | 118 } |
122 | 119 |
123 HTMLElement* HTMLFormControlsCollection::namedItem( | 120 HTMLElement* HTMLFormControlsCollection::namedItem( |
124 const AtomicString& name) const { | 121 const AtomicString& name) const { |
125 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/nameditem
.asp | 122 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/nameditem
.asp |
126 // This method first searches for an object with a matching id | 123 // This method first searches for an object with a matching id |
127 // 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 |
128 // object with a matching name attribute, but only on those elements | 125 // object with a matching name attribute, but only on those elements |
129 // that are allowed a name attribute. | 126 // that are allowed a name attribute. |
130 if (HTMLElement* item = firstNamedItem(formControlElements(), idAttr, name)) | 127 if (HTMLElement* item = firstNamedItem(listedElements(), idAttr, name)) |
131 return item; | 128 return item; |
132 return firstNamedItem(formControlElements(), nameAttr, name); | 129 return firstNamedItem(listedElements(), nameAttr, name); |
133 } | 130 } |
134 | 131 |
135 void HTMLFormControlsCollection::updateIdNameCache() const { | 132 void HTMLFormControlsCollection::updateIdNameCache() const { |
136 if (hasValidIdNameCache()) | 133 if (hasValidIdNameCache()) |
137 return; | 134 return; |
138 | 135 |
139 NamedItemCache* cache = NamedItemCache::create(); | 136 NamedItemCache* cache = NamedItemCache::create(); |
140 HashSet<StringImpl*> foundInputElements; | 137 HashSet<StringImpl*> foundInputElements; |
141 | 138 |
142 const FormAssociatedElement::List& elementsArray = formControlElements(); | 139 const ListedElement::List& elementsArray = listedElements(); |
143 | 140 |
144 for (unsigned i = 0; i < elementsArray.size(); ++i) { | 141 for (unsigned i = 0; i < elementsArray.size(); ++i) { |
145 FormAssociatedElement* associatedElement = elementsArray[i]; | 142 ListedElement* listedElement = elementsArray[i]; |
146 if (associatedElement->isEnumeratable()) { | 143 if (listedElement->isEnumeratable()) { |
147 HTMLElement* element = toHTMLElement(associatedElement); | 144 HTMLElement* element = toHTMLElement(listedElement); |
148 const AtomicString& idAttrVal = element->getIdAttribute(); | 145 const AtomicString& idAttrVal = element->getIdAttribute(); |
149 const AtomicString& nameAttrVal = element->getNameAttribute(); | 146 const AtomicString& nameAttrVal = element->getNameAttribute(); |
150 if (!idAttrVal.isEmpty()) { | 147 if (!idAttrVal.isEmpty()) { |
151 cache->addElementWithId(idAttrVal, element); | 148 cache->addElementWithId(idAttrVal, element); |
152 foundInputElements.add(idAttrVal.impl()); | 149 foundInputElements.add(idAttrVal.impl()); |
153 } | 150 } |
154 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { | 151 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { |
155 cache->addElementWithName(nameAttrVal, element); | 152 cache->addElementWithName(nameAttrVal, element); |
156 foundInputElements.add(nameAttrVal.impl()); | 153 foundInputElements.add(nameAttrVal.impl()); |
157 } | 154 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } | 224 } |
228 } | 225 } |
229 } | 226 } |
230 | 227 |
231 DEFINE_TRACE(HTMLFormControlsCollection) { | 228 DEFINE_TRACE(HTMLFormControlsCollection) { |
232 visitor->trace(m_cachedElement); | 229 visitor->trace(m_cachedElement); |
233 HTMLCollection::trace(visitor); | 230 HTMLCollection::trace(visitor); |
234 } | 231 } |
235 | 232 |
236 } // namespace blink | 233 } // namespace blink |
OLD | NEW |