UIEvent.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/RefPtr.h>
  8. #include <LibWeb/DOM/Event.h>
  9. #include <LibWeb/HTML/Window.h>
  10. namespace Web::UIEvents {
  11. struct UIEventInit : public DOM::EventInit {
  12. JS::GCPtr<HTML::Window> view;
  13. int detail { 0 };
  14. };
  15. class UIEvent : public DOM::Event {
  16. WEB_PLATFORM_OBJECT(UIEvent, DOM::Event);
  17. public:
  18. static WebIDL::ExceptionOr<JS::NonnullGCPtr<UIEvent>> create(JS::Realm&, FlyString const& type);
  19. static WebIDL::ExceptionOr<JS::NonnullGCPtr<UIEvent>> construct_impl(JS::Realm&, FlyString const& event_name, UIEventInit const& event_init);
  20. virtual ~UIEvent() override;
  21. HTML::Window const* view() const { return m_view.ptr(); }
  22. int detail() const { return m_detail; }
  23. virtual u32 which() const { return 0; }
  24. void init_ui_event(String const& type, bool bubbles, bool cancelable, HTML::Window* view, int detail)
  25. {
  26. init_event(type, bubbles, cancelable);
  27. m_view = view;
  28. m_detail = detail;
  29. }
  30. protected:
  31. UIEvent(JS::Realm&, FlyString const& event_name);
  32. UIEvent(JS::Realm&, FlyString const& event_name, UIEventInit const& event_init);
  33. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  34. virtual void visit_edges(Cell::Visitor&) override;
  35. JS::GCPtr<HTML::Window> m_view;
  36. int m_detail { 0 };
  37. };
  38. }