From 4477a2da40c1a6c884e808252f3bddc38357a7a0 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 14 Apr 2017 08:09:27 +0200 Subject: [PATCH] Add the 'system' descriptor of @counter-style --- components/style/counter_style.rs | 51 +++++++++++++++++++++++++++++-- components/style/gecko/rules.rs | 12 ++++++++ components/style/stylesheets.rs | 4 +-- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/components/style/counter_style.rs b/components/style/counter_style.rs index a78a64f31ecd..19290f8ea3b2 100644 --- a/components/style/counter_style.rs +++ b/components/style/counter_style.rs @@ -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::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 { @@ -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 ?' + Fixed { + /// '?' + first_symbol_value: Option + }, + /// 'extends ' + Extends(CustomIdent), } impl Parse for System { fn parse(_context: &ParserContext, input: &mut Parser) -> Result { 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(&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) + } } } } diff --git a/components/style/gecko/rules.rs b/components/style/gecko/rules.rs index 0dced7dea569..086600059bbb 100644 --- a/components/style/gecko/rules.rs +++ b/components/style/gecko/rules.rs @@ -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!() + } } } } diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index 7429370a4582..bf7c10178f06 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -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" => {