diff --git a/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp b/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp index 0e7a3fea4d8..97e35352a73 100644 --- a/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp +++ b/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp @@ -462,6 +462,31 @@ Optional AnimationEffect::current_iteration() const return floor(overall_progress().value()); } +// https://www.w3.org/TR/web-animations-1/#transformed-progress +Optional AnimationEffect::transformed_progress() const +{ + // 1. If the directed progress is unresolved, return unresolved. + auto directed_progress = this->directed_progress(); + if (!directed_progress.has_value()) + return {}; + + // 2. Calculate the value of the before flag as follows: + + // 1. Determine the current direction using the procedure defined in §4.9.1 Calculating the directed progress. + auto current_direction = this->current_direction(); + + // 2. If the current direction is forwards, let going forwards be true, otherwise it is false. + auto going_forwards = current_direction == AnimationDirection::Forwards; + + // 3. The before flag is set if the animation effect is in the before phase and going forwards is true; or if the animation effect + // is in the after phase and going forwards is false. + auto before_flag = (is_in_the_before_phase() && going_forwards) || (is_in_the_after_phase() && !going_forwards); + + // 3. Return the result of evaluating the animation effect’s timing function passing directed progress as the input progress value and + // before flag as the before flag. + return m_timing_function(directed_progress.value(), before_flag); +} + AnimationEffect::AnimationEffect(JS::Realm& realm) : Bindings::PlatformObject(realm) { diff --git a/Userland/Libraries/LibWeb/Animations/AnimationEffect.h b/Userland/Libraries/LibWeb/Animations/AnimationEffect.h index c583fe70044..ef4aa4dcfa0 100644 --- a/Userland/Libraries/LibWeb/Animations/AnimationEffect.h +++ b/Userland/Libraries/LibWeb/Animations/AnimationEffect.h @@ -125,6 +125,7 @@ public: AnimationDirection current_direction() const; Optional simple_iteration_progress() const; Optional current_iteration() const; + Optional transformed_progress() const; protected: AnimationEffect(JS::Realm&);