aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/attr.rs
diff options
context:
space:
mode:
authorSam Gibson <sam@ifdown.net>2015-08-23 16:11:04 +1200
committerSam Gibson <sam@ifdown.net>2015-12-03 14:00:51 +1100
commitd26c555e2a2fe0e10b9237e1ccf48d96665828c7 (patch)
tree58913878ca756d3cd2234c202814e66cb2933b4b /components/style/attr.rs
parent2be60be062e14c937af601faed78a6aceccdb062 (diff)
downloadservo-d26c555e2a2fe0e10b9237e1ccf48d96665828c7.tar.gz
servo-d26c555e2a2fe0e10b9237e1ccf48d96665828c7.zip
Adds support for input element's maxlength attr
servo/servo#7320 servo/servo#7004
Diffstat (limited to 'components/style/attr.rs')
-rw-r--r--components/style/attr.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/components/style/attr.rs b/components/style/attr.rs
index 625eeee3a5c..e50071e3b3f 100644
--- a/components/style/attr.rs
+++ b/components/style/attr.rs
@@ -5,7 +5,7 @@
use cssparser::RGBA;
use std::ops::Deref;
use string_cache::{Atom, Namespace};
-use util::str::{DOMString, LengthOrPercentageOrAuto, parse_unsigned_integer, parse_legacy_color, parse_length};
+use util::str::{DOMString, LengthOrPercentageOrAuto, parse_integer, parse_unsigned_integer, parse_legacy_color, parse_length};
use util::str::{split_html_space_chars, str_join};
use values::specified::{Length};
@@ -17,6 +17,7 @@ pub enum AttrValue {
String(DOMString),
TokenList(DOMString, Vec<Atom>),
UInt(DOMString, u32),
+ Int(DOMString, i32),
Atom(Atom),
Length(DOMString, Option<Length>),
Color(DOMString, Option<RGBA>),
@@ -52,6 +53,12 @@ impl AttrValue {
AttrValue::UInt(string, result)
}
+ // https://html.spec.whatwg.org/multipage/infrastructure.html#limited-to-only-non-negative-numbers
+ pub fn from_i32(string: DOMString, default: i32) -> AttrValue {
+ let result = parse_integer(string.chars()).unwrap_or(default);
+ AttrValue::Int(string, result)
+ }
+
// https://html.spec.whatwg.org/multipage/#limited-to-only-non-negative-numbers-greater-than-zero
pub fn from_limited_u32(string: DOMString, default: u32) -> AttrValue {
let result = parse_unsigned_integer(string.chars()).unwrap_or(default);
@@ -165,6 +172,7 @@ impl Deref for AttrValue {
AttrValue::UInt(ref value, _) |
AttrValue::Length(ref value, _) |
AttrValue::Color(ref value, _) |
+ AttrValue::Int(ref value, _) |
AttrValue::Dimension(ref value, _) => &value,
AttrValue::Atom(ref value) => &value,
}