CustomEvent.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. public:
  18. static WebIDL::ExceptionOr<JS::NonnullGCPtr<CustomEvent>> create(JS::Realm&, FlyString const& event_name, CustomEventInit const& event_init = {});
  19. static WebIDL::ExceptionOr<JS::NonnullGCPtr<CustomEvent>> construct_impl(JS::Realm&, FlyString const& event_name, CustomEventInit const& event_init);
  20. virtual ~CustomEvent() override;
  21. // https://dom.spec.whatwg.org/#dom-customevent-detail
  22. JS::Value detail() const { return m_detail; }
  23. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  24. virtual void visit_edges(JS::Cell::Visitor&) override;
  25. void init_custom_event(String const& type, bool bubbles, bool cancelable, JS::Value detail);
  26. private:
  27. CustomEvent(JS::Realm&, FlyString const& event_name, CustomEventInit const& event_init);
  28. // https://dom.spec.whatwg.org/#dom-customevent-initcustomevent-type-bubbles-cancelable-detail-detail
  29. JS::Value m_detail { JS::js_null() };
  30. };
  31. }