| 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 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 namespace WebCore { | 31 namespace WebCore { |
| 32 | 32 |
| 33 using namespace HTMLNames; | 33 using namespace HTMLNames; |
| 34 | 34 |
| 35 // Since the collections are to be "live", we have to do the | 35 // Since the collections are to be "live", we have to do the |
| 36 // calculation every time if anything has changed. | 36 // calculation every time if anything has changed. |
| 37 | 37 |
| 38 HTMLFormControlsCollection::HTMLFormControlsCollection(Node* ownerNode) | 38 HTMLFormControlsCollection::HTMLFormControlsCollection(Node* ownerNode) |
| 39 : HTMLCollection(ownerNode, FormControls, OverridesItemAfter) | 39 : HTMLCollection(ownerNode, FormControls, OverridesItemAfter) |
| 40 , m_cachedElement(0) |
| 41 , m_cachedElementOffsetInArray(0) |
| 40 { | 42 { |
| 41 ASSERT(ownerNode->hasTagName(formTag) || ownerNode->hasTagName(fieldsetTag))
; | 43 ASSERT(ownerNode->hasTagName(formTag) || ownerNode->hasTagName(fieldsetTag))
; |
| 42 ScriptWrappable::init(this); | 44 ScriptWrappable::init(this); |
| 43 } | 45 } |
| 44 | 46 |
| 45 PassRefPtr<HTMLFormControlsCollection> HTMLFormControlsCollection::create(Node*
ownerNode, CollectionType) | 47 PassRefPtr<HTMLFormControlsCollection> HTMLFormControlsCollection::create(Node*
ownerNode, CollectionType) |
| 46 { | 48 { |
| 47 return adoptRef(new HTMLFormControlsCollection(ownerNode)); | 49 return adoptRef(new HTMLFormControlsCollection(ownerNode)); |
| 48 } | 50 } |
| 49 | 51 |
| 50 HTMLFormControlsCollection::~HTMLFormControlsCollection() | 52 HTMLFormControlsCollection::~HTMLFormControlsCollection() |
| 51 { | 53 { |
| 52 } | 54 } |
| 53 | 55 |
| 54 const Vector<FormAssociatedElement*>& HTMLFormControlsCollection::formControlEle
ments() const | 56 const Vector<FormAssociatedElement*>& HTMLFormControlsCollection::formControlEle
ments() const |
| 55 { | 57 { |
| 56 ASSERT(ownerNode()); | 58 ASSERT(ownerNode()); |
| 57 ASSERT(ownerNode()->hasTagName(formTag) || ownerNode()->hasTagName(fieldsetT
ag)); | 59 ASSERT(ownerNode()->hasTagName(formTag) || ownerNode()->hasTagName(fieldsetT
ag)); |
| 58 if (ownerNode()->hasTagName(formTag)) | 60 if (ownerNode()->hasTagName(formTag)) |
| 59 return toHTMLFormElement(ownerNode())->associatedElements(); | 61 return toHTMLFormElement(ownerNode())->associatedElements(); |
| 60 return toHTMLFieldSetElement(ownerNode())->associatedElements(); | 62 return toHTMLFieldSetElement(ownerNode())->associatedElements(); |
| 61 } | 63 } |
| 62 | 64 |
| 63 const Vector<HTMLImageElement*>& HTMLFormControlsCollection::formImageElements()
const | 65 const Vector<HTMLImageElement*>& HTMLFormControlsCollection::formImageElements()
const |
| 64 { | 66 { |
| 65 ASSERT(ownerNode()); | 67 ASSERT(ownerNode()); |
| 66 return toHTMLFormElement(ownerNode())->imageElements(); | 68 return toHTMLFormElement(ownerNode())->imageElements(); |
| 67 } | 69 } |
| 68 | 70 |
| 69 Element* HTMLFormControlsCollection::virtualItemAfter(unsigned& offset, Element*
previousItem) const | 71 static unsigned findFormAssociatedElement(const Vector<FormAssociatedElement*>&
associatedElements, Element* element) |
| 70 { | 72 { |
| 71 const Vector<FormAssociatedElement*>& elementsArray = formControlElements(); | 73 unsigned i = 0; |
| 72 if (previousItem) | 74 for (; i < associatedElements.size(); ++i) { |
| 73 offset++; | 75 FormAssociatedElement* associatedElement = associatedElements[i]; |
| 74 while (offset < elementsArray.size()) { | 76 if (associatedElement->isEnumeratable() && toHTMLElement(associatedEleme
nt) == element) |
| 75 FormAssociatedElement* element = elementsArray[offset]; | 77 break; |
| 76 if (element->isEnumeratable()) | 78 } |
| 77 return toHTMLElement(element); | 79 return i; |
| 78 offset++; | 80 } |
| 81 |
| 82 Element* HTMLFormControlsCollection::virtualItemAfter(Element* previous) const |
| 83 { |
| 84 const Vector<FormAssociatedElement*>& associatedElements = formControlElemen
ts(); |
| 85 unsigned offset; |
| 86 if (!previous) |
| 87 offset = 0; |
| 88 else if (m_cachedElement == previous) |
| 89 offset = m_cachedElementOffsetInArray + 1; |
| 90 else |
| 91 offset = findFormAssociatedElement(associatedElements, previous) + 1; |
| 92 |
| 93 for (unsigned i = offset; i < associatedElements.size(); ++i) { |
| 94 FormAssociatedElement* associatedElement = associatedElements[i]; |
| 95 if (associatedElement->isEnumeratable()) { |
| 96 m_cachedElement = toHTMLElement(associatedElement); |
| 97 m_cachedElementOffsetInArray = i; |
| 98 return m_cachedElement; |
| 99 } |
| 79 } | 100 } |
| 80 return 0; | 101 return 0; |
| 81 } | 102 } |
| 82 | 103 |
| 104 void HTMLFormControlsCollection::invalidateCache() const |
| 105 { |
| 106 HTMLCollection::invalidateCache(); |
| 107 m_cachedElement = 0; |
| 108 m_cachedElementOffsetInArray = 0; |
| 109 } |
| 110 |
| 83 static HTMLElement* firstNamedItem(const Vector<FormAssociatedElement*>& element
sArray, | 111 static HTMLElement* firstNamedItem(const Vector<FormAssociatedElement*>& element
sArray, |
| 84 const Vector<HTMLImageElement*>* imageElementsArray, const QualifiedName& at
trName, const String& name) | 112 const Vector<HTMLImageElement*>* imageElementsArray, const QualifiedName& at
trName, const String& name) |
| 85 { | 113 { |
| 86 ASSERT(attrName == idAttr || attrName == nameAttr); | 114 ASSERT(attrName == idAttr || attrName == nameAttr); |
| 87 | 115 |
| 88 for (unsigned i = 0; i < elementsArray.size(); ++i) { | 116 for (unsigned i = 0; i < elementsArray.size(); ++i) { |
| 89 HTMLElement* element = toHTMLElement(elementsArray[i]); | 117 HTMLElement* element = toHTMLElement(elementsArray[i]); |
| 90 if (elementsArray[i]->isEnumeratable() && element->fastGetAttribute(attr
Name) == name) | 118 if (elementsArray[i]->isEnumeratable() && element->fastGetAttribute(attr
Name) == name) |
| 91 return element; | 119 return element; |
| 92 } | 120 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 returnValue1Enabled = true; | 199 returnValue1Enabled = true; |
| 172 returnValue1 = namedItems.at(0); | 200 returnValue1 = namedItems.at(0); |
| 173 return; | 201 return; |
| 174 } | 202 } |
| 175 | 203 |
| 176 returnValue0Enabled = true; | 204 returnValue0Enabled = true; |
| 177 returnValue0 = this->ownerNode()->radioNodeList(name); | 205 returnValue0 = this->ownerNode()->radioNodeList(name); |
| 178 } | 206 } |
| 179 | 207 |
| 180 } | 208 } |
| OLD | NEW |