/* * Copyright (c) 2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Web::DOM { class EventTarget { AK_MAKE_NONCOPYABLE(EventTarget); AK_MAKE_NONMOVABLE(EventTarget); public: virtual ~EventTarget(); void ref() { ref_event_target(); } void unref() { unref_event_target(); } void add_event_listener(const FlyString& event_name, RefPtr); void remove_event_listener(const FlyString& event_name, RefPtr); void remove_from_event_listener_list(NonnullRefPtr); virtual bool dispatch_event(NonnullRefPtr) = 0; ExceptionOr dispatch_event_binding(NonnullRefPtr); virtual JS::Object* create_wrapper(JS::GlobalObject&) = 0; Bindings::ScriptExecutionContext* script_execution_context() { return m_script_execution_context; } virtual EventTarget* get_parent(const Event&) { return nullptr; } struct EventListenerRegistration { FlyString event_name; NonnullRefPtr listener; }; Vector& listeners() { return m_listeners; } const Vector& listeners() const { return m_listeners; } Function activation_behavior; // NOTE: These only exist for checkbox and radio input elements. Function legacy_pre_activation_behavior; Function legacy_cancelled_activation_behavior; protected: explicit EventTarget(Bindings::ScriptExecutionContext&); virtual void ref_event_target() = 0; virtual void unref_event_target() = 0; private: // FIXME: This should not be a raw pointer. Bindings::ScriptExecutionContext* m_script_execution_context { nullptr }; Vector m_listeners; }; }