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