mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Implements FormControl for HTMLTextAreaElement
This commit is contained in:
parent
a3b3295d80
commit
7e0c39a82d
4 changed files with 62 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue