diff options
-rw-r--r-- | components/style/counter_style/mod.rs | 26 | ||||
-rw-r--r-- | components/style/gecko/rules.rs | 6 |
2 files changed, 13 insertions, 19 deletions
diff --git a/components/style/counter_style/mod.rs b/components/style/counter_style/mod.rs index 475a2186b04..8ef206fd64e 100644 --- a/components/style/counter_style/mod.rs +++ b/components/style/counter_style/mod.rs @@ -299,7 +299,7 @@ counter_style_descriptors! { /// <https://drafts.csswg.org/css-counter-styles/#counter-style-pad> "pad" pad / eCSSCounterDesc_Pad: Pad = { - Pad(0, Symbol::String("".to_owned())) + Pad(Integer::new(0), Symbol::String("".to_owned())) } /// <https://drafts.csswg.org/css-counter-styles/#counter-style-fallback> @@ -336,14 +336,14 @@ pub enum System { /// 'fixed <integer>?' Fixed { /// '<integer>?' - first_symbol_value: Option<i32> + first_symbol_value: Option<Integer> }, /// 'extends <counter-style-name>' Extends(CustomIdent), } impl Parse for System { - fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { + fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { try_match_ident_ignore_ascii_case! { input, "cyclic" => Ok(System::Cyclic), "numeric" => Ok(System::Numeric), @@ -351,7 +351,7 @@ impl Parse for System { "symbolic" => Ok(System::Symbolic), "additive" => Ok(System::Additive), "fixed" => { - let first_symbol_value = input.try(|i| i.expect_integer()).ok(); + let first_symbol_value = input.try(|i| Integer::parse(context, i)).ok(); Ok(System::Fixed { first_symbol_value: first_symbol_value }) } "extends" => { @@ -515,17 +515,14 @@ where /// <https://drafts.csswg.org/css-counter-styles/#counter-style-pad> #[derive(Clone, Debug, ToCss)] -pub struct Pad(pub u32, pub Symbol); +pub struct Pad(pub Integer, pub Symbol); impl Parse for Pad { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { let pad_with = input.try(|input| Symbol::parse(context, input)); - let min_length = input.expect_integer()?; - if min_length < 0 { - return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) - } + let min_length = Integer::parse_non_negative(context, input)?; let pad_with = pad_with.or_else(|_| Symbol::parse(context, input))?; - Ok(Pad(min_length as u32, pad_with)) + Ok(Pad(min_length, pad_with)) } } @@ -580,7 +577,7 @@ impl Parse for AdditiveSymbols { #[derive(Clone, Debug, ToCss)] pub struct AdditiveTuple { /// <integer> - pub weight: u32, + pub weight: Integer, /// <symbol> pub symbol: Symbol, } @@ -592,13 +589,10 @@ impl OneOrMoreSeparated for AdditiveTuple { impl Parse for AdditiveTuple { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { let symbol = input.try(|input| Symbol::parse(context, input)); - let weight = input.expect_integer()?; - if weight < 0 { - return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) - } + let weight = Integer::parse_non_negative(context, input)?; let symbol = symbol.or_else(|_| Symbol::parse(context, input))?; Ok(AdditiveTuple { - weight: weight as u32, + weight: weight, symbol: symbol, }) } diff --git a/components/style/gecko/rules.rs b/components/style/gecko/rules.rs index bca5196b110..329d66b2f58 100644 --- a/components/style/gecko/rules.rs +++ b/components/style/gecko/rules.rs @@ -281,7 +281,7 @@ impl ToNsCssValue for counter_style::System { let mut a = nsCSSValue::null(); let mut b = nsCSSValue::null(); a.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_FIXED as i32); - b.set_integer(first_symbol_value.unwrap_or(1)); + b.set_integer(first_symbol_value.map_or(1, |v| v.value())); nscssvalue.set_pair(&a, &b); } Extends(other) => { @@ -345,7 +345,7 @@ impl ToNsCssValue for counter_style::Pad { fn convert(self, nscssvalue: &mut nsCSSValue) { let mut min_length = nsCSSValue::null(); let mut pad_with = nsCSSValue::null(); - min_length.set_integer(self.0 as i32); + min_length.set_integer(self.0.value()); pad_with.set_from(self.1); nscssvalue.set_pair(&min_length, &pad_with); } @@ -372,7 +372,7 @@ impl ToNsCssValue for counter_style::AdditiveSymbols { nscssvalue.set_pair_list(self.0.into_iter().map(|tuple| { let mut weight = nsCSSValue::null(); let mut symbol = nsCSSValue::null(); - weight.set_integer(tuple.weight as i32); + weight.set_integer(tuple.weight.value()); symbol.set_from(tuple.symbol); (weight, symbol) })); |