CloseEvent.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2021, Dex♪ <dexes.ttp@gmail.com>
  3. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/FlyString.h>
  9. #include <LibWeb/DOM/Event.h>
  10. namespace Web::HTML {
  11. struct CloseEventInit : public DOM::EventInit {
  12. bool was_clean { false };
  13. u16 code { 0 };
  14. String reason;
  15. };
  16. class CloseEvent : public DOM::Event {
  17. WEB_PLATFORM_OBJECT(CloseEvent, DOM::Event);
  18. JS_DECLARE_ALLOCATOR(CloseEvent);
  19. public:
  20. [[nodiscard]] static JS::NonnullGCPtr<CloseEvent> create(JS::Realm&, FlyString const& event_name, CloseEventInit const& event_init = {});
  21. static WebIDL::ExceptionOr<JS::NonnullGCPtr<CloseEvent>> construct_impl(JS::Realm&, FlyString const& event_name, CloseEventInit const& event_init);
  22. virtual ~CloseEvent() override;
  23. bool was_clean() const { return m_was_clean; }
  24. u16 code() const { return m_code; }
  25. String reason() const { return m_reason; }
  26. private:
  27. CloseEvent(JS::Realm&, FlyString const& event_name, CloseEventInit const& event_init);
  28. virtual void initialize(JS::Realm&) override;
  29. bool m_was_clean { false };
  30. u16 m_code { 0 };
  31. String m_reason;
  32. };
  33. }