diff --git a/components/style/counter_style.rs b/components/style/counter_style.rs index 88de60751f72..84bfb8806fb9 100644 --- a/components/style/counter_style.rs +++ b/components/style/counter_style.rs @@ -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 = ! + + /// 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 @@ -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, + /// + Other(CustomIdent), +} + +impl Parse for SpeakAs { + fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + 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 . + // See bug 1024178. + return Err(()) + } + result.or_else(|()| { + Ok(SpeakAs::Other(parse_counter_style_name(input)?)) + }) + } +} + +impl ToCss for SpeakAs { + fn to_css(&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), + } + } +} diff --git a/components/style/gecko/rules.rs b/components/style/gecko/rules.rs index d9e27faf6831..d26fd08b689b 100644 --- a/components/style/gecko/rules.rs +++ b/components/style/gecko/rules.rs @@ -241,3 +241,16 @@ impl ToNsCssValue for Vec { // 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), + } + } +}