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
This commit is contained in:
Emilio Cobos Álvarez 2023-05-27 06:05:52 +02:00 committed by Oriol Brufau
parent 93fb8861ae
commit 3dc3fb9412
3 changed files with 10 additions and 5 deletions

View file

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

View file

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

View file

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