From 2fc8fdf3817a4e94e760a1c5a68bcc329316c82d Mon Sep 17 00:00:00 2001 From: Simon Farre Date: Sun, 13 Apr 2025 16:22:15 +0200 Subject: [PATCH] LibWeb: Set user activation when `this` is `Document` EventTarget::dispatch_event, per comments, does ad-hoc solution for UA, and I don't know why it checks if `this` is window or `element`, but web platform tests would fail, because `this` would actually be a `Document` type. --- Libraries/LibWeb/DOM/EventTarget.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Libraries/LibWeb/DOM/EventTarget.cpp b/Libraries/LibWeb/DOM/EventTarget.cpp index b37bf0a415f..596b7cf3aec 100644 --- a/Libraries/LibWeb/DOM/EventTarget.cpp +++ b/Libraries/LibWeb/DOM/EventTarget.cpp @@ -859,16 +859,22 @@ bool EventTarget::dispatch_event(Event& event) auto unsafe_shared_time = HighResolutionTime::unsafe_shared_current_time(); auto current_time = HighResolutionTime::relative_high_resolution_time(unsafe_shared_time, realm().global_object()); - if (is(this)) { - auto* window = static_cast(this); + GC::Ptr window = [&]() { + if (is(this)) + return GC::Ptr { static_cast(this) }; + + if (is(this)) + return static_cast(this)->document().window(); + + if (is(this)) + return static_cast(this)->window(); + + return GC::Ptr { nullptr }; + }(); + + if (window) { window->set_last_activation_timestamp(current_time); window->close_watcher_manager()->notify_about_user_activation(); - } else if (is(this)) { - auto const* element = static_cast(this); - if (auto window = element->document().window()) { - window->set_last_activation_timestamp(current_time); - window->close_watcher_manager()->notify_about_user_activation(); - } } }