2024-03-27 12:30:54 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2024, Matthew Olsson <mattco@serenityos.org>.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2025-12-28 13:24:36 -03:00
|
|
|
#include <LibWeb/Animations/Animation.h>
|
2026-04-18 05:54:06 -03:00
|
|
|
#include <LibWeb/Bindings/InternalAnimationTimeline.h>
|
2024-03-27 12:30:54 -03:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
2024-03-28 21:49:00 -03:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
|
|
|
#include <LibWeb/HTML/Window.h>
|
2024-03-27 12:30:54 -03:00
|
|
|
#include <LibWeb/Internals/InternalAnimationTimeline.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::Internals {
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DEFINE_ALLOCATOR(InternalAnimationTimeline);
|
2024-03-27 12:30:54 -03:00
|
|
|
|
2025-11-26 05:00:34 -03:00
|
|
|
void InternalAnimationTimeline::update_current_time(double)
|
2024-03-27 12:30:54 -03:00
|
|
|
{
|
|
|
|
|
// Do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InternalAnimationTimeline::set_time(Optional<double> time)
|
|
|
|
|
{
|
2025-11-30 04:31:57 -03:00
|
|
|
set_current_time(time.map([](double value) -> Animations::TimeValue { return { Animations::TimeValue::Type::Milliseconds, value }; }));
|
2025-12-28 13:24:36 -03: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 08:36:21 -03:00
|
|
|
for (auto& animation : associated_animations())
|
|
|
|
|
animation.update();
|
2024-03-27 12:30:54 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InternalAnimationTimeline::InternalAnimationTimeline(JS::Realm& realm)
|
|
|
|
|
: AnimationTimeline(realm)
|
|
|
|
|
{
|
2025-11-30 04:31:57 -03:00
|
|
|
m_current_time = { Animations::TimeValue::Type::Milliseconds, 0.0 };
|
2025-07-29 05:15:12 -03:00
|
|
|
m_is_monotonically_increasing = true;
|
2024-03-28 21:49:00 -03:00
|
|
|
|
2025-01-21 11:12:05 -03:00
|
|
|
auto& document = as<HTML::Window>(HTML::relevant_global_object(*this)).associated_document();
|
2024-03-28 21:49:00 -03:00
|
|
|
document.associate_with_timeline(*this);
|
2024-03-27 12:30:54 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InternalAnimationTimeline::initialize(JS::Realm& realm)
|
|
|
|
|
{
|
|
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(InternalAnimationTimeline);
|
2025-04-20 11:22:57 -03:00
|
|
|
Base::initialize(realm);
|
2024-03-27 12:30:54 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|