layout: Actually calculate restyle damage while styling.

...oops. Looks like I forgot to do this.

r? @pcwalton
This commit is contained in:
Clark Gaebel 2014-10-28 11:42:48 -07:00
parent b8de54bc63
commit 314a0d671e

View file

@ -5,8 +5,10 @@
//! High-level interface to CSS selector matching. //! High-level interface to CSS selector matching.
use css::node_style::StyledNode; use css::node_style::StyledNode;
use incremental;
use incremental::RestyleDamage;
use util::{LayoutDataAccess, LayoutDataWrapper}; use util::{LayoutDataAccess, LayoutDataWrapper};
use wrapper::{LayoutElement, LayoutNode}; use wrapper::{LayoutElement, LayoutNode, ThreadSafeLayoutNode};
use wrapper::{TLayoutNode}; use wrapper::{TLayoutNode};
use script::dom::node::{TextNodeTypeId}; use script::dom::node::{TextNodeTypeId};
@ -312,7 +314,7 @@ trait PrivateMatchMethods {
style: &mut Option<Arc<ComputedValues>>, style: &mut Option<Arc<ComputedValues>>,
applicable_declarations_cache: &mut applicable_declarations_cache: &mut
ApplicableDeclarationsCache, ApplicableDeclarationsCache,
shareable: bool); shareable: bool) -> RestyleDamage;
fn share_style_with_candidate_if_possible(&self, fn share_style_with_candidate_if_possible(&self,
parent_node: Option<LayoutNode>, parent_node: Option<LayoutNode>,
@ -327,7 +329,7 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
style: &mut Option<Arc<ComputedValues>>, style: &mut Option<Arc<ComputedValues>>,
applicable_declarations_cache: &mut applicable_declarations_cache: &mut
ApplicableDeclarationsCache, ApplicableDeclarationsCache,
shareable: bool) { shareable: bool) -> RestyleDamage {
let this_style; let this_style;
let cacheable; let cacheable;
match parent_style { match parent_style {
@ -359,7 +361,9 @@ impl<'ln> PrivateMatchMethods for LayoutNode<'ln> {
applicable_declarations_cache.insert(applicable_declarations, this_style.clone()); applicable_declarations_cache.insert(applicable_declarations, this_style.clone());
} }
let ret = incremental::compute_damage(&*style, this_style.deref());
*style = Some(this_style); *style = Some(this_style);
ret
} }
@ -451,8 +455,10 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
Some(shared_style) => { Some(shared_style) => {
// Yay, cache hit. Share the style. // Yay, cache hit. Share the style.
let mut layout_data_ref = self.mutate_layout_data(); let mut layout_data_ref = self.mutate_layout_data();
let shared_data = &mut layout_data_ref.as_mut().unwrap().shared_data; let layout_data = layout_data_ref.as_mut().unwrap();
let style = &mut shared_data.style; let style = &mut layout_data.shared_data.style;
layout_data.data.restyle_damage.insert(
incremental::compute_damage(&*style, &*shared_style));
*style = Some(shared_style); *style = Some(shared_style);
return StyleWasShared(i) return StyleWasShared(i)
} }
@ -508,6 +514,8 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
parent: Option<LayoutNode>, parent: Option<LayoutNode>,
applicable_declarations: &ApplicableDeclarations, applicable_declarations: &ApplicableDeclarations,
applicable_declarations_cache: &mut ApplicableDeclarationsCache) { applicable_declarations_cache: &mut ApplicableDeclarationsCache) {
let mut restyle_damage = ThreadSafeLayoutNode::new(self).restyle_damage();
// Get our parent's style. This must be unsafe so that we don't touch the parent's // Get our parent's style. This must be unsafe so that we don't touch the parent's
// borrow flags. // borrow flags.
// //
@ -516,58 +524,58 @@ impl<'ln> MatchMethods for LayoutNode<'ln> {
let parent_style = match parent { let parent_style = match parent {
None => None, None => None,
Some(parent_node) => { Some(parent_node) => {
let parent_layout_data = parent_node.borrow_layout_data_unchecked(); let parent_layout_data_ref = parent_node.borrow_layout_data_unchecked();
match *parent_layout_data { let parent_layout_data = (&*parent_layout_data_ref).as_ref().expect("no parent data!?");
None => fail!("no parent data?!"), let parent_style = parent_layout_data.shared_data.style.as_ref().expect("parent hasn't been styled yet!");
Some(ref parent_layout_data) => { Some(parent_style)
match parent_layout_data.shared_data.style {
None => fail!("parent hasn't been styled yet?!"),
Some(ref style) => Some(style),
}
}
}
} }
}; };
let mut layout_data_ref = self.mutate_layout_data();
match &mut *layout_data_ref { {
&None => fail!("no layout data"), let mut layout_data_ref = self.mutate_layout_data();
&Some(ref mut layout_data) => { let layout_data = layout_data_ref.as_mut().expect("no layout_data");
match self.type_id() { match self.type_id() {
Some(TextNodeTypeId) => { Some(TextNodeTypeId) => {
// Text nodes get a copy of the parent style. This ensures // Text nodes get a copy of the parent style. This ensures
// that during fragment construction any non-inherited // that during fragment construction any non-inherited
// CSS properties (such as vertical-align) are correctly // CSS properties (such as vertical-align) are correctly
// set on the fragment(s). // set on the fragment(s).
let cloned_parent_style = parent_style.unwrap().clone(); let cloned_parent_style = parent_style.unwrap().clone();
layout_data.shared_data.style = Some(cloned_parent_style); restyle_damage.insert(
} incremental::compute_damage(&layout_data.shared_data.style, &*cloned_parent_style));
_ => { layout_data.shared_data.style = Some(cloned_parent_style);
}
_ => {
restyle_damage.insert(
self.cascade_node_pseudo_element( self.cascade_node_pseudo_element(
parent_style, parent_style,
applicable_declarations.normal.as_slice(), applicable_declarations.normal.as_slice(),
&mut layout_data.shared_data.style, &mut layout_data.shared_data.style,
applicable_declarations_cache, applicable_declarations_cache,
applicable_declarations.normal_shareable); applicable_declarations.normal_shareable));
if applicable_declarations.before.len() > 0 { if applicable_declarations.before.len() > 0 {
self.cascade_node_pseudo_element( restyle_damage.insert(
Some(layout_data.shared_data.style.as_ref().unwrap()), self.cascade_node_pseudo_element(
applicable_declarations.before.as_slice(), Some(layout_data.shared_data.style.as_ref().unwrap()),
&mut layout_data.data.before_style, applicable_declarations.before.as_slice(),
applicable_declarations_cache, &mut layout_data.data.before_style,
false); applicable_declarations_cache,
} false));
if applicable_declarations.after.len() > 0 { }
if applicable_declarations.after.len() > 0 {
restyle_damage.insert(
self.cascade_node_pseudo_element( self.cascade_node_pseudo_element(
Some(layout_data.shared_data.style.as_ref().unwrap()), Some(layout_data.shared_data.style.as_ref().unwrap()),
applicable_declarations.after.as_slice(), applicable_declarations.after.as_slice(),
&mut layout_data.data.after_style, &mut layout_data.data.after_style,
applicable_declarations_cache, applicable_declarations_cache,
false); false));
}
} }
} }
} }
} }
ThreadSafeLayoutNode::new(self).set_restyle_damage(restyle_damage);
} }
} }