mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Add has_current_styles_for_traversal().
In animation-only restyle, we just need to check the element has animation restyle hints or has recascade self which is a result of animation-only restyle for ancestors. has_current_styles() in Servo_ResolveStyle() is intentionally left there, it will be changed in a subsequent patch.
This commit is contained in:
parent
ae55e51aaf
commit
f91126ba86
4 changed files with 37 additions and 7 deletions
|
@ -33,6 +33,7 @@ use std::ops::Deref;
|
||||||
use stylearc::{Arc, ArcBorrow};
|
use stylearc::{Arc, ArcBorrow};
|
||||||
use stylist::Stylist;
|
use stylist::Stylist;
|
||||||
use thread_state;
|
use thread_state;
|
||||||
|
use traversal::TraversalFlags;
|
||||||
|
|
||||||
pub use style_traits::UnsafeNode;
|
pub use style_traits::UnsafeNode;
|
||||||
|
|
||||||
|
@ -478,6 +479,29 @@ pub trait TElement : Eq + PartialEq + Debug + Hash + Sized + Copy + Clone +
|
||||||
data.has_styles() && !data.has_invalidations()
|
data.has_styles() && !data.has_invalidations()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns whether the element's styles are up-to-date for |traversal_flags|.
|
||||||
|
fn has_current_styles_for_traversal(&self,
|
||||||
|
data: &ElementData,
|
||||||
|
traversal_flags: TraversalFlags) -> bool {
|
||||||
|
if traversal_flags.for_animation_only() {
|
||||||
|
// In animation-only restyle we never touch snapshots and don't
|
||||||
|
// care about them. But we can't assert '!self.handled_snapshot()'
|
||||||
|
// here since there are some cases that a second animation-only
|
||||||
|
// restyle which is a result of normal restyle (e.g. setting
|
||||||
|
// animation-name in normal restyle and creating a new CSS
|
||||||
|
// animation in a SequentialTask) is processed after the normal
|
||||||
|
// traversal in that we had elements that handled snapshot.
|
||||||
|
return data.has_styles() &&
|
||||||
|
!data.restyle.hint.has_animation_hint_or_recascade();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.has_snapshot() && !self.handled_snapshot() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.has_styles() && !data.has_invalidations()
|
||||||
|
}
|
||||||
|
|
||||||
/// Flags an element and its ancestors with a given `DescendantsBit`.
|
/// Flags an element and its ancestors with a given `DescendantsBit`.
|
||||||
///
|
///
|
||||||
/// TODO(emilio): We call this conservatively from restyle_element_internal
|
/// TODO(emilio): We call this conservatively from restyle_element_internal
|
||||||
|
|
|
@ -131,6 +131,13 @@ impl RestyleHint {
|
||||||
self.intersects(Self::for_animations())
|
self.intersects(Self::for_animations())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns whether the hint specifies that an animation cascade level must
|
||||||
|
/// be replaced.
|
||||||
|
#[inline]
|
||||||
|
pub fn has_animation_hint_or_recascade(&self) -> bool {
|
||||||
|
self.intersects(Self::for_animations() | RECASCADE_SELF)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns whether the hint specifies some restyle work other than an
|
/// Returns whether the hint specifies some restyle work other than an
|
||||||
/// animation cascade level replacement.
|
/// animation cascade level replacement.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -675,7 +675,7 @@ impl<E: TElement> StyleSharingCandidateCache<E> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = candidate.element.borrow_data().unwrap();
|
let data = candidate.element.borrow_data().unwrap();
|
||||||
debug_assert!(target.has_current_styles(&data));
|
debug_assert!(target.has_current_styles_for_traversal(&data, shared.traversal_flags));
|
||||||
|
|
||||||
debug!("Sharing style between {:?} and {:?}",
|
debug!("Sharing style between {:?} and {:?}",
|
||||||
target.element, candidate.element);
|
target.element, candidate.element);
|
||||||
|
|
|
@ -328,8 +328,7 @@ pub trait DomTraversal<E: TElement> : Sync {
|
||||||
// animation-only restyle hint or recascade.
|
// animation-only restyle hint or recascade.
|
||||||
if traversal_flags.for_animation_only() {
|
if traversal_flags.for_animation_only() {
|
||||||
return el.has_animation_only_dirty_descendants() ||
|
return el.has_animation_only_dirty_descendants() ||
|
||||||
data.restyle.hint.has_animation_hint() ||
|
data.restyle.hint.has_animation_hint_or_recascade();
|
||||||
data.restyle.hint.has_recascade_self();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the dirty descendants bit is set, we need to traverse no matter
|
// If the dirty descendants bit is set, we need to traverse no matter
|
||||||
|
@ -341,7 +340,7 @@ pub trait DomTraversal<E: TElement> : Sync {
|
||||||
// If we have a restyle hint or need to recascade, we need to visit the
|
// If we have a restyle hint or need to recascade, we need to visit the
|
||||||
// element.
|
// element.
|
||||||
//
|
//
|
||||||
// Note that this is different than checking has_current_styles(),
|
// Note that this is different than checking has_current_styles_for_traversal(),
|
||||||
// since that can return true even if we have a restyle hint indicating
|
// since that can return true even if we have a restyle hint indicating
|
||||||
// that the element's descendants (but not necessarily the element) need
|
// that the element's descendants (but not necessarily the element) need
|
||||||
// restyling.
|
// restyling.
|
||||||
|
@ -527,7 +526,8 @@ where
|
||||||
debug_assert!(!element.has_snapshot() || element.handled_snapshot(),
|
debug_assert!(!element.has_snapshot() || element.handled_snapshot(),
|
||||||
"Should've handled snapshots here already");
|
"Should've handled snapshots here already");
|
||||||
|
|
||||||
let compute_self = !element.has_current_styles(data);
|
let compute_self =
|
||||||
|
!element.has_current_styles_for_traversal(data, context.shared.traversal_flags);
|
||||||
let mut hint = RestyleHint::empty();
|
let mut hint = RestyleHint::empty();
|
||||||
|
|
||||||
debug!("recalc_style_at: {:?} (compute_self={:?}, \
|
debug!("recalc_style_at: {:?} (compute_self={:?}, \
|
||||||
|
@ -580,8 +580,7 @@ where
|
||||||
propagated_hint,
|
propagated_hint,
|
||||||
data.styles.is_display_none(),
|
data.styles.is_display_none(),
|
||||||
element.implemented_pseudo_element());
|
element.implemented_pseudo_element());
|
||||||
debug_assert!(element.has_current_styles(data) ||
|
debug_assert!(element.has_current_styles_for_traversal(data, context.shared.traversal_flags),
|
||||||
context.shared.traversal_flags.for_animation_only(),
|
|
||||||
"Should have computed style or haven't yet valid computed \
|
"Should have computed style or haven't yet valid computed \
|
||||||
style in case of animation-only restyle");
|
style in case of animation-only restyle");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue