From e27de3842d052470b88ca99e528ec69d958e7826 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 14 Apr 2017 09:56:34 +0200 Subject: [PATCH] Add 'pad' descritor of @counter-style --- components/style/counter_style.rs | 27 +++++++++++++++++++++++++++ components/style/gecko/rules.rs | 11 +++++++++++ 2 files changed, 38 insertions(+) diff --git a/components/style/counter_style.rs b/components/style/counter_style.rs index ad8897e99c2..62d9156467d 100644 --- a/components/style/counter_style.rs +++ b/components/style/counter_style.rs @@ -145,6 +145,9 @@ counter_style_descriptors! { /// https://drafts.csswg.org/css-counter-styles/#counter-style-range "range" range / eCSSCounterDesc_Range: Ranges = Ranges(Vec::new()); // Empty Vec represents 'auto' + + /// 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-system @@ -331,3 +334,27 @@ fn bound_to_css(range: Option, dest: &mut W) -> fmt::Result where W: fmt dest.write_str("infinite") } } + +/// https://drafts.csswg.org/css-counter-styles/#counter-style-pad +#[derive(Debug)] +pub struct Pad(pub u32, pub Symbol); + +impl Parse for Pad { + fn parse(context: &ParserContext, input: &mut Parser) -> Result { + let pad_with = input.try(|input| Symbol::parse(context, input)); + let min_length = input.expect_integer()?; + if min_length < 0 { + return Err(()) + } + let pad_with = pad_with.or_else(|()| Symbol::parse(context, input))?; + Ok(Pad(min_length as u32, pad_with)) + } +} + +impl ToCss for Pad { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + write!(dest, "{}", self.0)?; + dest.write_char(' ')?; + self.1.to_css(dest) + } +} diff --git a/components/style/gecko/rules.rs b/components/style/gecko/rules.rs index 83429275e03..6a1f3b6b5e4 100644 --- a/components/style/gecko/rules.rs +++ b/components/style/gecko/rules.rs @@ -210,3 +210,14 @@ impl ToNsCssValue for counter_style::Ranges { } } } + +impl ToNsCssValue for counter_style::Pad { + fn convert(&self, _nscssvalue: &mut nsCSSValue) { + let mut min_length = nsCSSValue::null(); + let mut pad_with = nsCSSValue::null(); + min_length.set_integer(self.0 as i32); + pad_with.set_from(&self.1); + // FIXME: add bindings for nsCSSValue::SetPairValue + //nscssvalue.set_pair(min_length, pad_with); + } +}