mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:17:36 +00:00
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.
This commit is contained in:
parent
2666cb7b01
commit
3e6aaa3520
1 changed files with 18 additions and 3 deletions
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue