mirror of
https://github.com/servo/servo.git
synced 2025-06-21 07:38:59 +01:00
Auto merge of #16148 - emilio:cleanup-animation-only-restyle, r=hiikezoe
style: Cleanup a bit the restyle hint propagation code. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16148) <!-- Reviewable:end -->
This commit is contained in:
commit
0ebb9ec9e8
2 changed files with 42 additions and 32 deletions
|
@ -135,13 +135,20 @@ pub struct StoredRestyleHint(RestyleHint);
|
||||||
|
|
||||||
impl StoredRestyleHint {
|
impl StoredRestyleHint {
|
||||||
/// Propagates this restyle hint to a child element.
|
/// Propagates this restyle hint to a child element.
|
||||||
pub fn propagate(&self) -> Self {
|
pub fn propagate(&mut self) -> Self {
|
||||||
// If we have RESTYLE_CSS_ANIMATIONS restyle hint, it means we are in the
|
use std::mem;
|
||||||
// middle of an animation only restyle. In that case, we don't need to
|
|
||||||
// propagate any restyle hints.
|
// If we have RESTYLE_CSS_ANIMATIONS restyle hint, it means we are in
|
||||||
StoredRestyleHint(if self.0.contains(RESTYLE_CSS_ANIMATIONS) {
|
// the middle of an animation only restyle. In that case, we don't need
|
||||||
RestyleHint::empty()
|
// to propagate any restyle hints, and we need to remove ourselves.
|
||||||
} else if self.0.contains(RESTYLE_DESCENDANTS) {
|
if self.0.contains(RESTYLE_CSS_ANIMATIONS) {
|
||||||
|
self.0.remove(RESTYLE_CSS_ANIMATIONS);
|
||||||
|
return Self::empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Else we should clear ourselves, and return the propagated hint.
|
||||||
|
let hint = mem::replace(&mut self.0, RestyleHint::empty());
|
||||||
|
StoredRestyleHint(if hint.contains(RESTYLE_DESCENDANTS) {
|
||||||
RESTYLE_SELF | RESTYLE_DESCENDANTS
|
RESTYLE_SELF | RESTYLE_DESCENDANTS
|
||||||
} else {
|
} else {
|
||||||
RestyleHint::empty()
|
RestyleHint::empty()
|
||||||
|
@ -180,11 +187,6 @@ impl StoredRestyleHint {
|
||||||
self.0 |= other.0
|
self.0 |= other.0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove animation restyle hint.
|
|
||||||
pub fn remove_animation_hint(&mut self) {
|
|
||||||
self.0.remove(RESTYLE_CSS_ANIMATIONS)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if the hint has animation-only restyle.
|
/// Returns true if the hint has animation-only restyle.
|
||||||
pub fn has_animation_hint(&self) -> bool {
|
pub fn has_animation_hint(&self) -> bool {
|
||||||
self.0.contains(RESTYLE_CSS_ANIMATIONS)
|
self.0.contains(RESTYLE_CSS_ANIMATIONS)
|
||||||
|
|
|
@ -15,7 +15,6 @@ use restyle_hints::{RESTYLE_DESCENDANTS, RESTYLE_SELF};
|
||||||
use selector_parser::RestyleDamage;
|
use selector_parser::RestyleDamage;
|
||||||
use servo_config::opts;
|
use servo_config::opts;
|
||||||
use std::borrow::BorrowMut;
|
use std::borrow::BorrowMut;
|
||||||
use std::mem;
|
|
||||||
use stylist::Stylist;
|
use stylist::Stylist;
|
||||||
|
|
||||||
/// A per-traversal-level chunk of data. This is sent down by the traversal, and
|
/// A per-traversal-level chunk of data. This is sent down by the traversal, and
|
||||||
|
@ -484,37 +483,46 @@ pub fn recalc_style_at<E, D>(traversal: &D,
|
||||||
|
|
||||||
// Now that matching and cascading is done, clear the bits corresponding to
|
// Now that matching and cascading is done, clear the bits corresponding to
|
||||||
// those operations and compute the propagated restyle hint.
|
// those operations and compute the propagated restyle hint.
|
||||||
let empty_hint = StoredRestyleHint::empty();
|
|
||||||
let propagated_hint = match data.get_restyle_mut() {
|
let propagated_hint = match data.get_restyle_mut() {
|
||||||
None => empty_hint,
|
None => StoredRestyleHint::empty(),
|
||||||
Some(r) => {
|
Some(r) => {
|
||||||
|
debug_assert!(context.shared.animation_only_restyle ||
|
||||||
|
!r.hint.has_animation_hint(),
|
||||||
|
"animation restyle hint should be handled during \
|
||||||
|
animation-only restyles");
|
||||||
r.recascade = false;
|
r.recascade = false;
|
||||||
if r.hint.has_animation_hint() {
|
r.hint.propagate()
|
||||||
debug_assert!(context.shared.animation_only_restyle,
|
|
||||||
"animation restyle hint should be handled during animation-only restyles");
|
|
||||||
// Drop animation restyle hint.
|
|
||||||
let propagated_hint = r.hint.propagate();
|
|
||||||
r.hint.remove_animation_hint();
|
|
||||||
propagated_hint
|
|
||||||
} else {
|
|
||||||
mem::replace(&mut r.hint, empty_hint).propagate()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
debug_assert!(data.has_current_styles() || context.shared.animation_only_restyle,
|
debug_assert!(data.has_current_styles() || context.shared.animation_only_restyle,
|
||||||
"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={:?}", propagated_hint, inherited_style_changed);
|
trace!("propagated_hint={:?}, inherited_style_changed={:?}",
|
||||||
|
propagated_hint, inherited_style_changed);
|
||||||
|
|
||||||
|
let has_dirty_descendants_for_this_restyle =
|
||||||
|
if context.shared.animation_only_restyle {
|
||||||
|
element.has_animation_only_dirty_descendants()
|
||||||
|
} else {
|
||||||
|
element.has_dirty_descendants()
|
||||||
|
};
|
||||||
|
|
||||||
// Preprocess children, propagating restyle hints and handling sibling relationships.
|
// Preprocess children, propagating restyle hints and handling sibling relationships.
|
||||||
if traversal.should_traverse_children(&mut context.thread_local, element, &data, DontLog) &&
|
if traversal.should_traverse_children(&mut context.thread_local,
|
||||||
((!context.shared.animation_only_restyle && element.has_dirty_descendants()) ||
|
element,
|
||||||
(context.shared.animation_only_restyle && element.has_animation_only_dirty_descendants()) ||
|
&data,
|
||||||
!propagated_hint.is_empty() ||
|
DontLog) &&
|
||||||
inherited_style_changed) {
|
(has_dirty_descendants_for_this_restyle ||
|
||||||
|
!propagated_hint.is_empty() ||
|
||||||
|
inherited_style_changed) {
|
||||||
let damage_handled = data.get_restyle().map_or(RestyleDamage::empty(), |r| {
|
let damage_handled = data.get_restyle().map_or(RestyleDamage::empty(), |r| {
|
||||||
r.damage_handled() | r.damage.handled_for_descendants()
|
r.damage_handled() | r.damage.handled_for_descendants()
|
||||||
});
|
});
|
||||||
preprocess_children(traversal, element, propagated_hint, damage_handled, inherited_style_changed);
|
|
||||||
|
preprocess_children(traversal,
|
||||||
|
element,
|
||||||
|
propagated_hint,
|
||||||
|
damage_handled,
|
||||||
|
inherited_style_changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.shared.animation_only_restyle {
|
if context.shared.animation_only_restyle {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue