Skip to content

Commit

Permalink
Add missing 'additive-symbols' validity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Apr 26, 2017
1 parent 331acfa commit ade56bb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
46 changes: 35 additions & 11 deletions components/style/counter_style.rs
Expand Up @@ -234,7 +234,7 @@ counter_style_descriptors! {
"symbols" symbols / eCSSCounterDesc_Symbols: Symbols = !

/// https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-additive-symbols
"additive-symbols" additive_symbols / eCSSCounterDesc_AdditiveSymbols: Vec<AdditiveSymbol> = !
"additive-symbols" additive_symbols / eCSSCounterDesc_AdditiveSymbols: AdditiveSymbols = !

/// https://drafts.csswg.org/css-counter-styles/#counter-style-speak-as
"speak-as" speak_as / eCSSCounterDesc_SpeakAs: SpeakAs = {
Expand Down Expand Up @@ -502,26 +502,50 @@ impl ToCss for Symbols {

/// https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-additive-symbols
#[derive(Debug, Clone)]
pub struct AdditiveSymbol {
value: i32,
pub struct AdditiveSymbols(pub Vec<AdditiveTuple>);

impl Parse for AdditiveSymbols {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
let tuples = Vec::<AdditiveTuple>::parse(context, input)?;
// FIXME maybe? https://github.com/w3c/csswg-drafts/issues/1220
if tuples.windows(2).any(|window| window[0].value <= window[1].value) {
return Err(())
}
Ok(AdditiveSymbols(tuples))
}
}

impl ToCss for AdditiveSymbols {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.0.to_css(dest)
}
}

/// <integer> && <symbol>
#[derive(Debug, Clone)]
pub struct AdditiveTuple {
value: u32,
symbol: Symbol,
}

impl OneOrMoreCommaSeparated for AdditiveSymbol {}
impl OneOrMoreCommaSeparated for AdditiveTuple {}

impl Parse for AdditiveSymbol {
impl Parse for AdditiveTuple {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
let value = input.try(|input| input.expect_integer());
let symbol = Symbol::parse(context, input)?;
let value = value.or_else(|()| input.expect_integer())?;
Ok(AdditiveSymbol {
value: value,
let symbol = input.try(|input| Symbol::parse(context, input));
let value = input.expect_integer()?;
if value < 0 {
return Err(())
}
let symbol = symbol.or_else(|()| Symbol::parse(context, input))?;
Ok(AdditiveTuple {
value: value as u32,
symbol: symbol,
})
}
}

impl ToCss for AdditiveSymbol {
impl ToCss for AdditiveTuple {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
write!(dest, "{} ", self.value)?;
self.symbol.to_css(dest)
Expand Down
4 changes: 2 additions & 2 deletions components/style/gecko/rules.rs
Expand Up @@ -235,9 +235,9 @@ impl ToNsCssValue for counter_style::Symbols {
}
}

impl ToNsCssValue for Vec<counter_style::AdditiveSymbol> {
impl ToNsCssValue for counter_style::AdditiveSymbols {
fn convert(&self, _nscssvalue: &mut nsCSSValue) {
debug_assert!(!self.is_empty());
debug_assert!(!self.0.is_empty());
// FIXME: add bindings for nsCSSValuePairList
}
}
Expand Down

0 comments on commit ade56bb

Please sign in to comment.