mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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:
parent
c5a5db6324
commit
c0867ec90a
3 changed files with 42 additions and 41 deletions
|
@ -303,6 +303,8 @@ pub trait HTMLInputElementHelpers {
|
|||
fn update_checked_state(self, checked: bool, dirty: bool);
|
||||
fn get_size(&self) -> u32;
|
||||
fn get_indeterminate_state(self) -> bool;
|
||||
fn mutable(self) -> bool;
|
||||
fn reset(self);
|
||||
}
|
||||
|
||||
#[allow(unsafe_blocks)]
|
||||
|
@ -392,6 +394,26 @@ impl<'a> HTMLInputElementHelpers for JSRef<'a, HTMLInputElement> {
|
|||
fn get_indeterminate_state(self) -> bool {
|
||||
self.indeterminate.get()
|
||||
}
|
||||
// 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
|
||||
let node: JSRef<Node> = NodeCast::from_ref(self);
|
||||
!(node.get_disabled_state() || self.ReadOnly())
|
||||
}
|
||||
fn reset(self) {
|
||||
match self.input_type.get() {
|
||||
InputType::InputRadio | InputType::InputCheckbox => {
|
||||
self.update_checked_state(self.DefaultChecked(), false);
|
||||
self.checked_changed.set(false);
|
||||
},
|
||||
InputType::InputImage => (),
|
||||
_ => ()
|
||||
}
|
||||
|
||||
self.SetValue(self.DefaultValue());
|
||||
self.value_changed.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> {
|
||||
|
@ -583,32 +605,8 @@ impl<'a> FormControl<'a> for JSRef<'a, HTMLInputElement> {
|
|||
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-input-element:concept-fe-mutable
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#the-readonly-attribute:concept-fe-mutable
|
||||
let node: JSRef<Node> = NodeCast::from_ref(self);
|
||||
!(node.get_disabled_state() || self.ReadOnly())
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#the-input-element:concept-form-reset-control
|
||||
fn reset(self) {
|
||||
match self.input_type.get() {
|
||||
InputType::InputRadio | InputType::InputCheckbox => {
|
||||
self.update_checked_state(self.DefaultChecked(), false);
|
||||
self.checked_changed.set(false);
|
||||
},
|
||||
InputType::InputImage => (),
|
||||
_ => ()
|
||||
}
|
||||
|
||||
self.SetValue(self.DefaultValue());
|
||||
self.value_changed.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'a> Activatable for JSRef<'a, HTMLInputElement> {
|
||||
fn as_element(&self) -> Temporary<Element> {
|
||||
Temporary::from_rooted(ElementCast::from_ref(*self))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue