CloseWatcher.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2024, the Ladybird developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Forward.h>
  8. #include <LibWeb/DOM/EventTarget.h>
  9. namespace Web::HTML {
  10. // https://html.spec.whatwg.org/multipage/interaction.html#closewatcheroptions
  11. struct CloseWatcherOptions {
  12. GC::Ptr<DOM::AbortSignal> signal;
  13. };
  14. // https://html.spec.whatwg.org/multipage/interaction.html#the-closewatcher-interface
  15. class CloseWatcher final : public DOM::EventTarget {
  16. WEB_PLATFORM_OBJECT(CloseWatcher, DOM::EventTarget);
  17. GC_DECLARE_ALLOCATOR(CloseWatcher);
  18. public:
  19. static WebIDL::ExceptionOr<GC::Ref<CloseWatcher>> construct_impl(JS::Realm&, CloseWatcherOptions const& = {});
  20. [[nodiscard]] static GC::Ref<CloseWatcher> establish(HTML::Window&);
  21. bool request_close();
  22. void close();
  23. void destroy();
  24. virtual ~CloseWatcher() override = default;
  25. void set_oncancel(WebIDL::CallbackType*);
  26. WebIDL::CallbackType* oncancel();
  27. void set_onclose(WebIDL::CallbackType*);
  28. WebIDL::CallbackType* onclose();
  29. private:
  30. CloseWatcher(JS::Realm&);
  31. virtual void initialize(JS::Realm&) override;
  32. bool m_is_running_cancel_action { false };
  33. bool m_is_active { true };
  34. };
  35. }