style: Return early instead of indenting in animation code.

And also leave some WTF comments, because they make no sense so far.
This commit is contained in:
Emilio Cobos Álvarez 2018-02-24 22:28:02 +01:00
parent e77dd773d8
commit e5bd8fc5d8
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 47 additions and 32 deletions

View file

@ -606,7 +606,6 @@ pub fn update_style_for_animation_frame(mut new_style: &mut Arc<ComputedValues>,
true true
} }
/// Updates a single animation and associated style based on the current time. /// Updates a single animation and associated style based on the current time.
/// If `damage` is provided, inserts the appropriate restyle damage.
pub fn update_style_for_animation<E>( pub fn update_style_for_animation<E>(
context: &SharedStyleContext, context: &SharedStyleContext,
animation: &Animation, animation: &Animation,
@ -796,8 +795,11 @@ where
/// Update the style in the node when it finishes. /// Update the style in the node when it finishes.
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
pub fn complete_expired_transitions(node: OpaqueNode, style: &mut Arc<ComputedValues>, pub fn complete_expired_transitions(
context: &SharedStyleContext) -> bool { node: OpaqueNode,
style: &mut Arc<ComputedValues>,
context: &SharedStyleContext,
) -> bool {
let had_animations_to_expire; let had_animations_to_expire;
{ {
let all_expired_animations = context.expired_animations.read(); let all_expired_animations = context.expired_animations.read();

View file

@ -334,8 +334,10 @@ trait PrivateMatchMethods: TElement {
let after_change_style_ref = let after_change_style_ref =
after_change_style.as_ref().unwrap_or(&new_values); after_change_style.as_ref().unwrap_or(&new_values);
self.needs_transitions_update(old_values.as_ref().unwrap(), self.needs_transitions_update(
after_change_style_ref) old_values.as_ref().unwrap(),
after_change_style_ref,
)
}; };
if needs_transitions_update { if needs_transitions_update {
@ -344,7 +346,8 @@ trait PrivateMatchMethods: TElement {
} }
tasks.insert(UpdateAnimationsTasks::CSS_TRANSITIONS); tasks.insert(UpdateAnimationsTasks::CSS_TRANSITIONS);
// We need to clone old_values into SequentialTask, so we can use it later. // We need to clone old_values into SequentialTask, so we can
// use it later.
old_values.clone() old_values.clone()
} else { } else {
None None
@ -531,6 +534,12 @@ trait PrivateMatchMethods: TElement {
ChildCascadeRequirement::MustCascadeChildrenIfInheritResetStyle ChildCascadeRequirement::MustCascadeChildrenIfInheritResetStyle
} }
// FIXME(emilio): It's not clear to me that the name of this method
// represents anything of what it does.
//
// Also, this function gets the old style, for some reason I don't really
// get, but the functions called (mainly update_style_for_animation) expects
// the new style, wtf?
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
fn update_animations_for_cascade( fn update_animations_for_cascade(
&self, &self,
@ -546,34 +555,38 @@ trait PrivateMatchMethods: TElement {
let this_opaque = self.as_node().opaque(); let this_opaque = self.as_node().opaque();
animation::complete_expired_transitions(this_opaque, style, context); animation::complete_expired_transitions(this_opaque, style, context);
// Merge any running transitions into the current style, and cancel them. // Merge any running animations into the current style, and cancel them.
let had_running_animations = let had_running_animations =
context.running_animations.read().get(&this_opaque).is_some(); context.running_animations.read().get(&this_opaque).is_some();
if had_running_animations { if !had_running_animations {
let mut all_running_animations = context.running_animations.write(); return;
for running_animation in all_running_animations.get_mut(&this_opaque).unwrap() { }
// This shouldn't happen frequently, but under some
// circumstances mainly huge load or debug builds, the let mut all_running_animations = context.running_animations.write();
// constellation might be delayed in sending the for running_animation in all_running_animations.get_mut(&this_opaque).unwrap() {
// `TickAllAnimations` message to layout. // This shouldn't happen frequently, but under some circumstances
// // mainly huge load or debug builds, the constellation might be
// Thus, we can't assume all the animations have been already // delayed in sending the `TickAllAnimations` message to layout.
// updated by layout, because other restyle due to script might //
// be triggered by layout before the animation tick. // Thus, we can't assume all the animations have been already
// // updated by layout, because other restyle due to script might be
// See #12171 and the associated PR for an example where this // triggered by layout before the animation tick.
// happened while debugging other release panic. //
if !running_animation.is_expired() { // See #12171 and the associated PR for an example where this
animation::update_style_for_animation::<Self>( // happened while debugging other release panic.
context, if running_animation.is_expired() {
running_animation, continue;
style, }
font_metrics,
); animation::update_style_for_animation::<Self>(
if let Animation::Transition(_, _, ref frame, _) = *running_animation { context,
possibly_expired_animations.push(frame.property_animation.clone()) running_animation,
} style,
} font_metrics,
);
if let Animation::Transition(_, _, ref frame, _) = *running_animation {
possibly_expired_animations.push(frame.property_animation.clone())
} }
} }
} }