AnimationEvent.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2024, Matthew Olsson <mattco@serenityos.org>.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Bindings/PlatformObject.h>
  8. #include <LibWeb/DOM/Event.h>
  9. namespace Web::CSS {
  10. // https://www.w3.org/TR/css-animations-1/#dictdef-animationeventinit
  11. struct AnimationEventInit : public DOM::EventInit {
  12. FlyString animation_name { ""_fly_string };
  13. double elapsed_time { 0.0 };
  14. FlyString pseudo_element { ""_fly_string };
  15. };
  16. // https://www.w3.org/TR/css-animations-1/#animationevent
  17. class AnimationEvent : public DOM::Event {
  18. WEB_PLATFORM_OBJECT(AnimationEvent, DOM::Event);
  19. JS_DECLARE_ALLOCATOR(AnimationEvent);
  20. public:
  21. [[nodiscard]] static JS::NonnullGCPtr<AnimationEvent> create(JS::Realm&, FlyString const& type, AnimationEventInit const& event_init = {});
  22. static WebIDL::ExceptionOr<JS::NonnullGCPtr<AnimationEvent>> construct_impl(JS::Realm&, FlyString const& type, AnimationEventInit const& event_init);
  23. virtual ~AnimationEvent() override = default;
  24. FlyString const& animation_name() const { return m_animation_name; }
  25. double elapsed_time() const { return m_elapsed_time; }
  26. FlyString const& pseudo_element() const { return m_pseudo_element; }
  27. private:
  28. AnimationEvent(JS::Realm&, FlyString const& type, AnimationEventInit const& event_init);
  29. virtual void initialize(JS::Realm&) override;
  30. // https://www.w3.org/TR/css-animations-1/#dom-animationevent-animationname
  31. FlyString m_animation_name {};
  32. // https://www.w3.org/TR/css-animations-1/#dom-animationevent-elapsedtime
  33. double m_elapsed_time { 0.0 };
  34. // https://www.w3.org/TR/css-animations-1/#dom-animationevent-pseudoelement
  35. FlyString m_pseudo_element {};
  36. };
  37. }