summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-02-06 19:28:09 +0100
committerAndreas Kling <kling@serenityos.org>2022-02-06 22:13:13 +0100
commit3e6aaa3520168a93927b0df38b50653803c85810 (patch)
tree1eafcb5cb641bb9938edab5668b4381fc4e05ba6 /Userland
parent2666cb7b01543d07c745038db1c5a510f65b383f (diff)
downloadserenity-3e6aaa3520168a93927b0df38b50653803c85810.zip
LibWeb: Update focus target when handling mousedown events
If the mousedown event hits something with is_focusable()==true, we now update the document's focused element *instead* of placing the text cursor at the focusable element. This allows you to begin editing input elements by clicking them. This feels very hackish and we'll need to come up with something nicer.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/Page/EventHandler.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp
index f0b13d8424..fe9301f2c6 100644
--- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp
@@ -266,9 +266,24 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
if (button == GUI::MouseButton::Primary) {
auto result = layout_root()->hit_test(position, Layout::HitTestType::TextCursor);
if (result.layout_node && result.layout_node->dom_node()) {
- m_browsing_context.set_cursor_position(DOM::Position(*result.layout_node->dom_node(), result.index_in_node));
- layout_root()->set_selection({ { result.layout_node, result.index_in_node }, {} });
- m_in_mouse_selection = true;
+
+ // See if we want to focus something.
+ 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()));
+ did_focus_something = true;
+ break;
+ }
+ }
+
+ // If we didn't focus anything, place the document text cursor at the mouse position.
+ // FIXME: This is all rather strange. Find a better solution.
+ if (!did_focus_something) {
+ m_browsing_context.set_cursor_position(DOM::Position(*result.layout_node->dom_node(), result.index_in_node));
+ layout_root()->set_selection({ { result.layout_node, result.index_in_node }, {} });
+ m_in_mouse_selection = true;
+ }
}
} else if (button == GUI::MouseButton::Secondary) {
if (auto* page = m_browsing_context.page())