Commit e6c995f7 authored by Ana Salazar's avatar Ana Salazar Committed by Commit Bot

Cros: Allow scroll with mousewheel over shelf

This change will allow users to use the mousewheel to scroll over
the contents of the scrollable shelf.

Bug: 1018016
Change-Id: I949eb241a74be365b0a366f56c59cba04ce6099b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1901354Reviewed-by: default avatarManu Cornet <manucornet@chromium.org>
Commit-Queue: Ana Salazar <anasalazar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713271}
parent 745a9ac2
......@@ -1153,7 +1153,16 @@ void ScrollableShelfView::HandleMouseWheelEvent(ui::MouseWheelEvent* event) {
return;
if (GetShelf()->IsHorizontalAlignment()) {
ScrollByXOffset(CalculatePageScrollingOffset(event->x_offset() < 0),
const float x_offset = event->x_offset();
const float y_offset = event->y_offset();
// If the shelf is bottom aligned, we can scroll over the shelf contents if
// the scroll is horizontal or vertical (in the case of a mousewheel
// scroll). We take the biggest offset difference of the vertical and
// horizontal components to determine the offset to scroll over the
// contents.
float max_absolute_offset =
abs(x_offset) > abs(y_offset) ? x_offset : y_offset;
ScrollByXOffset(CalculatePageScrollingOffset(max_absolute_offset < 0),
/*animating=*/true);
} else {
ScrollByYOffset(CalculatePageScrollingOffset(event->y_offset() < 0),
......
......@@ -467,4 +467,41 @@ TEST_F(ScrollableShelfViewTest, CorrectUIInTabletWithoutOverflow) {
EXPECT_EQ(hotseat_background.right() - 4, last_tappable_view_bounds.right());
}
// Verifies that doing a mousewheel scroll on the scrollable shelf does scroll
// forward.
TEST_F(ScrollableShelfViewTest, ScrollWithMouseWheel) {
// The scroll threshold. Taken from |KScrollOffsetThreshold| in
// scrollable_shelf_view.cc.
constexpr int scroll_threshold = 20;
AddAppShortcutsUntilOverflow();
ASSERT_EQ(ScrollableShelfView::kShowRightArrowButton,
scrollable_shelf_view_->layout_strategy_for_test());
// Do a mousewheel scroll with a positive offset bigger than the scroll
// threshold to scroll forward. Unlike touchpad scrolls, mousewheel scrolls
// can only be along the cross axis.
GetEventGenerator()->MoveMouseTo(
scrollable_shelf_view_->GetBoundsInScreen().CenterPoint());
GetEventGenerator()->MoveMouseWheel(0, -(scroll_threshold + 1));
ASSERT_EQ(ScrollableShelfView::kShowLeftArrowButton,
scrollable_shelf_view_->layout_strategy_for_test());
// Do a mousewheel scroll with a negative offset bigger than the scroll
// threshold to scroll backwards.
GetEventGenerator()->MoveMouseWheel(0, scroll_threshold + 1);
ASSERT_EQ(ScrollableShelfView::kShowRightArrowButton,
scrollable_shelf_view_->layout_strategy_for_test());
// Do a mousewheel scroll with an offset smaller than the scroll
// threshold should be ignored.
GetEventGenerator()->MoveMouseWheel(0, scroll_threshold);
ASSERT_EQ(ScrollableShelfView::kShowRightArrowButton,
scrollable_shelf_view_->layout_strategy_for_test());
GetEventGenerator()->MoveMouseWheel(0, -scroll_threshold);
ASSERT_EQ(ScrollableShelfView::kShowRightArrowButton,
scrollable_shelf_view_->layout_strategy_for_test());
}
} // namespace ash
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment