aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmltextareaelement.rs
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2014-12-16 15:03:49 -0700
committerbors-servo <metajack+bors@gmail.com>2014-12-16 15:03:49 -0700
commit5951056973fc0e08e70224214740a274ca8ef20f (patch)
treea8007d81bb3377bd6803f0b589ed1c69ad3463dd /components/script/dom/htmltextareaelement.rs
parentb6a593650bcc33e4188153d135e9a2781a488f96 (diff)
parente4963869d3820d47865cf5d67a8c13f547061f5e (diff)
downloadservo-5951056973fc0e08e70224214740a274ca8ef20f.tar.gz
servo-5951056973fc0e08e70224214740a274ca8ef20f.zip
auto merge of #4133 : mttr/servo/form_resetting, r=jdm
We can reset `<input type=text>` fields! I wish I could've done something with checkboxes, but unfortunately, that's it for now. In addition to that, this PR implements `HTMLInputAttribute.defaultValue`, updates wpt-test to expect passing tests as a result of that implementation, and fixes an index error crash with text inputs. edit: also includes an html example where one may lazily watch form resets in action: ` tests/html/form_reset_handsfree.html`
Diffstat (limited to 'components/script/dom/htmltextareaelement.rs')
-rw-r--r--components/script/dom/htmltextareaelement.rs37
1 files changed, 32 insertions, 5 deletions
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index 642feb38b93..969454afc86 100644
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -12,13 +12,14 @@ use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLTextAreaElementDerived, HTMLFieldSetElementDerived};
use dom::bindings::codegen::InheritTypes::{KeyboardEventCast, TextDerived};
-use dom::bindings::js::{JS, JSRef, Temporary};
+use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::{Document, DocumentHelpers};
-use dom::element::{AttributeHandlers, HTMLTextAreaElementTypeId};
+use dom::element::{AttributeHandlers, HTMLTextAreaElementTypeId, Element};
use dom::event::Event;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
+use dom::htmlformelement::FormControl;
use dom::keyboardevent::KeyboardEvent;
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, OtherNodeDamage, ElementNodeTypeId};
use dom::node::{document_from_node};
@@ -124,6 +125,12 @@ impl<'a> HTMLTextAreaElementMethods for JSRef<'a, HTMLTextAreaElement> {
// https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-placeholder
make_setter!(SetPlaceholder, "placeholder")
+ // https://html.spec.whatwg.org/multipage/forms.html#attr-textarea-readonly
+ make_bool_getter!(ReadOnly)
+
+ // https://html.spec.whatwg.org/multipage/forms.html#attr-textarea-readonly
+ make_bool_setter!(SetReadOnly, "readonly")
+
// https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-required
make_bool_getter!(Required)
@@ -161,7 +168,7 @@ impl<'a> HTMLTextAreaElementMethods for JSRef<'a, HTMLTextAreaElement> {
// if the element's dirty value flag is false, then the element's
// raw value must be set to the value of the element's textContent IDL attribute
if !self.value_changed.get() {
- self.SetValue(node.GetTextContent().unwrap());
+ self.reset();
}
}
@@ -172,7 +179,9 @@ impl<'a> HTMLTextAreaElementMethods for JSRef<'a, HTMLTextAreaElement> {
// https://html.spec.whatwg.org/multipage/forms.html#dom-textarea-value
fn SetValue(self, value: DOMString) {
+ // TODO move the cursor to the end of the field
self.textinput.borrow_mut().set_content(value);
+ self.value_changed.set(true);
self.force_relayout();
}
}
@@ -286,8 +295,8 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTextAreaElement> {
_ => (),
}
- if child.is_text() {
- self.SetValue(self.DefaultValue());
+ if child.is_text() && !self.value_changed.get() {
+ self.reset();
}
}
@@ -326,3 +335,21 @@ impl Reflectable for HTMLTextAreaElement {
self.htmlelement.reflector()
}
}
+
+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);
+ }
+}