Skip to content

Commit

Permalink
Add the 'system' descriptor of @counter-style
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Apr 26, 2017
1 parent 797f40b commit 4477a2d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
51 changes: 49 additions & 2 deletions components/style/counter_style.rs
Expand Up @@ -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, ()> {
Expand Down Expand Up @@ -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(())
}
}
Expand All @@ -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)
}
}
}
}
12 changes: 12 additions & 0 deletions components/style/gecko/rules.rs
Expand Up @@ -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!()
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/style/stylesheets.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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" => {
Expand Down

0 comments on commit 4477a2d

Please sign in to comment.