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.
This commit is contained in:
Simon Farre 2025-04-13 16:22:15 +02:00
parent d8cb5fc788
commit 2fc8fdf381

View file

@ -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<HTML::Window>(this)) {
auto* window = static_cast<HTML::Window*>(this);
GC::Ptr<HTML::Window> window = [&]() {
if (is<HTML::Window>(this))
return GC::Ptr { static_cast<HTML::Window*>(this) };
if (is<DOM::Element>(this))
return static_cast<DOM::Element const*>(this)->document().window();
if (is<DOM::Document>(this))
return static_cast<DOM::Document const*>(this)->window();
return GC::Ptr<HTML::Window> { nullptr };
}();
if (window) {
window->set_last_activation_timestamp(current_time);
window->close_watcher_manager()->notify_about_user_activation();
} else if (is<DOM::Element>(this)) {
auto const* element = static_cast<DOM::Element const*>(this);
if (auto window = element->document().window()) {
window->set_last_activation_timestamp(current_time);
window->close_watcher_manager()->notify_about_user_activation();
}
}
}