mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +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>(
|
fn parse_block<'t>(
|
||||||
&mut self,
|
&mut self,
|
||||||
prelude: BlockType,
|
prelude: BlockType,
|
||||||
|
_location: SourceLocation,
|
||||||
input: &mut Parser<'i, 't>
|
input: &mut Parser<'i, 't>
|
||||||
) -> Result<Self::AtRule, ParseError<'i>> {
|
) -> Result<Self::AtRule, ParseError<'i>> {
|
||||||
debug_assert_eq!(self.context.rule_type(), CssRuleType::FontFeatureValues);
|
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>;
|
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> {
|
impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {
|
||||||
type Prelude = KeyframeSelectorParserPrelude;
|
type Prelude = KeyframeSelector;
|
||||||
type QualifiedRule = Arc<Locked<Keyframe>>;
|
type QualifiedRule = Arc<Locked<Keyframe>>;
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
|
|
||||||
|
@ -525,27 +519,21 @@ impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self::Prelude, ParseError<'i>> {
|
) -> Result<Self::Prelude, ParseError<'i>> {
|
||||||
let start_position = input.position();
|
let start_position = input.position();
|
||||||
let start_location = input.current_source_location();
|
KeyframeSelector::parse(input).map_err(|e| {
|
||||||
match KeyframeSelector::parse(input) {
|
let location = e.location;
|
||||||
Ok(sel) => Ok(KeyframeSelectorParserPrelude {
|
let error = ContextualParseError::InvalidKeyframeRule(
|
||||||
selector: sel,
|
input.slice_from(start_position),
|
||||||
source_location: start_location,
|
e.clone(),
|
||||||
}),
|
|
||||||
Err(e) => {
|
|
||||||
let location = e.location;
|
|
||||||
let error = ContextualParseError::InvalidKeyframeRule(
|
|
||||||
input.slice_from(start_position),
|
|
||||||
e.clone(),
|
|
||||||
);
|
);
|
||||||
self.context.log_css_error(location, error);
|
self.context.log_css_error(location, error);
|
||||||
Err(e)
|
e
|
||||||
},
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_block<'t>(
|
fn parse_block<'t>(
|
||||||
&mut self,
|
&mut self,
|
||||||
prelude: Self::Prelude,
|
selector: Self::Prelude,
|
||||||
|
source_location: SourceLocation,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self::QualifiedRule, ParseError<'i>> {
|
) -> Result<Self::QualifiedRule, ParseError<'i>> {
|
||||||
let context = ParserContext::new_with_rule_type(
|
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.
|
// `parse_important` is not called here, `!important` is not allowed in keyframe blocks.
|
||||||
}
|
}
|
||||||
Ok(Arc::new(self.shared_lock.wrap(Keyframe {
|
Ok(Arc::new(self.shared_lock.wrap(Keyframe {
|
||||||
selector: prelude.selector,
|
selector,
|
||||||
block: Arc::new(self.shared_lock.wrap(block)),
|
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.
|
/// A rule prelude for at-rule with block.
|
||||||
pub enum AtRuleBlockPrelude {
|
pub enum AtRuleBlockPrelude {
|
||||||
/// A @font-face rule prelude.
|
/// A @font-face rule prelude.
|
||||||
FontFace(SourceLocation),
|
FontFace,
|
||||||
/// A @font-feature-values rule prelude, with its FamilyName list.
|
/// 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.
|
/// A @counter-style rule prelude, with its counter style name.
|
||||||
CounterStyle(CustomIdent, SourceLocation),
|
CounterStyle(CustomIdent),
|
||||||
/// A @media rule prelude, with its media queries.
|
/// A @media rule prelude, with its media queries.
|
||||||
Media(Arc<Locked<MediaList>>, SourceLocation),
|
Media(Arc<Locked<MediaList>>),
|
||||||
/// An @supports rule, with its conditional
|
/// An @supports rule, with its conditional
|
||||||
Supports(SupportsCondition, SourceLocation),
|
Supports(SupportsCondition),
|
||||||
/// A @viewport rule prelude.
|
/// A @viewport rule prelude.
|
||||||
Viewport,
|
Viewport,
|
||||||
/// A @keyframes rule, with its animation name and vendor prefix if exists.
|
/// 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.
|
/// A @page rule prelude.
|
||||||
Page(SourceLocation),
|
Page,
|
||||||
/// A @document rule, with its conditional.
|
/// A @document rule, with its conditional.
|
||||||
Document(DocumentCondition, SourceLocation),
|
Document(DocumentCondition),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A rule prelude for at-rule without block.
|
/// A rule prelude for at-rule without block.
|
||||||
pub enum AtRuleNonBlockPrelude {
|
pub enum AtRuleNonBlockPrelude {
|
||||||
/// A @import rule prelude.
|
/// A @import rule prelude.
|
||||||
Import(CssUrl, Arc<Locked<MediaList>>, SourceLocation),
|
Import(CssUrl, Arc<Locked<MediaList>>),
|
||||||
/// A @namespace rule prelude.
|
/// A @namespace rule prelude.
|
||||||
Namespace(Option<Prefix>, Namespace, SourceLocation),
|
Namespace(Option<Prefix>, Namespace),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
|
impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
|
||||||
|
@ -184,7 +184,6 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
|
||||||
name: CowRcStr<'i>,
|
name: CowRcStr<'i>,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<AtRuleType<AtRuleNonBlockPrelude, AtRuleBlockPrelude>, ParseError<'i>> {
|
) -> Result<AtRuleType<AtRuleNonBlockPrelude, AtRuleBlockPrelude>, ParseError<'i>> {
|
||||||
let location = input.current_source_location();
|
|
||||||
match_ignore_ascii_case! { &*name,
|
match_ignore_ascii_case! { &*name,
|
||||||
"import" => {
|
"import" => {
|
||||||
if !self.check_state(State::Imports) {
|
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 = MediaList::parse(&self.context, input);
|
||||||
let media = Arc::new(self.shared_lock.wrap(media));
|
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));
|
return Ok(AtRuleType::WithoutBlock(prelude));
|
||||||
},
|
},
|
||||||
"namespace" => {
|
"namespace" => {
|
||||||
|
@ -215,7 +214,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
|
||||||
Err(e) => return Err(e.into()),
|
Err(e) => return Err(e.into()),
|
||||||
};
|
};
|
||||||
let url = Namespace::from(maybe_namespace.as_ref());
|
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));
|
return Ok(AtRuleType::WithoutBlock(prelude));
|
||||||
},
|
},
|
||||||
// @charset is removed by rust-cssparser if it’s the first rule in the stylesheet
|
// @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>(
|
fn parse_block<'t>(
|
||||||
&mut self,
|
&mut self,
|
||||||
prelude: AtRuleBlockPrelude,
|
prelude: AtRuleBlockPrelude,
|
||||||
|
location: SourceLocation,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<CssRule, ParseError<'i>> {
|
) -> 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;
|
self.state = State::Body;
|
||||||
rule
|
rule
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rule_without_block(&mut self, prelude: AtRuleNonBlockPrelude) -> CssRule {
|
fn rule_without_block(
|
||||||
|
&mut self,
|
||||||
|
prelude: AtRuleNonBlockPrelude,
|
||||||
|
source_location: SourceLocation,
|
||||||
|
) -> CssRule {
|
||||||
match prelude {
|
match prelude {
|
||||||
AtRuleNonBlockPrelude::Import(url, media, location) => {
|
AtRuleNonBlockPrelude::Import(url, media) => {
|
||||||
let loader = self.loader
|
let loader = self.loader
|
||||||
.expect("Expected a stylesheet loader for @import");
|
.expect("Expected a stylesheet loader for @import");
|
||||||
|
|
||||||
let import_rule = loader.request_stylesheet(
|
let import_rule = loader.request_stylesheet(
|
||||||
url,
|
url,
|
||||||
location,
|
source_location,
|
||||||
&self.context,
|
&self.context,
|
||||||
&self.shared_lock,
|
&self.shared_lock,
|
||||||
media,
|
media,
|
||||||
|
@ -264,7 +268,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> {
|
||||||
self.state = State::Imports;
|
self.state = State::Imports;
|
||||||
CssRule::Import(import_rule)
|
CssRule::Import(import_rule)
|
||||||
},
|
},
|
||||||
AtRuleNonBlockPrelude::Namespace(prefix, url, source_location) => {
|
AtRuleNonBlockPrelude::Namespace(prefix, url) => {
|
||||||
let prefix = if let Some(prefix) = prefix {
|
let prefix = if let Some(prefix) = prefix {
|
||||||
self.namespaces.prefixes.insert(prefix.clone(), url.clone());
|
self.namespaces.prefixes.insert(prefix.clone(), url.clone());
|
||||||
Some(prefix)
|
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> {
|
impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> {
|
||||||
type Prelude = QualifiedRuleParserPrelude;
|
type Prelude = SelectorList<SelectorImpl>;
|
||||||
type QualifiedRule = CssRule;
|
type QualifiedRule = CssRule;
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
|
|
||||||
|
@ -298,7 +297,7 @@ impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> {
|
||||||
fn parse_prelude<'t>(
|
fn parse_prelude<'t>(
|
||||||
&mut self,
|
&mut self,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<QualifiedRuleParserPrelude, ParseError<'i>> {
|
) -> Result<Self::Prelude, ParseError<'i>> {
|
||||||
if !self.check_state(State::Body) {
|
if !self.check_state(State::Body) {
|
||||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||||
}
|
}
|
||||||
|
@ -309,10 +308,16 @@ impl<'a, 'i> QualifiedRuleParser<'i> for TopLevelRuleParser<'a> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn parse_block<'t>(
|
fn parse_block<'t>(
|
||||||
&mut self,
|
&mut self,
|
||||||
prelude: QualifiedRuleParserPrelude,
|
prelude: Self::Prelude,
|
||||||
|
location: SourceLocation,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<CssRule, ParseError<'i>> {
|
) -> 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;
|
self.state = State::Body;
|
||||||
result
|
result
|
||||||
})
|
})
|
||||||
|
@ -373,20 +378,18 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
||||||
name: CowRcStr<'i>,
|
name: CowRcStr<'i>,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<AtRuleType<AtRuleNonBlockPrelude, AtRuleBlockPrelude>, ParseError<'i>> {
|
) -> Result<AtRuleType<AtRuleNonBlockPrelude, AtRuleBlockPrelude>, ParseError<'i>> {
|
||||||
let location = input.current_source_location();
|
|
||||||
|
|
||||||
match_ignore_ascii_case! { &*name,
|
match_ignore_ascii_case! { &*name,
|
||||||
"media" => {
|
"media" => {
|
||||||
let media_queries = MediaList::parse(self.context, input);
|
let media_queries = MediaList::parse(self.context, input);
|
||||||
let arc = Arc::new(self.shared_lock.wrap(media_queries));
|
let arc = Arc::new(self.shared_lock.wrap(media_queries));
|
||||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Media(arc, location)))
|
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Media(arc)))
|
||||||
},
|
},
|
||||||
"supports" => {
|
"supports" => {
|
||||||
let cond = SupportsCondition::parse(input)?;
|
let cond = SupportsCondition::parse(input)?;
|
||||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Supports(cond, location)))
|
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Supports(cond)))
|
||||||
},
|
},
|
||||||
"font-face" => {
|
"font-face" => {
|
||||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::FontFace(location)))
|
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::FontFace))
|
||||||
},
|
},
|
||||||
"font-feature-values" => {
|
"font-feature-values" => {
|
||||||
if !cfg!(feature = "gecko") {
|
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())))
|
return Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
|
||||||
}
|
}
|
||||||
let family_names = parse_family_name_list(self.context, input)?;
|
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" => {
|
"counter-style" => {
|
||||||
if !cfg!(feature = "gecko") {
|
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())))
|
return Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
|
||||||
}
|
}
|
||||||
let name = parse_counter_style_name_definition(input)?;
|
let name = parse_counter_style_name_definition(input)?;
|
||||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::CounterStyle(name, location)))
|
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::CounterStyle(name)))
|
||||||
},
|
},
|
||||||
"viewport" => {
|
"viewport" => {
|
||||||
if viewport_rule::enabled() {
|
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)?;
|
let name = KeyframesName::parse(self.context, input)?;
|
||||||
|
|
||||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Keyframes(name, prefix, location)))
|
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Keyframes(name, prefix)))
|
||||||
},
|
},
|
||||||
"page" => {
|
"page" => {
|
||||||
if cfg!(feature = "gecko") {
|
if cfg!(feature = "gecko") {
|
||||||
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Page(location)))
|
Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Page))
|
||||||
} else {
|
} else {
|
||||||
Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
|
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)?;
|
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())))
|
_ => 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>(
|
fn parse_block<'t>(
|
||||||
&mut self,
|
&mut self,
|
||||||
prelude: AtRuleBlockPrelude,
|
prelude: AtRuleBlockPrelude,
|
||||||
|
source_location: SourceLocation,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<CssRule, ParseError<'i>> {
|
) -> Result<CssRule, ParseError<'i>> {
|
||||||
match prelude {
|
match prelude {
|
||||||
AtRuleBlockPrelude::FontFace(location) => {
|
AtRuleBlockPrelude::FontFace => {
|
||||||
let context = ParserContext::new_with_rule_type(
|
let context = ParserContext::new_with_rule_type(
|
||||||
self.context,
|
self.context,
|
||||||
CssRuleType::FontFace,
|
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(
|
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(
|
let context = ParserContext::new_with_rule_type(
|
||||||
self.context,
|
self.context,
|
||||||
CssRuleType::FontFeatureValues,
|
CssRuleType::FontFeatureValues,
|
||||||
|
@ -478,11 +482,11 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
||||||
&context,
|
&context,
|
||||||
input,
|
input,
|
||||||
family_names,
|
family_names,
|
||||||
location,
|
source_location,
|
||||||
),
|
),
|
||||||
))))
|
))))
|
||||||
},
|
},
|
||||||
AtRuleBlockPrelude::CounterStyle(name, location) => {
|
AtRuleBlockPrelude::CounterStyle(name) => {
|
||||||
let context = ParserContext::new_with_rule_type(
|
let context = ParserContext::new_with_rule_type(
|
||||||
self.context,
|
self.context,
|
||||||
CssRuleType::CounterStyle,
|
CssRuleType::CounterStyle,
|
||||||
|
@ -495,19 +499,19 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
||||||
name,
|
name,
|
||||||
&context,
|
&context,
|
||||||
input,
|
input,
|
||||||
location,
|
source_location,
|
||||||
)?.into(),
|
)?.into(),
|
||||||
),
|
),
|
||||||
)))
|
)))
|
||||||
},
|
},
|
||||||
AtRuleBlockPrelude::Media(media_queries, source_location) => {
|
AtRuleBlockPrelude::Media(media_queries) => {
|
||||||
Ok(CssRule::Media(Arc::new(self.shared_lock.wrap(MediaRule {
|
Ok(CssRule::Media(Arc::new(self.shared_lock.wrap(MediaRule {
|
||||||
media_queries,
|
media_queries,
|
||||||
rules: self.parse_nested_rules(input, CssRuleType::Media),
|
rules: self.parse_nested_rules(input, CssRuleType::Media),
|
||||||
source_location,
|
source_location,
|
||||||
}))))
|
}))))
|
||||||
},
|
},
|
||||||
AtRuleBlockPrelude::Supports(condition, source_location) => {
|
AtRuleBlockPrelude::Supports(condition) => {
|
||||||
let eval_context = ParserContext::new_with_rule_type(
|
let eval_context = ParserContext::new_with_rule_type(
|
||||||
self.context,
|
self.context,
|
||||||
CssRuleType::Style,
|
CssRuleType::Style,
|
||||||
|
@ -535,7 +539,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
||||||
ViewportRule::parse(&context, input)?,
|
ViewportRule::parse(&context, input)?,
|
||||||
))))
|
))))
|
||||||
},
|
},
|
||||||
AtRuleBlockPrelude::Keyframes(name, vendor_prefix, source_location) => {
|
AtRuleBlockPrelude::Keyframes(name, vendor_prefix) => {
|
||||||
let context = ParserContext::new_with_rule_type(
|
let context = ParserContext::new_with_rule_type(
|
||||||
self.context,
|
self.context,
|
||||||
CssRuleType::Keyframes,
|
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(
|
let context = ParserContext::new_with_rule_type(
|
||||||
self.context,
|
self.context,
|
||||||
CssRuleType::Page,
|
CssRuleType::Page,
|
||||||
|
@ -569,7 +573,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
||||||
source_location,
|
source_location,
|
||||||
}))))
|
}))))
|
||||||
},
|
},
|
||||||
AtRuleBlockPrelude::Document(condition, source_location) => {
|
AtRuleBlockPrelude::Document(condition) => {
|
||||||
if !cfg!(feature = "gecko") {
|
if !cfg!(feature = "gecko") {
|
||||||
unreachable!()
|
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> {
|
impl<'a, 'b, 'i> QualifiedRuleParser<'i> for NestedRuleParser<'a, 'b> {
|
||||||
type Prelude = QualifiedRuleParserPrelude;
|
type Prelude = SelectorList<SelectorImpl>;
|
||||||
type QualifiedRule = CssRule;
|
type QualifiedRule = CssRule;
|
||||||
type Error = StyleParseErrorKind<'i>;
|
type Error = StyleParseErrorKind<'i>;
|
||||||
|
|
||||||
fn parse_prelude<'t>(
|
fn parse_prelude<'t>(
|
||||||
&mut self,
|
&mut self,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<QualifiedRuleParserPrelude, ParseError<'i>> {
|
) -> Result<Self::Prelude, ParseError<'i>> {
|
||||||
let selector_parser = SelectorParser {
|
let selector_parser = SelectorParser {
|
||||||
stylesheet_origin: self.stylesheet_origin,
|
stylesheet_origin: self.stylesheet_origin,
|
||||||
namespaces: self.namespaces,
|
namespaces: self.namespaces,
|
||||||
url_data: Some(self.context.url_data),
|
url_data: Some(self.context.url_data),
|
||||||
};
|
};
|
||||||
|
SelectorList::parse(&selector_parser, input)
|
||||||
let source_location = input.current_source_location();
|
|
||||||
let selectors = SelectorList::parse(&selector_parser, input)?;
|
|
||||||
|
|
||||||
Ok(QualifiedRuleParserPrelude { selectors, source_location, })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_block<'t>(
|
fn parse_block<'t>(
|
||||||
&mut self,
|
&mut self,
|
||||||
prelude: QualifiedRuleParserPrelude,
|
selectors: Self::Prelude,
|
||||||
|
source_location: SourceLocation,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<CssRule, ParseError<'i>> {
|
) -> Result<CssRule, ParseError<'i>> {
|
||||||
let context =
|
let context =
|
||||||
ParserContext::new_with_rule_type(self.context, CssRuleType::Style, self.namespaces);
|
ParserContext::new_with_rule_type(self.context, CssRuleType::Style, self.namespaces);
|
||||||
|
|
||||||
let declarations = parse_property_declaration_list(&context, input);
|
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 {
|
Ok(CssRule::Style(Arc::new(self.shared_lock.wrap(StyleRule {
|
||||||
selectors: prelude.selectors,
|
selectors,
|
||||||
block: Arc::new(self.shared_lock.wrap(declarations)),
|
block,
|
||||||
source_location: prelude.source_location,
|
source_location,
|
||||||
}))))
|
}))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue