/* * Copyright (c) 2023, Matthew Olsson . * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace Web::Animations { // https://www.w3.org/TR/web-animations-1/#the-animation-interface class Animation : public DOM::EventTarget { WEB_PLATFORM_OBJECT(Animation, DOM::EventTarget); public: static JS::NonnullGCPtr create(JS::Realm&, JS::GCPtr, JS::GCPtr); static WebIDL::ExceptionOr> construct_impl(JS::Realm&, JS::GCPtr, JS::GCPtr); FlyString const& id() const { return m_id; } void set_id(FlyString value) { m_id = move(value); } JS::GCPtr effect() const { return m_effect; } void set_effect(JS::GCPtr); JS::GCPtr timeline() const { return m_timeline; } void set_timeline(JS::GCPtr); Optional const& start_time() const { return m_start_time; } void set_start_time(Optional const&); Optional current_time() const; WebIDL::ExceptionOr set_current_time(Optional const&); double playback_rate() const { return m_playback_rate; } WebIDL::ExceptionOr set_playback_rate(double value); Bindings::AnimationPlayState play_state() const; Bindings::AnimationReplaceState replace_state() const { return m_replace_state; } // https://www.w3.org/TR/web-animations-1/#dom-animation-ready JS::NonnullGCPtr ready() const { return *current_ready_promise()->promise(); } // https://www.w3.org/TR/web-animations-1/#dom-animation-finished JS::NonnullGCPtr finished() const { return *current_finished_promise()->promise(); } protected: Animation(JS::Realm&); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; private: JS::NonnullGCPtr current_ready_promise() const; JS::NonnullGCPtr current_finished_promise() const; // https://www.w3.org/TR/web-animations-1/#dom-animation-id FlyString m_id; // https://www.w3.org/TR/web-animations-1/#dom-animation-effect JS::GCPtr m_effect; // https://www.w3.org/TR/web-animations-1/#dom-animation-timeline JS::GCPtr m_timeline; // https://www.w3.org/TR/web-animations-1/#animation-start-time Optional m_start_time {}; // https://www.w3.org/TR/web-animations-1/#playback-rate double m_playback_rate { 1.0 }; // https://www.w3.org/TR/web-animations-1/#dom-animation-replacestate Bindings::AnimationReplaceState m_replace_state { Bindings::AnimationReplaceState::Active }; // Note: The following promises are initialized lazily to avoid constructing them outside of an execution context // https://www.w3.org/TR/web-animations-1/#current-ready-promise mutable JS::GCPtr m_current_ready_promise; // https://www.w3.org/TR/web-animations-1/#current-finished-promise mutable JS::GCPtr m_current_finished_promise; }; }