From 17257f94b93cbf5c371c910484f9c71e527e9f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 27 Feb 2018 12:46:11 +0100 Subject: [PATCH] style: Split out NonCustomPropertyId::enabled_for_all_content from allowed_in. --- .../style/properties/properties.mako.rs | 103 +++++++++++------- 1 file changed, 65 insertions(+), 38 deletions(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index d3b6687b5e3..f1057c61bbe 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -438,45 +438,17 @@ impl NonCustomPropertyId { MAP[self.0] } - fn allowed_in(self, context: &ParserContext) -> bool { - debug_assert!( - matches!( - context.rule_type(), - CssRuleType::Keyframe | CssRuleType::Page | CssRuleType::Style - ), - "Declarations are only expected inside a keyframe, page, or style rule." - ); + #[inline] + fn enabled_for_all_content(self) -> bool { + ${static_non_custom_property_id_set( + "EXPERIMENTAL", + lambda p: p.experimental(product) + )} - <% id_set = static_non_custom_property_id_set %> - - ${id_set("DISALLOWED_IN_KEYFRAME_BLOCK", lambda p: not p.allowed_in_keyframe_block)} - ${id_set("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; - } - _ => {} - } - - // The semantics of these are kinda hard to reason about, what follows - // is a description of the different combinations that can happen with - // these three sets. - // - // Experimental properties are generally controlled by prefs, but an - // experimental property explicitly enabled in certain context (UA or - // chrome sheets) is always usable in the context regardless of the - // pref value. - // - // Non-experimental properties are either normal properties which are - // usable everywhere, or internal-only properties which are only usable - // in certain context they are explicitly enabled in. - ${id_set("ENABLED_IN_UA_SHEETS", lambda p: p.explicitly_enabled_in_ua_sheets())} - ${id_set("ENABLED_IN_CHROME", lambda p: p.explicitly_enabled_in_chrome())} - ${id_set("EXPERIMENTAL", lambda p: p.experimental(product))} - ${id_set("ALWAYS_ENABLED", lambda p: (not p.experimental(product)) and p.enabled_in_content())} + ${static_non_custom_property_id_set( + "ALWAYS_ENABLED", + lambda p: (not p.experimental(product)) and p.enabled_in_content() + )} let passes_pref_check = || { % if product == "servo": @@ -508,6 +480,61 @@ impl NonCustomPropertyId { return true } + false + } + + fn allowed_in(self, context: &ParserContext) -> bool { + debug_assert!( + matches!( + context.rule_type(), + CssRuleType::Keyframe | CssRuleType::Page | CssRuleType::Style + ), + "Declarations are only expected inside a keyframe, page, or style rule." + ); + + ${static_non_custom_property_id_set( + "DISALLOWED_IN_KEYFRAME_BLOCK", + lambda p: not p.allowed_in_keyframe_block + )} + ${static_non_custom_property_id_set( + "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; + } + _ => {} + } + + // The semantics of these are kinda hard to reason about, what follows + // is a description of the different combinations that can happen with + // these three sets. + // + // Experimental properties are generally controlled by prefs, but an + // experimental property explicitly enabled in certain context (UA or + // chrome sheets) is always usable in the context regardless of the + // pref value. + // + // Non-experimental properties are either normal properties which are + // usable everywhere, or internal-only properties which are only usable + // in certain context they are explicitly enabled in. + if self.enabled_for_all_content() { + return true; + } + + ${static_non_custom_property_id_set( + "ENABLED_IN_UA_SHEETS", + lambda p: p.explicitly_enabled_in_ua_sheets() + )} + ${static_non_custom_property_id_set( + "ENABLED_IN_CHROME", + lambda p: p.explicitly_enabled_in_chrome() + )} + if context.stylesheet_origin == Origin::UserAgent && ENABLED_IN_UA_SHEETS.contains(self) {