From 90879a07ba6ab3cf61c52b3d601f1ed5052b807c Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 29 Feb 2024 10:35:25 +0100 Subject: [PATCH] LibWeb: Skip page scrolling for wheel events consumed by scrollable box Fixes the bug when we scroll both scrollable box and page. --- ...lable-should-not-be-propagated-to-body.txt | 2 ++ ...able-should-not-be-propagated-to-body.html | 32 +++++++++++++++++++ .../Libraries/LibWeb/Page/EventHandler.cpp | 7 ++-- 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/wheel-events-consumed-by-scrollable-should-not-be-propagated-to-body.txt create mode 100644 Tests/LibWeb/Text/input/wheel-events-consumed-by-scrollable-should-not-be-propagated-to-body.html diff --git a/Tests/LibWeb/Text/expected/wheel-events-consumed-by-scrollable-should-not-be-propagated-to-body.txt b/Tests/LibWeb/Text/expected/wheel-events-consumed-by-scrollable-should-not-be-propagated-to-body.txt new file mode 100644 index 00000000000..0f9ff1f8450 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wheel-events-consumed-by-scrollable-should-not-be-propagated-to-body.txt @@ -0,0 +1,2 @@ + scrollable.scrollTop: 100 +window.scrollY: 0 diff --git a/Tests/LibWeb/Text/input/wheel-events-consumed-by-scrollable-should-not-be-propagated-to-body.html b/Tests/LibWeb/Text/input/wheel-events-consumed-by-scrollable-should-not-be-propagated-to-body.html new file mode 100644 index 00000000000..9d4a3e80b1d --- /dev/null +++ b/Tests/LibWeb/Text/input/wheel-events-consumed-by-scrollable-should-not-be-propagated-to-body.html @@ -0,0 +1,32 @@ + + + + +
+ diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index 87bba02d696..bb096e1c724 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -174,10 +174,9 @@ bool EventHandler::handle_mousewheel(CSSPixelPoint position, CSSPixelPoint scree if (paintable) { auto* containing_block = paintable->containing_block(); while (containing_block) { - if (containing_block->is_user_scrollable()) { - const_cast(containing_block->paintable_box())->handle_mousewheel({}, position, buttons, modifiers, wheel_delta_x, wheel_delta_y); - break; - } + auto handled_scroll_event = const_cast(containing_block->paintable_box())->handle_mousewheel({}, position, buttons, modifiers, wheel_delta_x, wheel_delta_y); + if (handled_scroll_event) + return true; containing_block = containing_block->containing_block(); }