Serenity Operating System
at master 43 lines 1.4 kB view raw
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 8#pragma once 9 10#include <LibWeb/DOM/Event.h> 11 12namespace Web::DOM { 13 14struct CustomEventInit : public EventInit { 15 JS::Value detail { JS::js_null() }; 16}; 17 18// https://dom.spec.whatwg.org/#customevent 19class CustomEvent : public Event { 20 WEB_PLATFORM_OBJECT(CustomEvent, Event); 21 22public: 23 static WebIDL::ExceptionOr<JS::NonnullGCPtr<CustomEvent>> create(JS::Realm&, DeprecatedFlyString const& event_name, CustomEventInit const& event_init = {}); 24 static WebIDL::ExceptionOr<JS::NonnullGCPtr<CustomEvent>> construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, CustomEventInit const& event_init); 25 26 virtual ~CustomEvent() override; 27 28 // https://dom.spec.whatwg.org/#dom-customevent-detail 29 JS::Value detail() const { return m_detail; } 30 31 virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override; 32 virtual void visit_edges(JS::Cell::Visitor&) override; 33 34 void init_custom_event(DeprecatedString const& type, bool bubbles, bool cancelable, JS::Value detail); 35 36private: 37 CustomEvent(JS::Realm&, DeprecatedFlyString const& event_name, CustomEventInit const& event_init); 38 39 // https://dom.spec.whatwg.org/#dom-customevent-initcustomevent-type-bubbles-cancelable-detail-detail 40 JS::Value m_detail { JS::js_null() }; 41}; 42 43}