mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Remove location from preludes and take it from argument.
Bug: 1471104 Reviewed-by: emilio MozReview-Commit-ID: HeJUQvkacaf
This commit is contained in:
parent
0d0c6bd29e
commit
26a9c9f53c
3 changed files with 75 additions and 84 deletions
|
@ -428,6 +428,7 @@ macro_rules! font_feature_values_blocks {
|
|||
fn parse_block<'t>(
|
||||
&mut self,
|
||||
prelude: BlockType,
|
||||
_location: SourceLocation,
|
||||
input: &mut Parser<'i, 't>
|
||||
) -> Result<Self::AtRule, ParseError<'i>> {
|
||||
debug_assert_eq!(self.context.rule_type(), CssRuleType::FontFeatureValues);
|
||||
|
|
|
@ -509,14 +509,8 @@ impl<'a, 'i> AtRuleParser<'i> for KeyframeListParser<'a> {
|
|||
type Error = StyleParseErrorKind<'i>;
|
||||
}
|
||||
|
||||
/// A wrapper to wraps the KeyframeSelector with its source location
|
||||
struct KeyframeSelectorParserPrelude {
|
||||
selector: KeyframeSelector,
|
||||
source_location: SourceLocation,
|
||||
}
|
||||
|
||||
impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {
|
||||
type Prelude = KeyframeSelectorParserPrelude;
|
||||
type Prelude = KeyframeSelector;
|
||||
type QualifiedRule = Arc<Locked<Keyframe>>;
|
||||
type Error = StyleParseErrorKind<'i>;
|
||||
|
||||
|
@ -525,27 +519,21 @@ impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self::Prelude, ParseError<'i>> {
|
||||
let start_position = input.position();
|
||||
let start_location = input.current_source_location();
|
||||
match KeyframeSelector::parse(input) {
|
||||
Ok(sel) => Ok(KeyframeSelectorParserPrelude {
|
||||
selector: sel,
|
||||
source_location: start_location,
|
||||
}),
|
||||
Err(e) => {
|
||||
let location = e.location;
|
||||
let error = ContextualParseError::InvalidKeyframeRule(
|
||||
input.slice_from(start_position),
|
||||
e.clone(),
|
||||
KeyframeSelector::parse(input).map_err(|e| {
|
||||
let location = e.location;
|
||||
let error = ContextualParseError::InvalidKeyframeRule(
|
||||
input.slice_from(start_position),
|
||||
e.clone(),
|
||||
);
|
||||
self.context.log_css_error(location, error);
|
||||
Err(e)
|
||||
},
|
||||
}
|
||||
self.context.log_css_error(location, error);
|
||||
e
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_block<'t>(
|
||||
&mut self,
|
||||
prelude: Self::Prelude,
|
||||
selector: Self::Prelude,
|
||||
source_location: SourceLocation,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self::QualifiedRule, ParseError<'i>> {
|
||||
let context = ParserContext::new_with_rule_type(
|
||||
|
@ -580,9 +568,9 @@ impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {
|
|||
// `parse_important` is not called here, `!important` is not allowed in keyframe blocks.
|
||||
}
|
||||
Ok(Arc::new(self.shared_lock.wrap(Keyframe {
|
||||
selector: prelude.selector,
|
||||
selector,
|
||||
block: Arc::new(self.shared_lock.wrap(block)),
|
||||
source_location: prelude.source_location,
|
||||
source_location,
|
||||
})))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,31 +146,31 @@ pub enum VendorPrefix {
|
|||
/// A rule prelude for at-rule with block.
|
||||
pub enum AtRuleBlockPrelude {
|
||||
/// A @font-face rule prelude.
|
||||
FontFace(SourceLocation),
|
||||
FontFace,
|
||||
/// A @font-feature-values rule prelude, with its FamilyName list.
|
||||
FontFeatureValues(Vec<FamilyName>, SourceLocation),
|
||||
FontFeatureValues(Vec<FamilyName>),
|
||||
/// A @counter-style rule prelude, with its counter style name.
|
||||
CounterStyle(CustomIdent, SourceLocation),
|
||||
CounterStyle(CustomIdent),
|
||||
/// A @media rule prelude, with its media queries.
|
||||
Media(Arc<Locked<MediaList>>, SourceLocation),
|
||||
Media(Arc<Locked<MediaList>>),
|
||||
/// An @supports rule, with its conditional
|
||||
Supports(SupportsCondition, SourceLocation),
|
||||
Supports(SupportsCondition),
|
||||
/// A @viewport rule prelude.
|
||||
Viewport,
|
||||
/// A @keyframes rule, with its animation name and vendor prefix if exists.
|
||||
Keyframes(KeyframesName, Option<VendorPrefix>, SourceLocation),
|
||||
Keyframes(KeyframesName, Option<VendorPrefix>),
|
||||
/// A @page rule prelude.
|
||||
Page(SourceLocation),
|
||||
Page,
|
||||
/// A @document rule, with its conditional.
|
||||
Document(DocumentCondition, SourceLocation),
|
||||
Document(DocumentCondition),
|
||||
}
|
||||
|
||||
/// A rule prelude for at-rule without block.
|
||||
pub enum AtRuleNonBlockPrelude {
|
||||
/// A @import rule prelude.
|
||||
Import(CssUrl, Arc<Locked<MediaList>>, SourceLocation),
|
||||
Import(CssUrl, Arc<Locked<MediaList>>),
|
||||
/// A @namespace rule prelude.
|
||||
Namespace(Option<Prefix>, Namespace, SourceLocation),
|
||||
Namespace(Option<Prefix>, Namespace),
|
||||
}
|
||||
|
||||
impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
|
||||
|
@ -184,7 +184,6 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
|
|||
name: CowRcStr<'i>,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<AtRuleType<AtRuleNonBlockPrelude, AtRuleBlockPrelude>, ParseError<'i>> {
|
||||
let location = input.current_source_location();
|
||||
match_ignore_ascii_case! { &*name,
|
||||
"import" => {
|
||||
if !self.check_state(State::Imports) {
|
||||
|
@ -197,7 +196,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
|
|||
let media = MediaList::parse(&self.context, input);
|
||||
let media = Arc::new(self.shared_lock.wrap(media));
|
||||
|
||||
let prelude = AtRuleNonBlockPrelude::Import(url, media, location);
|
||||
let prelude = AtRuleNonBlockPrelude::Import(url, media);
|
||||
return Ok(AtRuleType::WithoutBlock(prelude));
|
||||
},
|
||||
"namespace" => {
|
||||
|
@ -215,7 +214,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
|
|||
Err(e) => return Err(e.into()),
|
||||
};
|
||||
let url = Namespace::from(maybe_namespace.as_ref());
|
||||
let prelude = AtRuleNonBlockPrelude::Namespace(prefix, url, location);
|
||||
let prelude = AtRuleNonBlockPrelude::Namespace(prefix, url);
|
||||
return Ok(AtRuleType::WithoutBlock(prelude));
|
||||
},
|
||||
// @charset is removed by rust-cssparser if it’s the first rule in the stylesheet
|
||||
|
@ -238,24 +237,29 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
|
|||
fn parse_block<'t>(
|
||||
&mut self,
|
||||
prelude: AtRuleBlockPrelude,
|
||||
location: SourceLocation,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<CssRule, ParseError<'i>> {
|
||||
AtRuleParser::parse_block(&mut self.nested(), prelude, input).map(|rule| {
|
||||
AtRuleParser::parse_block(&mut self.nested(), prelude, location, input).map(|rule| {
|
||||
self.state = State::Body;
|
||||
rule
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn rule_without_block(&mut self, prelude: AtRuleNonBlockPrelude) -> CssRule {
|
||||
fn rule_without_block(
|
||||
&mut self,
|
||||
prelude: AtRuleNonBlockPrelude,
|
||||
source_location: SourceLocation,
|
||||
) -> CssRule {
|
||||
match prelude {
|
||||
AtRuleNonBlockPrelude::Import(url, media, location) => {
|
||||
AtRuleNonBlockPrelude::Import(url, media) => {
|
||||
let loader = self.loader
|
||||
.expect("Expected a stylesheet loader for @import");
|
||||
|
||||
let import_rule = loader.request_stylesheet(
|
||||
url,
|
||||
location,
|
||||
source_location,
|
||||
&self.context,
|
||||
&self.shared_lock,
|
||||
media,
|
||||
|
@ -264,7 +268,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
|
|||
self.state = State::Imports;
|
||||
CssRule::Import(import_rule)
|
||||
},
|
||||
AtRuleNonBlockPrelude::Namespace(prefix, url, source_location) => {
|
||||
AtRuleNonBlockPrelude::Namespace(prefix, url) => {
|
||||
let prefix = if let Some(prefix) = prefix {
|
||||
self.namespaces.prefixes.insert(prefix.clone(), url.clone());
|
||||
Some(prefix)
|
||||
|
@ -284,13 +288,8 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct QualifiedRuleParserPrelude {
|
||||
selectors: SelectorList<SelectorImpl>,
|
||||
source_location: SourceLocation,
|
||||
}
|
||||
|
||||
impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> {
|
||||
type Prelude = QualifiedRuleParserPrelude;
|
||||
type Prelude = SelectorList<SelectorImpl>;
|
||||
type QualifiedRule = CssRule;
|
||||
type Error = StyleParseErrorKind<'i>;
|
||||
|
||||
|
@ -298,7 +297,7 @@ impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> {
|
|||
fn parse_prelude<'t>(
|
||||
&mut self,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<QualifiedRuleParserPrelude, ParseError<'i>> {
|
||||
) -> Result<Self::Prelude, ParseError<'i>> {
|
||||
if !self.check_state(State::Body) {
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
}
|
||||
|
@ -309,10 +308,16 @@ impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> {
|
|||
#[inline]
|
||||
fn parse_block<'t>(
|
||||
&mut self,
|
||||
prelude: QualifiedRuleParserPrelude,
|
||||
prelude: Self::Prelude,
|
||||
location: SourceLocation,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<CssRule, ParseError<'i>> {
|
||||
QualifiedRuleParser::parse_block(&mut self.nested(), prelude, input).map(|result| {
|
||||
QualifiedRuleParser::parse_block(
|
||||
&mut self.nested(),
|
||||
prelude,
|
||||
location,
|
||||
input,
|
||||
).map(|result| {
|
||||
self.state = State::Body;
|
||||
result
|
||||
})
|
||||
|
@ -373,20 +378,18 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
|||
name: CowRcStr<'i>,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<AtRuleType<AtRuleNonBlockPrelude, AtRuleBlockPrelude>, ParseError<'i>> {
|
||||
let location = input.current_source_location();
|
||||
|
||||
match_ignore_ascii_case! { &*name,
|
||||
"media" => {
|
||||
let media_queries = MediaList::parse(self.context, input);
|
||||
let arc = Arc::new(self.shared_lock.wrap(media_queries));
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Media(arc, location)))
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Media(arc)))
|
||||
},
|
||||
"supports" => {
|
||||
let cond = SupportsCondition::parse(input)?;
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Supports(cond, location)))
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Supports(cond)))
|
||||
},
|
||||
"font-face" => {
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::FontFace(location)))
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::FontFace))
|
||||
},
|
||||
"font-feature-values" => {
|
||||
if !cfg!(feature = "gecko") {
|
||||
|
@ -394,7 +397,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
|||
return Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
|
||||
}
|
||||
let family_names = parse_family_name_list(self.context, input)?;
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::FontFeatureValues(family_names, location)))
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::FontFeatureValues(family_names)))
|
||||
},
|
||||
"counter-style" => {
|
||||
if !cfg!(feature = "gecko") {
|
||||
|
@ -402,7 +405,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
|||
return Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
|
||||
}
|
||||
let name = parse_counter_style_name_definition(input)?;
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::CounterStyle(name, location)))
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::CounterStyle(name)))
|
||||
},
|
||||
"viewport" => {
|
||||
if viewport_rule::enabled() {
|
||||
|
@ -426,11 +429,11 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
|||
}
|
||||
let name = KeyframesName::parse(self.context, input)?;
|
||||
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Keyframes(name, prefix, location)))
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Keyframes(name, prefix)))
|
||||
},
|
||||
"page" => {
|
||||
if cfg!(feature = "gecko") {
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Page(location)))
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Page))
|
||||
} else {
|
||||
Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
|
||||
}
|
||||
|
@ -443,7 +446,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
|||
}
|
||||
|
||||
let cond = DocumentCondition::parse(self.context, input)?;
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Document(cond, location)))
|
||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Document(cond)))
|
||||
},
|
||||
_ => Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
|
||||
}
|
||||
|
@ -452,10 +455,11 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
|||
fn parse_block<'t>(
|
||||
&mut self,
|
||||
prelude: AtRuleBlockPrelude,
|
||||
source_location: SourceLocation,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<CssRule, ParseError<'i>> {
|
||||
match prelude {
|
||||
AtRuleBlockPrelude::FontFace(location) => {
|
||||
AtRuleBlockPrelude::FontFace => {
|
||||
let context = ParserContext::new_with_rule_type(
|
||||
self.context,
|
||||
CssRuleType::FontFace,
|
||||
|
@ -463,10 +467,10 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
|||
);
|
||||
|
||||
Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap(
|
||||
parse_font_face_block(&context, input, location).into(),
|
||||
parse_font_face_block(&context, input, source_location).into(),
|
||||
))))
|
||||
},
|
||||
AtRuleBlockPrelude::FontFeatureValues(family_names, location) => {
|
||||
AtRuleBlockPrelude::FontFeatureValues(family_names) => {
|
||||
let context = ParserContext::new_with_rule_type(
|
||||
self.context,
|
||||
CssRuleType::FontFeatureValues,
|
||||
|
@ -478,11 +482,11 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
|||
&context,
|
||||
input,
|
||||
family_names,
|
||||
location,
|
||||
source_location,
|
||||
),
|
||||
))))
|
||||
},
|
||||
AtRuleBlockPrelude::CounterStyle(name, location) => {
|
||||
AtRuleBlockPrelude::CounterStyle(name) => {
|
||||
let context = ParserContext::new_with_rule_type(
|
||||
self.context,
|
||||
CssRuleType::CounterStyle,
|
||||
|
@ -495,19 +499,19 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
|||
name,
|
||||
&context,
|
||||
input,
|
||||
location,
|
||||
source_location,
|
||||
)?.into(),
|
||||
),
|
||||
)))
|
||||
},
|
||||
AtRuleBlockPrelude::Media(media_queries, source_location) => {
|
||||
AtRuleBlockPrelude::Media(media_queries) => {
|
||||
Ok(CssRule::Media(Arc::new(self.shared_lock.wrap(MediaRule {
|
||||
media_queries,
|
||||
rules: self.parse_nested_rules(input, CssRuleType::Media),
|
||||
source_location,
|
||||
}))))
|
||||
},
|
||||
AtRuleBlockPrelude::Supports(condition, source_location) => {
|
||||
AtRuleBlockPrelude::Supports(condition) => {
|
||||
let eval_context = ParserContext::new_with_rule_type(
|
||||
self.context,
|
||||
CssRuleType::Style,
|
||||
|
@ -535,7 +539,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
|||
ViewportRule::parse(&context, input)?,
|
||||
))))
|
||||
},
|
||||
AtRuleBlockPrelude::Keyframes(name, vendor_prefix, source_location) => {
|
||||
AtRuleBlockPrelude::Keyframes(name, vendor_prefix) => {
|
||||
let context = ParserContext::new_with_rule_type(
|
||||
self.context,
|
||||
CssRuleType::Keyframes,
|
||||
|
@ -555,7 +559,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
|||
},
|
||||
))))
|
||||
},
|
||||
AtRuleBlockPrelude::Page(source_location) => {
|
||||
AtRuleBlockPrelude::Page => {
|
||||
let context = ParserContext::new_with_rule_type(
|
||||
self.context,
|
||||
CssRuleType::Page,
|
||||
|
@ -569,7 +573,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
|||
source_location,
|
||||
}))))
|
||||
},
|
||||
AtRuleBlockPrelude::Document(condition, source_location) => {
|
||||
AtRuleBlockPrelude::Document(condition) => {
|
||||
if !cfg!(feature = "gecko") {
|
||||
unreachable!()
|
||||
}
|
||||
|
@ -586,39 +590,37 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
|||
}
|
||||
|
||||
impl<'a, 'b, 'i> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
||||
type Prelude = QualifiedRuleParserPrelude;
|
||||
type Prelude = SelectorList<SelectorImpl>;
|
||||
type QualifiedRule = CssRule;
|
||||
type Error = StyleParseErrorKind<'i>;
|
||||
|
||||
fn parse_prelude<'t>(
|
||||
&mut self,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<QualifiedRuleParserPrelude, ParseError<'i>> {
|
||||
) -> Result<Self::Prelude, ParseError<'i>> {
|
||||
let selector_parser = SelectorParser {
|
||||
stylesheet_origin: self.stylesheet_origin,
|
||||
namespaces: self.namespaces,
|
||||
url_data: Some(self.context.url_data),
|
||||
};
|
||||
|
||||
let source_location = input.current_source_location();
|
||||
let selectors = SelectorList::parse(&selector_parser, input)?;
|
||||
|
||||
Ok(QualifiedRuleParserPrelude { selectors, source_location, })
|
||||
SelectorList::parse(&selector_parser, input)
|
||||
}
|
||||
|
||||
fn parse_block<'t>(
|
||||
&mut self,
|
||||
prelude: QualifiedRuleParserPrelude,
|
||||
selectors: Self::Prelude,
|
||||
source_location: SourceLocation,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<CssRule, ParseError<'i>> {
|
||||
let context =
|
||||
ParserContext::new_with_rule_type(self.context, CssRuleType::Style, self.namespaces);
|
||||
|
||||
let declarations = parse_property_declaration_list(&context, input);
|
||||
let block = Arc::new(self.shared_lock.wrap(declarations));
|
||||
Ok(CssRule::Style(Arc::new(self.shared_lock.wrap(StyleRule {
|
||||
selectors: prelude.selectors,
|
||||
block: Arc::new(self.shared_lock.wrap(declarations)),
|
||||
source_location: prelude.source_location,
|
||||
selectors,
|
||||
block,
|
||||
source_location,
|
||||
}))))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue