From 5c0f044d39276a263bf363a754fe431c366ca884 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Tue, 6 Jun 2023 17:11:32 +0200 Subject: [PATCH] Further changes required by Servo --- components/style/matching.rs | 2 ++ components/style/properties/properties.mako.rs | 10 +++++++++- tests/unit/style/custom_properties.rs | 9 +++++++-- tests/unit/style/rule_tree/bench.rs | 9 ++++++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/components/style/matching.rs b/components/style/matching.rs index 92fdee3f97b..f2d300df4b2 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -513,12 +513,14 @@ trait PrivateMatchMethods: TElement { Self::replace_single_rule_node( &context.shared, CascadeLevel::Transitions, + LayerOrder::root(), declarations.transitions.as_ref().map(|a| a.borrow_arc()), &mut rule_node, ); Self::replace_single_rule_node( &context.shared, CascadeLevel::Animations, + LayerOrder::root(), declarations.animations.as_ref().map(|a| a.borrow_arc()), &mut rule_node, ); diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index cdecfaae895..dee66cd59b0 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1067,6 +1067,14 @@ impl CSSWideKeyword { } } +#[inline] +fn cascade_layes_enabled() -> bool { + #[cfg(feature = "gecko")] + return static_prefs::pref!("layout.css.cascade-layers.enabled"); + #[cfg(feature = "servo")] + return false; +} + impl CSSWideKeyword { /// Parses a CSS wide keyword from a CSS identifier. pub fn from_ident(ident: &str) -> Result { @@ -1075,7 +1083,7 @@ impl CSSWideKeyword { "inherit" => CSSWideKeyword::Inherit, "unset" => CSSWideKeyword::Unset, "revert" => CSSWideKeyword::Revert, - "revert-layer" if static_prefs::pref!("layout.css.cascade-layers.enabled") => CSSWideKeyword::RevertLayer, + "revert-layer" if cascade_layes_enabled() => CSSWideKeyword::RevertLayer, _ => return Err(()), }) } diff --git a/tests/unit/style/custom_properties.rs b/tests/unit/style/custom_properties.rs index 1e4ab0a7282..21ce2ba3f86 100644 --- a/tests/unit/style/custom_properties.rs +++ b/tests/unit/style/custom_properties.rs @@ -5,13 +5,15 @@ use cssparser::{Parser, ParserInput}; use euclid::{Scale, Size2D}; use servo_arc::Arc; +use style::applicable_declarations::CascadePriority; use style::context::QuirksMode; use style::custom_properties::{ CustomPropertiesBuilder, CustomPropertiesMap, Name, SpecifiedValue, }; use style::media_queries::{Device, MediaType}; use style::properties::{CustomDeclaration, CustomDeclarationValue}; -use style::stylesheets::Origin; +use style::rule_tree::CascadeLevel; +use style::stylesheets::layer_rule::LayerOrder; use test::{self, Bencher}; fn cascade( @@ -38,7 +40,10 @@ fn cascade( let mut builder = CustomPropertiesBuilder::new(inherited, &device); for declaration in &declarations { - builder.cascade(declaration, Origin::Author); + builder.cascade( + declaration, + CascadePriority::new(CascadeLevel::same_tree_author_normal(), LayerOrder::root()), + ); } builder.build() diff --git a/tests/unit/style/rule_tree/bench.rs b/tests/unit/style/rule_tree/bench.rs index 9da1eb698e3..d7de685fbd8 100644 --- a/tests/unit/style/rule_tree/bench.rs +++ b/tests/unit/style/rule_tree/bench.rs @@ -6,12 +6,14 @@ use cssparser::SourceLocation; use rayon; use servo_arc::Arc; use servo_url::ServoUrl; +use style::applicable_declarations::CascadePriority; use style::context::QuirksMode; use style::error_reporting::{ContextualParseError, ParseErrorReporter}; use style::media_queries::MediaList; use style::properties::{longhands, Importance, PropertyDeclaration, PropertyDeclarationBlock}; use style::rule_tree::{CascadeLevel, RuleTree, StrongRuleNode, StyleSource}; use style::shared_lock::{SharedRwLock, StylesheetGuards}; +use style::stylesheets::layer_rule::LayerOrder; use style::stylesheets::{AllowImportRules, CssRule, Origin, Stylesheet}; use style::thread_state::{self, ThreadState}; use test::{self, Bencher}; @@ -85,7 +87,12 @@ fn parse_rules(lock: &SharedRwLock, css: &str) -> Vec<(StyleSource, CascadeLevel } fn test_insertion(rule_tree: &RuleTree, rules: Vec<(StyleSource, CascadeLevel)>) -> StrongRuleNode { - rule_tree.insert_ordered_rules(rules.into_iter()) + rule_tree.insert_ordered_rules(rules.into_iter().map(|(style_source, cascade_level)| { + ( + style_source, + CascadePriority::new(cascade_level, LayerOrder::root()), + ) + })) } fn test_insertion_style_attribute(