Chromium Code Reviews| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 | 48 |
| 49 HTMLFormControlsCollection* HTMLFormControlsCollection::create( | 49 HTMLFormControlsCollection* HTMLFormControlsCollection::create( |
| 50 ContainerNode& ownerNode, | 50 ContainerNode& ownerNode, |
| 51 CollectionType type) { | 51 CollectionType type) { |
| 52 DCHECK_EQ(type, FormControls); | 52 DCHECK_EQ(type, FormControls); |
| 53 return new HTMLFormControlsCollection(ownerNode); | 53 return new HTMLFormControlsCollection(ownerNode); |
| 54 } | 54 } |
| 55 | 55 |
| 56 HTMLFormControlsCollection::~HTMLFormControlsCollection() {} | 56 HTMLFormControlsCollection::~HTMLFormControlsCollection() {} |
| 57 | 57 |
| 58 const FormAssociatedElement::List& | 58 const ListedElement::List& HTMLFormControlsCollection::formControlElements() |
| 59 HTMLFormControlsCollection::formControlElements() const { | 59 const { |
| 60 DCHECK(isHTMLFormElement(ownerNode()) || isHTMLFieldSetElement(ownerNode())); | 60 DCHECK(isHTMLFormElement(ownerNode()) || isHTMLFieldSetElement(ownerNode())); |
| 61 if (isHTMLFormElement(ownerNode())) | 61 if (isHTMLFormElement(ownerNode())) |
| 62 return toHTMLFormElement(ownerNode()).associatedElements(); | 62 return toHTMLFormElement(ownerNode()).associatedElements(); |
| 63 return toHTMLFieldSetElement(ownerNode()).associatedElements(); | 63 return toHTMLFieldSetElement(ownerNode()).associatedElements(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 const HeapVector<Member<HTMLImageElement>>& | 66 const HeapVector<Member<HTMLImageElement>>& |
| 67 HTMLFormControlsCollection::formImageElements() const { | 67 HTMLFormControlsCollection::formImageElements() const { |
| 68 return toHTMLFormElement(ownerNode()).imageElements(); | 68 return toHTMLFormElement(ownerNode()).imageElements(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 static unsigned findFormAssociatedElement( | 71 static unsigned findListedElement(const ListedElement::List& associatedElements, |
| 72 const FormAssociatedElement::List& associatedElements, | 72 Element* element) { |
| 73 Element* element) { | |
| 74 unsigned i = 0; | 73 unsigned i = 0; |
| 75 for (; i < associatedElements.size(); ++i) { | 74 for (; i < associatedElements.size(); ++i) { |
| 76 FormAssociatedElement* associatedElement = associatedElements[i]; | 75 ListedElement* associatedElement = associatedElements[i]; |
| 77 if (associatedElement->isEnumeratable() && | 76 if (associatedElement->isEnumeratable() && |
| 78 toHTMLElement(associatedElement) == element) | 77 toHTMLElement(associatedElement) == element) |
| 79 break; | 78 break; |
| 80 } | 79 } |
| 81 return i; | 80 return i; |
| 82 } | 81 } |
| 83 | 82 |
| 84 HTMLElement* HTMLFormControlsCollection::virtualItemAfter( | 83 HTMLElement* HTMLFormControlsCollection::virtualItemAfter( |
| 85 Element* previous) const { | 84 Element* previous) const { |
| 86 const FormAssociatedElement::List& associatedElements = formControlElements(); | 85 const ListedElement::List& associatedElements = formControlElements(); |
|
tkent
2016/12/02 13:24:37
Rename this variable to listedElements.
| |
| 87 unsigned offset; | 86 unsigned offset; |
| 88 if (!previous) | 87 if (!previous) |
| 89 offset = 0; | 88 offset = 0; |
| 90 else if (m_cachedElement == previous) | 89 else if (m_cachedElement == previous) |
| 91 offset = m_cachedElementOffsetInArray + 1; | 90 offset = m_cachedElementOffsetInArray + 1; |
| 92 else | 91 else |
| 93 offset = findFormAssociatedElement(associatedElements, previous) + 1; | 92 offset = findListedElement(associatedElements, previous) + 1; |
| 94 | 93 |
| 95 for (unsigned i = offset; i < associatedElements.size(); ++i) { | 94 for (unsigned i = offset; i < associatedElements.size(); ++i) { |
| 96 FormAssociatedElement* associatedElement = associatedElements[i]; | 95 ListedElement* associatedElement = associatedElements[i]; |
| 97 if (associatedElement->isEnumeratable()) { | 96 if (associatedElement->isEnumeratable()) { |
| 98 m_cachedElement = toHTMLElement(associatedElement); | 97 m_cachedElement = toHTMLElement(associatedElement); |
| 99 m_cachedElementOffsetInArray = i; | 98 m_cachedElementOffsetInArray = i; |
| 100 return m_cachedElement; | 99 return m_cachedElement; |
| 101 } | 100 } |
| 102 } | 101 } |
| 103 return nullptr; | 102 return nullptr; |
| 104 } | 103 } |
| 105 | 104 |
| 106 void HTMLFormControlsCollection::invalidateCache(Document* oldDocument) const { | 105 void HTMLFormControlsCollection::invalidateCache(Document* oldDocument) const { |
| 107 HTMLCollection::invalidateCache(oldDocument); | 106 HTMLCollection::invalidateCache(oldDocument); |
| 108 m_cachedElement = nullptr; | 107 m_cachedElement = nullptr; |
| 109 m_cachedElementOffsetInArray = 0; | 108 m_cachedElementOffsetInArray = 0; |
| 110 } | 109 } |
| 111 | 110 |
| 112 static HTMLElement* firstNamedItem( | 111 static HTMLElement* firstNamedItem(const ListedElement::List& elementsArray, |
| 113 const FormAssociatedElement::List& elementsArray, | 112 const QualifiedName& attrName, |
| 114 const QualifiedName& attrName, | 113 const String& name) { |
| 115 const String& name) { | |
| 116 DCHECK(attrName == idAttr || attrName == nameAttr); | 114 DCHECK(attrName == idAttr || attrName == nameAttr); |
| 117 | 115 |
| 118 for (unsigned i = 0; i < elementsArray.size(); ++i) { | 116 for (unsigned i = 0; i < elementsArray.size(); ++i) { |
| 119 HTMLElement* element = toHTMLElement(elementsArray[i]); | 117 HTMLElement* element = toHTMLElement(elementsArray[i]); |
| 120 if (elementsArray[i]->isEnumeratable() && | 118 if (elementsArray[i]->isEnumeratable() && |
| 121 element->fastGetAttribute(attrName) == name) | 119 element->fastGetAttribute(attrName) == name) |
| 122 return element; | 120 return element; |
| 123 } | 121 } |
| 124 return nullptr; | 122 return nullptr; |
| 125 } | 123 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 136 return firstNamedItem(formControlElements(), nameAttr, name); | 134 return firstNamedItem(formControlElements(), nameAttr, name); |
| 137 } | 135 } |
| 138 | 136 |
| 139 void HTMLFormControlsCollection::updateIdNameCache() const { | 137 void HTMLFormControlsCollection::updateIdNameCache() const { |
| 140 if (hasValidIdNameCache()) | 138 if (hasValidIdNameCache()) |
| 141 return; | 139 return; |
| 142 | 140 |
| 143 NamedItemCache* cache = NamedItemCache::create(); | 141 NamedItemCache* cache = NamedItemCache::create(); |
| 144 HashSet<StringImpl*> foundInputElements; | 142 HashSet<StringImpl*> foundInputElements; |
| 145 | 143 |
| 146 const FormAssociatedElement::List& elementsArray = formControlElements(); | 144 const ListedElement::List& elementsArray = formControlElements(); |
| 147 | 145 |
| 148 for (unsigned i = 0; i < elementsArray.size(); ++i) { | 146 for (unsigned i = 0; i < elementsArray.size(); ++i) { |
| 149 FormAssociatedElement* associatedElement = elementsArray[i]; | 147 ListedElement* associatedElement = elementsArray[i]; |
|
tkent
2016/12/02 13:24:37
Rename this variable to listedElement.
| |
| 150 if (associatedElement->isEnumeratable()) { | 148 if (associatedElement->isEnumeratable()) { |
| 151 HTMLElement* element = toHTMLElement(associatedElement); | 149 HTMLElement* element = toHTMLElement(associatedElement); |
| 152 const AtomicString& idAttrVal = element->getIdAttribute(); | 150 const AtomicString& idAttrVal = element->getIdAttribute(); |
| 153 const AtomicString& nameAttrVal = element->getNameAttribute(); | 151 const AtomicString& nameAttrVal = element->getNameAttribute(); |
| 154 if (!idAttrVal.isEmpty()) { | 152 if (!idAttrVal.isEmpty()) { |
| 155 cache->addElementWithId(idAttrVal, element); | 153 cache->addElementWithId(idAttrVal, element); |
| 156 foundInputElements.add(idAttrVal.impl()); | 154 foundInputElements.add(idAttrVal.impl()); |
| 157 } | 155 } |
| 158 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { | 156 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal) { |
| 159 cache->addElementWithName(nameAttrVal, element); | 157 cache->addElementWithName(nameAttrVal, element); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 } | 236 } |
| 239 } | 237 } |
| 240 } | 238 } |
| 241 | 239 |
| 242 DEFINE_TRACE(HTMLFormControlsCollection) { | 240 DEFINE_TRACE(HTMLFormControlsCollection) { |
| 243 visitor->trace(m_cachedElement); | 241 visitor->trace(m_cachedElement); |
| 244 HTMLCollection::trace(visitor); | 242 HTMLCollection::trace(visitor); |
| 245 } | 243 } |
| 246 | 244 |
| 247 } // namespace blink | 245 } // namespace blink |
| OLD | NEW |