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), local_context_creation_data: Mutex::new(thread_local_style_context_creation_data),
timer: self.timer.clone(), timer: self.timer.clone(),
quirks_mode: self.quirks_mode.unwrap(), quirks_mode: self.quirks_mode.unwrap(),
animation_only_restyle: false, traversal_flags: TraversalFlags::empty(),
}, },
image_cache: self.image_cache.clone(), image_cache: self.image_cache.clone(),
font_cache_thread: Mutex::new(self.font_cache_thread.clone()), font_cache_thread: Mutex::new(self.font_cache_thread.clone()),

View file

@ -29,7 +29,7 @@ use stylist::Stylist;
use thread_state; use thread_state;
use time; use time;
use timer::Timer; use timer::Timer;
use traversal::DomTraversal; use traversal::{DomTraversal, TraversalFlags};
/// This structure is used to create a local style context from a shared one. /// This structure is used to create a local style context from a shared one.
pub struct ThreadLocalStyleContextCreationInfo { pub struct ThreadLocalStyleContextCreationInfo {
@ -89,8 +89,8 @@ pub struct SharedStyleContext<'a> {
/// The QuirksMode state which the document needs to be rendered with /// The QuirksMode state which the document needs to be rendered with
pub quirks_mode: QuirksMode, pub quirks_mode: QuirksMode,
/// True if the traversal is processing only animation restyles. /// Flags controlling how we traverse the tree.
pub animation_only_restyle: bool, pub traversal_flags: TraversalFlags,
} }
impl<'a> SharedStyleContext<'a> { 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 // in the name of animation-only traversal. Rest of restyle hints
// will be processed in a subsequent normal traversal. // will be processed in a subsequent normal traversal.
if hint.contains(RESTYLE_CSS_ANIMATIONS) { 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); let animation_rule = self.get_animation_rule(None);
replace_rule_node(CascadeLevel::Animations, replace_rule_node(CascadeLevel::Animations,

View file

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

View file

@ -141,7 +141,7 @@ unsafe fn dummy_url_data() -> &'static RefPtr<URLExtraData> {
fn create_shared_context<'a>(guard: &'a SharedRwLockReadGuard, fn create_shared_context<'a>(guard: &'a SharedRwLockReadGuard,
per_doc_data: &PerDocumentStyleDataImpl, per_doc_data: &PerDocumentStyleDataImpl,
animation_only: bool) -> SharedStyleContext<'a> { traversal_flags: TraversalFlags) -> SharedStyleContext<'a> {
let local_context_data = let local_context_data =
ThreadLocalStyleContextCreationInfo::new(per_doc_data.new_animations_sender.clone()); ThreadLocalStyleContextCreationInfo::new(per_doc_data.new_animations_sender.clone());
@ -156,7 +156,7 @@ fn create_shared_context<'a>(guard: &'a SharedRwLockReadGuard,
timer: Timer::new(), timer: Timer::new(),
// FIXME Find the real QuirksMode information for this document // FIXME Find the real QuirksMode information for this document
quirks_mode: QuirksMode::NoQuirks, quirks_mode: QuirksMode::NoQuirks,
animation_only_restyle: animation_only, traversal_flags: traversal_flags,
} }
} }
@ -183,8 +183,7 @@ fn traverse_subtree(element: GeckoElement, raw_data: RawServoStyleSetBorrowed,
let global_style_data = &*GLOBAL_STYLE_DATA; let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read(); let guard = global_style_data.shared_lock.read();
let shared_style_context = create_shared_context(&guard, &per_doc_data, let shared_style_context = create_shared_context(&guard, &per_doc_data, traversal_flags);
traversal_flags.for_animation_only());
let traversal_driver = if global_style_data.style_thread_pool.is_none() { let traversal_driver = if global_style_data.style_thread_pool.is_none() {
TraversalDriver::Sequential TraversalDriver::Sequential
@ -398,7 +397,7 @@ pub extern "C" fn Servo_StyleSet_GetBaseComputedValuesForElement(raw_data: RawSe
let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow(); let doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow();
let global_style_data = &*GLOBAL_STYLE_DATA; let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read(); let guard = global_style_data.shared_lock.read();
let shared_context = &create_shared_context(&guard, &doc_data, false); let shared_context = &create_shared_context(&guard, &doc_data, TraversalFlags::empty());
let element = GeckoElement(element); let element = GeckoElement(element);
let element_data = element.borrow_data().unwrap(); let element_data = element.borrow_data().unwrap();
@ -1631,7 +1630,7 @@ pub extern "C" fn Servo_ResolveStyleLazily(element: RawGeckoElementBorrowed,
} }
// We don't have the style ready. Go ahead and compute it as necessary. // We don't have the style ready. Go ahead and compute it as necessary.
let shared = create_shared_context(&guard, &mut doc_data.borrow_mut(), false); let shared = create_shared_context(&guard, &mut doc_data.borrow_mut(), TraversalFlags::empty());
let mut tlc = ThreadLocalStyleContext::new(&shared); let mut tlc = ThreadLocalStyleContext::new(&shared);
let mut context = StyleContext { let mut context = StyleContext {
shared: &shared, shared: &shared,