Skip to content

Commit

Permalink
Add the '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 0ba5cae commit fe15663
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
39 changes: 38 additions & 1 deletion components/style/counter_style.rs
Expand Up @@ -16,7 +16,7 @@ use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use std::ascii::AsciiExt;
use std::fmt;
use std::ops::Range;
use style_traits::ToCss;
use style_traits::{ToCss, OneOrMoreCommaSeparated};
use values::CustomIdent;

/// Parse the prelude of an @counter-style rule
Expand Down Expand Up @@ -153,6 +153,9 @@ counter_style_descriptors! {
/// https://drafts.csswg.org/css-counter-styles/#counter-style-fallback
"fallback" fallback / eCSSCounterDesc_Fallback: Fallback =
Fallback(CustomIdent(Atom::from("decimal")));

/// https://drafts.csswg.org/css-counter-styles/#counter-style-symbols
"symbols" symbols / eCSSCounterDesc_Symbols: Symbols = Symbols(Vec::new());
}

/// https://drafts.csswg.org/css-counter-styles/#counter-style-system
Expand Down Expand Up @@ -379,3 +382,37 @@ impl ToCss for Fallback {
self.0.to_css(dest)
}
}

/// https://drafts.csswg.org/css-counter-styles/#counter-style-symbols
#[derive(Debug)]
pub struct Symbols(pub Vec<Symbol>);

impl Parse for Symbols {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
let mut symbols = Vec::new();
loop {
if let Ok(s) = input.try(|input| Symbol::parse(context, input)) {
symbols.push(s)
} else {
if symbols.is_empty() {
return Err(())
} else {
return Ok(Symbols(symbols))
}
}
}
}
}

impl ToCss for Symbols {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let mut iter = self.0.iter();
let first = iter.next().expect("expected at least one symbol");
first.to_css(dest)?;
for item in iter {
dest.write_char(' ')?;
item.to_css(dest)?;
}
Ok(())
}
}
8 changes: 8 additions & 0 deletions components/style/gecko/rules.rs
Expand Up @@ -227,3 +227,11 @@ impl ToNsCssValue for counter_style::Fallback {
nscssvalue.set_ident_from_atom(&self.0 .0)
}
}

impl ToNsCssValue for counter_style::Symbols {
fn convert(&self, _nscssvalue: &mut nsCSSValue) {
if !self.0.is_empty() {
// FIXME: add bindings for nsCSSValueList
}
}
}

0 comments on commit fe15663

Please sign in to comment.