LibWeb: Set user activation when this is Document
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

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 committed by Andrew Kaster
parent 87f6a11e47
commit 55483b0096
Notes: github-actions[bot] 2025-04-13 16:37:34 +00:00

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();
}
}
}