diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index 1ee90e2fecf..9030e145276 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -588,7 +588,7 @@ impl Expression { let mut flags = 0; - if context.in_chrome_stylesheet() || + if context.chrome_rules_enabled() || context.stylesheet_origin == Origin::UserAgent { flags |= structs::nsMediaFeature_RequirementFlags_eUserAgentAndChromeOnly; } diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs index 5d6c46af464..0cfd252570e 100644 --- a/components/style/gecko/selector_parser.rs +++ b/components/style/gecko/selector_parser.rs @@ -295,14 +295,27 @@ impl ::selectors::SelectorImpl for SelectorImpl { } impl<'a> SelectorParser<'a> { - fn is_pseudo_class_enabled(&self, - pseudo_class: &NonTSPseudoClass) - -> bool { - pseudo_class.is_enabled_in_content() || - (self.in_user_agent_stylesheet() && - pseudo_class.has_any_flag(NonTSPseudoClassFlag::PSEUDO_CLASS_ENABLED_IN_UA_SHEETS)) || - (self.in_chrome_stylesheet() && - pseudo_class.has_any_flag(NonTSPseudoClassFlag::PSEUDO_CLASS_ENABLED_IN_CHROME)) + fn is_pseudo_class_enabled( + &self, + pseudo_class: &NonTSPseudoClass, + ) -> bool { + if pseudo_class.is_enabled_in_content() { + return true; + } + + if self.in_user_agent_stylesheet() && + pseudo_class.has_any_flag(NonTSPseudoClassFlag::PSEUDO_CLASS_ENABLED_IN_UA_SHEETS) + { + return true; + } + + if self.chrome_rules_enabled() && + pseudo_class.has_any_flag(NonTSPseudoClassFlag::PSEUDO_CLASS_ENABLED_IN_CHROME) + { + return true; + } + + return false; } } @@ -315,8 +328,11 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> { name.starts_with("-moz-tree-") // tree pseudo-elements } - fn parse_non_ts_pseudo_class(&self, location: SourceLocation, name: CowRcStr<'i>) - -> Result> { + fn parse_non_ts_pseudo_class( + &self, + location: SourceLocation, + name: CowRcStr<'i>, + ) -> Result> { macro_rules! pseudo_class_parse { (bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*], string: [$(($s_css:expr, $s_name:ident, $s_gecko_type:tt, $s_state:tt, $s_flags:tt),)*], @@ -337,10 +353,11 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> { } } - fn parse_non_ts_functional_pseudo_class<'t>(&self, - name: CowRcStr<'i>, - parser: &mut Parser<'i, 't>) - -> Result> { + fn parse_non_ts_functional_pseudo_class<'t>( + &self, + name: CowRcStr<'i>, + parser: &mut Parser<'i, 't>, + ) -> Result> { macro_rules! pseudo_class_string_parse { (bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*], string: [$(($s_css:expr, $s_name:ident, $s_gecko_type:tt, $s_state:tt, $s_flags:tt),)*], @@ -386,8 +403,11 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> { } } - fn parse_pseudo_element(&self, location: SourceLocation, name: CowRcStr<'i>) - -> Result> { + fn parse_pseudo_element( + &self, + location: SourceLocation, + name: CowRcStr<'i>, + ) -> Result> { PseudoElement::from_slice(&name, self.in_user_agent_stylesheet()) .or_else(|| { if name.starts_with("-moz-tree-") { @@ -399,9 +419,11 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> { .ok_or(location.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name.clone()))) } - fn parse_functional_pseudo_element<'t>(&self, name: CowRcStr<'i>, - parser: &mut Parser<'i, 't>) - -> Result> { + fn parse_functional_pseudo_element<'t>( + &self, + name: CowRcStr<'i>, + parser: &mut Parser<'i, 't>, + ) -> Result> { if name.starts_with("-moz-tree-") { // Tree pseudo-elements can have zero or more arguments, // separated by either comma or space. diff --git a/components/style/parser.rs b/components/style/parser.rs index 6ee905a8b87..eb0d8a4eb96 100644 --- a/components/style/parser.rs +++ b/components/style/parser.rs @@ -132,9 +132,9 @@ impl<'a> ParserContext<'a> { context.error_reporter.report_error(self.url_data, location, error) } - /// Returns whether this is a chrome stylesheets. - pub fn in_chrome_stylesheet(&self) -> bool { - self.url_data.is_chrome() + /// Returns whether chrome-only rules should be parsed. + pub fn chrome_rules_enabled(&self) -> bool { + self.url_data.is_chrome() || self.stylesheet_origin == Origin::User } } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 1b215c2ec04..d951ca804a5 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1158,7 +1158,7 @@ impl PropertyId { Some(context) => context, None => { default = PropertyParserContext { - in_chrome_stylesheet: false, + chrome_rules_enabled: false, stylesheet_origin: Origin::Author, rule_type: CssRuleType::Style, }; @@ -1346,7 +1346,7 @@ impl PropertyId { return Ok(()) } - if context.in_chrome_stylesheet && ENABLED_IN_CHROME.contains(id) { + if context.chrome_rules_enabled && ENABLED_IN_CHROME.contains(id) { return Ok(()) } @@ -1357,7 +1357,7 @@ impl PropertyId { /// Parsing Context for PropertyId. pub struct PropertyParserContext { /// Whether the property is parsed in a chrome:// stylesheet. - pub in_chrome_stylesheet: bool, + pub chrome_rules_enabled: bool, /// The Origin of the stylesheet, whether it's a user, /// author or user-agent stylesheet. pub stylesheet_origin: Origin, @@ -1369,7 +1369,7 @@ impl PropertyParserContext { /// Creates a PropertyParserContext with given stylesheet origin and rule type. pub fn new(context: &ParserContext) -> Self { Self { - in_chrome_stylesheet: context.in_chrome_stylesheet(), + chrome_rules_enabled: context.chrome_rules_enabled(), stylesheet_origin: context.stylesheet_origin, rule_type: context.rule_type(), } diff --git a/components/style/selector_parser.rs b/components/style/selector_parser.rs index 62d88f2bf3b..3fc9446713f 100644 --- a/components/style/selector_parser.rs +++ b/components/style/selector_parser.rs @@ -70,8 +70,9 @@ impl<'a> SelectorParser<'a> { /// Whether we're parsing selectors in a stylesheet that has chrome /// privilege. - pub fn in_chrome_stylesheet(&self) -> bool { - self.url_data.map_or(false, |d| d.is_chrome()) + pub fn chrome_rules_enabled(&self) -> bool { + self.url_data.map_or(false, |d| d.is_chrome()) || + self.stylesheet_origin == Origin::User } }