Coverage Report

Created: 2025-03-04 07:22

/src/serenity/Userland/Libraries/LibWeb/Animations/Animatable.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2024, Matthew Olsson <mattco@serenityos.org>
3
 * Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
4
 *
5
 * SPDX-License-Identifier: BSD-2-Clause
6
 */
7
8
#pragma once
9
10
#include <AK/FlyString.h>
11
#include <AK/HashMap.h>
12
#include <LibWeb/Animations/KeyframeEffect.h>
13
14
namespace Web::CSS {
15
class CSSTransition;
16
}
17
18
namespace Web::Animations {
19
20
// https://www.w3.org/TR/web-animations-1/#dictdef-keyframeanimationoptions
21
struct KeyframeAnimationOptions : public KeyframeEffectOptions {
22
    FlyString id { ""_fly_string };
23
    Optional<JS::GCPtr<AnimationTimeline>> timeline;
24
};
25
26
// https://www.w3.org/TR/web-animations-1/#dictdef-getanimationsoptions
27
struct GetAnimationsOptions {
28
    bool subtree { false };
29
};
30
31
// https://www.w3.org/TR/web-animations-1/#animatable
32
class Animatable {
33
public:
34
    struct TransitionAttributes {
35
        double delay;
36
        double duration;
37
        CSS::EasingStyleValue::Function timing_function;
38
    };
39
40
0
    virtual ~Animatable() = default;
41
42
    WebIDL::ExceptionOr<JS::NonnullGCPtr<Animation>> animate(Optional<JS::Handle<JS::Object>> keyframes, Variant<Empty, double, KeyframeAnimationOptions> options = {});
43
    Vector<JS::NonnullGCPtr<Animation>> get_animations(GetAnimationsOptions options = {});
44
    Vector<JS::NonnullGCPtr<Animation>> get_animations_internal(GetAnimationsOptions options = {});
45
46
    void associate_with_animation(JS::NonnullGCPtr<Animation>);
47
    void disassociate_with_animation(JS::NonnullGCPtr<Animation>);
48
49
    JS::GCPtr<CSS::CSSStyleDeclaration const> cached_animation_name_source(Optional<CSS::Selector::PseudoElement::Type>) const;
50
    void set_cached_animation_name_source(JS::GCPtr<CSS::CSSStyleDeclaration const> value, Optional<CSS::Selector::PseudoElement::Type>);
51
52
    JS::GCPtr<Animations::Animation> cached_animation_name_animation(Optional<CSS::Selector::PseudoElement::Type>) const;
53
    void set_cached_animation_name_animation(JS::GCPtr<Animations::Animation> value, Optional<CSS::Selector::PseudoElement::Type>);
54
55
0
    JS::GCPtr<CSS::CSSStyleDeclaration const> cached_transition_property_source() const { return m_cached_transition_property_source; }
56
0
    void set_cached_transition_property_source(JS::GCPtr<CSS::CSSStyleDeclaration const> value) { m_cached_transition_property_source = value; }
57
58
    void add_transitioned_properties(Vector<Vector<CSS::PropertyID>> properties, CSS::StyleValueVector delays, CSS::StyleValueVector durations, CSS::StyleValueVector timing_functions);
59
    Optional<TransitionAttributes const&> property_transition_attributes(CSS::PropertyID) const;
60
    void set_transition(CSS::PropertyID, JS::NonnullGCPtr<CSS::CSSTransition>);
61
    void remove_transition(CSS::PropertyID);
62
    JS::GCPtr<CSS::CSSTransition> property_transition(CSS::PropertyID) const;
63
    void clear_transitions();
64
65
protected:
66
    void visit_edges(JS::Cell::Visitor&);
67
68
private:
69
    Vector<JS::NonnullGCPtr<Animation>> m_associated_animations;
70
    bool m_is_sorted_by_composite_order { true };
71
72
    Array<JS::GCPtr<CSS::CSSStyleDeclaration const>, to_underlying(CSS::Selector::PseudoElement::Type::KnownPseudoElementCount) + 1> m_cached_animation_name_source;
73
    Array<JS::GCPtr<Animations::Animation>, to_underlying(CSS::Selector::PseudoElement::Type::KnownPseudoElementCount) + 1> m_cached_animation_name_animation;
74
75
    HashMap<CSS::PropertyID, size_t> m_transition_attribute_indices;
76
    Vector<TransitionAttributes> m_transition_attributes;
77
    JS::GCPtr<CSS::CSSStyleDeclaration const> m_cached_transition_property_source;
78
    HashMap<CSS::PropertyID, JS::NonnullGCPtr<CSS::CSSTransition>> m_associated_transitions;
79
};
80
81
}