diff --git a/components/style/counter_style.rs b/components/style/counter_style.rs index ebeeaa9bc2d..772707cbfa8 100644 --- a/components/style/counter_style.rs +++ b/components/style/counter_style.rs @@ -234,7 +234,7 @@ counter_style_descriptors! { "symbols" symbols / eCSSCounterDesc_Symbols: Symbols = ! /// https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-additive-symbols - "additive-symbols" additive_symbols / eCSSCounterDesc_AdditiveSymbols: Vec = ! + "additive-symbols" additive_symbols / eCSSCounterDesc_AdditiveSymbols: AdditiveSymbols = ! /// https://drafts.csswg.org/css-counter-styles/#counter-style-speak-as "speak-as" speak_as / eCSSCounterDesc_SpeakAs: SpeakAs = { @@ -502,26 +502,50 @@ impl ToCss for Symbols { /// https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-additive-symbols #[derive(Debug, Clone)] -pub struct AdditiveSymbol { - value: i32, +pub struct AdditiveSymbols(pub Vec); + +impl Parse for AdditiveSymbols { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + let tuples = Vec::::parse(context, input)?; + // FIXME maybe? https://github.com/w3c/csswg-drafts/issues/1220 + if tuples.windows(2).any(|window| window[0].value <= window[1].value) { + return Err(()) + } + Ok(AdditiveSymbols(tuples)) + } +} + +impl ToCss for AdditiveSymbols { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + self.0.to_css(dest) + } +} + +/// && +#[derive(Debug, Clone)] +pub struct AdditiveTuple { + value: u32, symbol: Symbol, } -impl OneOrMoreCommaSeparated for AdditiveSymbol {} +impl OneOrMoreCommaSeparated for AdditiveTuple {} -impl Parse for AdditiveSymbol { +impl Parse for AdditiveTuple { fn parse(context: &ParserContext, input: &mut Parser) -> Result { - let value = input.try(|input| input.expect_integer()); - let symbol = Symbol::parse(context, input)?; - let value = value.or_else(|()| input.expect_integer())?; - Ok(AdditiveSymbol { - value: value, + let symbol = input.try(|input| Symbol::parse(context, input)); + let value = input.expect_integer()?; + if value < 0 { + return Err(()) + } + let symbol = symbol.or_else(|()| Symbol::parse(context, input))?; + Ok(AdditiveTuple { + value: value as u32, symbol: symbol, }) } } -impl ToCss for AdditiveSymbol { +impl ToCss for AdditiveTuple { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { write!(dest, "{} ", self.value)?; self.symbol.to_css(dest) diff --git a/components/style/gecko/rules.rs b/components/style/gecko/rules.rs index d26fd08b689..d2d78de238a 100644 --- a/components/style/gecko/rules.rs +++ b/components/style/gecko/rules.rs @@ -235,9 +235,9 @@ impl ToNsCssValue for counter_style::Symbols { } } -impl ToNsCssValue for Vec { +impl ToNsCssValue for counter_style::AdditiveSymbols { fn convert(&self, _nscssvalue: &mut nsCSSValue) { - debug_assert!(!self.is_empty()); + debug_assert!(!self.0.is_empty()); // FIXME: add bindings for nsCSSValuePairList } }