mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add the 'system' descriptor of @counter-style
This commit is contained in:
parent
797f40b0a3
commit
4477a2da40
3 changed files with 63 additions and 4 deletions
|
@ -15,6 +15,11 @@ use std::fmt;
|
|||
use style_traits::ToCss;
|
||||
use values::CustomIdent;
|
||||
|
||||
/// Parse the prelude of an @counter-style rule
|
||||
pub fn parse_counter_style_name(input: &mut Parser) -> Result<CustomIdent, ()> {
|
||||
CustomIdent::from_ident(input.expect_ident()?, &["decimal", "none"])
|
||||
}
|
||||
|
||||
/// Parse the body (inside `{}`) of an @counter-style rule
|
||||
pub fn parse_counter_style_body(name: CustomIdent, context: &ParserContext, input: &mut Parser)
|
||||
-> Result<CounterStyleRule, ()> {
|
||||
|
@ -128,14 +133,41 @@ counter_style_descriptors! {
|
|||
/// Value of the 'system' descriptor
|
||||
#[derive(Debug)]
|
||||
pub enum System {
|
||||
/// Cycles through provided symbols, doubling, tripling, etc.
|
||||
/// 'cyclic'
|
||||
Cyclic,
|
||||
/// 'numeric'
|
||||
Numeric,
|
||||
/// 'alphabetic'
|
||||
Alphabetic,
|
||||
/// 'symbolic'
|
||||
Symbolic,
|
||||
/// 'additive'
|
||||
Additive,
|
||||
/// 'fixed <integer>?'
|
||||
Fixed {
|
||||
/// '<integer>?'
|
||||
first_symbol_value: Option<i32>
|
||||
},
|
||||
/// 'extends <counter-style-name>'
|
||||
Extends(CustomIdent),
|
||||
}
|
||||
|
||||
impl Parse for System {
|
||||
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
match_ignore_ascii_case! { &input.expect_ident()?,
|
||||
"cyclic" => Ok(System::Cyclic),
|
||||
"numeric" => Ok(System::Numeric),
|
||||
"alphabetic" => Ok(System::Alphabetic),
|
||||
"symbolic" => Ok(System::Symbolic),
|
||||
"additive" => Ok(System::Additive),
|
||||
"fixed" => {
|
||||
let first_symbol_value = input.try(|i| i.expect_integer()).ok();
|
||||
Ok(System::Fixed { first_symbol_value: first_symbol_value })
|
||||
}
|
||||
"extends" => {
|
||||
let other = parse_counter_style_name(input)?;
|
||||
Ok(System::Extends(other))
|
||||
}
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
|
@ -144,7 +176,22 @@ impl Parse for System {
|
|||
impl ToCss for System {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
System::Symbolic => dest.write_str("symbolic")
|
||||
System::Cyclic => dest.write_str("cyclic"),
|
||||
System::Numeric => dest.write_str("numeric"),
|
||||
System::Alphabetic => dest.write_str("alphabetic"),
|
||||
System::Symbolic => dest.write_str("symbolic"),
|
||||
System::Additive => dest.write_str("additive"),
|
||||
System::Fixed { first_symbol_value } => {
|
||||
if let Some(value) = first_symbol_value {
|
||||
write!(dest, "fixed {}", value)
|
||||
} else {
|
||||
dest.write_str("fixed")
|
||||
}
|
||||
}
|
||||
System::Extends(ref other) => {
|
||||
dest.write_str("extends ")?;
|
||||
other.to_css(dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,7 +141,19 @@ pub type CounterStyleDescriptors = [nsCSSValue; nsCSSCounterDesc::eCSSCounterDes
|
|||
impl ToNsCssValue for System {
|
||||
fn convert(&self, v: &mut nsCSSValue) {
|
||||
match *self {
|
||||
System::Cyclic => v.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_CYCLIC as i32),
|
||||
System::Numeric => v.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_NUMERIC as i32),
|
||||
System::Alphabetic => v.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_ALPHABETIC as i32),
|
||||
System::Symbolic => v.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_SYMBOLIC as i32),
|
||||
System::Additive => v.set_enum(structs::NS_STYLE_COUNTER_SYSTEM_ADDITIVE as i32),
|
||||
System::Fixed { first_symbol_value: _ } => {
|
||||
// FIXME: add bindings for nsCSSValue::SetPairValue or equivalent
|
||||
unimplemented!()
|
||||
}
|
||||
System::Extends(ref _other) => {
|
||||
// FIXME: add bindings for nsCSSValue::SetPairValue or equivalent
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#![deny(missing_docs)]
|
||||
|
||||
use {Atom, Prefix, Namespace};
|
||||
use counter_style::{CounterStyleRule, parse_counter_style_body};
|
||||
use counter_style::{CounterStyleRule, parse_counter_style_name, parse_counter_style_body};
|
||||
use cssparser::{AtRuleParser, Parser, QualifiedRuleParser};
|
||||
use cssparser::{AtRuleType, RuleListParser, Token, parse_one_rule};
|
||||
use cssparser::ToCss as ParserToCss;
|
||||
|
@ -1116,7 +1116,7 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
|
|||
// Support for this rule is not fully implemented in Servo yet.
|
||||
return Err(())
|
||||
}
|
||||
let name = CustomIdent::from_ident(input.expect_ident()?, &["decimal", "none"])?;
|
||||
let name = parse_counter_style_name(input)?;
|
||||
Ok(AtRuleType::WithBlock(AtRulePrelude::CounterStyle(name)))
|
||||
},
|
||||
"viewport" => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue