Add 'additive-symbols' descriptor for @counter-style

This commit is contained in:
Simon Sapin 2017-04-14 11:06:41 +02:00
parent f93a9a4b10
commit 62d261add4
2 changed files with 41 additions and 4 deletions

View file

@ -193,8 +193,11 @@ counter_style_descriptors! {
Fallback(CustomIdent(Atom::from("decimal"))) Fallback(CustomIdent(Atom::from("decimal")))
} }
/// https://drafts.csswg.org/css-counter-styles/#counter-style-symbols /// https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-symbols
"symbols" symbols / eCSSCounterDesc_Symbols: Symbols = ! "symbols" symbols / eCSSCounterDesc_Symbols: Symbols = !
/// https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-additive-symbols
"additive-symbols" additive_symbols / eCSSCounterDesc_AdditiveSymbols: Vec<AdditiveSymbol> = !
} }
/// https://drafts.csswg.org/css-counter-styles/#counter-style-system /// https://drafts.csswg.org/css-counter-styles/#counter-style-system
@ -400,8 +403,7 @@ impl Parse for Pad {
impl ToCss for Pad { impl ToCss for Pad {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
write!(dest, "{}", self.0)?; write!(dest, "{} ", self.0)?;
dest.write_char(' ')?;
self.1.to_css(dest) self.1.to_css(dest)
} }
} }
@ -422,7 +424,7 @@ impl ToCss for Fallback {
} }
} }
/// https://drafts.csswg.org/css-counter-styles/#counter-style-symbols /// https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-symbols
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Symbols(pub Vec<Symbol>); pub struct Symbols(pub Vec<Symbol>);
@ -455,3 +457,31 @@ impl ToCss for Symbols {
Ok(()) Ok(())
} }
} }
/// https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-additive-symbols
#[derive(Debug, Clone)]
pub struct AdditiveSymbol {
value: i32,
symbol: Symbol,
}
impl OneOrMoreCommaSeparated for AdditiveSymbol {}
impl Parse for AdditiveSymbol {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
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,
symbol: symbol,
})
}
}
impl ToCss for AdditiveSymbol {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
write!(dest, "{} ", self.value)?;
self.symbol.to_css(dest)
}
}

View file

@ -234,3 +234,10 @@ impl ToNsCssValue for counter_style::Symbols {
// FIXME: add bindings for nsCSSValueList // FIXME: add bindings for nsCSSValueList
} }
} }
impl ToNsCssValue for Vec<counter_style::AdditiveSymbol> {
fn convert(&self, _nscssvalue: &mut nsCSSValue) {
debug_assert!(!self.is_empty());
// FIXME: add bindings for nsCSSValuePairList
}
}