diff --git a/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp b/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp index 6214af5476..34224c9924 100644 --- a/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp +++ b/Userland/Libraries/LibWeb/Animations/AnimationEffect.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -181,8 +182,14 @@ WebIDL::ExceptionOr AnimationEffect::update_timing(OptionalEffectTiming ti m_playback_direction = timing.direction.value(); // - easing → timing function - if (timing.easing.has_value()) + if (timing.easing.has_value()) { m_easing_function = timing.easing.value(); + if (auto timing_function = parse_easing_string(realm(), m_easing_function)) { + m_timing_function = TimingFunction::from_easing_style_value(timing_function->as_easing()); + } else { + m_timing_function = Animations::linear_timing_function; + } + } if (auto animation = m_associated_animation) animation->effect_timing_changed({}); @@ -580,6 +587,20 @@ Optional AnimationEffect::transformed_progress() const return m_timing_function(directed_progress.value(), before_flag); } +RefPtr AnimationEffect::parse_easing_string(JS::Realm& realm, StringView value) +{ + auto maybe_parser = CSS::Parser::Parser::create(CSS::Parser::ParsingContext(realm), value); + if (maybe_parser.is_error()) + return {}; + + if (auto style_value = maybe_parser.release_value().parse_as_css_value(CSS::PropertyID::AnimationTimingFunction)) { + if (style_value->is_easing()) + return style_value; + } + + return {}; +} + 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 56204443aa..49f106d2fd 100644 --- a/Userland/Libraries/LibWeb/Animations/AnimationEffect.h +++ b/Userland/Libraries/LibWeb/Animations/AnimationEffect.h @@ -65,6 +65,8 @@ class AnimationEffect : public Bindings::PlatformObject { JS_DECLARE_ALLOCATOR(AnimationEffect); public: + static RefPtr parse_easing_string(JS::Realm& realm, StringView value); + static JS::NonnullGCPtr create(JS::Realm&); EffectTiming get_timing() const; diff --git a/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp b/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp index a503155b0b..0ded127403 100644 --- a/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp +++ b/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp @@ -287,19 +287,6 @@ static WebIDL::ExceptionOr> process_a_keyframes_argument(JS { auto& vm = realm.vm(); - auto parse_easing_string = [&](auto& value) -> RefPtr { - auto maybe_parser = CSS::Parser::Parser::create(CSS::Parser::ParsingContext(realm), value); - if (maybe_parser.is_error()) - return {}; - - if (auto style_value = maybe_parser.release_value().parse_as_css_value(CSS::PropertyID::AnimationTimingFunction)) { - if (style_value->is_easing()) - return style_value; - } - - return {}; - }; - // 1. If object is null, return an empty sequence of keyframes. if (!object) return Vector {}; @@ -525,7 +512,7 @@ static WebIDL::ExceptionOr> process_a_keyframes_argument(JS // // If parsing the "easing" property fails, throw a TypeError and abort this procedure. auto easing_string = keyframe.easing.get(); - auto easing_value = parse_easing_string(easing_string); + auto easing_value = AnimationEffect::parse_easing_string(realm, easing_string); if (!easing_value) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Invalid animation easing value: \"{}\"", easing_string)) }; @@ -537,7 +524,7 @@ static WebIDL::ExceptionOr> process_a_keyframes_argument(JS // interface, and if any of the values fail to parse, throw a TypeError and abort this procedure. for (auto& unused_easing : unused_easings) { auto easing_string = unused_easing.get(); - auto easing_value = parse_easing_string(easing_string); + auto easing_value = AnimationEffect::parse_easing_string(realm, easing_string); if (!easing_value) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Invalid animation easing value: \"{}\"", easing_string)) }; } @@ -729,6 +716,7 @@ WebIDL::ExceptionOr> KeyframeEffect::construct_ // - timing function. effect->m_easing_function = source->m_easing_function; + effect->m_timing_function = source->m_timing_function; return effect; }