From fe15663423fe5d090f937c1cf106b04c40f7d3fc Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 14 Apr 2017 10:35:13 +0200 Subject: [PATCH] Add the 'symbols' descriptor for @counter-style --- components/style/counter_style.rs | 39 ++++++++++++++++++++++++++++++- components/style/gecko/rules.rs | 8 +++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/components/style/counter_style.rs b/components/style/counter_style.rs index 4d467190714..95e3d971f53 100644 --- a/components/style/counter_style.rs +++ b/components/style/counter_style.rs @@ -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 @@ -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 @@ -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); + +impl Parse for Symbols { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + 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(&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(()) + } +} diff --git a/components/style/gecko/rules.rs b/components/style/gecko/rules.rs index 33fbe13cae7..13681b4b8f9 100644 --- a/components/style/gecko/rules.rs +++ b/components/style/gecko/rules.rs @@ -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 + } + } +}