CustomEvent.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
  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::DOM {
  11. struct CustomEventInit : public EventInit {
  12. JS::Value detail { JS::js_null() };
  13. };
  14. // https://dom.spec.whatwg.org/#customevent
  15. class CustomEvent : public Event {
  16. WEB_PLATFORM_OBJECT(CustomEvent, Event);
  17. JS_DECLARE_ALLOCATOR(CustomEvent);
  18. public:
  19. [[nodiscard]] static JS::NonnullGCPtr<CustomEvent> create(JS::Realm&, FlyString const& event_name, CustomEventInit const& = {});
  20. static WebIDL::ExceptionOr<JS::NonnullGCPtr<CustomEvent>> construct_impl(JS::Realm&, FlyString const& event_name, CustomEventInit const&);
  21. virtual ~CustomEvent() override;
  22. // https://dom.spec.whatwg.org/#dom-customevent-detail
  23. JS::Value detail() const { return m_detail; }
  24. virtual void initialize(JS::Realm&) override;
  25. virtual void visit_edges(JS::Cell::Visitor&) override;
  26. void init_custom_event(String const& type, bool bubbles, bool cancelable, JS::Value detail);
  27. private:
  28. CustomEvent(JS::Realm&, FlyString const& event_name, CustomEventInit const& event_init);
  29. // https://dom.spec.whatwg.org/#dom-customevent-initcustomevent-type-bubbles-cancelable-detail-detail
  30. JS::Value m_detail { JS::js_null() };
  31. };
  32. }