From 8cfe51cef44560b3b8f93b9d15b8c0b0b9934c47 Mon Sep 17 00:00:00 2001 From: ronak69 Date: Wed, 25 Sep 2024 17:37:44 +0000 Subject: [PATCH] LibWeb: Make horizontal scrollbar start from the left edge of viewport Horizontal scrollbar has to leave space at right edge for the vertical scrollbar to fully extend from top-to-bottom edge of viewport. Before, this was done by just moving it leftward beyond the edge of viewport. Now, it gets scaled down appropriately to fit between left edge of viewport & vertical scrollbar without clipping. --- .../LibWeb/Painting/PaintableBox.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 7c1d840be16..a6f15805b91 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -280,25 +280,28 @@ Optional PaintableBox::compute_scrollbar_data(Scrol return {}; } + bool is_horizontal = direction == ScrollDirection::Horizontal; + auto padding_rect = absolute_padding_box_rect(); auto scrollable_overflow_rect = this->scrollable_overflow_rect().value(); - auto scroll_overflow_size = direction == ScrollDirection::Horizontal ? scrollable_overflow_rect.width() : scrollable_overflow_rect.height(); - auto scrollport_size = direction == ScrollDirection::Horizontal ? padding_rect.width() : padding_rect.height(); + auto scroll_overflow_size = is_horizontal ? scrollable_overflow_rect.width() : scrollable_overflow_rect.height(); + auto scrollport_size = is_horizontal ? padding_rect.width() : padding_rect.height(); if (scroll_overflow_size == 0) return {}; - auto min_thumb_length = min(scrollport_size, 24); - auto thumb_length = max(scrollport_size * (scrollport_size / scroll_overflow_size), min_thumb_length); + auto scrollbar_rect_length = is_horizontal ? scrollport_size - scrollbar_thumb_thickness : scrollport_size; + + auto min_thumb_length = min(scrollbar_rect_length, 24); + auto thumb_length = max(scrollbar_rect_length * (scrollport_size / scroll_overflow_size), min_thumb_length); CSSPixelFraction scroll_size = 0; if (scroll_overflow_size > scrollport_size) - scroll_size = (scrollport_size - thumb_length) / (scroll_overflow_size - scrollport_size); + scroll_size = (scrollbar_rect_length - thumb_length) / (scroll_overflow_size - scrollport_size); CSSPixelRect rect; - if (direction == ScrollDirection::Vertical) { + if (is_horizontal) + rect = { padding_rect.left(), padding_rect.bottom() - scrollbar_thumb_thickness, thumb_length, scrollbar_thumb_thickness }; + else rect = { padding_rect.right() - scrollbar_thumb_thickness, padding_rect.top(), scrollbar_thumb_thickness, thumb_length }; - } else { - rect = { padding_rect.left() - scrollbar_thumb_thickness, padding_rect.bottom() - scrollbar_thumb_thickness, thumb_length, scrollbar_thumb_thickness }; - } return PaintableBox::ScrollbarData { rect, scroll_size }; }