From a4c331c199d03a888e3a9a0c1ad561d6e89a9ae5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 30 Jan 2025 15:54:14 +0100 Subject: [PATCH] LibWeb: Fix unnecessary wheel event consumption with `overflow: scroll` Allow wheel event to be consumed by a `overflow: scroll` box only if it has content that overflows a scrollport. This fixes the timing issue in the `Text/input/scroll-window-using-wheel-event.html` test, where a `` element with `overflow: scroll` was incorrectly consuming wheel events that should have propagated to the window. --- Libraries/LibWeb/Painting/PaintableBox.cpp | 16 ++++-- ...low-scroll-without-scrollable-overflow.txt | 1 + ...ow-scroll-without-scrollable-overflow.html | 51 +++++++++++++++++++ 3 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/scroll-by-dispatching-wheel-event-on-overflow-scroll-without-scrollable-overflow.txt create mode 100644 Tests/LibWeb/Text/input/scroll-by-dispatching-wheel-event-on-overflow-scroll-without-scrollable-overflow.html diff --git a/Libraries/LibWeb/Painting/PaintableBox.cpp b/Libraries/LibWeb/Painting/PaintableBox.cpp index 9055a09c5b1..30e6623363e 100644 --- a/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -343,9 +343,10 @@ bool PaintableBox::could_be_scrolled_by_wheel_event(ScrollDirection direction) c return false; auto scrollable_overflow_size = direction == ScrollDirection::Horizontal ? scrollable_overflow_rect->width() : scrollable_overflow_rect->height(); auto scrollport_size = direction == ScrollDirection::Horizontal ? absolute_padding_box_rect().width() : absolute_padding_box_rect().height(); - if ((is_viewport() && overflow != CSS::Overflow::Hidden) || overflow == CSS::Overflow::Auto) + auto overflow_value_allows_scrolling = overflow == CSS::Overflow::Auto || overflow == CSS::Overflow::Scroll; + if ((is_viewport() && overflow != CSS::Overflow::Hidden) || overflow_value_allows_scrolling) return scrollable_overflow_size > scrollport_size; - return overflow == CSS::Overflow::Scroll; + return false; } bool PaintableBox::could_be_scrolled_by_wheel_event() const @@ -375,7 +376,14 @@ Optional PaintableBox::scroll_thumb_rect(ScrollDirection direction Optional PaintableBox::compute_scrollbar_data(ScrollDirection direction) const { - if (!could_be_scrolled_by_wheel_event(direction)) { + bool is_horizontal = direction == ScrollDirection::Horizontal; + bool display_scrollbar = could_be_scrolled_by_wheel_event(direction); + if (is_horizontal) { + display_scrollbar |= computed_values().overflow_x() == CSS::Overflow::Scroll; + } else { + display_scrollbar |= computed_values().overflow_y() == CSS::Overflow::Scroll; + } + if (!display_scrollbar) { return {}; } @@ -383,8 +391,6 @@ 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 = is_horizontal ? scrollable_overflow_rect.width() : scrollable_overflow_rect.height(); diff --git a/Tests/LibWeb/Text/expected/scroll-by-dispatching-wheel-event-on-overflow-scroll-without-scrollable-overflow.txt b/Tests/LibWeb/Text/expected/scroll-by-dispatching-wheel-event-on-overflow-scroll-without-scrollable-overflow.txt new file mode 100644 index 00000000000..e8611e5bd57 --- /dev/null +++ b/Tests/LibWeb/Text/expected/scroll-by-dispatching-wheel-event-on-overflow-scroll-without-scrollable-overflow.txt @@ -0,0 +1 @@ +new scrollY: 100 diff --git a/Tests/LibWeb/Text/input/scroll-by-dispatching-wheel-event-on-overflow-scroll-without-scrollable-overflow.html b/Tests/LibWeb/Text/input/scroll-by-dispatching-wheel-event-on-overflow-scroll-without-scrollable-overflow.html new file mode 100644 index 00000000000..be70e754699 --- /dev/null +++ b/Tests/LibWeb/Text/input/scroll-by-dispatching-wheel-event-on-overflow-scroll-without-scrollable-overflow.html @@ -0,0 +1,51 @@ + + + + + + + +
+
Box 1
+
Box 2
+
Box 3
+
Box 4
+
Box 5
+
Box 6
+
Box 7
+
Box 8
+
+ + + \ No newline at end of file