diff --git a/components/style/counter_style/mod.rs b/components/style/counter_style/mod.rs index 4e6f5b6addc..4aa4de89551 100644 --- a/components/style/counter_style/mod.rs +++ b/components/style/counter_style/mod.rs @@ -22,8 +22,12 @@ use std::ops::Range; use style_traits::{Comma, OneOrMoreSeparated, ParseError, StyleParseErrorKind, ToCss}; use values::CustomIdent; -/// Parse the prelude of an @counter-style rule -pub fn parse_counter_style_name<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { +/// Parse a counter style name reference. +/// +/// This allows the reserved counter style names "decimal" and "disc". +pub fn parse_counter_style_name<'i, 't>( + input: &mut Parser<'i, 't> +) -> Result> { macro_rules! predefined { ($($name: expr,)+) => { { @@ -41,7 +45,7 @@ pub fn parse_counter_style_name<'i, 't>(input: &mut Parser<'i, 't>) -> Result value. CustomIdent::from_ident(location, ident, &["none"]) } } @@ -50,6 +54,20 @@ pub fn parse_counter_style_name<'i, 't>(input: &mut Parser<'i, 't>) -> Result( + input: &mut Parser<'i, 't> +) -> Result> { + parse_counter_style_name(input) + .and_then(|ident| { + if ident.0 == atom!("decimal") || ident.0 == atom!("disc") { + Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) + } else { + Ok(ident) + } + }) +} + /// Parse the body (inside `{}`) of an @counter-style rule pub fn parse_counter_style_body<'i, 't, R>(name: CustomIdent, context: &ParserContext, diff --git a/components/style/stylesheets/rule_parser.rs b/components/style/stylesheets/rule_parser.rs index a06e68f335c..ecbfd3332b6 100644 --- a/components/style/stylesheets/rule_parser.rs +++ b/components/style/stylesheets/rule_parser.rs @@ -5,7 +5,7 @@ //! Parsing of the stylesheet contents. use {Namespace, Prefix}; -use counter_style::{parse_counter_style_body, parse_counter_style_name}; +use counter_style::{parse_counter_style_body, parse_counter_style_name_definition}; use cssparser::{AtRuleParser, AtRuleType, Parser, QualifiedRuleParser, RuleListParser}; use cssparser::{CowRcStr, SourceLocation, BasicParseError, BasicParseErrorKind}; use error_reporting::{ContextualParseError, ParseErrorReporter}; @@ -383,13 +383,7 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a // Support for this rule is not fully implemented in Servo yet. return Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone()))) } - let name = parse_counter_style_name(input)?; - // ASCII-case-insensitive matches for "decimal" and "disc". - // The name is already lower-cased by `parse_counter_style_name` - // so we can use == here. - if name.0 == atom!("decimal") || name.0 == atom!("disc") { - return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) - } + let name = parse_counter_style_name_definition(input)?; Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::CounterStyle(name))) }, "viewport" => { diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 3a1af21f726..e9ef9d8104f 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -18,6 +18,7 @@ use std::ptr; use style::applicable_declarations::ApplicableDeclarationBlock; use style::context::{CascadeInputs, QuirksMode, SharedStyleContext, StyleContext}; use style::context::ThreadLocalStyleContext; +use style::counter_style; use style::data::{ElementStyles, self}; use style::dom::{ShowSubtreeData, TDocument, TElement, TNode}; use style::driver; @@ -4735,3 +4736,16 @@ pub unsafe extern "C" fn Servo_SourceSizeList_Evaluate( pub unsafe extern "C" fn Servo_SourceSizeList_Drop(list: RawServoSourceSizeListOwned) { let _ = list.into_box::(); } + +#[no_mangle] +pub extern "C" fn Servo_ParseCounterStyleName( + value: *const nsACString, +) -> *mut nsAtom { + let value = unsafe { value.as_ref().unwrap().as_str_unchecked() }; + let mut input = ParserInput::new(&value); + let mut parser = Parser::new(&mut input); + match parser.parse_entirely(counter_style::parse_counter_style_name_definition) { + Ok(name) => name.0.into_addrefed(), + Err(_) => ptr::null_mut(), + } +}