diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index fe52e6059c7..7bae033c9d4 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -1263,11 +1263,12 @@ pub fn parse_style_attribute( url_data: &UrlExtraData, error_reporter: Option<&dyn ParseErrorReporter>, quirks_mode: QuirksMode, + rule_type: CssRuleType, ) -> PropertyDeclarationBlock { let context = ParserContext::new( Origin::Author, url_data, - Some(CssRuleType::Style), + Some(rule_type), ParsingMode::DEFAULT, quirks_mode, error_reporter, @@ -1291,11 +1292,12 @@ pub fn parse_one_declaration_into( error_reporter: Option<&dyn ParseErrorReporter>, parsing_mode: ParsingMode, quirks_mode: QuirksMode, + rule_type: CssRuleType, ) -> Result<(), ()> { let context = ParserContext::new( Origin::Author, url_data, - Some(CssRuleType::Style), + Some(rule_type), parsing_mode, quirks_mode, error_reporter, diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 9f204a3c36d..f98df39a629 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -542,10 +542,12 @@ impl NonCustomPropertyId { false } - fn allowed_in(self, context: &ParserContext) -> bool { + /// Returns whether a given rule allows a given property. + #[inline] + pub fn allowed_in_rule(self, rule_type: CssRuleType) -> bool { debug_assert!( matches!( - context.rule_type(), + rule_type, CssRuleType::Keyframe | CssRuleType::Page | CssRuleType::Style ), "Declarations are only expected inside a keyframe, page, or style rule." @@ -559,14 +561,16 @@ impl NonCustomPropertyId { "DISALLOWED_IN_PAGE_RULE", lambda p: not p.allowed_in_page_rule )} - match context.rule_type() { - CssRuleType::Keyframe if DISALLOWED_IN_KEYFRAME_BLOCK.contains(self) => { - return false; - } - CssRuleType::Page if DISALLOWED_IN_PAGE_RULE.contains(self) => { - return false; - } - _ => {} + match rule_type { + CssRuleType::Keyframe => !DISALLOWED_IN_KEYFRAME_BLOCK.contains(self), + CssRuleType::Page => !DISALLOWED_IN_PAGE_RULE.contains(self), + _ => true + } + } + + fn allowed_in(self, context: &ParserContext) -> bool { + if !self.allowed_in_rule(context.rule_type()) { + return false; } self.allowed_in_ignoring_rule_type(context) diff --git a/components/style/stylesheets/mod.rs b/components/style/stylesheets/mod.rs index f83595dacef..a5e71140742 100644 --- a/components/style/stylesheets/mod.rs +++ b/components/style/stylesheets/mod.rs @@ -299,7 +299,7 @@ impl CssRule { } #[allow(missing_docs)] -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Copy, Debug, Eq, FromPrimitive, PartialEq)] pub enum CssRuleType { // https://drafts.csswg.org/cssom/#the-cssrule-interface Style = 1,