Add 'fallback' descriptor to @counter-style

This commit is contained in:
Simon Sapin 2017-04-14 10:08:44 +02:00
parent e27de3842d
commit 0ba5cae707
3 changed files with 32 additions and 0 deletions

View file

@ -6,6 +6,7 @@
//! //!
//! [counter-style]: https://drafts.csswg.org/css-counter-styles/ //! [counter-style]: https://drafts.csswg.org/css-counter-styles/
use Atom;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, Token}; use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, Token};
use cssparser::{serialize_string, serialize_identifier}; use cssparser::{serialize_string, serialize_identifier};
#[cfg(feature = "gecko")] use gecko::rules::CounterStyleDescriptors; #[cfg(feature = "gecko")] use gecko::rules::CounterStyleDescriptors;
@ -148,6 +149,10 @@ counter_style_descriptors! {
/// 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(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")));
} }
/// https://drafts.csswg.org/css-counter-styles/#counter-style-system /// https://drafts.csswg.org/css-counter-styles/#counter-style-system
@ -358,3 +363,19 @@ impl ToCss for Pad {
self.1.to_css(dest) 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<Self, ()> {
parse_counter_style_name(input).map(Fallback)
}
}
impl ToCss for Fallback {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.0.to_css(dest)
}
}

View file

@ -221,3 +221,9 @@ impl ToNsCssValue for counter_style::Pad {
//nscssvalue.set_pair(min_length, pad_with); //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)
}
}

View file

@ -124,6 +124,11 @@ impl nsCSSValue {
self.set_string_from_atom_internal(s, nsCSSUnit::eCSSUnit_String) 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 /// Set to an identifier value
pub fn set_ident(&mut self, s: &str) { pub fn set_ident(&mut self, s: &str) {
self.set_string_internal(s, nsCSSUnit::eCSSUnit_Ident) self.set_string_internal(s, nsCSSUnit::eCSSUnit_Ident)