From 9ac97dd8ad05f6f325152a0be22b5d62ec02d778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 9 May 2023 09:32:28 +0000 Subject: [PATCH] style: when iterating over a selector to find a bucket, choose the rightmost This restores the pre-regression behavior by choosing the later class in cases where folks use stuff like `.foo.bar`. This matches other browsers too. Differential Revision: https://phabricator.services.mozilla.com/D177398 --- components/style/selector_map.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/style/selector_map.rs b/components/style/selector_map.rs index 3b7515292bf..732168cbfd8 100644 --- a/components/style/selector_map.rs +++ b/components/style/selector_map.rs @@ -684,6 +684,11 @@ impl<'a> Bucket<'a> { } } + #[inline] + fn more_or_equally_specific_than(&self, other: &Self) -> bool { + self.specificity() >= other.specificity() + } + #[inline] fn more_specific_than(&self, other: &Self) -> bool { self.specificity() > other.specificity() @@ -787,7 +792,9 @@ fn find_bucket<'a>( loop { for ss in &mut iter { let new_bucket = specific_bucket_for(ss, disjoint_buckets, bucket_attributes); - if new_bucket.more_specific_than(¤t_bucket) { + // NOTE: When presented with the choice of multiple specific selectors, use the + // rightmost, on the assumption that that's less common, see bug 1829540. + if new_bucket.more_or_equally_specific_than(¤t_bucket) { current_bucket = new_bucket; } }