1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:57:44 +00:00

LibWeb: Use the focus steps instead of set_focused_element on user click

This makes clicking properly fire focus/blur events alongside setting
the focused element.
This commit is contained in:
Luke Wilde 2022-11-05 14:34:24 +00:00 committed by Andreas Kling
parent 547e006a12
commit a10204133a

View file

@ -9,6 +9,7 @@
#include <LibWeb/DOM/Range.h>
#include <LibWeb/DOM/Text.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/Focus.h>
#include <LibWeb/HTML/HTMLAnchorElement.h>
#include <LibWeb/HTML/HTMLIFrameElement.h>
#include <LibWeb/HTML/HTMLImageElement.h>
@ -382,7 +383,9 @@ bool EventHandler::handle_mousedown(Gfx::IntPoint const& position, unsigned butt
bool did_focus_something = false;
for (auto candidate = node; candidate; candidate = candidate->parent()) {
if (candidate->is_focusable()) {
document->set_focused_element(verify_cast<DOM::Element>(candidate.ptr()));
// When a user activates a click focusable focusable area, the user agent must run the focusing steps on the focusable area with focus trigger set to "click".
// Spec Note: Note that focusing is not an activation behavior, i.e. calling the click() method on an element or dispatching a synthetic click event on it won't cause the element to get focused.
HTML::run_focusing_steps(candidate.ptr(), nullptr, "click"sv);
did_focus_something = true;
break;
}