mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Cleanup some of the animation starting code.
This commit is contained in:
parent
5327758b9b
commit
d44bd82703
1 changed files with 59 additions and 56 deletions
|
@ -544,10 +544,9 @@ where
|
||||||
|
|
||||||
let box_style = new_style.get_box();
|
let box_style = new_style.get_box();
|
||||||
for (i, name) in box_style.animation_name_iter().enumerate() {
|
for (i, name) in box_style.animation_name_iter().enumerate() {
|
||||||
let name = if let Some(atom) = name.as_atom() {
|
let name = match name.as_atom() {
|
||||||
atom
|
Some(atom) => atom,
|
||||||
} else {
|
None => continue,
|
||||||
continue;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!("maybe_start_animations: name={}", name);
|
debug!("maybe_start_animations: name={}", name);
|
||||||
|
@ -556,61 +555,65 @@ where
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(anim) = context.stylist.get_animation(name, element) {
|
let anim = match context.stylist.get_animation(name, element) {
|
||||||
debug!("maybe_start_animations: animation {} found", name);
|
Some(animation) => animation,
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
|
||||||
// If this animation doesn't have any keyframe, we can just continue
|
debug!("maybe_start_animations: animation {} found", name);
|
||||||
// without submitting it to the compositor, since both the first and
|
|
||||||
// the second keyframes would be synthetised from the computed
|
|
||||||
// values.
|
|
||||||
if anim.steps.is_empty() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let delay = box_style.animation_delay_mod(i).seconds();
|
// If this animation doesn't have any keyframe, we can just continue
|
||||||
let now = context.timer.seconds();
|
// without submitting it to the compositor, since both the first and
|
||||||
let animation_start = now + delay as f64;
|
// the second keyframes would be synthetised from the computed
|
||||||
let duration = box_style.animation_duration_mod(i).seconds();
|
// values.
|
||||||
let iteration_state = match box_style.animation_iteration_count_mod(i) {
|
if anim.steps.is_empty() {
|
||||||
AnimationIterationCount::Infinite => KeyframesIterationState::Infinite,
|
continue;
|
||||||
AnimationIterationCount::Number(n) => KeyframesIterationState::Finite(0.0, n),
|
|
||||||
};
|
|
||||||
|
|
||||||
let animation_direction = box_style.animation_direction_mod(i);
|
|
||||||
|
|
||||||
let initial_direction = match animation_direction {
|
|
||||||
AnimationDirection::Normal | AnimationDirection::Alternate => {
|
|
||||||
AnimationDirection::Normal
|
|
||||||
},
|
|
||||||
AnimationDirection::Reverse | AnimationDirection::AlternateReverse => {
|
|
||||||
AnimationDirection::Reverse
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
let running_state = match box_style.animation_play_state_mod(i) {
|
|
||||||
AnimationPlayState::Paused => KeyframesRunningState::Paused(0.),
|
|
||||||
AnimationPlayState::Running => KeyframesRunningState::Running,
|
|
||||||
};
|
|
||||||
|
|
||||||
new_animations_sender
|
|
||||||
.send(Animation::Keyframes(
|
|
||||||
node,
|
|
||||||
anim.clone(),
|
|
||||||
name.clone(),
|
|
||||||
KeyframesAnimationState {
|
|
||||||
started_at: animation_start,
|
|
||||||
duration: duration as f64,
|
|
||||||
delay: delay as f64,
|
|
||||||
iteration_state: iteration_state,
|
|
||||||
running_state: running_state,
|
|
||||||
direction: animation_direction,
|
|
||||||
current_direction: initial_direction,
|
|
||||||
expired: false,
|
|
||||||
cascade_style: new_style.clone(),
|
|
||||||
},
|
|
||||||
)).unwrap();
|
|
||||||
had_animations = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let delay = box_style.animation_delay_mod(i).seconds();
|
||||||
|
let now = context.timer.seconds();
|
||||||
|
let animation_start = now + delay as f64;
|
||||||
|
let duration = box_style.animation_duration_mod(i).seconds();
|
||||||
|
let iteration_state = match box_style.animation_iteration_count_mod(i) {
|
||||||
|
AnimationIterationCount::Infinite => KeyframesIterationState::Infinite,
|
||||||
|
AnimationIterationCount::Number(n) => KeyframesIterationState::Finite(0.0, n),
|
||||||
|
};
|
||||||
|
|
||||||
|
let animation_direction = box_style.animation_direction_mod(i);
|
||||||
|
|
||||||
|
let initial_direction = match animation_direction {
|
||||||
|
AnimationDirection::Normal | AnimationDirection::Alternate => {
|
||||||
|
AnimationDirection::Normal
|
||||||
|
},
|
||||||
|
AnimationDirection::Reverse | AnimationDirection::AlternateReverse => {
|
||||||
|
AnimationDirection::Reverse
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let running_state = match box_style.animation_play_state_mod(i) {
|
||||||
|
AnimationPlayState::Paused => KeyframesRunningState::Paused(0.),
|
||||||
|
AnimationPlayState::Running => KeyframesRunningState::Running,
|
||||||
|
};
|
||||||
|
|
||||||
|
new_animations_sender
|
||||||
|
.send(Animation::Keyframes(
|
||||||
|
node,
|
||||||
|
anim.clone(),
|
||||||
|
name.clone(),
|
||||||
|
KeyframesAnimationState {
|
||||||
|
started_at: animation_start,
|
||||||
|
duration: duration as f64,
|
||||||
|
delay: delay as f64,
|
||||||
|
iteration_state,
|
||||||
|
running_state,
|
||||||
|
direction: animation_direction,
|
||||||
|
current_direction: initial_direction,
|
||||||
|
expired: false,
|
||||||
|
cascade_style: new_style.clone(),
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
|
had_animations = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
had_animations
|
had_animations
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue