2023-11-04 12:20:39 -07:00
|
|
|
/*
|
2026-02-16 14:23:14 +00:00
|
|
|
* Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org>
|
|
|
|
|
* Copyright (c) 2026, Sam Atkins <sam@ladybird.org>
|
2023-11-04 12:20:39 -07:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibWeb/Animations/AnimationPlaybackEvent.h>
|
2024-04-27 12:09:58 +12:00
|
|
|
#include <LibWeb/Bindings/AnimationPlaybackEventPrototype.h>
|
2023-11-04 12:20:39 -07:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2026-02-16 14:23:14 +00:00
|
|
|
#include <LibWeb/CSS/CSSNumericValue.h>
|
2023-11-04 12:20:39 -07:00
|
|
|
|
|
|
|
|
namespace Web::Animations {
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DEFINE_ALLOCATOR(AnimationPlaybackEvent);
|
2023-11-19 19:47:52 +01:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<AnimationPlaybackEvent> AnimationPlaybackEvent::create(JS::Realm& realm, FlyString const& type, AnimationPlaybackEventInit const& event_init)
|
2023-11-04 12:20:39 -07:00
|
|
|
{
|
2024-11-14 05:50:17 +13:00
|
|
|
return realm.create<AnimationPlaybackEvent>(realm, type, event_init);
|
2023-11-04 12:20:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://www.w3.org/TR/web-animations-1/#dom-animationplaybackevent-animationplaybackevent
|
2024-11-15 04:01:23 +13:00
|
|
|
WebIDL::ExceptionOr<GC::Ref<AnimationPlaybackEvent>> AnimationPlaybackEvent::construct_impl(JS::Realm& realm, FlyString const& type, AnimationPlaybackEventInit const& event_init)
|
2023-11-04 12:20:39 -07:00
|
|
|
{
|
2024-02-03 18:23:14 -07:00
|
|
|
return create(realm, type, event_init);
|
2023-11-04 12:20:39 -07:00
|
|
|
}
|
|
|
|
|
|
2026-02-17 14:57:03 +00:00
|
|
|
AnimationPlaybackEvent::CSSNumberishInternal AnimationPlaybackEvent::to_numberish_internal(NullableCSSNumberish const& numberish_root)
|
2026-02-16 14:23:14 +00:00
|
|
|
{
|
2026-02-17 14:57:03 +00:00
|
|
|
return numberish_root.visit(
|
|
|
|
|
[](Empty) -> CSSNumberishInternal { return Empty {}; },
|
2026-02-16 14:23:14 +00:00
|
|
|
[](GC::Root<CSS::CSSNumericValue> const& root) -> CSSNumberishInternal { return GC::Ref { *root }; },
|
|
|
|
|
[](auto const& other) -> CSSNumberishInternal { return other; });
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-03 18:23:14 -07:00
|
|
|
AnimationPlaybackEvent::AnimationPlaybackEvent(JS::Realm& realm, FlyString const& type, AnimationPlaybackEventInit const& event_init)
|
|
|
|
|
: DOM::Event(realm, type, event_init)
|
2026-02-16 14:23:14 +00:00
|
|
|
, m_current_time(to_numberish_internal(event_init.current_time))
|
|
|
|
|
, m_timeline_time(to_numberish_internal(event_init.timeline_time))
|
2023-11-04 12:20:39 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AnimationPlaybackEvent::initialize(JS::Realm& realm)
|
|
|
|
|
{
|
2024-03-16 13:13:08 +01:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(AnimationPlaybackEvent);
|
2025-04-20 16:22:57 +02:00
|
|
|
Base::initialize(realm);
|
2023-11-04 12:20:39 -07:00
|
|
|
}
|
|
|
|
|
|
2026-02-16 14:23:14 +00:00
|
|
|
void AnimationPlaybackEvent::visit_edges(Visitor& visitor)
|
|
|
|
|
{
|
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
|
|
|
|
|
|
auto visit_numberish_internal = [&](auto& numberish_internal) {
|
|
|
|
|
numberish_internal.visit(
|
|
|
|
|
[&](GC::Ref<CSS::CSSNumericValue> const& numeric) { visitor.visit(numeric); },
|
|
|
|
|
[](auto const&) {});
|
|
|
|
|
};
|
|
|
|
|
visit_numberish_internal(m_current_time);
|
|
|
|
|
visit_numberish_internal(m_timeline_time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NullableCSSNumberish AnimationPlaybackEvent::to_nullable_numberish(CSSNumberishInternal const& numberish)
|
|
|
|
|
{
|
|
|
|
|
return numberish.visit(
|
|
|
|
|
[](GC::Ref<CSS::CSSNumericValue> const& ref) -> NullableCSSNumberish { return GC::Root { *ref }; },
|
|
|
|
|
[](auto const& other) -> NullableCSSNumberish { return other; });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NullableCSSNumberish AnimationPlaybackEvent::current_time() const
|
|
|
|
|
{
|
|
|
|
|
return to_nullable_numberish(m_current_time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NullableCSSNumberish AnimationPlaybackEvent::timeline_time() const
|
|
|
|
|
{
|
|
|
|
|
return to_nullable_numberish(m_timeline_time);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-04 12:20:39 -07:00
|
|
|
}
|