Add source_location to CounterStyleRule. r?emilio
draft
Add source_location to CounterStyleRule. r?emilio
MozReview-Commit-ID: 9SX8c4nlCLv
--- a/servo/components/style/counter_style/mod.rs
+++ b/servo/components/style/counter_style/mod.rs
@@ -3,17 +3,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//! The [`@counter-style`][counter-style] at-rule.
//!
//! [counter-style]: https://drafts.csswg.org/css-counter-styles/
use Atom;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser};
-use cssparser::{Parser, Token, CowRcStr};
+use cssparser::{Parser, Token, CowRcStr, SourceLocation};
use error_reporting::{ContextualParseError, ParseErrorReporter};
#[cfg(feature = "gecko")] use gecko::rules::CounterStyleDescriptors;
#[cfg(feature = "gecko")] use gecko_bindings::structs::{ nsCSSCounterDesc, nsCSSValue };
use parser::{ParserContext, ParserErrorContext, Parse};
use selectors::parser::SelectorParseErrorKind;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use std::fmt::{self, Write};
use std::ops::Range;
@@ -65,25 +65,27 @@ pub fn parse_counter_style_name_definiti
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,
- error_context: &ParserErrorContext<R>,
- input: &mut Parser<'i, 't>)
- -> Result<CounterStyleRuleData, ParseError<'i>>
+pub fn parse_counter_style_body<'i, 't, R>(
+ name: CustomIdent,
+ context: &ParserContext,
+ error_context: &ParserErrorContext<R>,
+ input: &mut Parser<'i, 't>,
+ location: SourceLocation,
+) -> Result<CounterStyleRuleData, ParseError<'i>>
where R: ParseErrorReporter
{
let start = input.current_source_location();
- let mut rule = CounterStyleRuleData::empty(name);
+ let mut rule = CounterStyleRuleData::empty(name, location);
{
let parser = CounterStyleRuleParser {
context: context,
rule: &mut rule,
};
let mut iter = DeclarationListParser::new(input, parser);
while let Some(declaration) = iter.next() {
if let Err((error, slice)) = declaration {
@@ -148,25 +150,28 @@ macro_rules! counter_style_descriptors {
/// An @counter-style rule
#[derive(Clone, Debug)]
pub struct CounterStyleRuleData {
name: CustomIdent,
$(
#[$doc]
$ident: Option<$ty>,
)+
+ /// Line and column of the @counter-style rule source code.
+ pub source_location: SourceLocation,
}
impl CounterStyleRuleData {
- fn empty(name: CustomIdent) -> Self {
+ fn empty(name: CustomIdent, location: SourceLocation) -> Self {
CounterStyleRuleData {
name: name,
$(
$ident: None,
)+
+ source_location: location,
}
}
/// Get the name of the counter style rule.
pub fn name(&self) -> &CustomIdent {
&self.name
}
--- a/servo/components/style/stylesheets/rule_parser.rs
+++ b/servo/components/style/stylesheets/rule_parser.rs
@@ -109,17 +109,17 @@ pub enum VendorPrefix {
/// A rule prelude for at-rule with block.
pub enum AtRuleBlockPrelude {
/// A @font-face rule prelude.
FontFace(SourceLocation),
/// A @font-feature-values rule prelude, with its FamilyName list.
FontFeatureValues(Vec<FamilyName>, SourceLocation),
/// A @counter-style rule prelude, with its counter style name.
- CounterStyle(CustomIdent),
+ CounterStyle(CustomIdent, SourceLocation),
/// A @media rule prelude, with its media queries.
Media(Arc<Locked<MediaList>>, SourceLocation),
/// An @supports rule, with its conditional
Supports(SupportsCondition, SourceLocation),
/// A @viewport rule prelude.
Viewport,
/// A @keyframes rule, with its animation name and vendor prefix if exists.
Keyframes(KeyframesName, Option<VendorPrefix>, SourceLocation),
@@ -377,17 +377,17 @@ impl<'a, 'b, 'i, R: ParseErrorReporter>
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::FontFeatureValues(family_names, location)))
},
"counter-style" => {
if !cfg!(feature = "gecko") {
// 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_definition(input)?;
- Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::CounterStyle(name)))
+ Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::CounterStyle(name, location)))
},
"viewport" => {
if viewport_rule::enabled() {
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Viewport))
} else {
Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
}
},
@@ -450,25 +450,32 @@ impl<'a, 'b, 'i, R: ParseErrorReporter>
self.context,
CssRuleType::FontFeatureValues,
self.namespaces,
);
Ok(CssRule::FontFeatureValues(Arc::new(self.shared_lock.wrap(
FontFeatureValuesRule::parse(&context, self.error_context, input, family_names, location)))))
}
- AtRuleBlockPrelude::CounterStyle(name) => {
+ AtRuleBlockPrelude::CounterStyle(name, location) => {
let context = ParserContext::new_with_rule_type(
self.context,
CssRuleType::CounterStyle,
self.namespaces,
);
Ok(CssRule::CounterStyle(Arc::new(self.shared_lock.wrap(
- parse_counter_style_body(name, &context, self.error_context, input)?.into()))))
+ parse_counter_style_body(
+ name,
+ &context,
+ self.error_context,
+ input,
+ location
+ )?.into()
+ ))))
}
AtRuleBlockPrelude::Media(media_queries, location) => {
Ok(CssRule::Media(Arc::new(self.shared_lock.wrap(MediaRule {
media_queries: media_queries,
rules: self.parse_nested_rules(input, CssRuleType::Media),
source_location: location,
}))))
}