Commit eb4b0458 authored by Alex Newcomer's avatar Alex Newcomer Committed by Commit Bot

cros: Show context menu between gaps in apps in homecher mode.

Show a context menu between apps in homecher-tablet mode.
Don't show a menu between apps in laptop mode.

Bug: 869623
Change-Id: Idfb8f5d970f7716397ec42769b0e6a8f4473acb1
Reviewed-on: https://chromium-review.googlesource.com/1180249
Commit-Queue: Alex Newcomer <newcomer@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584786}
parent c21e382a
...@@ -82,6 +82,12 @@ void AppListTestViewDelegate::GetContextMenuModel( ...@@ -82,6 +82,12 @@ void AppListTestViewDelegate::GetContextMenuModel(
std::move(callback).Run(ash::menu_utils::GetMojoMenuItemsFromModel(menu)); std::move(callback).Run(ash::menu_utils::GetMojoMenuItemsFromModel(menu));
} }
void AppListTestViewDelegate::ShowWallpaperContextMenu(
const gfx::Point& onscreen_location,
ui::MenuSourceType source_type) {
++show_wallpaper_context_menu_count_;
}
void AppListTestViewDelegate::GetSearchResultContextMenuModel( void AppListTestViewDelegate::GetSearchResultContextMenuModel(
const std::string& result_id, const std::string& result_id,
GetContextMenuModelCallback callback) { GetContextMenuModelCallback callback) {
......
...@@ -32,11 +32,14 @@ class AppListTestViewDelegate : public AppListViewDelegate, ...@@ -32,11 +32,14 @@ class AppListTestViewDelegate : public AppListViewDelegate,
AppListTestViewDelegate(); AppListTestViewDelegate();
~AppListTestViewDelegate() override; ~AppListTestViewDelegate() override;
int dismiss_count() { return dismiss_count_; } int dismiss_count() const { return dismiss_count_; }
int open_search_result_count() { return open_search_result_count_; } int open_search_result_count() const { return open_search_result_count_; }
std::map<size_t, int>& open_search_result_counts() { std::map<size_t, int>& open_search_result_counts() {
return open_search_result_counts_; return open_search_result_counts_;
} }
int show_wallpaper_context_menu_count() const {
return show_wallpaper_context_menu_count_;
}
// Sets the number of apps that the model will be created with the next time // Sets the number of apps that the model will be created with the next time
// SetProfileByPath() is called. // SetProfileByPath() is called.
...@@ -72,7 +75,7 @@ class AppListTestViewDelegate : public AppListViewDelegate, ...@@ -72,7 +75,7 @@ class AppListTestViewDelegate : public AppListViewDelegate,
int command_id, int command_id,
int event_flags) override {} int event_flags) override {}
void ShowWallpaperContextMenu(const gfx::Point& onscreen_location, void ShowWallpaperContextMenu(const gfx::Point& onscreen_location,
ui::MenuSourceType source_type) override {} ui::MenuSourceType source_type) override;
// Do a bulk replacement of the items in the model. // Do a bulk replacement of the items in the model.
void ReplaceTestModel(int item_count); void ReplaceTestModel(int item_count);
...@@ -89,6 +92,7 @@ class AppListTestViewDelegate : public AppListViewDelegate, ...@@ -89,6 +92,7 @@ class AppListTestViewDelegate : public AppListViewDelegate,
int dismiss_count_ = 0; int dismiss_count_ = 0;
int open_search_result_count_ = 0; int open_search_result_count_ = 0;
int next_profile_app_count_ = 0; int next_profile_app_count_ = 0;
int show_wallpaper_context_menu_count_ = 0;
std::map<size_t, int> open_search_result_counts_; std::map<size_t, int> open_search_result_counts_;
std::unique_ptr<AppListTestModel> model_; std::unique_ptr<AppListTestModel> model_;
std::unique_ptr<SearchModel> search_model_; std::unique_ptr<SearchModel> search_model_;
......
...@@ -611,13 +611,6 @@ void AppListView::HandleClickOrTap(ui::LocatedEvent* event) { ...@@ -611,13 +611,6 @@ void AppListView::HandleClickOrTap(ui::LocatedEvent* event) {
// Clear focus if the located event is not handled by any child view. // Clear focus if the located event is not handled by any child view.
GetFocusManager()->ClearFocus(); GetFocusManager()->ClearFocus();
// 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 (GetAppsContainerView()->IsInFolderView()) { if (GetAppsContainerView()->IsInFolderView()) {
// Close the folder if it is opened. // Close the folder if it is opened.
GetAppsContainerView()->app_list_folder_view()->CloseFolderPage(); GetAppsContainerView()->app_list_folder_view()->CloseFolderPage();
...@@ -630,6 +623,7 @@ void AppListView::HandleClickOrTap(ui::LocatedEvent* event) { ...@@ -630,6 +623,7 @@ void AppListView::HandleClickOrTap(ui::LocatedEvent* event) {
event->AsGestureEvent()->type() == ui::ET_GESTURE_TWO_FINGER_TAP)) || event->AsGestureEvent()->type() == ui::ET_GESTURE_TWO_FINGER_TAP)) ||
(event->IsMouseEvent() && (event->IsMouseEvent() &&
event->AsMouseEvent()->IsOnlyRightMouseButton())) { event->AsMouseEvent()->IsOnlyRightMouseButton())) {
// Don't show menus on empty areas of the AppListView in clamshell mode.
if (!IsHomeLauncherEnabledInTabletMode()) if (!IsHomeLauncherEnabledInTabletMode())
return; return;
...@@ -643,6 +637,13 @@ void AppListView::HandleClickOrTap(ui::LocatedEvent* event) { ...@@ -643,6 +637,13 @@ void AppListView::HandleClickOrTap(ui::LocatedEvent* event) {
return; 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 (!search_box_view_->is_search_box_active()) {
if (!IsHomeLauncherEnabledInTabletMode()) if (!IsHomeLauncherEnabledInTabletMode())
Dismiss(); Dismiss();
......
...@@ -209,6 +209,20 @@ class AppListViewTest : public views::ViewsTestBase, ...@@ -209,6 +209,20 @@ class AppListViewTest : public views::ViewsTestBase,
return contents_view()->GetAppsContainerView()->apps_grid_view(); return contents_view()->GetAppsContainerView()->apps_grid_view();
} }
gfx::Point GetPointBetweenTwoApps() {
const views::ViewModelT<AppListItemView>* view_model =
apps_grid_view()->view_model();
const gfx::Rect bounds_1 = view_model->view_at(0)->GetBoundsInScreen();
const gfx::Rect bounds_2 = view_model->view_at(1)->GetBoundsInScreen();
return gfx::Point(bounds_1.right() + (bounds_2.x() - bounds_1.right()) / 2,
bounds_1.y());
}
int show_wallpaper_context_menu_count() {
return delegate_->show_wallpaper_context_menu_count();
}
AppListView* view_ = nullptr; // Owned by native widget. AppListView* view_ = nullptr; // Owned by native widget.
std::unique_ptr<AppListTestViewDelegate> delegate_; std::unique_ptr<AppListTestViewDelegate> delegate_;
std::unique_ptr<AppsGridViewTestApi> test_api_; std::unique_ptr<AppsGridViewTestApi> test_api_;
...@@ -2023,6 +2037,60 @@ TEST_F(AppListViewTest, DISABLED_MultiplePagesReinitializeOnInputPage) { ...@@ -2023,6 +2037,60 @@ TEST_F(AppListViewTest, DISABLED_MultiplePagesReinitializeOnInputPage) {
ASSERT_EQ(1, view_->GetAppsPaginationModel()->selected_page()); ASSERT_EQ(1, view_->GetAppsPaginationModel()->selected_page());
} }
// Tests that a context menu can be shown between app icons in tablet mode.
TEST_F(AppListViewTest, ShowContextMenuBetweenAppsInTabletMode) {
Initialize(0, true /* enable tablet mode */, false);
delegate_->GetTestModel()->PopulateApps(kInitialItems);
Show();
// Tap between two apps in tablet mode.
const gfx::Point middle = GetPointBetweenTwoApps();
ui::GestureEvent tap(middle.x(), middle.y(), 0, base::TimeTicks(),
ui::GestureEventDetails(ui::ET_GESTURE_TWO_FINGER_TAP));
view_->OnGestureEvent(&tap);
// The wallpaper context menu should show.
EXPECT_EQ(1, show_wallpaper_context_menu_count());
EXPECT_TRUE(view_->GetWidget()->IsVisible());
// Click between two apps in tablet mode.
ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, middle, middle,
ui::EventTimeForNow(), ui::EF_RIGHT_MOUSE_BUTTON,
ui::EF_RIGHT_MOUSE_BUTTON);
view_->OnMouseEvent(&mouse_event);
// The wallpaper context menu should show.
EXPECT_EQ(2, show_wallpaper_context_menu_count());
EXPECT_TRUE(view_->GetWidget()->IsVisible());
}
// Tests that context menus are not shown between app icons in clamshell mode.
TEST_F(AppListViewTest, DontShowContextMenuBetweenAppsInClamshellMode) {
Initialize(0, false /* disable tablet mode */, false);
delegate_->GetTestModel()->PopulateApps(kInitialItems);
Show();
// Tap between two apps in clamshell mode.
const gfx::Point middle = GetPointBetweenTwoApps();
ui::GestureEvent tap(middle.x(), middle.y(), 0, base::TimeTicks(),
ui::GestureEventDetails(ui::ET_GESTURE_TWO_FINGER_TAP));
view_->OnGestureEvent(&tap);
// The wallpaper menu should not show.
EXPECT_EQ(0, show_wallpaper_context_menu_count());
EXPECT_TRUE(view_->GetWidget()->IsVisible());
// Right click between two apps in clamshell mode.
ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, middle, middle,
ui::EventTimeForNow(), ui::EF_RIGHT_MOUSE_BUTTON,
ui::EF_RIGHT_MOUSE_BUTTON);
view_->OnMouseEvent(&mouse_event);
// The wallpaper menu should not show.
EXPECT_EQ(0, show_wallpaper_context_menu_count());
EXPECT_TRUE(view_->GetWidget()->IsVisible());
}
// Tests that pressing escape when in tablet mode closes the app list. // Tests that pressing escape when in tablet mode closes the app list.
TEST_F(AppListViewNonHomeLauncherTest, EscapeKeyTabletModeFullscreenToClosed) { TEST_F(AppListViewNonHomeLauncherTest, EscapeKeyTabletModeFullscreenToClosed) {
// Put into fullscreen by using tablet mode. // Put into fullscreen by using tablet mode.
......
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