Set rule_type in context when descending into any rule

Before, we only passed `rule_type` in specific cases where it was needed.  Now
that it's in `ParserContext`, it seems good to set it at each rule boundary, in
case we start to depend on the value in new places.

MozReview-Commit-ID: 7ZGD7NGZLR4
This commit is contained in:
J. Ryan Stinnett 2017-04-10 13:31:22 +08:00
parent 4574cd8ea6
commit 997015a4f7

View file

@ -1012,8 +1012,15 @@ struct NestedRuleParser<'a, 'b: 'a> {
} }
impl<'a, 'b> NestedRuleParser<'a, 'b> { impl<'a, 'b> NestedRuleParser<'a, 'b> {
fn parse_nested_rules(&self, input: &mut Parser) -> Arc<Locked<CssRules>> { fn parse_nested_rules(&self, input: &mut Parser, rule_type: CssRuleType) -> Arc<Locked<CssRules>> {
let mut iter = RuleListParser::new_for_nested_rule(input, self.clone()); let context = ParserContext::new_with_rule_type(self.context, Some(rule_type));
let nested_parser = NestedRuleParser {
stylesheet_origin: self.stylesheet_origin,
shared_lock: self.shared_lock,
context: &context,
namespaces: self.namespaces,
};
let mut iter = RuleListParser::new_for_nested_rule(input, nested_parser);
let mut rules = Vec::new(); let mut rules = Vec::new();
while let Some(result) = iter.next() { while let Some(result) = iter.next() {
match result { match result {
@ -1088,31 +1095,34 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> {
fn parse_block(&mut self, prelude: AtRulePrelude, input: &mut Parser) -> Result<CssRule, ()> { fn parse_block(&mut self, prelude: AtRulePrelude, input: &mut Parser) -> Result<CssRule, ()> {
match prelude { match prelude {
AtRulePrelude::FontFace => { AtRulePrelude::FontFace => {
let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::FontFace));
Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap( Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap(
parse_font_face_block(self.context, input).into())))) parse_font_face_block(&context, input).into()))))
} }
AtRulePrelude::Media(media_queries) => { AtRulePrelude::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, media_queries: media_queries,
rules: self.parse_nested_rules(input), rules: self.parse_nested_rules(input, CssRuleType::Media),
})))) }))))
} }
AtRulePrelude::Supports(cond) => { AtRulePrelude::Supports(cond) => {
let enabled = cond.eval(self.context); let enabled = cond.eval(self.context);
Ok(CssRule::Supports(Arc::new(self.shared_lock.wrap(SupportsRule { Ok(CssRule::Supports(Arc::new(self.shared_lock.wrap(SupportsRule {
condition: cond, condition: cond,
rules: self.parse_nested_rules(input), rules: self.parse_nested_rules(input, CssRuleType::Supports),
enabled: enabled, enabled: enabled,
})))) }))))
} }
AtRulePrelude::Viewport => { AtRulePrelude::Viewport => {
let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::Viewport));
Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap( Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap(
try!(ViewportRule::parse(self.context, input)))))) try!(ViewportRule::parse(&context, input))))))
} }
AtRulePrelude::Keyframes(name) => { AtRulePrelude::Keyframes(name) => {
let context = ParserContext::new_with_rule_type(self.context, Some(CssRuleType::Keyframes));
Ok(CssRule::Keyframes(Arc::new(self.shared_lock.wrap(KeyframesRule { Ok(CssRule::Keyframes(Arc::new(self.shared_lock.wrap(KeyframesRule {
name: name, name: name,
keyframes: parse_keyframe_list(&self.context, input, self.shared_lock), keyframes: parse_keyframe_list(&context, input, self.shared_lock),
})))) }))))
} }
AtRulePrelude::Page => { AtRulePrelude::Page => {