Skip to content

Commit

Permalink
Add speak-as 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 62d261a commit 6dc317f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
61 changes: 61 additions & 0 deletions components/style/counter_style.rs
Expand Up @@ -198,6 +198,11 @@ counter_style_descriptors! {

/// 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-speak-as
"speak-as" speak_as / eCSSCounterDesc_SpeakAs: SpeakAs = {
SpeakAs::Auto
}
}

/// https://drafts.csswg.org/css-counter-styles/#counter-style-system
Expand Down Expand Up @@ -485,3 +490,59 @@ impl ToCss for AdditiveSymbol {
self.symbol.to_css(dest)
}
}

/// https://drafts.csswg.org/css-counter-styles/#counter-style-speak-as
#[derive(Debug, Clone)]
pub enum SpeakAs {
/// auto
Auto,
/// bullets
Bullets,
/// numbers
Numbers,
/// words
Words,
// /// spell-out, not supported, see bug 1024178
// SpellOut,
/// <counter-style-name>
Other(CustomIdent),
}

impl Parse for SpeakAs {
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
let mut is_spell_out = false;
let result = input.try(|input| {
match_ignore_ascii_case! { &input.expect_ident()?,
"auto" => Ok(SpeakAs::Auto),
"bullets" => Ok(SpeakAs::Bullets),
"numbers" => Ok(SpeakAs::Numbers),
"words" => Ok(SpeakAs::Words),
"spell-out" => {
is_spell_out = true;
Err(())
}
_ => Err(())
}
});
if is_spell_out {
// spell-out is not supported, but don’t parse it as a <counter-style-name>.
// See bug 1024178.
return Err(())
}
result.or_else(|()| {
Ok(SpeakAs::Other(parse_counter_style_name(input)?))
})
}
}

impl ToCss for SpeakAs {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
SpeakAs::Auto => dest.write_str("auto"),
SpeakAs::Bullets => dest.write_str("bullets"),
SpeakAs::Numbers => dest.write_str("numbers"),
SpeakAs::Words => dest.write_str("words"),
SpeakAs::Other(ref other) => other.to_css(dest),
}
}
}
13 changes: 13 additions & 0 deletions components/style/gecko/rules.rs
Expand Up @@ -241,3 +241,16 @@ impl ToNsCssValue for Vec<counter_style::AdditiveSymbol> {
// FIXME: add bindings for nsCSSValuePairList
}
}

impl ToNsCssValue for counter_style::SpeakAs {
fn convert(&self, nscssvalue: &mut nsCSSValue) {
use counter_style::SpeakAs::*;
match *self {
Auto => {} //nscssvalue.set_auto(), // FIXME: add bindings for nsCSSValue::SetAutoValue
Bullets => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SPEAKAS_BULLETS as i32),
Numbers => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SPEAKAS_NUMBERS as i32),
Words => nscssvalue.set_enum(structs::NS_STYLE_COUNTER_SPEAKAS_WORDS as i32),
Other(ref other) => nscssvalue.set_ident_from_atom(&other.0),
}
}
}

0 comments on commit 6dc317f

Please sign in to comment.