mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb: Introduce variable dom_node
in EventHandler::handle_mousedown
to make the code more readable
This commit is contained in:
parent
dda7325358
commit
a2e4259099
Notes:
github-actions[bot]
2024-08-23 08:32:02 +00:00
Author: https://github.com/simonkrauter Commit: https://github.com/LadybirdBrowser/ladybird/commit/a2e42590990 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1125 Reviewed-by: https://github.com/AtkinsSJ
1 changed files with 6 additions and 5 deletions
|
@ -430,7 +430,8 @@ bool EventHandler::handle_mousedown(CSSPixelPoint viewport_position, CSSPixelPoi
|
||||||
if (button == UIEvents::MouseButton::Primary) {
|
if (button == UIEvents::MouseButton::Primary) {
|
||||||
if (auto result = paint_root()->hit_test(position, Painting::HitTestType::TextCursor); result.has_value()) {
|
if (auto result = paint_root()->hit_test(position, Painting::HitTestType::TextCursor); result.has_value()) {
|
||||||
auto paintable = result->paintable;
|
auto paintable = result->paintable;
|
||||||
if (paintable->dom_node()) {
|
auto dom_node = paintable->dom_node();
|
||||||
|
if (dom_node) {
|
||||||
// See if we want to focus something.
|
// See if we want to focus something.
|
||||||
bool did_focus_something = false;
|
bool did_focus_something = false;
|
||||||
for (auto candidate = node; candidate; candidate = candidate->parent_or_shadow_host()) {
|
for (auto candidate = node; candidate; candidate = candidate->parent_or_shadow_host()) {
|
||||||
|
@ -450,15 +451,15 @@ bool EventHandler::handle_mousedown(CSSPixelPoint viewport_position, CSSPixelPoi
|
||||||
|
|
||||||
// If we didn't focus anything, place the document text cursor at the mouse position.
|
// 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.
|
// FIXME: This is all rather strange. Find a better solution.
|
||||||
if (!did_focus_something || paintable->dom_node()->is_editable()) {
|
if (!did_focus_something || dom_node->is_editable()) {
|
||||||
auto& realm = document->realm();
|
auto& realm = document->realm();
|
||||||
document->set_cursor_position(DOM::Position::create(realm, *paintable->dom_node(), result->index_in_node));
|
document->set_cursor_position(DOM::Position::create(realm, *dom_node, result->index_in_node));
|
||||||
if (auto selection = document->get_selection()) {
|
if (auto selection = document->get_selection()) {
|
||||||
auto anchor_node = selection->anchor_node();
|
auto anchor_node = selection->anchor_node();
|
||||||
if (anchor_node && modifiers & UIEvents::KeyModifier::Mod_Shift) {
|
if (anchor_node && modifiers & UIEvents::KeyModifier::Mod_Shift) {
|
||||||
(void)selection->set_base_and_extent(*anchor_node, selection->anchor_offset(), *paintable->dom_node(), result->index_in_node);
|
(void)selection->set_base_and_extent(*anchor_node, selection->anchor_offset(), *dom_node, result->index_in_node);
|
||||||
} else {
|
} else {
|
||||||
(void)selection->set_base_and_extent(*paintable->dom_node(), result->index_in_node, *paintable->dom_node(), result->index_in_node);
|
(void)selection->set_base_and_extent(*dom_node, result->index_in_node, *dom_node, result->index_in_node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_in_mouse_selection = true;
|
m_in_mouse_selection = true;
|
||||||
|
|
Loading…
Reference in a new issue