diff options
author | Andreas Kling <kling@serenityos.org> | 2022-01-24 16:39:02 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-24 17:09:22 +0100 |
commit | 0b997b9d354be70a3f0197354c2b626d4131432c (patch) | |
tree | 8f959575a5bfdfa4c130b3d528d37f6dc4896e1a /Userland | |
parent | 43ddefec9ce7a9ab63ae0f1336936cd690c20226 (diff) | |
download | serenity-0b997b9d354be70a3f0197354c2b626d4131432c.zip |
LibWeb: Resolve a FIXME when determining target of an event handler
For body and frameset events that aren't part of the special handling
sets, just let them through to the element.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/EventTarget.cpp | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp index ef26616437..7b672de40c 100644 --- a/Userland/Libraries/LibWeb/DOM/EventTarget.cpp +++ b/Userland/Libraries/LibWeb/DOM/EventTarget.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -16,8 +16,10 @@ #include <LibWeb/DOM/EventTarget.h> #include <LibWeb/DOM/Window.h> #include <LibWeb/HTML/EventHandler.h> +#include <LibWeb/HTML/EventNames.h> #include <LibWeb/HTML/HTMLBodyElement.h> #include <LibWeb/HTML/HTMLFrameSetElement.h> +#include <LibWeb/UIEvents/EventNames.h> namespace Web::DOM { @@ -78,6 +80,40 @@ ExceptionOr<bool> EventTarget::dispatch_event_binding(NonnullRefPtr<Event> event return dispatch_event(event); } +// https://html.spec.whatwg.org/multipage/webappapis.html#window-reflecting-body-element-event-handler-set +static bool is_window_reflecting_body_element_event_handler(FlyString const& name) +{ + return name.is_one_of( + HTML::EventNames::blur, + HTML::EventNames::error, + HTML::EventNames::focus, + HTML::EventNames::load, + UIEvents::EventNames::resize, + "scroll"); +} + +// https://html.spec.whatwg.org/multipage/webappapis.html#windoweventhandlers +static bool is_window_event_handler(FlyString const& name) +{ + return name.is_one_of( + HTML::EventNames::afterprint, + HTML::EventNames::beforeprint, + HTML::EventNames::beforeunload, + HTML::EventNames::hashchange, + HTML::EventNames::languagechange, + HTML::EventNames::message, + HTML::EventNames::messageerror, + HTML::EventNames::offline, + HTML::EventNames::online, + HTML::EventNames::pagehide, + HTML::EventNames::pageshow, + HTML::EventNames::popstate, + HTML::EventNames::rejectionhandled, + HTML::EventNames::storage, + HTML::EventNames::unhandledrejection, + HTML::EventNames::unload); +} + // https://html.spec.whatwg.org/multipage/webappapis.html#determining-the-target-of-an-event-handler static EventTarget* determine_target_of_event_handler(EventTarget& event_target, FlyString const& name) { @@ -90,9 +126,10 @@ static EventTarget* determine_target_of_event_handler(EventTarget& event_target, auto& event_target_element = static_cast<HTML::HTMLElement&>(event_target); - // FIXME: 2. If name is not the name of an attribute member of the WindowEventHandlers interface mixin and the Window-reflecting - // body element event handler set does not contain name, then return eventTarget. - (void)name; + // 2. If name is not the name of an attribute member of the WindowEventHandlers interface mixin and the Window-reflecting + // body element event handler set does not contain name, then return eventTarget. + if (!is_window_event_handler(name) && !is_window_reflecting_body_element_event_handler(name)) + return &event_target; // 3. If eventTarget's node document is not an active document, then return null. if (!event_target_element.document().is_active()) |