diff options
author | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-15 18:07:56 +0000 |
---|---|---|
committer | davemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-15 18:07:56 +0000 |
commit | 8aa31e5bb274abd6f5eb43e6297e00cf6d365856 (patch) | |
tree | e2531465857525f8344007a9c38818e5d0bb2d3b /webkit | |
parent | 4e827189e8f3c3b8c06d4bde33d743faf7535e2b (diff) | |
download | chromium_src-8aa31e5bb274abd6f5eb43e6297e00cf6d365856.zip chromium_src-8aa31e5bb274abd6f5eb43e6297e00cf6d365856.tar.gz chromium_src-8aa31e5bb274abd6f5eb43e6297e00cf6d365856.tar.bz2 |
Make HTMLSelectElement and HTMLOptionsCollection return collections of options
elements if there are multiple options that share a name.
Currently Safari and chromium differ in their behavior in this area. Safari returns
multiple options in a collection if necessary, but only for HTMLOptionsCollection. For
HTMLSelectElement it always returns null.
Chromium returns a single option no matter what, but for both HTMLSelectElement
and HTMLOptionsCollection. It's also very slow at this, as it bypasses a webkit cache.
The HTML5 doc states that a collection should be returned if necessary for both.
The relevant parts of the spec are:
http://dev.w3.org/html5/spec/Overview.html#the-select-element
and
http://dev.w3.org/html5/spec/Overview.html#htmloptionscollection-0
So if you have:
<select id="sl1"><option value="Value" name="test" /></select>
and in JS code you do:
var test = document.getElementById("sl1").test
test should be a single HTMLOptionElement.
If instead you have:
<select id="sl2"><option value="Value1" name="test" /><option value="Value2"
name="test" /></select>
test should be a collection with 2 HTMLOptionElements.
This bug: https://bugs.webkit.org/show_bug.cgi?id=25191 has been filed against
webkit, with a new layout test to confirm the behavior
Review URL: http://codereview.chromium.org/67148
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/port/bindings/v8/v8_custom.cpp | 29 | ||||
-rw-r--r-- | webkit/port/bindings/v8/v8_custom.h | 1 | ||||
-rw-r--r-- | webkit/port/bindings/v8/v8_proxy.cpp | 13 |
3 files changed, 34 insertions, 9 deletions
diff --git a/webkit/port/bindings/v8/v8_custom.cpp b/webkit/port/bindings/v8/v8_custom.cpp index 4b2e545..4ac1554 100644 --- a/webkit/port/bindings/v8/v8_custom.cpp +++ b/webkit/port/bindings/v8/v8_custom.cpp @@ -41,6 +41,7 @@ #include "V8HTMLDocument.h" #include "V8HTMLImageElement.h" #include "V8HTMLOptionElement.h" +#include "V8NamedNodesCollection.h" #include "V8Node.h" #include "V8XPathNSResolver.h" #include "V8XPathResult.h" @@ -233,6 +234,34 @@ INDEXED_PROPERTY_SETTER(HTMLOptionsCollection) { return OptionsCollectionSetter(index, value, base); } +NAMED_PROPERTY_GETTER(HTMLSelectElementCollection) { + INC_STATS("DOM.HTMLSelectElementCollection.NamedPropertySetter"); + HTMLSelectElement* select = + V8Proxy::DOMWrapperToNode<HTMLSelectElement>(info.Holder()); + v8::Handle<v8::Value> value = info.Holder()->GetRealNamedPropertyInPrototypeChain(name); + + if (!value.IsEmpty()) + return value; + + // Search local callback properties next to find IDL defined + // properties. + if (info.Holder()->HasRealNamedCallbackProperty(name)) + return notHandledByInterceptor(); + + PassRefPtr<HTMLOptionsCollection> collection = select->options(); + + Vector<RefPtr<Node> > items; + collection->namedItems(v8StringToAtomicWebCoreString(name), items); + + if (!items.size()) + return v8::Handle<v8::Value>(); + + if (items.size() == 1) + return V8Proxy::NodeToV8Object(items.at(0).get()); + + NodeList* list = new V8NamedNodesCollection(items); + return V8Proxy::ToV8Object(V8ClassIndex::NODELIST, list); +} INDEXED_PROPERTY_SETTER(HTMLSelectElementCollection) { INC_STATS("DOM.HTMLSelectElementCollection.IndexedPropertySetter"); diff --git a/webkit/port/bindings/v8/v8_custom.h b/webkit/port/bindings/v8/v8_custom.h index 73b5f96..e8a0bad 100644 --- a/webkit/port/bindings/v8/v8_custom.h +++ b/webkit/port/bindings/v8/v8_custom.h @@ -477,6 +477,7 @@ DECLARE_INDEXED_PROPERTY_GETTER(NamedNodeMap) DECLARE_INDEXED_PROPERTY_GETTER(HTMLFormElement) DECLARE_INDEXED_PROPERTY_GETTER(HTMLOptionsCollection) DECLARE_INDEXED_PROPERTY_SETTER(HTMLOptionsCollection) +DECLARE_NAMED_PROPERTY_GETTER(HTMLSelectElementCollection) DECLARE_INDEXED_PROPERTY_SETTER(HTMLSelectElementCollection) DECLARE_NAMED_PROPERTY_GETTER(HTMLCollection) diff --git a/webkit/port/bindings/v8/v8_proxy.cpp b/webkit/port/bindings/v8/v8_proxy.cpp index 723d32b..f7af9db 100644 --- a/webkit/port/bindings/v8/v8_proxy.cpp +++ b/webkit/port/bindings/v8/v8_proxy.cpp @@ -1292,9 +1292,8 @@ v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate( V8ClassIndex::NODE); break; case V8ClassIndex::HTMLOPTIONSCOLLECTION: - setCollectionNamedGetter<HTMLOptionsCollection, Node>( - desc, - V8ClassIndex::NODE); + desc->InstanceTemplate()->SetNamedPropertyHandler( + USE_NAMED_PROPERTY_GETTER(HTMLCollection)); desc->InstanceTemplate()->SetIndexedPropertyHandler( USE_INDEXED_PROPERTY_GETTER(HTMLOptionsCollection), USE_INDEXED_PROPERTY_SETTER(HTMLOptionsCollection)); @@ -1303,12 +1302,7 @@ v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate( break; case V8ClassIndex::HTMLSELECTELEMENT: desc->InstanceTemplate()->SetNamedPropertyHandler( - nodeCollectionNamedPropertyGetter<HTMLSelectElement>, - 0, - 0, - 0, - 0, - v8::Integer::New(V8ClassIndex::NODE)); + USE_NAMED_PROPERTY_GETTER(HTMLSelectElementCollection)); desc->InstanceTemplate()->SetIndexedPropertyHandler( nodeCollectionIndexedPropertyGetter<HTMLSelectElement>, USE_INDEXED_PROPERTY_SETTER(HTMLSelectElementCollection), @@ -2409,6 +2403,7 @@ void* V8Proxy::ToNativeObjectImpl(V8ClassIndex::V8WrapperType type, return DOMWrapperToNative<void>(object); } + v8::Handle<v8::Object> V8Proxy::LookupDOMWrapper( V8ClassIndex::V8WrapperType type, v8::Handle<v8::Value> value) { |