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
This commit is contained in:
Emilio Cobos Álvarez 2023-05-09 09:32:28 +00:00 committed by Martin Robinson
parent 303ea410e2
commit 9ac97dd8ad

View file

@ -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(&current_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(&current_bucket) {
current_bucket = new_bucket;
}
}