Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(893)

Side by Side Diff: Source/core/html/HTMLFormControlsCollection.cpp

Issue 157013006: Update HTMLFormControlsCollection's named getter to behave according to spec (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove legacycaller Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 * Copyright (C) 2014 Samsung Electronics. All rights reserved.
5 * 6 *
6 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
10 * 11 *
11 * This library is distributed in the hope that it will be useful, 12 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 15 * Library General Public License for more details.
15 * 16 *
16 * You should have received a copy of the GNU Library General Public License 17 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to 18 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 20 * Boston, MA 02110-1301, USA.
20 * 21 *
21 */ 22 */
22 23
23 #include "config.h" 24 #include "config.h"
24 #include "core/html/HTMLFormControlsCollection.h" 25 #include "core/html/HTMLFormControlsCollection.h"
25 26
26 #include "HTMLNames.h" 27 #include "HTMLNames.h"
27 #include "core/frame/UseCounter.h" 28 #include "core/frame/UseCounter.h"
28 #include "core/html/HTMLFieldSetElement.h" 29 #include "core/html/HTMLFieldSetElement.h"
29 #include "core/html/HTMLFormElement.h" 30 #include "core/html/HTMLFormElement.h"
30 #include "core/html/HTMLImageElement.h" 31 #include "core/html/HTMLImageElement.h"
32 #include "wtf/HashSet.h"
31 33
32 namespace WebCore { 34 namespace WebCore {
33 35
34 using namespace HTMLNames; 36 using namespace HTMLNames;
35 37
36 // Since the collections are to be "live", we have to do the 38 // Since the collections are to be "live", we have to do the
37 // calculation every time if anything has changed. 39 // calculation every time if anything has changed.
38 40
39 HTMLFormControlsCollection::HTMLFormControlsCollection(ContainerNode* ownerNode) 41 HTMLFormControlsCollection::HTMLFormControlsCollection(ContainerNode* ownerNode)
40 : HTMLCollection(ownerNode, FormControls, OverridesItemAfter) 42 : HTMLCollection(ownerNode, FormControls, OverridesItemAfter)
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.i mpl())) 185 if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.i mpl()))
184 appendIdCache(idAttrVal, element); 186 appendIdCache(idAttrVal, element);
185 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInpu tElements.contains(nameAttrVal.impl())) 187 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && !foundInpu tElements.contains(nameAttrVal.impl()))
186 appendNameCache(nameAttrVal, element); 188 appendNameCache(nameAttrVal, element);
187 } 189 }
188 } 190 }
189 191
190 setHasNameCache(); 192 setHasNameCache();
191 } 193 }
192 194
193 void HTMLFormControlsCollection::namedGetter(const AtomicString& name, bool& ret urnValue0Enabled, RefPtr<RadioNodeList>& returnValue0, bool& returnValue1Enabled , RefPtr<Element>& returnValue1) 195 void HTMLFormControlsCollection::namedGetter(const AtomicString& name, bool& rad ioNodeListEnabled, RefPtr<RadioNodeList>& radioNodeList, bool& elementEnabled, R efPtr<Element>& element)
194 { 196 {
195 Vector<RefPtr<Element> > namedItems; 197 Vector<RefPtr<Element> > namedItems;
196 this->namedItems(name, namedItems); 198 this->namedItems(name, namedItems);
197 199
198 if (!namedItems.size()) 200 if (namedItems.isEmpty())
199 return; 201 return;
200 202
201 if (namedItems.size() == 1) { 203 if (namedItems.size() == 1) {
202 returnValue1Enabled = true; 204 elementEnabled = true;
203 returnValue1 = namedItems.at(0); 205 element = namedItems.first();
204 return; 206 return;
205 } 207 }
206 208
207 returnValue0Enabled = true; 209 radioNodeListEnabled = true;
208 returnValue0 = this->ownerNode()->radioNodeList(name); 210 radioNodeList = ownerNode()->radioNodeList(name);
211 }
212
213 void HTMLFormControlsCollection::supportedPropertyNames(Vector<String>& names)
214 {
215 // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-in terfaces.html#htmlformcontrolscollection-0:
216 // The supported property names consist of the non-empty values of all the i d and name attributes
217 // of all the elements represented by the collection, in tree order, ignorin g later duplicates,
218 // with the id of an element preceding its name if it contributes both, they differ from each
219 // other, and neither is the duplicate of an earlier entry.
220 HashSet<AtomicString> existingNames;
221 unsigned length = this->length();
222 for (unsigned i = 0; i < length; ++i) {
223 Element* element = item(i);
224 ASSERT(element);
225 const AtomicString& idAttribute = element->getIdAttribute();
226 if (!idAttribute.isEmpty()) {
227 HashSet<AtomicString>::AddResult addResult = existingNames.add(idAtt ribute);
228 if (addResult.isNewEntry)
229 names.append(idAttribute);
230 }
231 const AtomicString& nameAttribute = element->getNameAttribute();
232 if (!nameAttribute.isEmpty()) {
233 HashSet<AtomicString>::AddResult addResult = existingNames.add(nameA ttribute);
234 if (addResult.isNewEntry)
235 names.append(nameAttribute);
236 }
237 }
209 } 238 }
210 239
211 } 240 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLFormControlsCollection.h ('k') | Source/core/html/HTMLFormControlsCollection.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698