AnimationFrameCallbackDriver.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2022, the SerenityOS developers.
  3. * Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
  4. * Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/HashMap.h>
  10. #include <LibJS/Heap/GCPtr.h>
  11. #include <LibJS/Heap/HeapFunction.h>
  12. #include <LibWeb/WebIDL/Types.h>
  13. namespace Web::HTML {
  14. class AnimationFrameCallbackDriver final : public JS::Cell {
  15. JS_CELL(AnimationFrameCallbackDriver, JS::Cell);
  16. JS_DECLARE_ALLOCATOR(AnimationFrameCallbackDriver);
  17. using Callback = JS::NonnullGCPtr<JS::HeapFunction<void(double)>>;
  18. public:
  19. [[nodiscard]] WebIDL::UnsignedLong add(Callback handler);
  20. bool remove(WebIDL::UnsignedLong);
  21. bool has_callbacks() const;
  22. void run(double now);
  23. private:
  24. virtual void visit_edges(Cell::Visitor&) override;
  25. // https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#animation-frame-callback-identifier
  26. WebIDL::UnsignedLong m_animation_frame_callback_identifier { 0 };
  27. OrderedHashMap<WebIDL::UnsignedLong, Callback> m_callbacks;
  28. OrderedHashMap<WebIDL::UnsignedLong, Callback> m_executing_callbacks;
  29. };
  30. }