style: Inline RestyleData.

Bug: 1368236
MozReview-Commit-ID: 49s3SO0PMHf
This commit is contained in:
Emilio Cobos Álvarez 2017-06-13 15:04:18 +02:00
parent 0c53ba318a
commit ffc45e9aaa
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
11 changed files with 183 additions and 202 deletions

View file

@ -10,7 +10,6 @@ use data::{ElementData, ElementStyles};
use dom::{DirtyDescendants, NodeInfo, OpaqueNode, TElement, TNode};
use invalidation::element::restyle_hints::{RECASCADE_SELF, RECASCADE_DESCENDANTS, RestyleHint};
use matching::{ChildCascadeRequirement, MatchMethods};
use selector_parser::RestyleDamage;
use sharing::{StyleSharingBehavior, StyleSharingTarget};
#[cfg(feature = "servo")] use servo_config::opts;
use smallvec::SmallVec;
@ -296,10 +295,8 @@ pub trait DomTraversal<E: TElement> : Sync {
if el.is_native_anonymous() {
if let Some(parent) = el.traversal_parent() {
let parent_data = parent.borrow_data().unwrap();
let going_to_reframe = parent_data.get_restyle().map_or(false, |r| {
r.reconstructed_ancestor ||
r.damage.contains(RestyleDamage::reconstruct())
});
let going_to_reframe =
parent_data.restyle.reconstructed_self_or_ancestor();
let mut is_before_or_after_pseudo = false;
if let Some(pseudo) = el.implemented_pseudo_element() {
@ -337,9 +334,8 @@ pub trait DomTraversal<E: TElement> : Sync {
Some(d) => d,
None => return false,
};
return data.get_restyle()
.map_or(false, |r| r.hint.has_animation_hint() ||
r.hint.has_recascade_self());
return data.restyle.hint.has_animation_hint() ||
data.restyle.hint.has_recascade_self();
}
// If the dirty descendants bit is set, we need to traverse no
@ -360,18 +356,15 @@ pub trait DomTraversal<E: TElement> : Sync {
return true;
}
// Check the restyle data.
if let Some(r) = data.get_restyle() {
// If we have a restyle hint or need to recascade, we need to
// visit the element.
//
// Note that this is different than checking has_current_styles(),
// since that can return true even if we have a restyle hint
// indicating that the element's descendants (but not necessarily
// the element) need restyling.
if !r.hint.is_empty() {
return true;
}
// If we have a restyle hint or need to recascade, we need to
// visit the element.
//
// Note that this is different than checking has_current_styles(),
// since that can return true even if we have a restyle hint
// indicating that the element's descendants (but not necessarily
// the element) need restyling.
if !data.restyle.hint.is_empty() {
return true;
}
// Servo uses the post-order traversal for flow construction, so
@ -381,7 +374,7 @@ pub trait DomTraversal<E: TElement> : Sync {
// We also need to traverse nodes with explicit damage and no other
// restyle data, so that this damage can be cleared.
if (cfg!(feature = "servo") || traversal_flags.for_reconstruct()) &&
data.get_restyle().map_or(false, |r| !r.damage.is_empty()) {
!data.restyle.damage.is_empty() {
return true;
}
@ -690,20 +683,17 @@ pub fn recalc_style_at<E, D>(traversal: &D,
// Now that matching and cascading is done, clear the bits corresponding to
// those operations and compute the propagated restyle hint.
let mut propagated_hint = match data.get_restyle_mut() {
None => RestyleHint::empty(),
Some(r) => {
debug_assert!(context.shared.traversal_flags.for_animation_only() ||
!r.hint.has_animation_hint(),
"animation restyle hint should be handled during \
animation-only restyles");
r.hint.propagate(&context.shared.traversal_flags)
},
let mut propagated_hint = {
debug_assert!(context.shared.traversal_flags.for_animation_only() ||
!data.restyle.hint.has_animation_hint(),
"animation restyle hint should be handled during \
animation-only restyles");
data.restyle.hint.propagate(&context.shared.traversal_flags)
};
// FIXME(bholley): Need to handle explicitly-inherited reset properties
// somewhere.
propagated_hint.insert(hint.into());
propagated_hint.insert(hint);
trace!("propagated_hint={:?} \
is_display_none={:?}, implementing_pseudo={:?}",
@ -730,10 +720,9 @@ pub fn recalc_style_at<E, D>(traversal: &D,
DontLog) &&
(has_dirty_descendants_for_this_restyle ||
!propagated_hint.is_empty()) {
let reconstructed_ancestor = data.get_restyle().map_or(false, |r| {
r.reconstructed_ancestor ||
r.damage.contains(RestyleDamage::reconstruct())
});
let reconstructed_ancestor =
data.restyle.reconstructed_self_or_ancestor();
preprocess_children::<E, D>(
context,
element,
@ -746,7 +735,7 @@ pub fn recalc_style_at<E, D>(traversal: &D,
// data here, since we won't need to perform a post-traversal to pick up
// any change hints.
if context.shared.traversal_flags.for_reconstruct() {
data.clear_restyle();
data.clear_restyle_state();
}
if context.shared.traversal_flags.for_animation_only() {
@ -792,6 +781,10 @@ fn compute_style<E, D>(_traversal: &D,
debug!("compute_style: {:?} (kind={:?})", element, kind);
if data.has_styles() {
data.restyle.set_restyled();
}
match kind {
MatchAndCascade => {
debug_assert!(!context.shared.traversal_flags.for_animation_only(),
@ -870,31 +863,24 @@ where
continue;
}
// Handle element snapshots and invalidation of descendants and siblings
// as needed.
//
// NB: This will be a no-op if there's no restyle data and no snapshot.
child_data.invalidate_style_if_needed(child, &context.shared);
trace!(" > {:?} -> {:?} + {:?}, pseudo: {:?}",
child,
child_data.get_restyle().map(|r| &r.hint),
child_data.restyle.hint,
propagated_hint,
child.implemented_pseudo_element());
// If the child doesn't have pre-existing RestyleData and we don't have
// any reason to create one, avoid the useless allocation and move on to
// the next child.
if !reconstructed_ancestor && propagated_hint.is_empty() && !child_data.has_restyle() {
continue;
}
let mut restyle_data = child_data.ensure_restyle();
// Propagate the parent restyle hint, that may make us restyle the whole
// subtree.
restyle_data.reconstructed_ancestor = reconstructed_ancestor;
restyle_data.hint.insert(propagated_hint);
if reconstructed_ancestor {
child_data.restyle.set_reconstructed_ancestor();
}
child_data.restyle.hint.insert(propagated_hint);
// Handle element snapshots and invalidation of descendants and siblings
// as needed.
//
// NB: This will be a no-op if there's no snapshot.
child_data.invalidate_style_if_needed(child, &context.shared);
}
}