mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Define share_style_if_possible on LayoutElement.
This commit is contained in:
parent
e6e514c89a
commit
f3faaa6b01
2 changed files with 26 additions and 23 deletions
|
@ -377,6 +377,15 @@ pub trait ElementMatchMethods {
|
|||
parent_bf: Option<&BloomFilter>,
|
||||
applicable_declarations: &mut ApplicableDeclarations)
|
||||
-> bool;
|
||||
|
||||
/// Attempts to share a style with another node. This method is unsafe because it depends on
|
||||
/// the `style_sharing_candidate_cache` having only live nodes in it, and we have no way to
|
||||
/// guarantee that at the type system level yet.
|
||||
unsafe fn share_style_if_possible(&self,
|
||||
style_sharing_candidate_cache:
|
||||
&mut StyleSharingCandidateCache,
|
||||
parent: Option<LayoutNode>)
|
||||
-> StyleSharingResult;
|
||||
}
|
||||
|
||||
pub trait MatchMethods {
|
||||
|
@ -393,15 +402,6 @@ pub trait MatchMethods {
|
|||
/// called to reset the bloom filter after an `insert`.
|
||||
fn remove_from_bloom_filter(&self, bf: &mut BloomFilter);
|
||||
|
||||
/// Attempts to share a style with another node. This method is unsafe because it depends on
|
||||
/// the `style_sharing_candidate_cache` having only live nodes in it, and we have no way to
|
||||
/// guarantee that at the type system level yet.
|
||||
unsafe fn share_style_if_possible(&self,
|
||||
style_sharing_candidate_cache:
|
||||
&mut StyleSharingCandidateCache,
|
||||
parent: Option<LayoutNode>)
|
||||
-> StyleSharingResult;
|
||||
|
||||
unsafe fn cascade_node(&self,
|
||||
layout_context: &SharedLayoutContext,
|
||||
parent: Option<LayoutNode>,
|
||||
|
@ -574,9 +574,7 @@ impl<'ln> ElementMatchMethods for LayoutElement<'ln> {
|
|||
applicable_declarations.before.is_empty() &&
|
||||
applicable_declarations.after.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ln> MatchMethods for LayoutNode<'ln> {
|
||||
unsafe fn share_style_if_possible(&self,
|
||||
style_sharing_candidate_cache:
|
||||
&mut StyleSharingCandidateCache,
|
||||
|
@ -586,23 +584,19 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
|
|||
return StyleSharingResult::CannotShare(false)
|
||||
}
|
||||
|
||||
let element = match self.as_element() {
|
||||
Some(element) => element,
|
||||
None => return StyleSharingResult::CannotShare(false),
|
||||
};
|
||||
|
||||
if element.style_attribute().is_some() {
|
||||
if self.style_attribute().is_some() {
|
||||
return StyleSharingResult::CannotShare(false)
|
||||
}
|
||||
if element.get_attr(&ns!(""), &atom!("id")).is_some() {
|
||||
if self.get_attr(&ns!(""), &atom!("id")).is_some() {
|
||||
return StyleSharingResult::CannotShare(false)
|
||||
}
|
||||
|
||||
for (i, &(ref candidate, ())) in style_sharing_candidate_cache.iter().enumerate() {
|
||||
match element.share_style_with_candidate_if_possible(parent.clone(), candidate) {
|
||||
match self.share_style_with_candidate_if_possible(parent.clone(), candidate) {
|
||||
Some(shared_style) => {
|
||||
// Yay, cache hit. Share the style.
|
||||
let mut layout_data_ref = self.mutate_layout_data();
|
||||
let node = self.as_node();
|
||||
let mut layout_data_ref = node.mutate_layout_data();
|
||||
let shared_data = &mut layout_data_ref.as_mut().unwrap().shared_data;
|
||||
let style = &mut shared_data.style;
|
||||
let damage = incremental::compute_damage(style, &*shared_style);
|
||||
|
@ -615,7 +609,9 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
|
|||
|
||||
StyleSharingResult::CannotShare(true)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ln> MatchMethods for LayoutNode<'ln> {
|
||||
// The below two functions are copy+paste because I can't figure out how to
|
||||
// write a function which takes a generic function. I don't think it can
|
||||
// be done.
|
||||
|
|
|
@ -165,10 +165,17 @@ impl<'a> PreorderDomTraversal for RecalcStyleForNode<'a> {
|
|||
// Check to see whether we can share a style with someone.
|
||||
let style_sharing_candidate_cache =
|
||||
&mut self.layout_context.style_sharing_candidate_cache();
|
||||
let sharing_result = unsafe {
|
||||
node.share_style_if_possible(style_sharing_candidate_cache,
|
||||
|
||||
let sharing_result = match node.as_element() {
|
||||
Some(element) => {
|
||||
unsafe {
|
||||
element.share_style_if_possible(style_sharing_candidate_cache,
|
||||
parent_opt.clone())
|
||||
}
|
||||
},
|
||||
None => StyleSharingResult::CannotShare(false),
|
||||
};
|
||||
|
||||
// Otherwise, match and cascade selectors.
|
||||
match sharing_result {
|
||||
StyleSharingResult::CannotShare(mut shareable) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue