Skip to content

Commit

Permalink
Add 'additive-symbols' descriptor for @counter-style
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Apr 26, 2017
1 parent f93a9a4 commit 62d261a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
38 changes: 34 additions & 4 deletions components/style/counter_style.rs
Expand Up @@ -193,8 +193,11 @@ counter_style_descriptors! {
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 = !

/// 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
Expand Down Expand Up @@ -400,8 +403,7 @@ impl Parse for Pad {

impl ToCss for Pad {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
write!(dest, "{}", self.0)?;
dest.write_char(' ')?;
write!(dest, "{} ", self.0)?;
self.1.to_css(dest)
}
}
Expand All @@ -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)]
pub struct Symbols(pub Vec<Symbol>);

Expand Down Expand Up @@ -455,3 +457,31 @@ impl ToCss for Symbols {
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)
}
}
7 changes: 7 additions & 0 deletions components/style/gecko/rules.rs
Expand Up @@ -234,3 +234,10 @@ impl ToNsCssValue for counter_style::Symbols {
// 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
}
}

0 comments on commit 62d261a

Please sign in to comment.