mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
ScrollBar: Let clicking the gutter scroll by one page
Shift-clicking has the old behavior of jumping to the click position. This matches scrollbar behavior in macOS and Windows, and in many Linux apps.
This commit is contained in:
parent
326261094d
commit
cdf1282419
Notes:
sideshowbarker
2024-07-19 03:52:22 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/cdf1282419b Pull-request: https://github.com/SerenityOS/serenity/pull/3102
2 changed files with 27 additions and 3 deletions
|
@ -189,7 +189,7 @@ bool ScrollBar::has_scrubber() const
|
|||
return m_max != m_min;
|
||||
}
|
||||
|
||||
int ScrollBar::visible_scrubber_size() const
|
||||
int ScrollBar::unclamped_scrubber_size() const
|
||||
{
|
||||
int pixel_range = length(orientation()) - button_size() * 2;
|
||||
int value_range = m_max - m_min;
|
||||
|
@ -200,7 +200,12 @@ int ScrollBar::visible_scrubber_size() const
|
|||
// (page) in relation to the content (value range + page)
|
||||
scrubber_size = (m_page * pixel_range) / (value_range + m_page);
|
||||
}
|
||||
return ::max(scrubber_size, button_size());
|
||||
return scrubber_size;
|
||||
}
|
||||
|
||||
int ScrollBar::visible_scrubber_size() const
|
||||
{
|
||||
return ::max(unclamped_scrubber_size(), button_size());
|
||||
}
|
||||
|
||||
Gfx::IntRect ScrollBar::scrubber_rect() const
|
||||
|
@ -294,7 +299,11 @@ void ScrollBar::mousedown_event(MouseEvent& event)
|
|||
return;
|
||||
}
|
||||
|
||||
scroll_to_position(event.position());
|
||||
// FIXME: If scrolling by page, scroll every second or so while mouse is down.
|
||||
if (event.shift())
|
||||
scroll_to_position(event.position());
|
||||
else
|
||||
scroll_by_page(event.position());
|
||||
|
||||
m_scrubbing = true;
|
||||
m_scrub_start_value = value();
|
||||
|
@ -330,6 +339,19 @@ void ScrollBar::set_automatic_scrolling_active(bool active)
|
|||
}
|
||||
}
|
||||
|
||||
void ScrollBar::scroll_by_page(const Gfx::IntPoint& click_position)
|
||||
{
|
||||
float range_size = m_max - m_min;
|
||||
float available = scrubbable_range_in_pixels();
|
||||
float rel_scrubber_size = unclamped_scrubber_size() / available;
|
||||
float page_increment = range_size * rel_scrubber_size;
|
||||
|
||||
if (click_position.primary_offset_for_orientation(orientation()) < scrubber_rect().primary_offset_for_orientation(orientation()))
|
||||
set_value(value() - page_increment);
|
||||
else
|
||||
set_value(value() + page_increment);
|
||||
}
|
||||
|
||||
void ScrollBar::scroll_to_position(const Gfx::IntPoint& click_position)
|
||||
{
|
||||
float range_size = m_max - m_min;
|
||||
|
|
|
@ -87,12 +87,14 @@ private:
|
|||
Gfx::IntRect decrement_gutter_rect() const;
|
||||
Gfx::IntRect increment_gutter_rect() const;
|
||||
Gfx::IntRect scrubber_rect() const;
|
||||
int unclamped_scrubber_size() const;
|
||||
int visible_scrubber_size() const;
|
||||
int scrubbable_range_in_pixels() const;
|
||||
void on_automatic_scrolling_timer_fired();
|
||||
void set_automatic_scrolling_active(bool);
|
||||
|
||||
void scroll_to_position(const Gfx::IntPoint&);
|
||||
void scroll_by_page(const Gfx::IntPoint&);
|
||||
|
||||
int m_min { 0 };
|
||||
int m_max { 0 };
|
||||
|
|
Loading…
Add table
Reference in a new issue