From f898b49c8e82b622348da26ee5d58dc8b7632fd1 Mon Sep 17 00:00:00 2001 From: Matthew Olsson Date: Sat, 11 Nov 2023 08:03:31 -0700 Subject: [PATCH] LibWeb: Implement Animation::current_time --- .../Libraries/LibWeb/Animations/Animation.cpp | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/Animations/Animation.cpp b/Userland/Libraries/LibWeb/Animations/Animation.cpp index d608edf8e2..431f9acc3b 100644 --- a/Userland/Libraries/LibWeb/Animations/Animation.cpp +++ b/Userland/Libraries/LibWeb/Animations/Animation.cpp @@ -162,8 +162,28 @@ void Animation::set_start_time(Optional const& new_start_time) // https://www.w3.org/TR/web-animations-1/#animation-current-time Optional Animation::current_time() const { - // FIXME: Implement - return {}; + // The current time is calculated from the first matching condition from below: + + // -> If the animation’s hold time is resolved, + if (m_hold_time.has_value()) { + // The current time is the animation’s hold time. + return m_hold_time.value(); + } + + // -> If any of the following are true: + // - the animation has no associated timeline, or + // - the associated timeline is inactive, or + // - the animation’s start time is unresolved. + if (!m_timeline || m_timeline->is_inactive() || !m_start_time.has_value()) { + // The current time is an unresolved time value. + return {}; + } + + // -> Otherwise, + // current time = (timeline time - start time) × playback rate + // Where timeline time is the current time value of the associated timeline. The playback rate value is defined + // in §4.4.15 Speed control. + return (m_timeline->current_time().value() - m_start_time.value()) * playback_rate(); } // https://www.w3.org/TR/web-animations-1/#animation-set-the-current-time