Implement form control mutability, rename FormOwner -> FormControl

This commit is contained in:
Manish Goregaokar 2014-11-15 11:18:10 +05:30
parent 2c2d741b1f
commit 7d51a543d8
3 changed files with 19 additions and 4 deletions

View file

@ -410,7 +410,7 @@ impl<'a> FormSubmitter<'a> {
} }
} }
pub trait FormOwner<'a> : Copy { pub trait FormControl<'a> : Copy {
fn form_owner(self) -> Option<Temporary<HTMLFormElement>>; fn form_owner(self) -> Option<Temporary<HTMLFormElement>>;
fn get_form_attribute(self, fn get_form_attribute(self,
attr: &Atom, attr: &Atom,
@ -423,4 +423,6 @@ pub trait FormOwner<'a> : Copy {
} }
} }
fn to_element(self) -> JSRef<'a, Element>; fn to_element(self) -> JSRef<'a, Element>;
// https://html.spec.whatwg.org/multipage/forms.html#concept-fe-mutable
fn mutable(self) -> bool;
} }

View file

@ -23,7 +23,7 @@ use dom::event::Event;
use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement; use dom::htmlelement::HTMLElement;
use dom::keyboardevent::KeyboardEvent; use dom::keyboardevent::KeyboardEvent;
use dom::htmlformelement::{InputElement, FormOwner, HTMLFormElement, HTMLFormElementHelpers, NotFromFormSubmitMethod}; use dom::htmlformelement::{InputElement, FormControl, HTMLFormElement, HTMLFormElementHelpers, NotFromFormSubmitMethod};
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId, document_from_node, window_from_node}; use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId, document_from_node, window_from_node};
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use textinput::{Single, TextInput, TriggerDefaultAction, DispatchInput, Nothing}; use textinput::{Single, TextInput, TriggerDefaultAction, DispatchInput, Nothing};
@ -151,6 +151,12 @@ impl<'a> HTMLInputElementMethods for JSRef<'a, HTMLInputElement> {
// https://html.spec.whatwg.org/multipage/forms.html#dom-input-checked // https://html.spec.whatwg.org/multipage/forms.html#dom-input-checked
make_bool_setter!(SetChecked, "checked") make_bool_setter!(SetChecked, "checked")
// https://html.spec.whatwg.org/multipage/forms.html#dom-input-readonly
make_bool_getter!(ReadOnly)
// https://html.spec.whatwg.org/multipage/forms.html#dom-input-readonly
make_bool_setter!(SetReadOnly, "readonly")
// https://html.spec.whatwg.org/multipage/forms.html#dom-input-size // https://html.spec.whatwg.org/multipage/forms.html#dom-input-size
make_uint_getter!(Size) make_uint_getter!(Size)
@ -457,7 +463,7 @@ impl Reflectable for HTMLInputElement {
} }
} }
impl<'a> FormOwner<'a> for JSRef<'a, HTMLInputElement> { impl<'a> FormControl<'a> for JSRef<'a, HTMLInputElement> {
// FIXME: This is wrong (https://github.com/servo/servo/issues/3553) // FIXME: This is wrong (https://github.com/servo/servo/issues/3553)
// but we need html5ever to do it correctly // but we need html5ever to do it correctly
fn form_owner(self) -> Option<Temporary<HTMLFormElement>> { fn form_owner(self) -> Option<Temporary<HTMLFormElement>> {
@ -485,4 +491,11 @@ impl<'a> FormOwner<'a> for JSRef<'a, HTMLInputElement> {
fn to_element(self) -> JSRef<'a, Element> { fn to_element(self) -> JSRef<'a, Element> {
ElementCast::from_ref(self) ElementCast::from_ref(self)
} }
// https://html.spec.whatwg.org/multipage/forms.html#concept-fe-mutable
fn mutable(self) -> bool {
// https://html.spec.whatwg.org/multipage/forms.html#the-input-element:concept-fe-mutable
// https://html.spec.whatwg.org/multipage/forms.html#the-readonly-attribute:concept-fe-mutable
!(self.Disabled() || self.ReadOnly())
}
} }

View file

@ -32,7 +32,7 @@ interface HTMLInputElement : HTMLElement {
attribute DOMString name; attribute DOMString name;
// attribute DOMString pattern; // attribute DOMString pattern;
// attribute DOMString placeholder; // attribute DOMString placeholder;
// attribute boolean readOnly; attribute boolean readOnly;
// attribute boolean required; // attribute boolean required;
attribute unsigned long size; attribute unsigned long size;
// attribute DOMString src; // attribute DOMString src;