style: Move TraversalFlags into SharedStyleContext.

This commit is contained in:
Cameron McCormack 2017-04-08 16:36:09 +08:00
parent 5fa9a56247
commit 2bbeb21551
5 changed files with 19 additions and 19 deletions

View file

@ -523,7 +523,7 @@ impl LayoutThread {
local_context_creation_data: Mutex::new(thread_local_style_context_creation_data),
timer: self.timer.clone(),
quirks_mode: self.quirks_mode.unwrap(),
animation_only_restyle: false,
traversal_flags: TraversalFlags::empty(),
},
image_cache: self.image_cache.clone(),
font_cache_thread: Mutex::new(self.font_cache_thread.clone()),

View file

@ -29,7 +29,7 @@ use stylist::Stylist;
use thread_state;
use time;
use timer::Timer;
use traversal::DomTraversal;
use traversal::{DomTraversal, TraversalFlags};
/// This structure is used to create a local style context from a shared one.
pub struct ThreadLocalStyleContextCreationInfo {
@ -89,8 +89,8 @@ pub struct SharedStyleContext<'a> {
/// The QuirksMode state which the document needs to be rendered with
pub quirks_mode: QuirksMode,
/// True if the traversal is processing only animation restyles.
pub animation_only_restyle: bool,
/// Flags controlling how we traverse the tree.
pub traversal_flags: TraversalFlags,
}
impl<'a> SharedStyleContext<'a> {

View file

@ -1038,7 +1038,7 @@ pub trait MatchMethods : TElement {
// in the name of animation-only traversal. Rest of restyle hints
// will be processed in a subsequent normal traversal.
if hint.contains(RESTYLE_CSS_ANIMATIONS) {
debug_assert!(context.shared.animation_only_restyle);
debug_assert!(context.shared.traversal_flags.for_animation_only());
let animation_rule = self.get_animation_rule(None);
replace_rule_node(CascadeLevel::Animations,

View file

@ -175,7 +175,7 @@ pub trait DomTraversal<E: TElement> : Sync {
}
PreTraverseToken {
traverse: Self::node_needs_traversal(root.as_node(), traversal_flags.for_animation_only()),
traverse: Self::node_needs_traversal(root.as_node(), traversal_flags),
unstyled_children_only: false,
}
}
@ -189,7 +189,7 @@ pub trait DomTraversal<E: TElement> : Sync {
}
/// Returns true if traversal is needed for the given node and subtree.
fn node_needs_traversal(node: E::ConcreteNode, animation_only: bool) -> bool {
fn node_needs_traversal(node: E::ConcreteNode, traversal_flags: TraversalFlags) -> bool {
// Non-incremental layout visits every node.
if is_servo_nonincremental_layout() {
return true;
@ -216,7 +216,7 @@ pub trait DomTraversal<E: TElement> : Sync {
// In case of animation-only traversal we need to traverse
// the element if the element has animation only dirty
// descendants bit, animation-only restyle hint or recascade.
if animation_only {
if traversal_flags.for_animation_only() {
if el.has_animation_only_dirty_descendants() {
return true;
}
@ -341,7 +341,7 @@ pub trait DomTraversal<E: TElement> : Sync {
}
for kid in parent.as_node().children() {
if Self::node_needs_traversal(kid, self.shared_context().animation_only_restyle) {
if Self::node_needs_traversal(kid, self.shared_context().traversal_flags) {
let el = kid.as_element();
if el.as_ref().and_then(|el| el.borrow_data())
.map_or(false, |d| d.has_styles())
@ -517,7 +517,7 @@ pub fn recalc_style_at<E, D>(traversal: &D,
let propagated_hint = match data.get_restyle_mut() {
None => StoredRestyleHint::empty(),
Some(r) => {
debug_assert!(context.shared.animation_only_restyle ||
debug_assert!(context.shared.traversal_flags.for_animation_only() ||
!r.hint.has_animation_hint(),
"animation restyle hint should be handled during \
animation-only restyles");
@ -525,13 +525,14 @@ pub fn recalc_style_at<E, D>(traversal: &D,
r.hint.propagate()
},
};
debug_assert!(data.has_current_styles() || context.shared.animation_only_restyle,
debug_assert!(data.has_current_styles() ||
context.shared.traversal_flags.for_animation_only(),
"Should have computed style or haven't yet valid computed style in case of animation-only restyle");
trace!("propagated_hint={:?}, inherited_style_changed={:?}",
propagated_hint, inherited_style_changed);
let has_dirty_descendants_for_this_restyle =
if context.shared.animation_only_restyle {
if context.shared.traversal_flags.for_animation_only() {
element.has_animation_only_dirty_descendants()
} else {
element.has_dirty_descendants()
@ -556,7 +557,7 @@ pub fn recalc_style_at<E, D>(traversal: &D,
inherited_style_changed);
}
if context.shared.animation_only_restyle {
if context.shared.traversal_flags.for_animation_only() {
unsafe { element.unset_animation_only_dirty_descendants(); }
}