mirror of
https://github.com/servo/servo.git
synced 2025-06-23 00:24:35 +01:00
style: Ensure that precomputed pseudo-element declarations are correctly sorted.
This commit is contained in:
parent
6fe9fd2269
commit
db26ef9acb
2 changed files with 23 additions and 21 deletions
|
@ -210,13 +210,9 @@ impl Stylist {
|
||||||
self.state_deps.len());
|
self.state_deps.len());
|
||||||
|
|
||||||
SelectorImpl::each_precomputed_pseudo_element(|pseudo| {
|
SelectorImpl::each_precomputed_pseudo_element(|pseudo| {
|
||||||
// TODO: Consider not doing this and just getting the rules on the
|
|
||||||
// fly. It should be a bit slower, but we'd take rid of the
|
|
||||||
// extra field, and avoid this precomputation entirely.
|
|
||||||
if let Some(map) = self.pseudos_map.remove(&pseudo) {
|
if let Some(map) = self.pseudos_map.remove(&pseudo) {
|
||||||
let mut declarations = vec![];
|
let declarations =
|
||||||
map.user_agent.get_universal_rules(&mut declarations,
|
map.user_agent.get_universal_rules(CascadeLevel::UANormal,
|
||||||
CascadeLevel::UANormal,
|
|
||||||
CascadeLevel::UAImportant);
|
CascadeLevel::UAImportant);
|
||||||
self.precomputed_pseudo_element_decls.insert(pseudo, declarations);
|
self.precomputed_pseudo_element_decls.insert(pseudo, declarations);
|
||||||
}
|
}
|
||||||
|
@ -922,20 +918,21 @@ impl SelectorMap {
|
||||||
|
|
||||||
/// Append to `rule_list` all universal Rules (rules with selector `*|*`) in
|
/// Append to `rule_list` all universal Rules (rules with selector `*|*`) in
|
||||||
/// `self` sorted by specificity and source order.
|
/// `self` sorted by specificity and source order.
|
||||||
pub fn get_universal_rules<V>(&self,
|
pub fn get_universal_rules(&self,
|
||||||
matching_rules_list: &mut V,
|
|
||||||
cascade_level: CascadeLevel,
|
cascade_level: CascadeLevel,
|
||||||
important_cascade_level: CascadeLevel)
|
important_cascade_level: CascadeLevel)
|
||||||
where V: VecLike<ApplicableDeclarationBlock>
|
-> Vec<ApplicableDeclarationBlock> {
|
||||||
{
|
|
||||||
debug_assert!(!cascade_level.is_important());
|
debug_assert!(!cascade_level.is_important());
|
||||||
debug_assert!(important_cascade_level.is_important());
|
debug_assert!(important_cascade_level.is_important());
|
||||||
if self.empty {
|
if self.empty {
|
||||||
return
|
return vec![];
|
||||||
}
|
}
|
||||||
|
|
||||||
let init_len = matching_rules_list.len();
|
let mut matching_rules_list = vec![];
|
||||||
|
|
||||||
|
// We need to insert important rules _after_ normal rules for this to be
|
||||||
|
// correct, and also to not trigger rule tree assertions.
|
||||||
|
let mut important = vec![];
|
||||||
for rule in self.other_rules.iter() {
|
for rule in self.other_rules.iter() {
|
||||||
if rule.selector.compound_selector.is_empty() &&
|
if rule.selector.compound_selector.is_empty() &&
|
||||||
rule.selector.next.is_none() {
|
rule.selector.next.is_none() {
|
||||||
|
@ -946,14 +943,21 @@ impl SelectorMap {
|
||||||
rule.to_applicable_declaration_block(cascade_level));
|
rule.to_applicable_declaration_block(cascade_level));
|
||||||
}
|
}
|
||||||
if block.any_important() {
|
if block.any_important() {
|
||||||
matching_rules_list.push(
|
important.push(
|
||||||
rule.to_applicable_declaration_block(important_cascade_level));
|
rule.to_applicable_declaration_block(important_cascade_level));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort_by_key(&mut matching_rules_list[init_len..],
|
let normal_len = matching_rules_list.len();
|
||||||
|
matching_rules_list.extend(important.into_iter());
|
||||||
|
|
||||||
|
sort_by_key(&mut matching_rules_list[0..normal_len],
|
||||||
|block| (block.specificity, block.source_order));
|
|block| (block.specificity, block.source_order));
|
||||||
|
sort_by_key(&mut matching_rules_list[normal_len..],
|
||||||
|
|block| (block.specificity, block.source_order));
|
||||||
|
|
||||||
|
matching_rules_list
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_matching_rules_from_hash<E, Str, BorrowedStr: ?Sized, Vector>(
|
fn get_matching_rules_from_hash<E, Str, BorrowedStr: ?Sized, Vector>(
|
||||||
|
|
|
@ -112,10 +112,8 @@ fn test_insert() {
|
||||||
fn test_get_universal_rules() {
|
fn test_get_universal_rules() {
|
||||||
thread_state::initialize(thread_state::LAYOUT);
|
thread_state::initialize(thread_state::LAYOUT);
|
||||||
let map = get_mock_map(&["*|*", "#foo > *|*", ".klass", "#id"]);
|
let map = get_mock_map(&["*|*", "#foo > *|*", ".klass", "#id"]);
|
||||||
let mut decls = vec![];
|
|
||||||
|
|
||||||
map.get_universal_rules(&mut decls,
|
let decls = map.get_universal_rules(CascadeLevel::UserNormal,
|
||||||
CascadeLevel::UserNormal,
|
|
||||||
CascadeLevel::UserImportant);
|
CascadeLevel::UserImportant);
|
||||||
|
|
||||||
assert_eq!(decls.len(), 1);
|
assert_eq!(decls.len(), 1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue