From e76e8e22b524da92b3404747b975f1c985ceff68 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 16 Feb 2022 20:43:24 +0100 Subject: 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. --- Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp | 25 ++++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp') 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 + * Copyright (c) 2020-2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,11 +14,12 @@ #include #include #include +#include #include #include #include -#include #include +#include #include #include #include @@ -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& listeners, Event::Phase phase, bool invocation_target_in_shadow_tree) +bool EventDispatcher::inner_invoke(Event& event, Vector>& 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, Vectorpassive()) + 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); -- cgit v1.2.3