浏览代码

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.
Nico Weber 4 年之前
父节点
当前提交
98dd034c29
共有 2 个文件被更改,包括 11 次插入3 次删除
  1. 10 2
      Libraries/LibGUI/ScrollBar.cpp
  2. 1 1
      Libraries/LibGUI/ScrollBar.h

+ 10 - 2
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();

+ 1 - 1
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 };