Animatable.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2024, Matthew Olsson <mattco@serenityos.org>.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/FlyString.h>
  8. #include <LibWeb/Animations/KeyframeEffect.h>
  9. namespace Web::Animations {
  10. // https://www.w3.org/TR/web-animations-1/#dictdef-keyframeanimationoptions
  11. struct KeyframeAnimationOptions : public KeyframeEffectOptions {
  12. FlyString id { ""_fly_string };
  13. JS::GCPtr<AnimationTimeline> timeline;
  14. };
  15. // https://www.w3.org/TR/web-animations-1/#dictdef-getanimationsoptions
  16. struct GetAnimationsOptions {
  17. bool subtree { false };
  18. };
  19. // https://www.w3.org/TR/web-animations-1/#animatable
  20. class Animatable {
  21. public:
  22. virtual ~Animatable() = default;
  23. WebIDL::ExceptionOr<JS::NonnullGCPtr<Animation>> animate(Optional<JS::Handle<JS::Object>> keyframes, Variant<Empty, double, KeyframeAnimationOptions> options = {});
  24. Vector<JS::NonnullGCPtr<Animation>> get_animations(GetAnimationsOptions options = {});
  25. void associate_with_animation(JS::NonnullGCPtr<Animation>);
  26. void disassociate_with_animation(JS::NonnullGCPtr<Animation>);
  27. JS::GCPtr<CSS::CSSStyleDeclaration const> cached_animation_name_source() const { return m_cached_animation_name_source; }
  28. void set_cached_animation_name_source(JS::GCPtr<CSS::CSSStyleDeclaration const> value) { m_cached_animation_name_source = value; }
  29. JS::GCPtr<Animations::Animation> cached_animation_name_animation() const { return m_cached_animation_name_animation; }
  30. void set_cached_animation_name_animation(JS::GCPtr<Animations::Animation> value) { m_cached_animation_name_animation = value; }
  31. protected:
  32. void visit_edges(JS::Cell::Visitor&);
  33. private:
  34. Vector<JS::NonnullGCPtr<Animation>> m_associated_animations;
  35. bool m_is_sorted_by_composite_order { true };
  36. JS::GCPtr<CSS::CSSStyleDeclaration const> m_cached_animation_name_source;
  37. JS::GCPtr<Animations::Animation> m_cached_animation_name_animation;
  38. };
  39. }