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.