mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Implement most of HTMLFormElement's webidl
This commit is contained in:
parent
98d1ddfcd3
commit
332c94b730
4 changed files with 112 additions and 71 deletions
|
@ -3,20 +3,24 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::HTMLFormElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLFormElementBinding;
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLFormElementDerived;
|
use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods;
|
||||||
|
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLFormElementDerived};
|
||||||
use dom::bindings::js::{JSRef, Temporary};
|
use dom::bindings::js::{JSRef, Temporary};
|
||||||
use dom::bindings::utils::{Reflectable, Reflector};
|
use dom::bindings::utils::{Reflectable, Reflector};
|
||||||
use dom::document::Document;
|
use dom::document::{Document, DocumentHelpers};
|
||||||
use dom::element::HTMLFormElementTypeId;
|
use dom::element::{Element, AttributeHandlers, HTMLFormElementTypeId};
|
||||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{Node, ElementNodeTypeId};
|
use dom::node::{Node, ElementNodeTypeId, document_from_node};
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::DOMString;
|
||||||
|
use std::ascii::OwnedStrAsciiExt;
|
||||||
|
use url::UrlParser;
|
||||||
|
|
||||||
|
|
||||||
#[jstraceable]
|
#[jstraceable]
|
||||||
#[must_root]
|
#[must_root]
|
||||||
pub struct HTMLFormElement {
|
pub struct HTMLFormElement {
|
||||||
pub htmlelement: HTMLElement
|
pub htmlelement: HTMLElement,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HTMLFormElementDerived for EventTarget {
|
impl HTMLFormElementDerived for EventTarget {
|
||||||
|
@ -39,6 +43,100 @@ impl HTMLFormElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> {
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-acceptcharset
|
||||||
|
make_getter!(AcceptCharset, "accept-charset")
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-acceptcharset
|
||||||
|
make_setter!(SetAcceptCharset, "accept-charset")
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-action
|
||||||
|
fn Action(self) -> DOMString {
|
||||||
|
let elem: JSRef<Element> = ElementCast::from_ref(self);
|
||||||
|
let action = elem.get_string_attribute("action");
|
||||||
|
let doc = document_from_node(self).root();
|
||||||
|
let base = doc.url();
|
||||||
|
// https://html.spec.whatwg.org/multipage/infrastructure.html#reflect
|
||||||
|
match UrlParser::new().base_url(base).parse(action.as_slice()) {
|
||||||
|
Ok(parsed) => parsed.serialize(),
|
||||||
|
Err(_) => base.serialize()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-action
|
||||||
|
make_setter!(SetAction, "action")
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-autocomplete
|
||||||
|
fn Autocomplete(self) -> DOMString {
|
||||||
|
let elem: JSRef<Element> = ElementCast::from_ref(self);
|
||||||
|
let ac = elem.get_string_attribute("autocomplete").into_ascii_lower();
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#attr-form-autocomplete
|
||||||
|
match ac.as_slice() {
|
||||||
|
"off" => ac,
|
||||||
|
_ => "on".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-autocomplete
|
||||||
|
make_setter!(SetAutocomplete, "autocomplete")
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-enctype
|
||||||
|
fn Enctype(self) -> DOMString {
|
||||||
|
let elem: JSRef<Element> = ElementCast::from_ref(self);
|
||||||
|
let enctype = elem.get_string_attribute("enctype").into_ascii_lower();
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#attr-fs-enctype
|
||||||
|
match enctype.as_slice() {
|
||||||
|
"text/plain" | "multipart/form-data" => enctype,
|
||||||
|
_ => "application/x-www-form-urlencoded".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-enctype
|
||||||
|
make_setter!(SetEnctype, "enctype")
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-encoding
|
||||||
|
fn Encoding(self) -> DOMString {
|
||||||
|
self.Enctype()
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-encoding
|
||||||
|
fn SetEncoding(self, value: DOMString) {
|
||||||
|
self.SetEnctype(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-method
|
||||||
|
fn Method(self) -> DOMString {
|
||||||
|
let elem: JSRef<Element> = ElementCast::from_ref(self);
|
||||||
|
let method = elem.get_string_attribute("method").into_ascii_lower();
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#attr-fs-method
|
||||||
|
match method.as_slice() {
|
||||||
|
"post" | "dialog" => method,
|
||||||
|
_ => "get".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-method
|
||||||
|
make_setter!(SetMethod, "method")
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-name
|
||||||
|
make_getter!(Name)
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-form-name
|
||||||
|
make_setter!(SetName, "name")
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-novalidate
|
||||||
|
make_bool_getter!(NoValidate)
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-novalidate
|
||||||
|
make_bool_setter!(SetNoValidate, "novalidate")
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-target
|
||||||
|
make_getter!(Target)
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-fs-target
|
||||||
|
make_setter!(SetTarget, "target")
|
||||||
|
}
|
||||||
impl Reflectable for HTMLFormElement {
|
impl Reflectable for HTMLFormElement {
|
||||||
fn reflector<'a>(&'a self) -> &'a Reflector {
|
fn reflector<'a>(&'a self) -> &'a Reflector {
|
||||||
self.htmlelement.reflector()
|
self.htmlelement.reflector()
|
||||||
|
|
|
@ -6,15 +6,15 @@
|
||||||
// http://www.whatwg.org/html/#htmlformelement
|
// http://www.whatwg.org/html/#htmlformelement
|
||||||
//[OverrideBuiltins]
|
//[OverrideBuiltins]
|
||||||
interface HTMLFormElement : HTMLElement {
|
interface HTMLFormElement : HTMLElement {
|
||||||
// attribute DOMString acceptCharset;
|
attribute DOMString acceptCharset;
|
||||||
// attribute DOMString action;
|
attribute DOMString action;
|
||||||
// attribute DOMString autocomplete;
|
attribute DOMString autocomplete;
|
||||||
// attribute DOMString enctype;
|
attribute DOMString enctype;
|
||||||
// attribute DOMString encoding;
|
attribute DOMString encoding;
|
||||||
// attribute DOMString method;
|
attribute DOMString method;
|
||||||
// attribute DOMString name;
|
attribute DOMString name;
|
||||||
// attribute boolean noValidate;
|
attribute boolean noValidate;
|
||||||
// attribute DOMString target;
|
attribute DOMString target;
|
||||||
|
|
||||||
//readonly attribute HTMLFormControlsCollection elements;
|
//readonly attribute HTMLFormControlsCollection elements;
|
||||||
//readonly attribute long length;
|
//readonly attribute long length;
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
[case.html]
|
|
||||||
type: testharness
|
|
||||||
|
|
|
@ -5397,33 +5397,6 @@
|
||||||
[HTMLTableCellElement interface: attribute bgColor]
|
[HTMLTableCellElement interface: attribute bgColor]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[HTMLFormElement interface: attribute acceptCharset]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: attribute action]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: attribute autocomplete]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: attribute enctype]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: attribute encoding]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: attribute method]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: attribute name]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: attribute noValidate]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: attribute target]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: attribute elements]
|
[HTMLFormElement interface: attribute elements]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -5445,33 +5418,6 @@
|
||||||
[HTMLFormElement interface: operation requestAutocomplete()]
|
[HTMLFormElement interface: operation requestAutocomplete()]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[HTMLFormElement interface: document.createElement("form") must inherit property "acceptCharset" with the proper type (0)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: document.createElement("form") must inherit property "action" with the proper type (1)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: document.createElement("form") must inherit property "autocomplete" with the proper type (2)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: document.createElement("form") must inherit property "enctype" with the proper type (3)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: document.createElement("form") must inherit property "encoding" with the proper type (4)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: document.createElement("form") must inherit property "method" with the proper type (5)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: document.createElement("form") must inherit property "name" with the proper type (6)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: document.createElement("form") must inherit property "noValidate" with the proper type (7)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: document.createElement("form") must inherit property "target" with the proper type (8)]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[HTMLFormElement interface: document.createElement("form") must inherit property "elements" with the proper type (9)]
|
[HTMLFormElement interface: document.createElement("form") must inherit property "elements" with the proper type (9)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue