mirror of
https://github.com/servo/servo.git
synced 2025-08-11 16:35:33 +01:00
Allow style sharing for elements with ids as long as the ID is not being used for styling.
This commit is contained in:
parent
d031b5badb
commit
ad1309552d
5 changed files with 93 additions and 8 deletions
|
@ -6,6 +6,7 @@
|
|||
//! quickly whether it's worth to share style, and whether two different
|
||||
//! elements can indeed share the same style.
|
||||
|
||||
use Atom;
|
||||
use bloom::StyleBloom;
|
||||
use context::{SelectorFlagsMap, SharedStyleContext};
|
||||
use dom::TElement;
|
||||
|
@ -123,3 +124,28 @@ pub fn revalidate<E>(target: &mut StyleSharingTarget<E>,
|
|||
|
||||
for_element == for_candidate
|
||||
}
|
||||
|
||||
/// Checks whether we might have rules for either of the two ids.
|
||||
#[inline]
|
||||
pub fn may_have_rules_for_ids(shared_context: &SharedStyleContext,
|
||||
element_id: Option<&Atom>,
|
||||
candidate_id: Option<&Atom>) -> bool
|
||||
{
|
||||
// We shouldn't be called unless the ids are different.
|
||||
debug_assert!(element_id.is_some() || candidate_id.is_some());
|
||||
let stylist = &shared_context.stylist;
|
||||
|
||||
let may_have_rules_for_element = match element_id {
|
||||
Some(id) => stylist.may_have_rules_for_id(id),
|
||||
None => false
|
||||
};
|
||||
|
||||
if may_have_rules_for_element {
|
||||
return true;
|
||||
}
|
||||
|
||||
match candidate_id {
|
||||
Some(id) => stylist.may_have_rules_for_id(id),
|
||||
None => false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -509,11 +509,6 @@ impl<E: TElement> StyleSharingCandidateCache<E> {
|
|||
return StyleSharingResult::CannotShare;
|
||||
}
|
||||
|
||||
if target.get_id().is_some() {
|
||||
debug!("{:?} Cannot share style: element has id", target.element);
|
||||
return StyleSharingResult::CannotShare
|
||||
}
|
||||
|
||||
let mut should_clear_cache = false;
|
||||
for (i, candidate) in self.iter_mut().enumerate() {
|
||||
let sharing_result =
|
||||
|
@ -632,8 +627,14 @@ impl<E: TElement> StyleSharingCandidateCache<E> {
|
|||
miss!(State)
|
||||
}
|
||||
|
||||
if target.get_id() != candidate.element.get_id() {
|
||||
miss!(IdAttr)
|
||||
let element_id = target.element.get_id();
|
||||
let candidate_id = candidate.element.get_id();
|
||||
if element_id != candidate_id {
|
||||
// It's possible that there are no styles for either id.
|
||||
if checks::may_have_rules_for_ids(shared, element_id.as_ref(),
|
||||
candidate_id.as_ref()) {
|
||||
miss!(IdAttr)
|
||||
}
|
||||
}
|
||||
|
||||
if !checks::have_same_style_attribute(target, candidate) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue