diff --git a/servo/components/style/animation.rs b/servo/components/style/animation.rs index 302dc021f712..8fe9ae3d1995 100644 --- a/servo/components/style/animation.rs +++ b/servo/components/style/animation.rs @@ -173,6 +173,17 @@ impl KeyframesAnimationState { self.current_direction = old_direction; self.started_at = new_started_at; } + + /// Calculate the active-duration of this animation according to + /// https://drafts.csswg.org/css-animations/#active-duration. active-duration + /// is not really meaningful for infinite animations so we just return 0 + /// here in that case. + pub fn active_duration(&self) -> f64 { + match self.iteration_state { + KeyframesIterationState::Finite(_, max) => self.duration * (max as f64), + KeyframesIterationState::Infinite => 0., + } + } } impl fmt::Debug for KeyframesAnimationState {