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;
if context.in_chrome_stylesheet() ||
if context.chrome_rules_enabled() ||
context.stylesheet_origin == Origin::UserAgent {
flags |= structs::nsMediaFeature_RequirementFlags_eUserAgentAndChromeOnly;
}

View file

@ -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<NonTSPseudoClass, ParseError<'i>> {
fn parse_non_ts_pseudo_class(
&self,
location: SourceLocation,
name: CowRcStr<'i>,
) -> Result<NonTSPseudoClass, ParseError<'i>> {
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<NonTSPseudoClass, ParseError<'i>> {
fn parse_non_ts_functional_pseudo_class<'t>(
&self,
name: CowRcStr<'i>,
parser: &mut Parser<'i, 't>,
) -> Result<NonTSPseudoClass, ParseError<'i>> {
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<PseudoElement, ParseError<'i>> {
fn parse_pseudo_element(
&self,
location: SourceLocation,
name: CowRcStr<'i>,
) -> Result<PseudoElement, ParseError<'i>> {
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<PseudoElement, ParseError<'i>> {
fn parse_functional_pseudo_element<'t>(
&self,
name: CowRcStr<'i>,
parser: &mut Parser<'i, 't>,
) -> Result<PseudoElement, ParseError<'i>> {
if name.starts_with("-moz-tree-") {
// Tree pseudo-elements can have zero or more arguments,
// 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)
}
/// 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
}
}

View file

@ -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(),
}

View file

@ -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
}
}