OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2011, 2012 Apple Computer, Inc. | 2 * Copyright (C) 2006, 2011, 2012 Apple Computer, Inc. |
| 3 * Copyright (C) 2014 Samsung Electronics. All rights reserved. |
3 * | 4 * |
4 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
8 * | 9 * |
9 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 13 * Library General Public License for more details. |
(...skipping 17 matching lines...) Expand all Loading... |
30 | 31 |
31 namespace WebCore { | 32 namespace WebCore { |
32 | 33 |
33 HTMLOptionsCollection::HTMLOptionsCollection(ContainerNode* select) | 34 HTMLOptionsCollection::HTMLOptionsCollection(ContainerNode* select) |
34 : HTMLCollection(select, SelectOptions, DoesNotOverrideItemAfter) | 35 : HTMLCollection(select, SelectOptions, DoesNotOverrideItemAfter) |
35 { | 36 { |
36 ASSERT(select->hasTagName(HTMLNames::selectTag)); | 37 ASSERT(select->hasTagName(HTMLNames::selectTag)); |
37 ScriptWrappable::init(this); | 38 ScriptWrappable::init(this); |
38 } | 39 } |
39 | 40 |
| 41 void HTMLOptionsCollection::supportedPropertyNames(Vector<String>& names) |
| 42 { |
| 43 // As per http://www.whatwg.org/specs/web-apps/current-work/multipage/common
-dom-interfaces.html#htmloptionscollection: |
| 44 // The supported property names consist of the non-empty values of all the i
d and name attributes of all the elements |
| 45 // represented by the collection, in tree order, ignoring later duplicates,
with the id of an element preceding its |
| 46 // name if it contributes both, they differ from each other, and neither is
the duplicate of an earlier entry. |
| 47 HashSet<AtomicString> existingNames; |
| 48 unsigned length = this->length(); |
| 49 for (unsigned i = 0; i < length; ++i) { |
| 50 Element* element = item(i); |
| 51 ASSERT(element); |
| 52 const AtomicString& idAttribute = element->getIdAttribute(); |
| 53 if (!idAttribute.isEmpty()) { |
| 54 HashSet<AtomicString>::AddResult addResult = existingNames.add(idAtt
ribute); |
| 55 if (addResult.isNewEntry) |
| 56 names.append(idAttribute); |
| 57 } |
| 58 const AtomicString& nameAttribute = element->getNameAttribute(); |
| 59 if (!nameAttribute.isEmpty()) { |
| 60 HashSet<AtomicString>::AddResult addResult = existingNames.add(nameA
ttribute); |
| 61 if (addResult.isNewEntry) |
| 62 names.append(nameAttribute); |
| 63 } |
| 64 } |
| 65 } |
| 66 |
40 PassRefPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(ContainerNode* s
elect, CollectionType) | 67 PassRefPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(ContainerNode* s
elect, CollectionType) |
41 { | 68 { |
42 return adoptRef(new HTMLOptionsCollection(select)); | 69 return adoptRef(new HTMLOptionsCollection(select)); |
43 } | 70 } |
44 | 71 |
45 void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, Exception
State& exceptionState) | 72 void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, Exception
State& exceptionState) |
46 { | 73 { |
47 add(element, length(), exceptionState); | 74 add(element, length(), exceptionState); |
48 } | 75 } |
49 | 76 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 void HTMLOptionsCollection::setSelectedIndex(int index) | 116 void HTMLOptionsCollection::setSelectedIndex(int index) |
90 { | 117 { |
91 toHTMLSelectElement(ownerNode())->setSelectedIndex(index); | 118 toHTMLSelectElement(ownerNode())->setSelectedIndex(index); |
92 } | 119 } |
93 | 120 |
94 void HTMLOptionsCollection::setLength(unsigned length, ExceptionState& exception
State) | 121 void HTMLOptionsCollection::setLength(unsigned length, ExceptionState& exception
State) |
95 { | 122 { |
96 toHTMLSelectElement(ownerNode())->setLength(length, exceptionState); | 123 toHTMLSelectElement(ownerNode())->setLength(length, exceptionState); |
97 } | 124 } |
98 | 125 |
99 void HTMLOptionsCollection::anonymousNamedGetter(const AtomicString& name, bool&
returnValue0Enabled, RefPtr<NodeList>& returnValue0, bool& returnValue1Enabled,
RefPtr<Element>& returnValue1) | 126 void HTMLOptionsCollection::namedGetter(const AtomicString& name, bool& returnVa
lue0Enabled, RefPtr<NodeList>& returnValue0, bool& returnValue1Enabled, RefPtr<E
lement>& returnValue1) |
100 { | 127 { |
101 Vector<RefPtr<Element> > namedItems; | 128 Vector<RefPtr<Element> > namedItems; |
102 this->namedItems(name, namedItems); | 129 this->namedItems(name, namedItems); |
103 | 130 |
104 if (!namedItems.size()) | 131 if (!namedItems.size()) |
105 return; | 132 return; |
106 | 133 |
107 if (namedItems.size() == 1) { | 134 if (namedItems.size() == 1) { |
108 returnValue1Enabled = true; | 135 returnValue1Enabled = true; |
109 returnValue1 = namedItems.at(0); | 136 returnValue1 = namedItems.at(0); |
110 return; | 137 return; |
111 } | 138 } |
112 | 139 |
| 140 // FIXME: The spec and Firefox do not return a NodeList. They always return
the first matching Element. |
113 returnValue0Enabled = true; | 141 returnValue0Enabled = true; |
114 returnValue0 = NamedNodesCollection::create(namedItems); | 142 returnValue0 = NamedNodesCollection::create(namedItems); |
115 } | 143 } |
116 | 144 |
117 bool HTMLOptionsCollection::anonymousIndexedSetter(unsigned index, PassRefPtr<HT
MLOptionElement> value, ExceptionState& exceptionState) | 145 bool HTMLOptionsCollection::anonymousIndexedSetter(unsigned index, PassRefPtr<HT
MLOptionElement> value, ExceptionState& exceptionState) |
118 { | 146 { |
119 HTMLSelectElement* base = toHTMLSelectElement(ownerNode()); | 147 HTMLSelectElement* base = toHTMLSelectElement(ownerNode()); |
120 if (!value) { // undefined or null | 148 if (!value) { // undefined or null |
121 base->remove(index); | 149 base->remove(index); |
122 return true; | 150 return true; |
123 } | 151 } |
124 base->setOption(index, value.get(), exceptionState); | 152 base->setOption(index, value.get(), exceptionState); |
125 return true; | 153 return true; |
126 } | 154 } |
127 | 155 |
128 } //namespace | 156 } //namespace |
129 | 157 |
OLD | NEW |