summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2022-11-21 10:24:59 -0500
committerAndreas Kling <kling@serenityos.org>2022-12-26 09:27:19 +0100
commit5b02e6a46b8349babcb54c2363484232fbef0b30 (patch)
tree1e240252c72dc7697ec8bc1a93fdc1c7557515a6 /Userland/Libraries/LibGUI
parenta969eac848250b830775efb513f99f66f358f091 (diff)
downloadserenity-5b02e6a46b8349babcb54c2363484232fbef0b30.zip
LibGUI: Handle Enter+Leave events for automatic cursor trackers
Previously, automatic cursor tracking widgets consumed all mouse events but did not update their own hover state while active, meaning Enter and Leave events were not being dispatched. Fixes TextEditor's automatic selection scroll timer failing to stop and start while autotracking. Its manual workaround in mousedown is no longer needed.
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp1
-rw-r--r--Userland/Libraries/LibGUI/Window.cpp19
2 files changed, 12 insertions, 8 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index d018a1615e..d0bccc4eb9 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -280,7 +280,6 @@ void TextEditor::mousedown_event(MouseEvent& event)
}
m_in_drag_select = true;
- m_automatic_selection_scroll_timer->start();
set_cursor(text_position_at(event.position()));
diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp
index da83186297..44a43ecf44 100644
--- a/Userland/Libraries/LibGUI/Window.cpp
+++ b/Userland/Libraries/LibGUI/Window.cpp
@@ -370,23 +370,28 @@ void Window::handle_drop_event(DropEvent& event)
void Window::handle_mouse_event(MouseEvent& event)
{
+ if (!m_main_widget)
+ return;
+ auto result = m_main_widget->hit_test(event.position());
+ VERIFY(result.widget);
+
if (m_automatic_cursor_tracking_widget) {
auto window_relative_rect = m_automatic_cursor_tracking_widget->window_relative_rect();
Gfx::IntPoint local_point { event.x() - window_relative_rect.x(), event.y() - window_relative_rect.y() };
auto local_event = MouseEvent((Event::Type)event.type(), local_point, event.buttons(), event.button(), event.modifiers(), event.wheel_delta_x(), event.wheel_delta_y(), event.wheel_raw_delta_x(), event.wheel_raw_delta_y());
m_automatic_cursor_tracking_widget->dispatch_event(local_event, this);
- if (event.buttons() == 0)
+ if (event.buttons() == 0) {
m_automatic_cursor_tracking_widget = nullptr;
- return;
+ } else {
+ auto is_hovered = m_automatic_cursor_tracking_widget.ptr() == result.widget.ptr();
+ set_hovered_widget(is_hovered ? m_automatic_cursor_tracking_widget.ptr() : nullptr);
+ return;
+ }
}
- if (!m_main_widget)
- return;
- auto result = m_main_widget->hit_test(event.position());
- auto local_event = MouseEvent((Event::Type)event.type(), result.local_position, event.buttons(), event.button(), event.modifiers(), event.wheel_delta_x(), event.wheel_delta_y(), event.wheel_raw_delta_x(), event.wheel_raw_delta_y());
- VERIFY(result.widget);
set_hovered_widget(result.widget);
if (event.buttons() != 0 && !m_automatic_cursor_tracking_widget)
m_automatic_cursor_tracking_widget = *result.widget;
+ auto local_event = MouseEvent((Event::Type)event.type(), result.local_position, event.buttons(), event.button(), event.modifiers(), event.wheel_delta_x(), event.wheel_delta_y(), event.wheel_raw_delta_x(), event.wheel_raw_delta_y());
result.widget->dispatch_event(local_event, this);
}