style: CSSOM should respect rule-level property restrictions.

Differential Revision: https://phabricator.services.mozilla.com/D90729
This commit is contained in:
Emilio Cobos Álvarez 2020-09-21 09:57:46 +00:00
parent c99d6adf01
commit 60d89cfbc0
3 changed files with 19 additions and 13 deletions

View file

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

View file

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

View file

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