diff options
author | Andreas Kling <kling@serenityos.org> | 2022-02-16 20:43:24 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-16 22:21:45 +0100 |
commit | e76e8e22b524da92b3404747b975f1c985ceff68 (patch) | |
tree | a58efd28af971e327a159a9603009d9e2c97fff3 /Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp | |
parent | 0e2cd5540a4be6367168fb8d7e0445153486b26c (diff) | |
download | serenity-e76e8e22b524da92b3404747b975f1c985ceff68.zip |
LibWeb: Separate "event listener" from "EventListener"
I can't imagine how this happened, but it seems we've managed to
conflate the "event listener" and "EventListener" concepts from the DOM
specification in some parts of the code.
We previously had two things:
- DOM::EventListener
- DOM::EventTarget::EventListenerRegistration
DOM::EventListener was roughly the "EventListener" IDL type,
and DOM::EventTarget::EventListenerRegistration was roughly the "event
listener" concept. However, they were used interchangeably (and
incorrectly!) in many places.
After this patch, we now have:
- DOM::IDLEventListener
- DOM::DOMEventListener
DOM::IDLEventListener is the "EventListener" IDL type,
and DOM::DOMEventListener is the "event listener" concept.
This patch also updates the addEventListener() and removeEventListener()
functions to follow the spec more closely, along with the "inner invoke"
function in our EventDispatcher.
Diffstat (limited to 'Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp b/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp index 52f4331926..37e3c2d484 100644 --- a/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp +++ b/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,11 +14,12 @@ #include <LibWeb/Bindings/EventWrapperFactory.h> #include <LibWeb/Bindings/IDLAbstractOperations.h> #include <LibWeb/Bindings/WindowObject.h> +#include <LibWeb/DOM/AbortSignal.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Event.h> #include <LibWeb/DOM/EventDispatcher.h> -#include <LibWeb/DOM/EventListener.h> #include <LibWeb/DOM/EventTarget.h> +#include <LibWeb/DOM/IDLEventListener.h> #include <LibWeb/DOM/Node.h> #include <LibWeb/DOM/ShadowRoot.h> #include <LibWeb/DOM/Window.h> @@ -50,37 +51,37 @@ static EventTarget* retarget(EventTarget* left, EventTarget* right) } // https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke -bool EventDispatcher::inner_invoke(Event& event, Vector<EventTarget::EventListenerRegistration>& listeners, Event::Phase phase, bool invocation_target_in_shadow_tree) +bool EventDispatcher::inner_invoke(Event& event, Vector<NonnullRefPtr<DOM::DOMEventListener>>& listeners, Event::Phase phase, bool invocation_target_in_shadow_tree) { // 1. Let found be false. bool found = false; // 2. For each listener in listeners, whose removed is false: for (auto& listener : listeners) { - if (listener.listener->removed()) + if (listener->removed) continue; // 1. If eventās type attribute value is not listenerās type, then continue. - if (event.type() != listener.listener->type()) + if (event.type() != listener->type) continue; // 2. Set found to true. found = true; // 3. If phase is "capturing" and listenerās capture is false, then continue. - if (phase == Event::Phase::CapturingPhase && !listener.listener->capture()) + if (phase == Event::Phase::CapturingPhase && !listener->capture) continue; // 4. If phase is "bubbling" and listenerās capture is true, then continue. - if (phase == Event::Phase::BubblingPhase && listener.listener->capture()) + if (phase == Event::Phase::BubblingPhase && listener->capture) continue; // 5. If listenerās once is true, then remove listener from eventās currentTarget attribute valueās event listener list. - if (listener.listener->once()) - event.current_target()->remove_from_event_listener_list(listener.listener); + if (listener->once) + event.current_target()->remove_from_event_listener_list(listener); // 6. Let global be listener callbackās associated Realmās global object. - auto& callback = listener.listener->callback(); + auto& callback = listener->callback->callback(); auto& global = callback.callback.cell()->global_object(); // 7. Let currentEvent be undefined. @@ -100,7 +101,7 @@ bool EventDispatcher::inner_invoke(Event& event, Vector<EventTarget::EventListen } // 9. If listenerās passive is true, then set eventās in passive listener flag. - if (listener.listener->passive()) + if (listener->passive) event.set_in_passive_listener(true); // 10. Call a user objectās operation with listenerās callback, "handleEvent", Ā« event Ā», and eventās currentTarget attribute value. If this throws an exception, then: @@ -155,7 +156,7 @@ void EventDispatcher::invoke(Event::PathEntry& struct_, Event& event, Event::Pha event.set_current_target(struct_.invocation_target); // NOTE: This is an intentional copy. Any event listeners added after this point will not be invoked. - auto listeners = event.current_target()->listeners(); + auto listeners = event.current_target()->event_listener_list(); bool invocation_target_in_shadow_tree = struct_.invocation_target_in_shadow_tree; bool found = inner_invoke(event, listeners, phase, invocation_target_in_shadow_tree); |