2024-03-27 15:30:54 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2024, Matthew Olsson <mattco@serenityos.org>.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2025-12-28 16:24:36 +00:00
|
|
|
#include <LibWeb/Animations/Animation.h>
|
2024-04-27 12:09:58 +12:00
|
|
|
#include <LibWeb/Bindings/InternalAnimationTimelinePrototype.h>
|
2024-03-27 15:30:54 +00:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2024-03-28 17:49:00 -07:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
|
|
|
#include <LibWeb/HTML/Window.h>
|
2024-03-27 15:30:54 +00:00
|
|
|
#include <LibWeb/Internals/InternalAnimationTimeline.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::Internals {
|
|
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DEFINE_ALLOCATOR(InternalAnimationTimeline);
|
2024-03-27 15:30:54 +00:00
|
|
|
|
2025-11-26 21:00:34 +13:00
|
|
|
void InternalAnimationTimeline::update_current_time(double)
|
2024-03-27 15:30:54 +00:00
|
|
|
{
|
|
|
|
|
// Do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InternalAnimationTimeline::set_time(Optional<double> time)
|
|
|
|
|
{
|
2025-11-30 20:31:57 +13:00
|
|
|
set_current_time(time.map([](double value) -> Animations::TimeValue { return { Animations::TimeValue::Type::Milliseconds, value }; }));
|
2025-12-28 16:24:36 +00:00
|
|
|
|
|
|
|
|
// https://drafts.csswg.org/web-animations-1/#animation-frame-loop
|
|
|
|
|
// Note: Due to the hierarchical nature of the timing model, updating the current time of a timeline also involves:
|
|
|
|
|
// - Updating the current time of any animations associated with the timeline.
|
|
|
|
|
// - Running the update an animation's finished state procedure for any animations whose current time has been
|
|
|
|
|
// updated.
|
|
|
|
|
// - Queueing animation events for any such animations.
|
|
|
|
|
// NB: This mirrors what the event loop does for DocumentTimeline in Document::update_animations_and_send_events().
|
2026-02-24 12:36:21 +01:00
|
|
|
for (auto& animation : associated_animations())
|
|
|
|
|
animation.update();
|
2024-03-27 15:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InternalAnimationTimeline::InternalAnimationTimeline(JS::Realm& realm)
|
|
|
|
|
: AnimationTimeline(realm)
|
|
|
|
|
{
|
2025-11-30 20:31:57 +13:00
|
|
|
m_current_time = { Animations::TimeValue::Type::Milliseconds, 0.0 };
|
2025-07-29 10:15:12 +02:00
|
|
|
m_is_monotonically_increasing = true;
|
2024-03-28 17:49:00 -07:00
|
|
|
|
2025-01-21 09:12:05 -05:00
|
|
|
auto& document = as<HTML::Window>(HTML::relevant_global_object(*this)).associated_document();
|
2024-03-28 17:49:00 -07:00
|
|
|
document.associate_with_timeline(*this);
|
2024-03-27 15:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InternalAnimationTimeline::initialize(JS::Realm& realm)
|
|
|
|
|
{
|
|
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(InternalAnimationTimeline);
|
2025-04-20 16:22:57 +02:00
|
|
|
Base::initialize(realm);
|
2024-03-27 15:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|