AnimationFrameCallbackDriver.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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/Cell.h>
  11. #include <LibJS/Heap/GCPtr.h>
  12. #include <LibJS/Heap/HeapFunction.h>
  13. #include <LibWeb/WebIDL/Types.h>
  14. namespace Web::HTML {
  15. class AnimationFrameCallbackDriver final : public JS::Cell {
  16. JS_CELL(AnimationFrameCallbackDriver, JS::Cell);
  17. JS_DECLARE_ALLOCATOR(AnimationFrameCallbackDriver);
  18. using Callback = JS::NonnullGCPtr<JS::HeapFunction<void(double)>>;
  19. public:
  20. [[nodiscard]] WebIDL::UnsignedLong add(Callback handler);
  21. bool remove(WebIDL::UnsignedLong);
  22. bool has_callbacks() const;
  23. void run(double now);
  24. private:
  25. virtual void visit_edges(Cell::Visitor&) override;
  26. // https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#animation-frame-callback-identifier
  27. WebIDL::UnsignedLong m_animation_frame_callback_identifier { 0 };
  28. OrderedHashMap<WebIDL::UnsignedLong, Callback> m_callbacks;
  29. OrderedHashMap<WebIDL::UnsignedLong, Callback> m_executing_callbacks;
  30. };
  31. }