aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authoryodalee <lc85301@gmail.com>2015-01-08 01:28:57 +0800
committeryodalee <lc85301@gmail.com>2015-02-03 19:50:31 +0800
commitc0867ec90aa91fb770ac9440ec15af4a3b33bf6c (patch)
treee4d58c5f82e8f172753dfb6e497cf30818b21760 /components/script/dom
parentc5a5db6324c3ef1c1d25b2a87edcebcd408a4c8b (diff)
downloadservo-c0867ec90aa91fb770ac9440ec15af4a3b33bf6c.tar.gz
servo-c0867ec90aa91fb770ac9440ec15af4a3b33bf6c.zip
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
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/htmlformelement.rs7
-rw-r--r--components/script/dom/htmlinputelement.rs46
-rw-r--r--components/script/dom/htmltextareaelement.rs30
3 files changed, 42 insertions, 41 deletions
diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index 2bc35264f64..bf6fe0d1c5f 100644
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -18,8 +18,8 @@ use dom::event::{Event, EventHelpers, EventBubbles, EventCancelable};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::element::ElementTypeId;
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
-use dom::htmlinputelement::HTMLInputElement;
-use dom::htmltextareaelement::HTMLTextAreaElement;
+use dom::htmlinputelement::{HTMLInputElement, HTMLInputElementHelpers};
+use dom::htmltextareaelement::{HTMLTextAreaElement, HTMLTextAreaElementHelpers};
use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node};
use hyper::method::Method;
use servo_msg::constellation_msg::LoadData;
@@ -523,7 +523,4 @@ pub trait FormControl<'a> : Copy + Sized {
}
fn to_element(self) -> JSRef<'a, Element>;
- // https://html.spec.whatwg.org/multipage/forms.html#concept-fe-mutable
- fn mutable(self) -> bool;
- fn reset(self);
}
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index ede6ee71fb0..0af4eb62790 100644
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -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))
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index 7196b4ff891..ed7fb71a954 100644
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -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);
- }
}