Coverage Report

Created: 2025-08-28 06:26

/src/serenity/Userland/Libraries/LibWeb/Animations/AnimationTimeline.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2023-2024, Matthew Olsson <mattco@serenityos.org>.
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include <LibWeb/Animations/Animation.h>
8
#include <LibWeb/Animations/AnimationTimeline.h>
9
#include <LibWeb/Bindings/AnimationTimelinePrototype.h>
10
#include <LibWeb/DOM/Document.h>
11
12
namespace Web::Animations {
13
14
JS_DEFINE_ALLOCATOR(AnimationTimeline);
15
16
void AnimationTimeline::set_current_time(Optional<double> value)
17
0
{
18
0
    if (value == m_current_time)
19
0
        return;
20
21
0
    if (m_is_monotonically_increasing && m_current_time.has_value()) {
22
0
        if (!value.has_value() || value.value() < m_current_time.value())
23
0
            m_is_monotonically_increasing = false;
24
0
    }
25
26
0
    m_current_time = value;
27
0
    for (auto& animation : m_associated_animations)
28
0
        animation->notify_timeline_time_did_change();
29
0
}
30
31
void AnimationTimeline::set_associated_document(JS::GCPtr<DOM::Document> document)
32
0
{
33
0
    if (document)
34
0
        document->associate_with_timeline(*this);
35
0
    if (m_associated_document)
36
0
        m_associated_document->disassociate_with_timeline(*this);
37
0
    m_associated_document = document;
38
0
}
39
40
// https://www.w3.org/TR/web-animations-1/#inactive-timeline
41
bool AnimationTimeline::is_inactive() const
42
0
{
43
    // A timeline is considered to be inactive when its time value is unresolved.
44
0
    return !m_current_time.has_value();
45
0
}
46
47
AnimationTimeline::AnimationTimeline(JS::Realm& realm)
48
0
    : Bindings::PlatformObject(realm)
49
0
{
50
0
}
51
52
void AnimationTimeline::finalize()
53
0
{
54
0
    if (m_associated_document)
55
0
        m_associated_document->disassociate_with_timeline(*this);
56
0
}
57
58
void AnimationTimeline::initialize(JS::Realm& realm)
59
0
{
60
0
    Base::initialize(realm);
61
0
    WEB_SET_PROTOTYPE_FOR_INTERFACE(AnimationTimeline);
62
0
}
63
64
void AnimationTimeline::visit_edges(Cell::Visitor& visitor)
65
0
{
66
0
    Base::visit_edges(visitor);
67
0
    visitor.visit(m_associated_document);
68
0
    visitor.visit(m_associated_animations);
69
0
}
70
71
}