Timer.h 987 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Forward.h>
  8. #include <LibCore/Forward.h>
  9. #include <LibJS/Heap/Handle.h>
  10. #include <LibJS/Runtime/FunctionObject.h>
  11. #include <LibWeb/Forward.h>
  12. namespace Web::DOM {
  13. class Timer final : public RefCounted<Timer> {
  14. public:
  15. enum class Type {
  16. Interval,
  17. Timeout,
  18. };
  19. static NonnullRefPtr<Timer> create_interval(Window&, int milliseconds, JS::FunctionObject&);
  20. static NonnullRefPtr<Timer> create_timeout(Window&, int milliseconds, JS::FunctionObject&);
  21. ~Timer();
  22. i32 id() const { return m_id; }
  23. Type type() const { return m_type; }
  24. JS::FunctionObject& callback() { return *m_callback.cell(); }
  25. private:
  26. Timer(Window&, Type, int ms, JS::FunctionObject&);
  27. Window& m_window;
  28. RefPtr<Core::Timer> m_timer;
  29. Type m_type;
  30. int m_id { 0 };
  31. JS::Handle<JS::FunctionObject> m_callback;
  32. };
  33. }