Skip to content

Commit

Permalink
Add type IDL attr for submittable elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Oct 11, 2014
1 parent e048f3f commit 8a2c746
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 9 deletions.
19 changes: 17 additions & 2 deletions components/script/dom/htmlbuttonelement.rs
Expand Up @@ -4,18 +4,19 @@

use dom::bindings::codegen::Bindings::HTMLButtonElementBinding;
use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElementMethods;
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLButtonElementDerived, HTMLFieldSetElementDerived};
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document;
use dom::element::{AttributeHandlers, HTMLButtonElementTypeId};
use dom::element::{AttributeHandlers, Element, HTMLButtonElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId, window_from_node};
use dom::validitystate::ValidityState;
use dom::virtualmethods::VirtualMethods;

use std::ascii::OwnedStrAsciiExt;
use servo_util::str::DOMString;
use string_cache::Atom;

Expand Down Expand Up @@ -56,6 +57,20 @@ impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> {

// http://www.whatwg.org/html/#dom-fe-disabled
make_bool_setter!(SetDisabled, "disabled")

// https://html.spec.whatwg.org/multipage/forms.html#dom-button-type
fn Type(self) -> DOMString {
let elem: JSRef<Element> = ElementCast::from_ref(self);
let ty = elem.get_string_attribute("type").into_ascii_lower();
// https://html.spec.whatwg.org/multipage/forms.html#attr-button-type
match ty.as_slice() {
"reset" | "button" | "menu" => ty,
_ => "submit".to_string()
}
}

// https://html.spec.whatwg.org/multipage/forms.html#dom-button-type
make_setter!(SetType, "type")
}

impl<'a> VirtualMethods for JSRef<'a, HTMLButtonElement> {
Expand Down
21 changes: 21 additions & 0 deletions components/script/dom/htmlinputelement.rs
Expand Up @@ -24,6 +24,7 @@ use dom::virtualmethods::VirtualMethods;
use servo_util::str::{DOMString, parse_unsigned_integer};
use string_cache::Atom;

use std::ascii::OwnedStrAsciiExt;
use std::cell::{Cell, RefCell};
use std::mem;

Expand Down Expand Up @@ -131,6 +132,26 @@ impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> {
// https://html.spec.whatwg.org/multipage/forms.html#dom-input-size
make_uint_setter!(SetSize, "size")

// https://html.spec.whatwg.org/multipage/forms.html#dom-input-type
fn Type(self) -> DOMString {
let elem: JSRef<Element> = ElementCast::from_ref(self);
let ty = elem.get_string_attribute("type").into_ascii_lower();
// https://html.spec.whatwg.org/multipage/forms.html#attr-input-type
match ty.as_slice() {
"hidden" | "search" | "tel" |
"url" | "email" | "password" |
"datetime" | "date" | "month" |
"week" | "time" | "datetime-local" |
"number" | "range" | "color" |
"checkbox" | "radio" | "file" |
"submit" | "image" | "reset" | "button" => ty,
_ => "text".to_string()
}
}

// https://html.spec.whatwg.org/multipage/forms.html#dom-input-type
make_setter!(SetType, "type")

// https://html.spec.whatwg.org/multipage/forms.html#dom-input-value
make_getter!(Value)

Expand Down
6 changes: 6 additions & 0 deletions components/script/dom/htmlobjectelement.rs
Expand Up @@ -86,6 +86,12 @@ impl<'a> HTMLObjectElementMethods for JSRef<'a, HTMLObjectElement> {
let window = window_from_node(self).root();
ValidityState::new(*window)
}

// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-object-type
make_getter!(Type)

// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-object-type
make_setter!(SetType, "type")
}

impl<'a> VirtualMethods for JSRef<'a, HTMLObjectElement> {
Expand Down
14 changes: 12 additions & 2 deletions components/script/dom/htmlselectelement.rs
Expand Up @@ -5,13 +5,13 @@
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::{HTMLSelectElementDerived, HTMLFieldSetElementDerived};
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLSelectElementDerived, HTMLFieldSetElementDerived};
use dom::bindings::codegen::UnionTypes::HTMLElementOrLong::HTMLElementOrLong;
use dom::bindings::codegen::UnionTypes::HTMLOptionElementOrHTMLOptGroupElement::HTMLOptionElementOrHTMLOptGroupElement;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document;
use dom::element::{AttributeHandlers, HTMLSelectElementTypeId};
use dom::element::{AttributeHandlers, Element, HTMLSelectElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId, window_from_node};
Expand Down Expand Up @@ -62,6 +62,16 @@ impl<'a> HTMLSelectElementMethods for JSRef<'a, HTMLSelectElement> {

// http://www.whatwg.org/html/#dom-fe-disabled
make_bool_setter!(SetDisabled, "disabled")

// https://html.spec.whatwg.org/multipage/forms.html#dom-select-type
fn Type(self) -> DOMString {
let elem: JSRef<Element> = ElementCast::from_ref(self);
if elem.has_attribute("multiple") {
"select-multiple".to_string()
} else {
"select-one".to_string()
}
}
}

impl<'a> VirtualMethods for JSRef<'a, HTMLSelectElement> {
Expand Down
5 changes: 5 additions & 0 deletions components/script/dom/htmltextareaelement.rs
Expand Up @@ -50,6 +50,11 @@ impl<'a> HTMLTextAreaElementMethods for JSRef<'a, HTMLTextAreaElement> {

// http://www.whatwg.org/html/#dom-fe-disabled
make_bool_setter!(SetDisabled, "disabled")

// https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-type
fn Type(self) -> DOMString {
"textarea".to_string()
}
}

impl<'a> VirtualMethods for JSRef<'a, HTMLTextAreaElement> {
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/HTMLButtonElement.webidl
Expand Up @@ -14,7 +14,7 @@ interface HTMLButtonElement : HTMLElement {
// attribute boolean formNoValidate;
// attribute DOMString formTarget;
// attribute DOMString name;
// attribute DOMString type;
attribute DOMString type;
// attribute DOMString value;
// attribute HTMLMenuElement? menu;

Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/HTMLInputElement.webidl
Expand Up @@ -37,7 +37,7 @@ interface HTMLInputElement : HTMLElement {
attribute unsigned long size;
// attribute DOMString src;
// attribute DOMString step;
// attribute DOMString type; //XXXjdm need binaryName
attribute DOMString type; //XXXjdm need binaryName
// attribute DOMString defaultValue;
[TreatNullAs=EmptyString] attribute DOMString value;
// attribute Date? valueAsDate;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/HTMLObjectElement.webidl
Expand Up @@ -6,7 +6,7 @@
// http://www.whatwg.org/html/#htmlobjectelement
interface HTMLObjectElement : HTMLElement {
// attribute DOMString data;
// attribute DOMString type;
attribute DOMString type;
// attribute boolean typeMustMatch;
// attribute DOMString name;
// attribute DOMString useMap;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/HTMLSelectElement.webidl
Expand Up @@ -13,7 +13,7 @@ interface HTMLSelectElement : HTMLElement {
// attribute boolean required;
// attribute unsigned long size;

//readonly attribute DOMString type;
readonly attribute DOMString type;

//readonly attribute HTMLOptionsCollection options;
// attribute unsigned long length;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/HTMLTextAreaElement.webidl
Expand Up @@ -21,7 +21,7 @@ interface HTMLTextAreaElement : HTMLElement {
// attribute unsigned long rows;
// attribute DOMString wrap;

//readonly attribute DOMString type;
readonly attribute DOMString type;
// attribute DOMString defaultValue;
//[TreatNullAs=EmptyString] attribute DOMString value;
//readonly attribute unsigned long textLength;
Expand Down

0 comments on commit 8a2c746

Please sign in to comment.