diff options
author | Keith Yeung <kungfukeith11@gmail.com> | 2016-04-12 09:38:25 -0400 |
---|---|---|
committer | Keith Yeung <kungfukeith11@gmail.com> | 2016-05-24 10:12:18 -0400 |
commit | c93ed39f3366b8a3b889884b0bdab30c1fadbde1 (patch) | |
tree | 2cb946e74e51cadc50ca317052bdd9e0df09305f /components/style/attr.rs | |
parent | e18bf819059e4439d276b02083a60f6353aaa359 (diff) | |
download | servo-c93ed39f3366b8a3b889884b0bdab30c1fadbde1.tar.gz servo-c93ed39f3366b8a3b889884b0bdab30c1fadbde1.zip |
Parse HTMLInputElement attributes
Diffstat (limited to 'components/style/attr.rs')
-rw-r--r-- | components/style/attr.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/components/style/attr.rs b/components/style/attr.rs index 8bb307040ea..0ba247e101f 100644 --- a/components/style/attr.rs +++ b/components/style/attr.rs @@ -11,7 +11,7 @@ use std::str::FromStr; use string_cache::{Atom, Namespace}; use url::Url; 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}; // Duplicated from script::dom::values. @@ -124,6 +124,15 @@ impl AttrValue { 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. pub fn from_atomic_tokens(atoms: Vec<Atom>) -> AttrValue { 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 pub fn from_double(string: String, default: f64) -> AttrValue { let result = parse_double(&string).unwrap_or(default); - let result = if result.is_infinite() { - default + + if result.is_normal() { + AttrValue::Double(string, result) } else { - result - }; - AttrValue::Double(string, result) + AttrValue::Double(string, default) + } } // https://html.spec.whatwg.org/multipage/#limited-to-only-non-negative-numbers |