Commit 272abd85 authored by Angus L. M. McLean IV's avatar Angus L. M. McLean IV Committed by Commit Bot

Pass mouse scrolling over empty area to Shelf

Bug: 1071218
Change-Id: I79da1693562db63262084853b1d3c35cdb97518e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2537936
Commit-Queue: Angus McLean <angusmclean@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827869}
parent c8a9fc64
...@@ -1649,6 +1649,15 @@ bool ScrollableShelfView::ProcessGestureEvent(const ui::GestureEvent& event) { ...@@ -1649,6 +1649,15 @@ bool ScrollableShelfView::ProcessGestureEvent(const ui::GestureEvent& event) {
void ScrollableShelfView::HandleMouseWheelEvent(ui::MouseWheelEvent* event) { void ScrollableShelfView::HandleMouseWheelEvent(ui::MouseWheelEvent* event) {
// Note that the scrolling from touchpad is propagated as mouse wheel event. // Note that the scrolling from touchpad is propagated as mouse wheel event.
// Let the shelf handle mouse wheel events over the empty area of the shelf
// view, as these events would be ignored by the scrollable shelf view.
gfx::Point location_in_shelf_view = event->location();
View::ConvertPointToTarget(this, shelf_view_, &location_in_shelf_view);
if (!shelf_view_->LocationInsideVisibleShelfItemBounds(
location_in_shelf_view)) {
GetShelf()->ProcessMouseWheelEvent(event, false);
return;
}
if (!ShouldHandleScroll(gfx::Vector2dF(event->x_offset(), event->y_offset()), if (!ShouldHandleScroll(gfx::Vector2dF(event->x_offset(), event->y_offset()),
/*is_gesture_fling=*/false)) { /*is_gesture_fling=*/false)) {
......
...@@ -871,6 +871,55 @@ TEST_F(ScrollableShelfViewTest, RipOffShelfItem) { ...@@ -871,6 +871,55 @@ TEST_F(ScrollableShelfViewTest, RipOffShelfItem) {
} }
// Verifies that the scrollable shelf handles the mouse wheel event as expected. // Verifies that the scrollable shelf handles the mouse wheel event as expected.
TEST_F(ScrollableShelfViewTest, MouseWheelOnEmptyShelfShouldExpandAppList) {
// First mouse wheel over apps and then over empty shelf. When apps are not
// overflowing, and we mouse wheel over the app icons, the launcher should
// stay hidden. When we mouse wheel over the empty area of the shelf, the
// launcher should expand. https://crbug.com/1071218
// Add a couple of apps to start, so we have some to put the cursor over for
// testing.
AddAppShortcut();
AddAppShortcut();
int shelf_scroll_threshold =
ShelfConfig::Get()->mousewheel_scroll_offset_threshold();
GetEventGenerator()->MoveMouseTo(
scrollable_shelf_view_->GetBoundsInScreen().CenterPoint());
GetEventGenerator()->MoveMouseWheel(0, shelf_scroll_threshold + 1);
// The app list's view is lazily loaded. Since this is the first time, and we
// didn't scroll in the right spot, it shouldn't have been created yet.
EXPECT_EQ(nullptr,
Shell::Get()->app_list_controller()->presenter()->GetView());
auto empty_shelf_point = scrollable_shelf_view_->GetBoundsInScreen().origin();
empty_shelf_point.Offset(10, 10);
GetEventGenerator()->MoveMouseTo(empty_shelf_point);
GetEventGenerator()->MoveMouseWheel(0, shelf_scroll_threshold + 1);
EXPECT_EQ(AppListViewState::kPeeking, Shell::Get()
->app_list_controller()
->presenter()
->GetView()
->app_list_state());
// Scrolling again should expand to all apps.
GetEventGenerator()->MoveMouseWheel(0, shelf_scroll_threshold + 1);
EXPECT_EQ(AppListViewState::kFullscreenAllApps, Shell::Get()
->app_list_controller()
->presenter()
->GetView()
->app_list_state());
// Scrolling again will close the app list.
GetEventGenerator()->MoveMouseWheel(0, shelf_scroll_threshold + 1);
EXPECT_EQ(AppListViewState::kClosed, Shell::Get()
->app_list_controller()
->presenter()
->GetView()
->app_list_state());
}
TEST_F(ScrollableShelfViewTest, ScrollsByMouseWheelEvent) { TEST_F(ScrollableShelfViewTest, ScrollsByMouseWheelEvent) {
AddAppShortcutsUntilOverflow(); AddAppShortcutsUntilOverflow();
ASSERT_EQ(ScrollableShelfView::kShowRightArrowButton, ASSERT_EQ(ScrollableShelfView::kShowRightArrowButton,
......
...@@ -497,12 +497,16 @@ void ShelfView::AnnounceShelfItemNotificationBadge(views::View* button) { ...@@ -497,12 +497,16 @@ void ShelfView::AnnounceShelfItemNotificationBadge(views::View* button) {
/*send_native_event=*/true); /*send_native_event=*/true);
} }
bool ShelfView::LocationInsideVisibleShelfItemBounds(
const gfx::Point& location) const {
return visible_shelf_item_bounds_union_.Contains(location);
}
bool ShelfView::ShouldHideTooltip(const gfx::Point& cursor_location) const { bool ShelfView::ShouldHideTooltip(const gfx::Point& cursor_location) const {
// There are thin gaps between launcher buttons but the tooltip shouldn't hide // There are thin gaps between launcher buttons but the tooltip shouldn't hide
// in the gaps, but the tooltip should hide if the mouse moved totally outside // in the gaps, but the tooltip should hide if the mouse moved totally outside
// of the buttons area. // of the buttons area.
return !LocationInsideVisibleShelfItemBounds(cursor_location);
return !visible_shelf_item_bounds_union_.Contains(cursor_location);
} }
const std::vector<aura::Window*> ShelfView::GetOpenWindowsForView( const std::vector<aura::Window*> ShelfView::GetOpenWindowsForView(
......
...@@ -117,6 +117,10 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView, ...@@ -117,6 +117,10 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
// for showing tooltips without stuttering over gaps. // for showing tooltips without stuttering over gaps.
void UpdateVisibleShelfItemBoundsUnion(); void UpdateVisibleShelfItemBoundsUnion();
// Returns true if the given location is within the bounds of all visiable app
// icons. Used for tool tip visibility and scrolling event propogation.
bool LocationInsideVisibleShelfItemBounds(const gfx::Point& location) const;
// ShelfTooltipDelegate: // ShelfTooltipDelegate:
bool ShouldShowTooltipForView(const views::View* view) const override; bool ShouldShowTooltipForView(const views::View* view) const override;
bool ShouldHideTooltip(const gfx::Point& cursor_location) const override; bool ShouldHideTooltip(const gfx::Point& cursor_location) const override;
......
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