diff options
author | Luke Wilde <lukew@serenityos.org> | 2021-10-14 18:03:08 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-02-08 17:47:44 +0000 |
commit | 5aacec65ab6da8feb5d2f29405ef4ed3cd89501f (patch) | |
tree | 2845921fb0bba58c40dc89acad0e9918657cc596 /Userland/Libraries/LibWeb/DOM/EventTarget.h | |
parent | 3bb5c6207fbdbe80041bd603882063165b440e00 (diff) | |
download | serenity-5aacec65ab6da8feb5d2f29405ef4ed3cd89501f.zip |
LibWeb: Rewrite EventTarget to more closely match the spec
This isn't perfect (especially the global object situation in
activate_event_handler), but I believe it's in a much more complete
state now :^)
This fixes the issue of crashing in prepare_for_ordinary_call with the
`i < m_size` crash, as it now uses the IDL callback functions which
requires the Environment Settings Object. The environment settings
object for the callback is fetched at the time the callback is created,
for example, WrapperGenerator gets the incumbent settings object for
the callback at the time of wrapping. This allows us to remove passing
in ScriptExecutionContext into EventTarget's constructor.
With this, we can now drop ScriptExecutionContext.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM/EventTarget.h')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/EventTarget.h | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/EventTarget.h b/Userland/Libraries/LibWeb/DOM/EventTarget.h index d3a118c9aa..65d7054baa 100644 --- a/Userland/Libraries/LibWeb/DOM/EventTarget.h +++ b/Userland/Libraries/LibWeb/DOM/EventTarget.h @@ -13,6 +13,7 @@ #include <LibJS/Forward.h> #include <LibWeb/DOM/ExceptionOr.h> #include <LibWeb/Forward.h> +#include <LibWeb/HTML/EventHandler.h> namespace Web::DOM { @@ -37,7 +38,6 @@ public: ExceptionOr<bool> dispatch_event_binding(NonnullRefPtr<Event>); 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; } @@ -55,20 +55,33 @@ public: Function<void()> legacy_pre_activation_behavior; Function<void()> legacy_cancelled_activation_behavior; - HTML::EventHandler event_handler_attribute(FlyString const& name); - void set_event_handler_attribute(FlyString const& name, HTML::EventHandler); + Bindings::CallbackType* event_handler_attribute(FlyString const& name); + void set_event_handler_attribute(FlyString const& name, Optional<Bindings::CallbackType>); protected: - explicit EventTarget(Bindings::ScriptExecutionContext&); + EventTarget(); 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 }; + void element_event_handler_attribute_changed(FlyString const& local_name, String const& value); +private: Vector<EventListenerRegistration> m_listeners; + + // https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-map + // Spec Note: The order of the entries of event handler map could be arbitrary. It is not observable through any algorithms that operate on the map. + HashMap<FlyString, HTML::EventHandler> m_event_handler_map; + + enum class IsAttribute { + No, + Yes, + }; + + Bindings::CallbackType* get_current_value_of_event_handler(FlyString const& name); + void activate_event_handler(FlyString const& name, HTML::EventHandler& event_handler, IsAttribute is_attribute); + void deactivate_event_handler(FlyString const& name); + JS::ThrowCompletionOr<void> process_event_handler_for_event(FlyString const& name, Event& event); }; } |