Remove initial value of @counter-style rule descriptors.

This commit is contained in:
Xidorn Quan 2018-04-05 08:43:51 +10:00
parent e06f0d32d0
commit 9ad03d3ec9

View file

@ -15,7 +15,6 @@ use error_reporting::{ContextualParseError, ParseErrorReporter};
use parser::{ParserContext, ParserErrorContext, Parse}; use parser::{ParserContext, ParserErrorContext, Parse};
use selectors::parser::SelectorParseErrorKind; use selectors::parser::SelectorParseErrorKind;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use std::borrow::Cow;
use std::fmt::{self, Write}; use std::fmt::{self, Write};
use std::ops::Range; use std::ops::Range;
use str::CssStringWriter; use str::CssStringWriter;
@ -94,7 +93,7 @@ pub fn parse_counter_style_body<'i, 't, R>(name: CustomIdent,
} }
} }
} }
let error = match *rule.system() { let error = match *rule.resolved_system() {
ref system @ System::Cyclic | ref system @ System::Cyclic |
ref system @ System::Fixed { .. } | ref system @ System::Fixed { .. } |
ref system @ System::Symbolic | ref system @ System::Symbolic |
@ -142,29 +141,9 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for CounterStyleRuleParser<'a, 'b> {
type Error = StyleParseErrorKind<'i>; type Error = StyleParseErrorKind<'i>;
} }
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 { macro_rules! counter_style_descriptors {
( (
$( #[$doc: meta] $name: tt $ident: ident / $gecko_ident: ident: $ty: ty = $initial: tt )+ $( #[$doc: meta] $name: tt $ident: ident / $gecko_ident: ident: $ty: ty, )+
) => { ) => {
/// An @counter-style rule /// An @counter-style rule
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -191,8 +170,20 @@ macro_rules! counter_style_descriptors {
&self.name &self.name
} }
/// Get the system of this counter style rule, default to
/// `symbolic` if not specified.
pub fn resolved_system(&self) -> &System {
match self.system {
Some(ref system) => system,
None => &System::Symbolic,
}
}
$( $(
accessor!(#[$doc] $name $ident: $ty = $initial); #[$doc]
pub fn $ident(&self) -> Option<&$ty> {
self.$ident.as_ref()
}
)+ )+
/// Convert to Gecko types /// Convert to Gecko types
@ -273,51 +264,34 @@ macro_rules! counter_style_descriptors {
counter_style_descriptors! { counter_style_descriptors! {
/// <https://drafts.csswg.org/css-counter-styles/#counter-style-system> /// <https://drafts.csswg.org/css-counter-styles/#counter-style-system>
"system" system / eCSSCounterDesc_System: System = { "system" system / eCSSCounterDesc_System: System,
System::Symbolic
}
/// <https://drafts.csswg.org/css-counter-styles/#counter-style-negative> /// <https://drafts.csswg.org/css-counter-styles/#counter-style-negative>
"negative" negative / eCSSCounterDesc_Negative: Negative = { "negative" negative / eCSSCounterDesc_Negative: Negative,
Negative(Symbol::String("-".to_owned()), None)
}
/// <https://drafts.csswg.org/css-counter-styles/#counter-style-prefix> /// <https://drafts.csswg.org/css-counter-styles/#counter-style-prefix>
"prefix" prefix / eCSSCounterDesc_Prefix: Symbol = { "prefix" prefix / eCSSCounterDesc_Prefix: Symbol,
Symbol::String("".to_owned())
}
/// <https://drafts.csswg.org/css-counter-styles/#counter-style-suffix> /// <https://drafts.csswg.org/css-counter-styles/#counter-style-suffix>
"suffix" suffix / eCSSCounterDesc_Suffix: Symbol = { "suffix" suffix / eCSSCounterDesc_Suffix: Symbol,
Symbol::String(". ".to_owned())
}
/// <https://drafts.csswg.org/css-counter-styles/#counter-style-range> /// <https://drafts.csswg.org/css-counter-styles/#counter-style-range>
"range" range / eCSSCounterDesc_Range: Ranges = { "range" range / eCSSCounterDesc_Range: Ranges,
Ranges(Vec::new()) // Empty Vec represents 'auto'
}
/// <https://drafts.csswg.org/css-counter-styles/#counter-style-pad> /// <https://drafts.csswg.org/css-counter-styles/#counter-style-pad>
"pad" pad / eCSSCounterDesc_Pad: Pad = { "pad" pad / eCSSCounterDesc_Pad: Pad,
Pad(Integer::new(0), Symbol::String("".to_owned()))
}
/// <https://drafts.csswg.org/css-counter-styles/#counter-style-fallback> /// <https://drafts.csswg.org/css-counter-styles/#counter-style-fallback>
"fallback" fallback / eCSSCounterDesc_Fallback: Fallback = { "fallback" fallback / eCSSCounterDesc_Fallback: Fallback,
// FIXME https://bugzilla.mozilla.org/show_bug.cgi?id=1359323 use atom!()
Fallback(CustomIdent(Atom::from("decimal")))
}
/// <https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-symbols> /// <https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-symbols>
"symbols" symbols / eCSSCounterDesc_Symbols: Symbols = ! "symbols" symbols / eCSSCounterDesc_Symbols: Symbols,
/// <https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-additive-symbols> /// <https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-additive-symbols>
"additive-symbols" additive_symbols / eCSSCounterDesc_AdditiveSymbols: AdditiveSymbols = ! "additive-symbols" additive_symbols / eCSSCounterDesc_AdditiveSymbols: AdditiveSymbols,
/// <https://drafts.csswg.org/css-counter-styles/#counter-style-speak-as> /// <https://drafts.csswg.org/css-counter-styles/#counter-style-speak-as>
"speak-as" speak_as / eCSSCounterDesc_SpeakAs: SpeakAs = { "speak-as" speak_as / eCSSCounterDesc_SpeakAs: SpeakAs,
SpeakAs::Auto
}
} }
/// <https://drafts.csswg.org/css-counter-styles/#counter-style-system> /// <https://drafts.csswg.org/css-counter-styles/#counter-style-system>