Commit 62162751 authored by Kevin Strohbehn's avatar Kevin Strohbehn Committed by Commit Bot

Simplifies Tap/Long-Press handling in AppsGridView

These events were being sent up to AppListView, then back to
AppsGridView. In reality, these events can all be handled before
letting them pass through, just based on the nearest tile.

Bug: 893216
Change-Id: I9fee2bd9be03efb54a90b07d87bcf9f1a772d6f8
Reviewed-on: https://chromium-review.googlesource.com/c/1286129
Commit-Queue: Kevin Strohbehn <ginko@google.com>
Reviewed-by: default avatarWeidong Guo <weidongg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600611}
parent 9f8a97b7
......@@ -1486,6 +1486,8 @@ TEST_F(AppListPresenterDelegateHomeLauncherTest, WallpaperContextMenu) {
GetAppListTestHelper()->CheckVisibility(true);
// Long press on the app list to open the context menu.
// TODO(ginko) look into a way to populate an apps grid, then get a point
// between these apps so that clicks/taps between apps can be tested
const gfx::Point onscreen_point(GetPointOutsideSearchbox());
ui::test::EventGenerator* generator = GetEventGenerator();
ui::GestureEvent long_press(
......
......@@ -700,13 +700,6 @@ void AppListView::HandleClickOrTap(ui::LocatedEvent* event) {
return;
}
// No-op if app list is on fullscreen all apps state and the event location is
// near an app.
if (app_list_state_ == AppListViewState::FULLSCREEN_ALL_APPS &&
GetRootAppsGridView()->IsEventNearAppIcon(*event)) {
return;
}
if (!search_box_view_->is_search_box_active()) {
if (!IsHomeLauncherEnabledInTabletMode())
Dismiss();
......
......@@ -356,6 +356,11 @@ const char* AppsContainerView::GetClassName() const {
}
void AppsContainerView::OnGestureEvent(ui::GestureEvent* event) {
// Ignore tap/long-press, allow those to pass to the ancestor view.
if (event->type() == ui::ET_GESTURE_TAP ||
event->type() == ui::ET_GESTURE_LONG_PRESS)
return;
// Will forward events to |apps_grid_view_| if they occur in the same y-region
if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN &&
event->location().y() <= apps_grid_view_->bounds().y()) {
......
......@@ -1012,6 +1012,19 @@ void AppsGridView::ViewHierarchyChanged(
}
void AppsGridView::OnGestureEvent(ui::GestureEvent* event) {
// If a tap/long-press occurs within a valid tile, it is usually a mistake and
// should not close the launcher in clamshell mode. Otherwise, we should let
// those events pass to the ancestor views.
if (!contents_view_->app_list_view()->IsHomeLauncherEnabledInTabletMode() &&
(event->type() == ui::ET_GESTURE_TAP ||
event->type() == ui::ET_GESTURE_LONG_PRESS)) {
GridIndex nearest_tile_index =
GetNearestTileIndexForPoint(event->location());
if (IsValidIndex(nearest_tile_index))
event->SetHandled();
return;
}
// Bail on STATE_START or no apps page to make PaginationModel happy.
if (contents_view_->GetActiveState() == ash::AppListState::kStateStart ||
pagination_model_.total_pages() <= 0) {
......@@ -1996,22 +2009,6 @@ bool AppsGridView::HandleScrollFromAppListView(int offset, ui::EventType type) {
return true;
}
bool AppsGridView::IsEventNearAppIcon(const ui::LocatedEvent& event) {
// Convert the event location to AppsGridView coordinates.
std::unique_ptr<ui::Event> cloned_event = ui::Event::Clone(event);
ui::LocatedEvent* cloned_located_event = cloned_event->AsLocatedEvent();
event.target()->ConvertEventToTarget(this, cloned_located_event);
const gfx::Point point_in_apps_grid_view = cloned_located_event->location();
// GetNearestTileIndexForPoint will always return a slot, even if the point is
// outside of this.
if (!bounds().Contains(point_in_apps_grid_view))
return false;
return GetViewDisplayedAtSlotOnCurrentPage(
GetNearestTileIndexForPoint(point_in_apps_grid_view).slot);
}
AppListItemView* AppsGridView::GetCurrentPageFirstItemViewInFolder() {
DCHECK(folder_delegate_);
int first_index = pagination_model_.selected_page() * kMaxFolderItemsPerPage;
......
......@@ -248,9 +248,6 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
// returns true if this scroll would change pages.
bool HandleScrollFromAppListView(int offset, ui::EventType type);
// Returns whether the event is within a slot that is occupied by an app icon.
bool IsEventNearAppIcon(const ui::LocatedEvent& event);
// Returns the first app list item view in the selected page in the folder.
AppListItemView* GetCurrentPageFirstItemViewInFolder();
......
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