/src/serenity/Userland/Libraries/LibWeb/CSS/CSSTransition.h
Line | Count | Source |
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 <LibWeb/Animations/Animation.h> |
11 | | #include <LibWeb/CSS/CSSStyleValue.h> |
12 | | #include <LibWeb/CSS/PropertyID.h> |
13 | | #include <LibWeb/CSS/StyleValues/EasingStyleValue.h> |
14 | | #include <LibWeb/CSS/Time.h> |
15 | | |
16 | | namespace Web::CSS { |
17 | | |
18 | | class CSSTransition : public Animations::Animation { |
19 | | WEB_PLATFORM_OBJECT(CSSTransition, Animations::Animation); |
20 | | JS_DECLARE_ALLOCATOR(CSSTransition); |
21 | | |
22 | | public: |
23 | | static JS::NonnullGCPtr<CSSTransition> start_a_transition(DOM::Element&, PropertyID, size_t transition_generation, |
24 | | double start_time, double end_time, NonnullRefPtr<CSSStyleValue const> start_value, NonnullRefPtr<CSSStyleValue const> end_value, |
25 | | NonnullRefPtr<CSSStyleValue const> reversing_adjusted_start_value, double reversing_shortening_factor); |
26 | | |
27 | 0 | StringView transition_property() const { return string_from_property_id(m_transition_property); } |
28 | | |
29 | | virtual Animations::AnimationClass animation_class() const override; |
30 | | virtual Optional<int> class_specific_composite_order(JS::NonnullGCPtr<Animations::Animation> other) const override; |
31 | | |
32 | 0 | double transition_start_time() const { return m_start_time; } |
33 | 0 | double transition_end_time() const { return m_end_time; } |
34 | 0 | NonnullRefPtr<CSSStyleValue const> transition_start_value() const { return m_start_value; } |
35 | 0 | NonnullRefPtr<CSSStyleValue const> transition_end_value() const { return m_end_value; } |
36 | 0 | NonnullRefPtr<CSSStyleValue const> reversing_adjusted_start_value() const { return m_reversing_adjusted_start_value; } |
37 | 0 | double reversing_shortening_factor() const { return m_reversing_shortening_factor; } |
38 | | |
39 | | double timing_function_output_at_time(double t) const; |
40 | | NonnullRefPtr<CSSStyleValue const> value_at_time(double t) const; |
41 | | |
42 | | private: |
43 | | CSSTransition(JS::Realm&, DOM::Element&, PropertyID, size_t transition_generation, |
44 | | double start_time, double end_time, NonnullRefPtr<CSSStyleValue const> start_value, NonnullRefPtr<CSSStyleValue const> end_value, |
45 | | NonnullRefPtr<CSSStyleValue const> reversing_adjusted_start_value, double reversing_shortening_factor); |
46 | | |
47 | | virtual void initialize(JS::Realm&) override; |
48 | | virtual void visit_edges(Cell::Visitor&) override; |
49 | | |
50 | 0 | virtual bool is_css_transition() const override { return true; } |
51 | | |
52 | | PropertyID m_transition_property; |
53 | | |
54 | | // https://drafts.csswg.org/css-transitions-2/#transition-generation |
55 | | size_t m_transition_generation; |
56 | | |
57 | | // https://drafts.csswg.org/css-transitions/#transition-start-time |
58 | | double m_start_time; |
59 | | |
60 | | // https://drafts.csswg.org/css-transitions/#transition-end-time |
61 | | double m_end_time; |
62 | | |
63 | | // https://drafts.csswg.org/css-transitions/#transition-start-value |
64 | | NonnullRefPtr<CSS::CSSStyleValue const> m_start_value; |
65 | | |
66 | | // https://drafts.csswg.org/css-transitions/#transition-end-value |
67 | | NonnullRefPtr<CSS::CSSStyleValue const> m_end_value; |
68 | | |
69 | | // https://drafts.csswg.org/css-transitions/#transition-reversing-adjusted-start-value |
70 | | NonnullRefPtr<CSS::CSSStyleValue const> m_reversing_adjusted_start_value; |
71 | | |
72 | | // https://drafts.csswg.org/css-transitions/#transition-reversing-shortening-factor |
73 | | double m_reversing_shortening_factor; |
74 | | |
75 | | JS::NonnullGCPtr<Animations::KeyframeEffect> m_keyframe_effect; |
76 | | |
77 | | JS::GCPtr<CSS::CSSStyleDeclaration const> m_cached_declaration; |
78 | | }; |
79 | | |
80 | | } |