CustomEvent.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 <LibWeb/DOM/Event.h>
  9. namespace Web::DOM {
  10. struct CustomEventInit : public EventInit {
  11. JS::Value detail { JS::js_null() };
  12. };
  13. // https://dom.spec.whatwg.org/#customevent
  14. class CustomEvent : public Event {
  15. WEB_PLATFORM_OBJECT(CustomEvent, Event);
  16. public:
  17. static WebIDL::ExceptionOr<JS::NonnullGCPtr<CustomEvent>> create(JS::Realm&, DeprecatedFlyString const& event_name, CustomEventInit const& event_init = {});
  18. static WebIDL::ExceptionOr<JS::NonnullGCPtr<CustomEvent>> construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, CustomEventInit const& event_init);
  19. virtual ~CustomEvent() override;
  20. // https://dom.spec.whatwg.org/#dom-customevent-detail
  21. JS::Value detail() const { return m_detail; }
  22. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  23. virtual void visit_edges(JS::Cell::Visitor&) override;
  24. void init_custom_event(DeprecatedString const& type, bool bubbles, bool cancelable, JS::Value detail);
  25. private:
  26. CustomEvent(JS::Realm&, DeprecatedFlyString const& event_name, CustomEventInit const& event_init);
  27. // https://dom.spec.whatwg.org/#dom-customevent-initcustomevent-type-bubbles-cancelable-detail-detail
  28. JS::Value m_detail { JS::js_null() };
  29. };
  30. }