Add type IDL attr for submittable elements

This commit is contained in:
Manish Goregaokar 2014-10-10 15:46:45 +05:30
parent e048f3f940
commit 8a2c746e61
10 changed files with 66 additions and 9 deletions

View file

@ -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;
@ -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> {

View file

@ -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;
@ -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)

View file

@ -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> {

View file

@ -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};
@ -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> {

View file

@ -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> {

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;