From f93a9a4b107f715b7d8f2f5eefad1bab5ed2e03c Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 14 Apr 2017 10:52:47 +0200 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20make=20up=20initial=20values=20?= =?UTF-8?q?not=20in=20spec=20for=20@counter-style=20descriptors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/style/counter_style.rs | 63 +++++++++++++++++++++---------- components/style/gecko/rules.rs | 5 +-- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/components/style/counter_style.rs b/components/style/counter_style.rs index 763037884b1..0a3581a99b9 100644 --- a/components/style/counter_style.rs +++ b/components/style/counter_style.rs @@ -58,10 +58,29 @@ impl<'a, 'b> AtRuleParser for CounterStyleRuleParser<'a, 'b> { type AtRule = (); } +macro_rules! accessor { + (#[$doc: meta] $name: tt $ident: ident: $ty: ty = !) => { + #[$doc] + pub fn $ident(&self) -> Option<&$ty> { + self.$ident.as_ref() + } + }; + + (#[$doc: meta] $name: tt $ident: ident: $ty: ty = $initial: expr) => { + #[$doc] + pub fn $ident(&self) -> Cow<$ty> { + if let Some(ref value) = self.$ident { + Cow::Borrowed(value) + } else { + Cow::Owned($initial) + } + } + } +} macro_rules! counter_style_descriptors { ( - $( #[$doc: meta] $name: tt $ident: ident / $gecko_ident: ident: $ty: ty = $initial: expr; )+ + $( #[$doc: meta] $name: tt $ident: ident / $gecko_ident: ident: $ty: ty = $initial: tt )+ ) => { /// An @counter-style rule #[derive(Debug)] @@ -84,14 +103,7 @@ macro_rules! counter_style_descriptors { } $( - #[$doc] - pub fn $ident(&self) -> Cow<$ty> { - if let Some(ref value) = self.$ident { - Cow::Borrowed(value) - } else { - Cow::Owned($initial) - } - } + accessor!(#[$doc] $name $ident: $ty = $initial); )+ /// Convert to Gecko types @@ -147,31 +159,42 @@ macro_rules! counter_style_descriptors { counter_style_descriptors! { /// https://drafts.csswg.org/css-counter-styles/#counter-style-system - "system" system / eCSSCounterDesc_System: System = System::Symbolic; + "system" system / eCSSCounterDesc_System: System = { + System::Symbolic + } /// https://drafts.csswg.org/css-counter-styles/#counter-style-negative - "negative" negative / eCSSCounterDesc_Negative: Negative = - Negative(Symbol::String("-".to_owned()), None); + "negative" negative / eCSSCounterDesc_Negative: Negative = { + Negative(Symbol::String("-".to_owned()), None) + } /// https://drafts.csswg.org/css-counter-styles/#counter-style-prefix - "prefix" prefix / eCSSCounterDesc_Prefix: Symbol = Symbol::String("".to_owned()); + "prefix" prefix / eCSSCounterDesc_Prefix: Symbol = { + Symbol::String("".to_owned()) + } /// https://drafts.csswg.org/css-counter-styles/#counter-style-suffix - "suffix" suffix / eCSSCounterDesc_Suffix: Symbol = Symbol::String(". ".to_owned()); + "suffix" suffix / eCSSCounterDesc_Suffix: Symbol = { + Symbol::String(". ".to_owned()) + } /// https://drafts.csswg.org/css-counter-styles/#counter-style-range - "range" range / eCSSCounterDesc_Range: Ranges = - Ranges(Vec::new()); // Empty Vec represents 'auto' + "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())); + "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"))); + "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()); + "symbols" symbols / eCSSCounterDesc_Symbols: Symbols = ! } /// https://drafts.csswg.org/css-counter-styles/#counter-style-system diff --git a/components/style/gecko/rules.rs b/components/style/gecko/rules.rs index 13681b4b8f9..e36b1a5c724 100644 --- a/components/style/gecko/rules.rs +++ b/components/style/gecko/rules.rs @@ -230,8 +230,7 @@ impl ToNsCssValue for counter_style::Fallback { impl ToNsCssValue for counter_style::Symbols { fn convert(&self, _nscssvalue: &mut nsCSSValue) { - if !self.0.is_empty() { - // FIXME: add bindings for nsCSSValueList - } + debug_assert!(!self.0.is_empty()); + // FIXME: add bindings for nsCSSValueList } }