diff --git a/components/style/counter_style/mod.rs b/components/style/counter_style/mod.rs index 0919a9d7619..fa614d476de 100644 --- a/components/style/counter_style/mod.rs +++ b/components/style/counter_style/mod.rs @@ -444,7 +444,18 @@ impl Parse for Negative { /// /// Empty Vec represents 'auto' #[derive(Clone, Debug)] -pub struct Ranges(pub Vec>>); +pub struct Ranges(pub Vec>); + +/// A bound found in `Ranges`. +#[derive(Clone, Copy, Debug)] +pub enum CounterBound { + /// An integer bound. + /// + /// FIXME(https://github.com/servo/servo/issues/20197) + Integer(i32), + /// The infinite bound. + Infinite, +} impl Parse for Ranges { fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { @@ -454,7 +465,7 @@ impl Parse for Ranges { input.parse_comma_separated(|input| { let opt_start = parse_bound(input)?; let opt_end = parse_bound(input)?; - if let (Some(start), Some(end)) = (opt_start, opt_end) { + if let (CounterBound::Integer(start), CounterBound::Integer(end)) = (opt_start, opt_end) { if start > end { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) } @@ -465,11 +476,17 @@ impl Parse for Ranges { } } -fn parse_bound<'i, 't>(input: &mut Parser<'i, 't>) -> Result, ParseError<'i>> { +fn parse_bound<'i, 't>( + input: &mut Parser<'i, 't>, +) -> Result> { let location = input.current_source_location(); match *input.next()? { - Token::Number { int_value: Some(v), .. } => Ok(Some(v)), - Token::Ident(ref ident) if ident.eq_ignore_ascii_case("infinite") => Ok(None), + Token::Number { int_value: Some(v), .. } => { + Ok(CounterBound::Integer(v)) + } + Token::Ident(ref ident) if ident.eq_ignore_ascii_case("infinite") => { + Ok(CounterBound::Infinite) + } ref t => Err(location.new_unexpected_token_error(t.clone())), } } @@ -493,7 +510,7 @@ impl ToCss for Ranges { } } -fn range_to_css(range: &Range>, dest: &mut CssWriter) -> fmt::Result +fn range_to_css(range: &Range, dest: &mut CssWriter) -> fmt::Result where W: Write, { @@ -502,11 +519,11 @@ where bound_to_css(range.end, dest) } -fn bound_to_css(range: Option, dest: &mut CssWriter) -> fmt::Result +fn bound_to_css(range: CounterBound, dest: &mut CssWriter) -> fmt::Result where W: Write, { - if let Some(finite) = range { + if let CounterBound::Integer(finite) = range { finite.to_css(dest) } else { dest.write_str("infinite") diff --git a/components/style/gecko/rules.rs b/components/style/gecko/rules.rs index 9460ab2e74b..90d061cd738 100644 --- a/components/style/gecko/rules.rs +++ b/components/style/gecko/rules.rs @@ -6,7 +6,7 @@ use byteorder::{BigEndian, WriteBytesExt}; use computed_values::{font_stretch, font_style, font_weight}; -use counter_style; +use counter_style::{self, CounterBound}; use cssparser::UnicodeRange; use font_face::{FontFaceRuleData, Source, FontDisplay, FontWeight}; use gecko_bindings::bindings; @@ -324,8 +324,8 @@ impl ToNsCssValue for counter_style::Ranges { nscssvalue.set_auto(); } else { nscssvalue.set_pair_list(self.0.into_iter().map(|range| { - fn set_bound(bound: Option, nscssvalue: &mut nsCSSValue) { - if let Some(finite) = bound { + fn set_bound(bound: CounterBound, nscssvalue: &mut nsCSSValue) { + if let CounterBound::Integer(finite) = bound { nscssvalue.set_integer(finite) } else { nscssvalue.set_enum(structs::NS_STYLE_COUNTER_RANGE_INFINITE as i32)