aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/css/matching.rs
diff options
context:
space:
mode:
authorMs2ger <Ms2ger@gmail.com>2015-10-15 13:55:02 +0200
committerMs2ger <Ms2ger@gmail.com>2015-10-19 15:01:29 +0200
commitf3faaa6b01dda2b9d134d78e8b6f181fb1535344 (patch)
tree730407a8f8ac320aa54d93f7db425a8c41874b7a /components/layout/css/matching.rs
parente6e514c89ae93d859415aac04f4fa4192878f853 (diff)
downloadservo-f3faaa6b01dda2b9d134d78e8b6f181fb1535344.tar.gz
servo-f3faaa6b01dda2b9d134d78e8b6f181fb1535344.zip
Define share_style_if_possible on LayoutElement.
Diffstat (limited to 'components/layout/css/matching.rs')
-rw-r--r--components/layout/css/matching.rs36
1 files changed, 16 insertions, 20 deletions
diff --git a/components/layout/css/matching.rs b/components/layout/css/matching.rs
index 71aa44147be..281d3e77438 100644
--- a/components/layout/css/matching.rs
+++ b/components/layout/css/matching.rs
@@ -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.