Skip to content

Commit

Permalink
Implement HTMLSelectElement.{multiple, name, size} (fixes #6017)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinwoo-Song committed May 12, 2015
1 parent 10d8200 commit 656a8ee
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 444 deletions.
37 changes: 31 additions & 6 deletions components/script/dom/htmlselectelement.rs
Expand Up @@ -2,17 +2,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use dom::attr::Attr;
use dom::attr::AttrHelpers;
use dom::attr::{Attr, AttrHelpers, AttrValue};
use dom::bindings::codegen::Bindings::HTMLSelectElementBinding;
use dom::bindings::codegen::Bindings::HTMLSelectElementBinding::HTMLSelectElementMethods;
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLSelectElementDerived, HTMLFieldSetElementDerived};
use dom::bindings::codegen::InheritTypes::{HTMLSelectElementDerived, HTMLFieldSetElementDerived};
use dom::bindings::codegen::UnionTypes::HTMLElementOrLong;
use dom::bindings::codegen::UnionTypes::HTMLOptionElementOrHTMLOptGroupElement;
use dom::bindings::js::{JSRef, Rootable, Temporary};
use dom::document::Document;
use dom::element::{AttributeHandlers, Element};
use dom::element::AttributeHandlers;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::element::ElementTypeId;
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
Expand All @@ -36,6 +35,8 @@ impl HTMLSelectElementDerived for EventTarget {
}
}

static DEFAULT_SELECT_SIZE: u32 = 0;

impl HTMLSelectElement {
fn new_inherited(localName: DOMString, prefix: Option<DOMString>, document: JSRef<Document>) -> HTMLSelectElement {
HTMLSelectElement {
Expand Down Expand Up @@ -66,10 +67,27 @@ impl<'a> HTMLSelectElementMethods for JSRef<'a, HTMLSelectElement> {
// https://www.whatwg.org/html/#dom-fe-disabled
make_bool_setter!(SetDisabled, "disabled");

// https://html.spec.whatwg.org/multipage/#dom-select-multiple
make_bool_getter!(Multiple);

// https://html.spec.whatwg.org/multipage/#dom-select-multiple
make_bool_setter!(SetMultiple, "multiple");

// https://html.spec.whatwg.org/multipage/#dom-fe-name
make_getter!(Name);

// https://html.spec.whatwg.org/multipage/#dom-fe-name
make_setter!(SetName, "name");

// https://html.spec.whatwg.org/multipage/#dom-select-size
make_uint_getter!(Size, "size", DEFAULT_SELECT_SIZE);

// https://html.spec.whatwg.org/multipage/#dom-select-size
make_uint_setter!(SetSize, "size", DEFAULT_SELECT_SIZE);

// https://html.spec.whatwg.org/multipage/#dom-select-type
fn Type(self) -> DOMString {
let elem: JSRef<Element> = ElementCast::from_ref(self);
if elem.has_attribute(&atom!("multiple")) {
if self.Multiple() {
"select-multiple".to_owned()
} else {
"select-one".to_owned()
Expand Down Expand Up @@ -135,5 +153,12 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLSelectElement> {
node.check_disabled_attribute();
}
}

fn parse_plain_attribute(&self, local_name: &Atom, value: DOMString) -> AttrValue {
match local_name {
&atom!("size") => AttrValue::from_u32(value, DEFAULT_SELECT_SIZE),
_ => self.super_type().unwrap().parse_plain_attribute(local_name, value),
}
}
}

6 changes: 3 additions & 3 deletions components/script/dom/webidls/HTMLSelectElement.webidl
Expand Up @@ -8,10 +8,10 @@ interface HTMLSelectElement : HTMLElement {
// attribute boolean autofocus;
attribute boolean disabled;
//readonly attribute HTMLFormElement? form;
// attribute boolean multiple;
// attribute DOMString name;
attribute boolean multiple;
attribute DOMString name;
// attribute boolean required;
// attribute unsigned long size;
attribute unsigned long size;

readonly attribute DOMString type;

Expand Down
18 changes: 0 additions & 18 deletions tests/wpt/metadata/html/dom/interfaces.html.ini
Expand Up @@ -5808,18 +5808,9 @@
[HTMLSelectElement interface: attribute form]
expected: FAIL

[HTMLSelectElement interface: attribute multiple]
expected: FAIL

[HTMLSelectElement interface: attribute name]
expected: FAIL

[HTMLSelectElement interface: attribute required]
expected: FAIL

[HTMLSelectElement interface: attribute size]
expected: FAIL

[HTMLSelectElement interface: attribute options]
expected: FAIL

Expand Down Expand Up @@ -5877,18 +5868,9 @@
[HTMLSelectElement interface: document.createElement("select") must inherit property "form" with the proper type (3)]
expected: FAIL

[HTMLSelectElement interface: document.createElement("select") must inherit property "multiple" with the proper type (4)]
expected: FAIL

[HTMLSelectElement interface: document.createElement("select") must inherit property "name" with the proper type (5)]
expected: FAIL

[HTMLSelectElement interface: document.createElement("select") must inherit property "required" with the proper type (6)]
expected: FAIL

[HTMLSelectElement interface: document.createElement("select") must inherit property "size" with the proper type (7)]
expected: FAIL

[HTMLSelectElement interface: document.createElement("select") must inherit property "options" with the proper type (9)]
expected: FAIL

Expand Down

0 comments on commit 656a8ee

Please sign in to comment.