diff options
author | Matthew Rasmus <mattr@zzntd.com> | 2014-12-07 11:04:39 -0800 |
---|---|---|
committer | Matthew Rasmus <mattr@zzntd.com> | 2014-12-16 11:34:04 -0800 |
commit | 7e0c39a82d5ca9d766c0065f4cb6ba79b1cbe037 (patch) | |
tree | 0e0c5a9c40bde5ad035d5f556411725cf3d59a34 /components/script/dom/htmltextareaelement.rs | |
parent | a3b3295d80194becf83f153e480df7f19c3e2971 (diff) | |
download | servo-7e0c39a82d5ca9d766c0065f4cb6ba79b1cbe037.tar.gz servo-7e0c39a82d5ca9d766c0065f4cb6ba79b1cbe037.zip |
Implements FormControl for HTMLTextAreaElement
Diffstat (limited to 'components/script/dom/htmltextareaelement.rs')
-rw-r--r-- | components/script/dom/htmltextareaelement.rs | 57 |
1 files changed, 53 insertions, 4 deletions
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); + } +} |