From 3dc3fb9412d23769ab05e0cdb13f2f11b1fe1f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 27 May 2023 06:05:52 +0200 Subject: [PATCH] style: Plumb layer order through ApplicableDeclarationBlock, and make it have an effect Same, I want to land this separately to see if it affects micro-benchmarks. If so, we might want to pack the layer order _somewhere_ (though in this case I'm not sure where, tbh). With this, layer rules should have an effect on the page. There are a few things missing before being able to enable them: * Fix nested layer order in some cases (when parent layers are declared out of order, see the previous commit mentioning this). * Some kind of OM representation, perhaps. * Tests of course, which are coming in bug 1728722 and bug 1727276. But this should be enough to allow playing with them. Depends on D124337 Differential Revision: https://phabricator.services.mozilla.com/D124338 --- components/style/applicable_declarations.rs | 10 +++++++--- components/style/rule_collector.rs | 2 +- components/style/stylist.rs | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/components/style/applicable_declarations.rs b/components/style/applicable_declarations.rs index 6353fb4c5e5..168aae643cd 100644 --- a/components/style/applicable_declarations.rs +++ b/components/style/applicable_declarations.rs @@ -69,8 +69,10 @@ pub struct ApplicableDeclarationBlock { /// The bits containing the source order, cascade level, and shadow cascade /// order. bits: ApplicableDeclarationBits, - /// The specificity of the selector this block is represented by. + /// The specificity of the selector. pub specificity: u32, + /// The layer order of the selector. + pub layer_order: u32, } impl ApplicableDeclarationBlock { @@ -85,16 +87,18 @@ impl ApplicableDeclarationBlock { source: StyleSource::from_declarations(declarations), bits: ApplicableDeclarationBits::new(0, level), specificity: 0, + layer_order: 0, } } /// Constructs an applicable declaration block from the given components #[inline] - pub fn new(source: StyleSource, order: u32, level: CascadeLevel, specificity: u32) -> Self { + pub fn new(source: StyleSource, source_order: u32, level: CascadeLevel, specificity: u32, layer_order: u32) -> Self { ApplicableDeclarationBlock { source, - bits: ApplicableDeclarationBits::new(order, level), + bits: ApplicableDeclarationBits::new(source_order, level), specificity, + layer_order, } } diff --git a/components/style/rule_collector.rs b/components/style/rule_collector.rs index 86293e5c785..bb34396f9aa 100644 --- a/components/style/rule_collector.rs +++ b/components/style/rule_collector.rs @@ -148,7 +148,7 @@ where f(self); if start != self.rules.len() { self.rules[start..] - .sort_unstable_by_key(|block| (block.specificity, block.source_order())); + .sort_unstable_by_key(|block| (block.layer_order, block.specificity, block.source_order())); } self.context.current_host = old_host; self.in_sort_scope = false; diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 7298e0d2fc9..0a87da95bc8 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -2176,6 +2176,7 @@ impl CascadeData { self.rules_source_order, CascadeLevel::UANormal, selector.specificity(), + current_layer_order, )); continue; } @@ -2678,7 +2679,7 @@ impl Rule { level: CascadeLevel, ) -> ApplicableDeclarationBlock { let source = StyleSource::from_rule(self.style_rule.clone()); - ApplicableDeclarationBlock::new(source, self.source_order, level, self.specificity()) + ApplicableDeclarationBlock::new(source, self.source_order, level, self.specificity(), self.layer_order) } /// Creates a new Rule.