style: Enable chrome-only CSS features in user stylesheets.

MozReview-Commit-ID: FJ4vTiOrotH
Reviewed-by: heycam
Bug: 1418963
This commit is contained in:
Emilio Cobos Álvarez 2017-11-21 10:11:05 +01:00
parent b74e71fdd1
commit c7a3c929f6
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
5 changed files with 52 additions and 29 deletions

View file

@ -588,7 +588,7 @@ impl Expression {
let mut flags = 0; let mut flags = 0;
if context.in_chrome_stylesheet() || if context.chrome_rules_enabled() ||
context.stylesheet_origin == Origin::UserAgent { context.stylesheet_origin == Origin::UserAgent {
flags |= structs::nsMediaFeature_RequirementFlags_eUserAgentAndChromeOnly; flags |= structs::nsMediaFeature_RequirementFlags_eUserAgentAndChromeOnly;
} }

View file

@ -295,14 +295,27 @@ impl ::selectors::SelectorImpl for SelectorImpl {
} }
impl<'a> SelectorParser<'a> { impl<'a> SelectorParser<'a> {
fn is_pseudo_class_enabled(&self, fn is_pseudo_class_enabled(
pseudo_class: &NonTSPseudoClass) &self,
-> bool { pseudo_class: &NonTSPseudoClass,
pseudo_class.is_enabled_in_content() || ) -> bool {
(self.in_user_agent_stylesheet() && if pseudo_class.is_enabled_in_content() {
pseudo_class.has_any_flag(NonTSPseudoClassFlag::PSEUDO_CLASS_ENABLED_IN_UA_SHEETS)) || return true;
(self.in_chrome_stylesheet() && }
pseudo_class.has_any_flag(NonTSPseudoClassFlag::PSEUDO_CLASS_ENABLED_IN_CHROME))
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 name.starts_with("-moz-tree-") // tree pseudo-elements
} }
fn parse_non_ts_pseudo_class(&self, location: SourceLocation, name: CowRcStr<'i>) fn parse_non_ts_pseudo_class(
-> Result<NonTSPseudoClass, ParseError<'i>> { &self,
location: SourceLocation,
name: CowRcStr<'i>,
) -> Result<NonTSPseudoClass, ParseError<'i>> {
macro_rules! pseudo_class_parse { macro_rules! pseudo_class_parse {
(bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*], (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),)*], 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, fn parse_non_ts_functional_pseudo_class<'t>(
name: CowRcStr<'i>, &self,
parser: &mut Parser<'i, 't>) name: CowRcStr<'i>,
-> Result<NonTSPseudoClass, ParseError<'i>> { parser: &mut Parser<'i, 't>,
) -> Result<NonTSPseudoClass, ParseError<'i>> {
macro_rules! pseudo_class_string_parse { macro_rules! pseudo_class_string_parse {
(bare: [$(($css:expr, $name:ident, $gecko_type:tt, $state:tt, $flags:tt),)*], (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),)*], 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>) fn parse_pseudo_element(
-> Result<PseudoElement, ParseError<'i>> { &self,
location: SourceLocation,
name: CowRcStr<'i>,
) -> Result<PseudoElement, ParseError<'i>> {
PseudoElement::from_slice(&name, self.in_user_agent_stylesheet()) PseudoElement::from_slice(&name, self.in_user_agent_stylesheet())
.or_else(|| { .or_else(|| {
if name.starts_with("-moz-tree-") { 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()))) .ok_or(location.new_custom_error(SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name.clone())))
} }
fn parse_functional_pseudo_element<'t>(&self, name: CowRcStr<'i>, fn parse_functional_pseudo_element<'t>(
parser: &mut Parser<'i, 't>) &self,
-> Result<PseudoElement, ParseError<'i>> { name: CowRcStr<'i>,
parser: &mut Parser<'i, 't>,
) -> Result<PseudoElement, ParseError<'i>> {
if name.starts_with("-moz-tree-") { if name.starts_with("-moz-tree-") {
// Tree pseudo-elements can have zero or more arguments, // Tree pseudo-elements can have zero or more arguments,
// separated by either comma or space. // separated by either comma or space.

View file

@ -132,9 +132,9 @@ impl<'a> ParserContext<'a> {
context.error_reporter.report_error(self.url_data, location, error) context.error_reporter.report_error(self.url_data, location, error)
} }
/// Returns whether this is a chrome stylesheets. /// Returns whether chrome-only rules should be parsed.
pub fn in_chrome_stylesheet(&self) -> bool { pub fn chrome_rules_enabled(&self) -> bool {
self.url_data.is_chrome() self.url_data.is_chrome() || self.stylesheet_origin == Origin::User
} }
} }

View file

@ -1158,7 +1158,7 @@ impl PropertyId {
Some(context) => context, Some(context) => context,
None => { None => {
default = PropertyParserContext { default = PropertyParserContext {
in_chrome_stylesheet: false, chrome_rules_enabled: false,
stylesheet_origin: Origin::Author, stylesheet_origin: Origin::Author,
rule_type: CssRuleType::Style, rule_type: CssRuleType::Style,
}; };
@ -1346,7 +1346,7 @@ impl PropertyId {
return Ok(()) return Ok(())
} }
if context.in_chrome_stylesheet && ENABLED_IN_CHROME.contains(id) { if context.chrome_rules_enabled && ENABLED_IN_CHROME.contains(id) {
return Ok(()) return Ok(())
} }
@ -1357,7 +1357,7 @@ impl PropertyId {
/// Parsing Context for PropertyId. /// Parsing Context for PropertyId.
pub struct PropertyParserContext { pub struct PropertyParserContext {
/// Whether the property is parsed in a chrome:// stylesheet. /// 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, /// The Origin of the stylesheet, whether it's a user,
/// author or user-agent stylesheet. /// author or user-agent stylesheet.
pub stylesheet_origin: Origin, pub stylesheet_origin: Origin,
@ -1369,7 +1369,7 @@ impl PropertyParserContext {
/// Creates a PropertyParserContext with given stylesheet origin and rule type. /// Creates a PropertyParserContext with given stylesheet origin and rule type.
pub fn new(context: &ParserContext) -> Self { pub fn new(context: &ParserContext) -> Self {
Self { Self {
in_chrome_stylesheet: context.in_chrome_stylesheet(), chrome_rules_enabled: context.chrome_rules_enabled(),
stylesheet_origin: context.stylesheet_origin, stylesheet_origin: context.stylesheet_origin,
rule_type: context.rule_type(), rule_type: context.rule_type(),
} }

View file

@ -70,8 +70,9 @@ impl<'a> SelectorParser<'a> {
/// Whether we're parsing selectors in a stylesheet that has chrome /// Whether we're parsing selectors in a stylesheet that has chrome
/// privilege. /// privilege.
pub fn in_chrome_stylesheet(&self) -> bool { pub fn chrome_rules_enabled(&self) -> bool {
self.url_data.map_or(false, |d| d.is_chrome()) self.url_data.map_or(false, |d| d.is_chrome()) ||
self.stylesheet_origin == Origin::User
} }
} }