mirror of
https://github.com/servo/servo.git
synced 2025-06-20 15:18:58 +01:00
Add missing 'additive-symbols' validity checks
This commit is contained in:
parent
331acfaf9b
commit
ade56bbe8d
2 changed files with 37 additions and 13 deletions
|
@ -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 = {
|
||||
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue