mirror of
https://github.com/servo/servo.git
synced 2025-06-25 09:34:32 +01:00
Parse HTMLInputElement attributes
This commit is contained in:
parent
e18bf81905
commit
c93ed39f33
4 changed files with 44 additions and 132 deletions
|
@ -271,22 +271,22 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
|
||||||
|
|
||||||
impl HTMLInputElementMethods for HTMLInputElement {
|
impl HTMLInputElementMethods for HTMLInputElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-accept
|
// https://html.spec.whatwg.org/multipage/#dom-input-accept
|
||||||
make_getter!(Accept, "accept");
|
make_getter!(Accept, "accept");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-accept
|
// https://html.spec.whatwg.org/multipage/#dom-input-accept
|
||||||
make_setter!(SetAccept, "accept");
|
make_setter!(SetAccept, "accept");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-alt
|
// https://html.spec.whatwg.org/multipage/#dom-input-alt
|
||||||
make_getter!(Alt, "alt");
|
make_getter!(Alt, "alt");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-alt
|
// https://html.spec.whatwg.org/multipage/#dom-input-alt
|
||||||
make_setter!(SetAlt, "alt");
|
make_setter!(SetAlt, "alt");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-dirName
|
// https://html.spec.whatwg.org/multipage/#dom-input-dirName
|
||||||
make_getter!(DirName, "dirname");
|
make_getter!(DirName, "dirname");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-dirName
|
// https://html.spec.whatwg.org/multipage/#dom-input-dirName
|
||||||
make_setter!(SetDirName, "dirname");
|
make_setter!(SetDirName, "dirname");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-fe-disabled
|
// https://html.spec.whatwg.org/multipage/#dom-fe-disabled
|
||||||
|
@ -415,10 +415,10 @@ impl HTMLInputElementMethods for HTMLInputElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-fe-name
|
// https://html.spec.whatwg.org/multipage/#attr-fe-name
|
||||||
make_atomic_setter!(SetName, "name");
|
make_atomic_setter!(SetName, "name");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-placeholder
|
// https://html.spec.whatwg.org/multipage/#dom-input-placeholder
|
||||||
make_getter!(Placeholder, "placeholder");
|
make_getter!(Placeholder, "placeholder");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-placeholder
|
// https://html.spec.whatwg.org/multipage/#dom-input-placeholder
|
||||||
make_setter!(SetPlaceholder, "placeholder");
|
make_setter!(SetPlaceholder, "placeholder");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-input-formaction
|
// https://html.spec.whatwg.org/multipage/#dom-input-formaction
|
||||||
|
@ -454,10 +454,10 @@ impl HTMLInputElementMethods for HTMLInputElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-fs-formnovalidate
|
// https://html.spec.whatwg.org/multipage/#attr-fs-formnovalidate
|
||||||
make_bool_setter!(SetFormNoValidate, "formnovalidate");
|
make_bool_setter!(SetFormNoValidate, "formnovalidate");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-max
|
// https://html.spec.whatwg.org/multipage/#dom-input-max
|
||||||
make_getter!(Max, "max");
|
make_getter!(Max, "max");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-max
|
// https://html.spec.whatwg.org/multipage/#dom-input-max
|
||||||
make_setter!(SetMax, "max");
|
make_setter!(SetMax, "max");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-input-maxlength
|
// https://html.spec.whatwg.org/multipage/#dom-input-maxlength
|
||||||
|
@ -466,40 +466,40 @@ impl HTMLInputElementMethods for HTMLInputElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-input-maxlength
|
// https://html.spec.whatwg.org/multipage/#dom-input-maxlength
|
||||||
make_limited_int_setter!(SetMaxLength, "maxlength", DEFAULT_MAX_LENGTH);
|
make_limited_int_setter!(SetMaxLength, "maxlength", DEFAULT_MAX_LENGTH);
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-min
|
// https://html.spec.whatwg.org/multipage/#dom-input-min
|
||||||
make_getter!(Min, "min");
|
make_getter!(Min, "min");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-min
|
// https://html.spec.whatwg.org/multipage/#dom-input-min
|
||||||
make_setter!(SetMin, "min");
|
make_setter!(SetMin, "min");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-multiple
|
// https://html.spec.whatwg.org/multipage/#dom-input-multiple
|
||||||
make_bool_getter!(Multiple, "multiple");
|
make_bool_getter!(Multiple, "multiple");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-multiple
|
// https://html.spec.whatwg.org/multipage/#dom-input-multiple
|
||||||
make_bool_setter!(SetMultiple, "multiple");
|
make_bool_setter!(SetMultiple, "multiple");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-pattern
|
// https://html.spec.whatwg.org/multipage/#dom-input-pattern
|
||||||
make_getter!(Pattern, "pattern");
|
make_getter!(Pattern, "pattern");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-pattern
|
// https://html.spec.whatwg.org/multipage/#dom-input-pattern
|
||||||
make_setter!(SetPattern, "pattern");
|
make_setter!(SetPattern, "pattern");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-required
|
// https://html.spec.whatwg.org/multipage/#dom-input-required
|
||||||
make_bool_getter!(Required, "required");
|
make_bool_getter!(Required, "required");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-required
|
// https://html.spec.whatwg.org/multipage/#dom-input-required
|
||||||
make_bool_setter!(SetRequired, "required");
|
make_bool_setter!(SetRequired, "required");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-src
|
// https://html.spec.whatwg.org/multipage/#dom-input-src
|
||||||
make_getter!(Src, "src");
|
make_url_getter!(Src, "src");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-src
|
// https://html.spec.whatwg.org/multipage/#dom-input-src
|
||||||
make_setter!(SetSrc, "src");
|
make_url_setter!(SetSrc, "src");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-step
|
// https://html.spec.whatwg.org/multipage/#dom-input-step
|
||||||
make_getter!(Step, "step");
|
make_getter!(Step, "step");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-input-step
|
// https://html.spec.whatwg.org/multipage/#dom-input-step
|
||||||
make_setter!(SetStep, "step");
|
make_setter!(SetStep, "step");
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-input-indeterminate
|
// https://html.spec.whatwg.org/multipage/#dom-input-indeterminate
|
||||||
|
@ -881,6 +881,7 @@ impl VirtualMethods for HTMLInputElement {
|
||||||
|
|
||||||
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
|
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
|
||||||
match name {
|
match name {
|
||||||
|
&atom!("accept") => AttrValue::from_comma_separated_tokenlist(value.into()),
|
||||||
&atom!("name") => AttrValue::from_atomic(value.into()),
|
&atom!("name") => AttrValue::from_atomic(value.into()),
|
||||||
&atom!("size") => AttrValue::from_limited_u32(value.into(), DEFAULT_INPUT_SIZE),
|
&atom!("size") => AttrValue::from_limited_u32(value.into(), DEFAULT_INPUT_SIZE),
|
||||||
&atom!("type") => AttrValue::from_atomic(value.into()),
|
&atom!("type") => AttrValue::from_atomic(value.into()),
|
||||||
|
|
|
@ -11,7 +11,7 @@ use std::str::FromStr;
|
||||||
use string_cache::{Atom, Namespace};
|
use string_cache::{Atom, Namespace};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use util::str::{LengthOrPercentageOrAuto, HTML_SPACE_CHARACTERS};
|
use util::str::{LengthOrPercentageOrAuto, HTML_SPACE_CHARACTERS};
|
||||||
use util::str::{read_exponent, read_fraction, read_numbers, split_html_space_chars};
|
use util::str::{read_exponent, read_fraction, read_numbers, split_commas, split_html_space_chars};
|
||||||
use values::specified::{Length};
|
use values::specified::{Length};
|
||||||
|
|
||||||
// Duplicated from script::dom::values.
|
// Duplicated from script::dom::values.
|
||||||
|
@ -124,6 +124,15 @@ impl AttrValue {
|
||||||
AttrValue::TokenList(tokens, atoms)
|
AttrValue::TokenList(tokens, atoms)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_comma_separated_tokenlist(tokens: String) -> AttrValue {
|
||||||
|
let atoms = split_commas(&tokens).map(Atom::from)
|
||||||
|
.fold(vec![], |mut acc, atom| {
|
||||||
|
if !acc.contains(&atom) { acc.push(atom) }
|
||||||
|
acc
|
||||||
|
});
|
||||||
|
AttrValue::TokenList(tokens, atoms)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "gecko"))] // Gecko can't borrow atoms as UTF-8.
|
#[cfg(not(feature = "gecko"))] // Gecko can't borrow atoms as UTF-8.
|
||||||
pub fn from_atomic_tokens(atoms: Vec<Atom>) -> AttrValue {
|
pub fn from_atomic_tokens(atoms: Vec<Atom>) -> AttrValue {
|
||||||
use util::str::str_join;
|
use util::str::str_join;
|
||||||
|
@ -151,12 +160,12 @@ impl AttrValue {
|
||||||
// https://html.spec.whatwg.org/multipage/#reflecting-content-attributes-in-idl-attributes:idl-double
|
// https://html.spec.whatwg.org/multipage/#reflecting-content-attributes-in-idl-attributes:idl-double
|
||||||
pub fn from_double(string: String, default: f64) -> AttrValue {
|
pub fn from_double(string: String, default: f64) -> AttrValue {
|
||||||
let result = parse_double(&string).unwrap_or(default);
|
let result = parse_double(&string).unwrap_or(default);
|
||||||
let result = if result.is_infinite() {
|
|
||||||
default
|
if result.is_normal() {
|
||||||
} else {
|
|
||||||
result
|
|
||||||
};
|
|
||||||
AttrValue::Double(string, result)
|
AttrValue::Double(string, result)
|
||||||
|
} else {
|
||||||
|
AttrValue::Double(string, default)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#limited-to-only-non-negative-numbers
|
// https://html.spec.whatwg.org/multipage/#limited-to-only-non-negative-numbers
|
||||||
|
|
|
@ -41,6 +41,10 @@ pub fn split_html_space_chars<'a>(s: &'a str) ->
|
||||||
s.split(HTML_SPACE_CHARACTERS).filter(not_empty as fn(&&str) -> bool)
|
s.split(HTML_SPACE_CHARACTERS).filter(not_empty as fn(&&str) -> bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn split_commas<'a>(s: &'a str) -> Filter<Split<'a, char>, fn(&&str) -> bool> {
|
||||||
|
fn not_empty(&split: &&str) -> bool { !split.is_empty() }
|
||||||
|
s.split(',').filter(not_empty as fn(&&str) -> bool)
|
||||||
|
}
|
||||||
|
|
||||||
fn is_ascii_digit(c: &char) -> bool {
|
fn is_ascii_digit(c: &char) -> bool {
|
||||||
match *c {
|
match *c {
|
||||||
|
|
|
@ -4341,108 +4341,6 @@
|
||||||
[input.inputMode: IDL set to "URL" followed by IDL get]
|
[input.inputMode: IDL set to "URL" followed by IDL get]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[input.src: setAttribute() to "" followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to " foo " followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to "//site.example/path???@#l" followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to "\\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f " followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to undefined followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to 7 followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to 1.5 followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to true followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to false followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to object "[object Object\]" followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to NaN followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to Infinity followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to -Infinity followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to "\\0" followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to null followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to object "test-toString" followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: setAttribute() to object "test-valueOf" followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to "" followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to " foo " followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to "//site.example/path???@#l" followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to "\\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f " followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to undefined followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to 7 followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to 1.5 followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to true followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to false followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to object "[object Object\]" followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to NaN followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to Infinity followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to -Infinity followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to "\\0" followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to null followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to object "test-toString" followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.src: IDL set to object "test-valueOf" followed by IDL get]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[input.align: typeof IDL attribute]
|
[input.align: typeof IDL attribute]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue