aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorMatthew Rasmus <mattr@zzntd.com>2014-12-07 11:04:39 -0800
committerMatthew Rasmus <mattr@zzntd.com>2014-12-16 11:34:04 -0800
commit7e0c39a82d5ca9d766c0065f4cb6ba79b1cbe037 (patch)
tree0e0c5a9c40bde5ad035d5f556411725cf3d59a34 /components/script
parenta3b3295d80194becf83f153e480df7f19c3e2971 (diff)
downloadservo-7e0c39a82d5ca9d766c0065f4cb6ba79b1cbe037.tar.gz
servo-7e0c39a82d5ca9d766c0065f4cb6ba79b1cbe037.zip
Implements FormControl for HTMLTextAreaElement
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/htmlformelement.rs8
-rw-r--r--components/script/dom/htmltextareaelement.rs57
-rw-r--r--components/script/dom/webidls/HTMLTextAreaElement.webidl2
3 files changed, 59 insertions, 8 deletions
diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index 8f5b0180c02..62b08649f7f 100644
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::HTMLFormElementBinding;
use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods;
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
use dom::bindings::codegen::InheritTypes::{EventTargetCast, HTMLFormElementDerived, NodeCast};
-use dom::bindings::codegen::InheritTypes::HTMLInputElementCast;
+use dom::bindings::codegen::InheritTypes::{HTMLInputElementCast, HTMLTextAreaElementCast};
use dom::bindings::global::Window;
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector};
@@ -20,6 +20,7 @@ use dom::event::{Event, EventHelpers, Bubbles, Cancelable};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::htmlinputelement::HTMLInputElement;
+use dom::htmltextareaelement::HTMLTextAreaElement;
use dom::node::{Node, NodeHelpers, ElementNodeTypeId, document_from_node, window_from_node};
use hyper::method::Post;
use servo_msg::constellation_msg::LoadData;
@@ -362,8 +363,9 @@ impl<'a> HTMLFormElementHelpers for JSRef<'a, HTMLFormElement> {
{}
}
ElementNodeTypeId(HTMLTextAreaElementTypeId) => {
- // Unimplemented
- {}
+ let textarea: JSRef<HTMLTextAreaElement> = HTMLTextAreaElementCast::to_ref(child)
+ .unwrap();
+ textarea.reset()
}
ElementNodeTypeId(HTMLOutputElementTypeId) => {
// Unimplemented
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index 05d3a5d0868..a22279a3deb 100644
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -5,20 +5,22 @@
use dom::attr::{Attr, AttrValue};
use dom::attr::AttrHelpers;
use dom::bindings::cell::DOMRefCell;
+use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding;
use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding::HTMLTextAreaElementMethods;
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::codegen::InheritTypes::{KeyboardEventCast, TextDerived, HTMLFormElementCast};
+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, HTMLFormElement};
use dom::keyboardevent::KeyboardEvent;
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, OtherNodeDamage, ElementNodeTypeId};
use dom::node::{document_from_node};
@@ -103,6 +105,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)
@@ -248,7 +256,7 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLTextAreaElement> {
}
if child.is_text() {
- self.SetValue(self.DefaultValue());
+ self.reset();
}
}
@@ -287,3 +295,44 @@ impl Reflectable for HTMLTextAreaElement {
self.htmlelement.reflector()
}
}
+
+impl<'a> FormControl<'a> for JSRef<'a, HTMLTextAreaElement> {
+ // FIXME: This is wrong (https://github.com/servo/servo/issues/3553)
+ // but we need html5ever to do it correctly
+ fn form_owner(self) -> Option<Temporary<HTMLFormElement>> {
+ // https://html.spec.whatwg.org/multipage/forms.html#reset-the-form-owner
+ let elem: JSRef<Element> = ElementCast::from_ref(self);
+ let owner = elem.get_string_attribute(&atom!("form"));
+ if !owner.is_empty() {
+ let doc = document_from_node(self).root();
+ let owner = doc.GetElementById(owner).root();
+ match owner {
+ Some(o) => {
+ let maybe_form: Option<JSRef<HTMLFormElement>> = HTMLFormElementCast::to_ref(*o);
+ if maybe_form.is_some() {
+ return maybe_form.map(Temporary::from_rooted);
+ }
+ },
+ _ => ()
+ }
+ }
+ let node: JSRef<Node> = NodeCast::from_ref(self);
+ node.ancestors().filter_map(|a| HTMLFormElementCast::to_ref(a)).next()
+ .map(Temporary::from_rooted)
+ }
+
+ 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) {
+ self.SetValue(self.DefaultValue());
+ self.value_changed.set(false);
+ }
+}
diff --git a/components/script/dom/webidls/HTMLTextAreaElement.webidl b/components/script/dom/webidls/HTMLTextAreaElement.webidl
index 59d10658b14..4bc4510d2a2 100644
--- a/components/script/dom/webidls/HTMLTextAreaElement.webidl
+++ b/components/script/dom/webidls/HTMLTextAreaElement.webidl
@@ -16,7 +16,7 @@ interface HTMLTextAreaElement : HTMLElement {
// attribute long minLength;
attribute DOMString name;
attribute DOMString placeholder;
- // attribute boolean readOnly;
+ attribute boolean readOnly;
attribute boolean required;
attribute unsigned long rows;
attribute DOMString wrap;