formcontrol trait to element trait

mutable function and reset function in formcontrol
move into trait of single element
currently only TextArea element and Input element
This commit is contained in:
yodalee 2015-01-08 01:28:57 +08:00
parent c5a5db6324
commit c0867ec90a
3 changed files with 42 additions and 41 deletions

View file

@ -187,6 +187,24 @@ impl<'a> HTMLTextAreaElementMethods for JSRef<'a, HTMLTextAreaElement> {
}
}
pub trait HTMLTextAreaElementHelpers {
fn mutable(self) -> bool;
fn reset(self);
}
impl<'a> HTMLTextAreaElementHelpers for JSRef<'a, HTMLTextAreaElement> {
// https://html.spec.whatwg.org/multipage/forms.html#concept-fe-mutable
fn mutable(self) -> bool {
// https://html.spec.whatwg.org/multipage/forms.html#the-textarea-element:concept-fe-mutable
!(self.Disabled() || self.ReadOnly())
}
fn reset(self) {
// https://html.spec.whatwg.org/multipage/forms.html#the-textarea-element:concept-form-reset-control
self.SetValue(self.DefaultValue());
self.value_changed.set(false);
}
}
trait PrivateHTMLTextAreaElementHelpers {
fn force_relayout(self);
}
@ -335,16 +353,4 @@ impl<'a> FormControl<'a> for JSRef<'a, HTMLTextAreaElement> {
fn to_element(self) -> JSRef<'a, Element> {
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-textarea-element:concept-fe-mutable
!(self.Disabled() || self.ReadOnly())
}
fn reset(self) {
// https://html.spec.whatwg.org/multipage/forms.html#the-textarea-element:concept-form-reset-control
self.SetValue(self.DefaultValue());
self.value_changed.set(false);
}
}