From 0ba5cae7078ec3db21eadd523fabf5ec65d918ac Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 14 Apr 2017 10:08:44 +0200 Subject: [PATCH] Add 'fallback' descriptor to @counter-style --- components/style/counter_style.rs | 21 +++++++++++++++++++ components/style/gecko/rules.rs | 6 ++++++ .../gecko_bindings/sugar/ns_css_value.rs | 5 +++++ 3 files changed, 32 insertions(+) diff --git a/components/style/counter_style.rs b/components/style/counter_style.rs index 62d9156467d..4d467190714 100644 --- a/components/style/counter_style.rs +++ b/components/style/counter_style.rs @@ -6,6 +6,7 @@ //! //! [counter-style]: https://drafts.csswg.org/css-counter-styles/ +use Atom; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, Token}; use cssparser::{serialize_string, serialize_identifier}; #[cfg(feature = "gecko")] use gecko::rules::CounterStyleDescriptors; @@ -148,6 +149,10 @@ counter_style_descriptors! { /// https://drafts.csswg.org/css-counter-styles/#counter-style-pad "pad" pad / eCSSCounterDesc_Pad: Pad = Pad(0, Symbol::String("".to_owned())); + + /// 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-system @@ -358,3 +363,19 @@ impl ToCss for Pad { self.1.to_css(dest) } } + +/// https://drafts.csswg.org/css-counter-styles/#counter-style-fallback +#[derive(Debug)] +pub struct Fallback(pub CustomIdent); + +impl Parse for Fallback { + fn parse(_context: &ParserContext, input: &mut Parser) -> Result { + parse_counter_style_name(input).map(Fallback) + } +} + +impl ToCss for Fallback { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + self.0.to_css(dest) + } +} diff --git a/components/style/gecko/rules.rs b/components/style/gecko/rules.rs index 6a1f3b6b5e4..33fbe13cae7 100644 --- a/components/style/gecko/rules.rs +++ b/components/style/gecko/rules.rs @@ -221,3 +221,9 @@ impl ToNsCssValue for counter_style::Pad { //nscssvalue.set_pair(min_length, pad_with); } } + +impl ToNsCssValue for counter_style::Fallback { + fn convert(&self, nscssvalue: &mut nsCSSValue) { + nscssvalue.set_ident_from_atom(&self.0 .0) + } +} diff --git a/components/style/gecko_bindings/sugar/ns_css_value.rs b/components/style/gecko_bindings/sugar/ns_css_value.rs index d22f1148549..8d89db94c9c 100644 --- a/components/style/gecko_bindings/sugar/ns_css_value.rs +++ b/components/style/gecko_bindings/sugar/ns_css_value.rs @@ -124,6 +124,11 @@ impl nsCSSValue { self.set_string_from_atom_internal(s, nsCSSUnit::eCSSUnit_String) } + /// Set to a ident value from the given atom + pub fn set_ident_from_atom(&mut self, s: &Atom) { + self.set_string_from_atom_internal(s, nsCSSUnit::eCSSUnit_Ident) + } + /// Set to an identifier value pub fn set_ident(&mut self, s: &str) { self.set_string_internal(s, nsCSSUnit::eCSSUnit_Ident)