CloseEvent.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. public:
  19. [[nodiscard]] static JS::NonnullGCPtr<CloseEvent> create(JS::Realm&, FlyString const& event_name, CloseEventInit const& event_init = {});
  20. static WebIDL::ExceptionOr<JS::NonnullGCPtr<CloseEvent>> construct_impl(JS::Realm&, FlyString const& event_name, CloseEventInit const& event_init);
  21. virtual ~CloseEvent() override;
  22. bool was_clean() const { return m_was_clean; }
  23. u16 code() const { return m_code; }
  24. String reason() const { return m_reason; }
  25. private:
  26. CloseEvent(JS::Realm&, FlyString const& event_name, CloseEventInit const& event_init);
  27. virtual void initialize(JS::Realm&) override;
  28. bool m_was_clean { false };
  29. u16 m_code { 0 };
  30. String m_reason;
  31. };
  32. }