From 98dd034c2926c61b4fae47172a89b4e68a6eb43c Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 25 Aug 2020 11:14:45 -0400 Subject: [PATCH] LibGUI: Make scrollbars keep scrolling by page while clicking the gutter Note that m_hovered_component is only updated on mouse move, not while just keeping left down. It's arguably wrong to update it on mouse move while the mouse is down, I'll probably change things so that it doesn't update there either. The behavior on click-in-gutter-keep-left-down-then-move-mouse varies a surprising amount between platforms. This implements the macOS behavior where the scrubber follows the mouse direction while scrolling by pages. (To be precise, it's the macOS behavior of Finder and Preview, Safari has Windows's scrollbar behavior). On Windows, the first click locks in the scroll direction and then dragging the mouse off the scrubber in that direction makes the scroll continue, but dragging it off the other direction has no effect. I see no reason for that behavior. --- Libraries/LibGUI/ScrollBar.cpp | 12 ++++++++++-- Libraries/LibGUI/ScrollBar.h | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Libraries/LibGUI/ScrollBar.cpp b/Libraries/LibGUI/ScrollBar.cpp index d33be96876..7f95b199eb 100644 --- a/Libraries/LibGUI/ScrollBar.cpp +++ b/Libraries/LibGUI/ScrollBar.cpp @@ -269,6 +269,10 @@ void ScrollBar::on_automatic_scrolling_timer_fired() set_value(value() + m_step); return; } + if (m_automatic_scrolling_kind == AutomaticScrollingKind::Gutter && component_at_position(m_last_mouse_position) == Component::Gutter) { + scroll_by_page(m_last_mouse_position); + return; + } } void ScrollBar::mousedown_event(MouseEvent& event) @@ -308,8 +312,8 @@ void ScrollBar::mousedown_event(MouseEvent& event) ASSERT(!event.shift()); ASSERT(clicked_component == Component::Gutter); - // FIXME: If scrolling by page, scroll every second or so while mouse is down. - scroll_by_page(event.position()); + set_automatic_scrolling_active(true, AutomaticScrollingKind::Gutter); + update(); } void ScrollBar::mouseup_event(MouseEvent& event) @@ -333,6 +337,10 @@ void ScrollBar::mousewheel_event(MouseEvent& event) void ScrollBar::set_automatic_scrolling_active(bool active, AutomaticScrollingKind kind) { m_automatic_scrolling_kind = kind; + if (m_automatic_scrolling_kind == AutomaticScrollingKind::Gutter) + m_automatic_scrolling_timer->set_interval(200); + else + m_automatic_scrolling_timer->set_interval(100); if (active) { on_automatic_scrolling_timer_fired(); diff --git a/Libraries/LibGUI/ScrollBar.h b/Libraries/LibGUI/ScrollBar.h index d885f494ae..cace204c0f 100644 --- a/Libraries/LibGUI/ScrollBar.h +++ b/Libraries/LibGUI/ScrollBar.h @@ -82,6 +82,7 @@ private: None = 0, DecrementButton, IncrementButton, + Gutter, }; int default_button_size() const { return 16; } @@ -103,7 +104,6 @@ private: void scroll_by_page(const Gfx::IntPoint&); Component component_at_position(const Gfx::IntPoint&); - void update_hovered_component(const Gfx::IntPoint&); int m_min { 0 }; int m_max { 0 };