Commit 053b929f authored by Weidong Guo's avatar Weidong Guo Committed by Commit Bot

Show wallpaper context menu in home launcher

Changes:
Show the context menu in home launcher in the same way as that in
wallpaper when the background is long-pressed or right clicked.

BUG=832993

Change-Id: I5f2d769884b2313a8a32254522428a73e13b9665
Reviewed-on: https://chromium-review.googlesource.com/1024728
Commit-Queue: Weidong Guo <weidongg@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553371}
parent f250ade2
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ash/public/cpp/shelf_model.h" #include "ash/public/cpp/shelf_model.h"
#include "ash/public/cpp/shelf_types.h" #include "ash/public/cpp/shelf_types.h"
#include "ash/public/cpp/shell_window_ids.h" #include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_controller.h" #include "ash/shelf/shelf_controller.h"
#include "ash/shelf/shelf_layout_manager.h" #include "ash/shelf/shelf_layout_manager.h"
...@@ -20,6 +21,7 @@ ...@@ -20,6 +21,7 @@
#include "ash/shell_port.h" #include "ash/shell_port.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "ash/wm/overview/window_selector_controller.h" #include "ash/wm/overview/window_selector_controller.h"
#include "ash/wm/root_window_finder.h"
#include "ash/wm/splitview/split_view_controller.h" #include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
...@@ -1289,4 +1291,45 @@ TEST_F(AppListPresenterDelegateHomeLauncherTest, AppListButtonEndOverViewMode) { ...@@ -1289,4 +1291,45 @@ TEST_F(AppListPresenterDelegateHomeLauncherTest, AppListButtonEndOverViewMode) {
GetAppListTestHelper()->CheckVisibility(true); GetAppListTestHelper()->CheckVisibility(true);
} }
// Tests that the context menu is triggered in the same way as if we are on
// the wallpaper.
TEST_F(AppListPresenterDelegateHomeLauncherTest, WallpaperContextMenu) {
// Show app list in tablet mode.
EnableTabletMode(true);
GetAppListTestHelper()->CheckVisibility(true);
// Long press on the app list to open the context menu.
const gfx::Point onscreen_point(GetPointOutsideSearchbox());
ui::test::EventGenerator& generator = GetEventGenerator();
ui::GestureEvent long_press(
onscreen_point.x(), onscreen_point.y(), 0, base::TimeTicks(),
ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS));
generator.Dispatch(&long_press);
GetAppListTestHelper()->WaitUntilIdle();
const aura::Window* root = wm::GetRootWindowAt(onscreen_point);
const RootWindowController* root_window_controller =
RootWindowController::ForWindow(root);
EXPECT_TRUE(root_window_controller->IsContextMenuShown());
// Tap down to close the context menu.
ui::GestureEvent tap_down(onscreen_point.x(), onscreen_point.y(), 0,
base::TimeTicks(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN));
generator.Dispatch(&tap_down);
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_FALSE(root_window_controller->IsContextMenuShown());
// Right click to open the context menu.
generator.MoveMouseTo(onscreen_point);
generator.PressRightButton();
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_TRUE(root_window_controller->IsContextMenuShown());
// Left click to close the context menu.
generator.MoveMouseTo(onscreen_point);
generator.PressLeftButton();
GetAppListTestHelper()->WaitUntilIdle();
EXPECT_FALSE(root_window_controller->IsContextMenuShown());
}
} // namespace ash } // namespace ash
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/app_list/model/app_list_model.h" #include "ash/app_list/model/app_list_model.h"
#include "ash/app_list/model/search/search_model.h" #include "ash/app_list/model/search/search_model.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/shell_port.h"
#include "ash/wallpaper/wallpaper_controller.h" #include "ash/wallpaper/wallpaper_controller.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
...@@ -114,4 +115,10 @@ void AppListViewDelegateMash::RemoveObserver( ...@@ -114,4 +115,10 @@ void AppListViewDelegateMash::RemoveObserver(
observers_.RemoveObserver(observer); observers_.RemoveObserver(observer);
} }
void AppListViewDelegateMash::ShowWallpaperContextMenu(
const gfx::Point& onscreen_location,
ui::MenuSourceType source_type) {
ShellPort::Get()->ShowContextMenu(onscreen_location, source_type);
}
} // namespace ash } // namespace ash
...@@ -50,6 +50,9 @@ class ASH_EXPORT AppListViewDelegateMash ...@@ -50,6 +50,9 @@ class ASH_EXPORT AppListViewDelegateMash
void AddObserver(app_list::AppListViewDelegateObserver* observer) override; void AddObserver(app_list::AppListViewDelegateObserver* observer) override;
void RemoveObserver(app_list::AppListViewDelegateObserver* observer) override; void RemoveObserver(app_list::AppListViewDelegateObserver* observer) override;
void ShowWallpaperContextMenu(const gfx::Point& onscreen_location,
ui::MenuSourceType source_type) override;
private: private:
ash::AppListControllerImpl* owner_; ash::AppListControllerImpl* owner_;
base::string16 last_raw_query_; base::string16 last_raw_query_;
......
...@@ -639,6 +639,10 @@ void RootWindowController::HideContextMenu() { ...@@ -639,6 +639,10 @@ void RootWindowController::HideContextMenu() {
menu_runner_->Cancel(); menu_runner_->Cancel();
} }
bool RootWindowController::IsContextMenuShown() const {
return menu_runner_ && menu_runner_->IsRunning();
}
void RootWindowController::UpdateAfterLoginStatusChange(LoginStatus status) { void RootWindowController::UpdateAfterLoginStatusChange(LoginStatus status) {
StatusAreaWidget* status_area_widget = StatusAreaWidget* status_area_widget =
shelf_->shelf_widget()->status_area_widget(); shelf_->shelf_widget()->status_area_widget();
......
...@@ -231,6 +231,7 @@ class ASH_EXPORT RootWindowController { ...@@ -231,6 +231,7 @@ class ASH_EXPORT RootWindowController {
void ShowContextMenu(const gfx::Point& location_in_screen, void ShowContextMenu(const gfx::Point& location_in_screen,
ui::MenuSourceType source_type); ui::MenuSourceType source_type);
void HideContextMenu(); void HideContextMenu();
bool IsContextMenuShown() const;
// Called when the login status changes after login (such as lock/unlock). // Called when the login status changes after login (such as lock/unlock).
void UpdateAfterLoginStatusChange(LoginStatus status); void UpdateAfterLoginStatusChange(LoginStatus status);
......
...@@ -305,6 +305,11 @@ class ExampleAppListViewDelegate : public app_list::AppListViewDelegate { ...@@ -305,6 +305,11 @@ class ExampleAppListViewDelegate : public app_list::AppListViewDelegate {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
void ShowWallpaperContextMenu(const gfx::Point& onscreen_location,
ui::MenuSourceType source_type) override {
NOTIMPLEMENTED();
}
std::unique_ptr<app_list::AppListModel> model_; std::unique_ptr<app_list::AppListModel> model_;
std::unique_ptr<app_list::SearchModel> search_model_; std::unique_ptr<app_list::SearchModel> search_model_;
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/app_list/app_list_export.h" #include "ui/app_list/app_list_export.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/geometry/point.h"
namespace gfx { namespace gfx {
class Size; class Size;
...@@ -96,6 +98,10 @@ class APP_LIST_EXPORT AppListViewDelegate { ...@@ -96,6 +98,10 @@ class APP_LIST_EXPORT AppListViewDelegate {
// Add/remove observer for AppListViewDelegate. // Add/remove observer for AppListViewDelegate.
virtual void AddObserver(AppListViewDelegateObserver* observer) = 0; virtual void AddObserver(AppListViewDelegateObserver* observer) = 0;
virtual void RemoveObserver(AppListViewDelegateObserver* observer) = 0; virtual void RemoveObserver(AppListViewDelegateObserver* observer) = 0;
// Show wallpaper context menu from the specified onscreen location.
virtual void ShowWallpaperContextMenu(const gfx::Point& onscreen_location,
ui::MenuSourceType source_type) = 0;
}; };
} // namespace app_list } // namespace app_list
......
...@@ -65,6 +65,8 @@ class AppListTestViewDelegate : public AppListViewDelegate { ...@@ -65,6 +65,8 @@ class AppListTestViewDelegate : public AppListViewDelegate {
void AddObserver(app_list::AppListViewDelegateObserver* observer) override {} void AddObserver(app_list::AppListViewDelegateObserver* observer) override {}
void RemoveObserver( void RemoveObserver(
app_list::AppListViewDelegateObserver* observer) override {} app_list::AppListViewDelegateObserver* observer) override {}
void ShowWallpaperContextMenu(const gfx::Point& onscreen_location,
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);
......
...@@ -553,11 +553,22 @@ void AppListView::HandleClickOrTap(ui::LocatedEvent* event) { ...@@ -553,11 +553,22 @@ void AppListView::HandleClickOrTap(ui::LocatedEvent* event) {
return; return;
} }
// No-op if the event was a right-click or two-finger tap.
if ((event->IsGestureEvent() && if ((event->IsGestureEvent() &&
event->AsGestureEvent()->type() == ui::ET_GESTURE_TWO_FINGER_TAP) || (event->AsGestureEvent()->type() == ui::ET_GESTURE_LONG_PRESS ||
event->AsGestureEvent()->type() == ui::ET_GESTURE_LONG_TAP ||
event->AsGestureEvent()->type() == ui::ET_GESTURE_TWO_FINGER_TAP)) ||
(event->IsMouseEvent() && (event->IsMouseEvent() &&
event->AsMouseEvent()->IsOnlyRightMouseButton())) { event->AsMouseEvent()->IsOnlyRightMouseButton())) {
if (!IsHomeLauncherEnabledInTabletMode())
return;
// Home launcher is shown on top of wallpaper with trasparent background. So
// trigger the wallpaper context menu for the same events.
gfx::Point onscreen_location(event->location());
ConvertPointToScreen(this, &onscreen_location);
delegate_->ShowWallpaperContextMenu(
onscreen_location, event->IsGestureEvent() ? ui::MENU_SOURCE_TOUCH
: ui::MENU_SOURCE_MOUSE);
return; return;
} }
...@@ -933,6 +944,9 @@ void AppListView::OnMouseEvent(ui::MouseEvent* event) { ...@@ -933,6 +944,9 @@ void AppListView::OnMouseEvent(ui::MouseEvent* event) {
void AppListView::OnGestureEvent(ui::GestureEvent* event) { void AppListView::OnGestureEvent(ui::GestureEvent* event) {
switch (event->type()) { switch (event->type()) {
case ui::ET_GESTURE_TAP: case ui::ET_GESTURE_TAP:
case ui::ET_GESTURE_LONG_PRESS:
case ui::ET_GESTURE_LONG_TAP:
case ui::ET_GESTURE_TWO_FINGER_TAP:
SetIsInDrag(false); SetIsInDrag(false);
event->SetHandled(); event->SetHandled();
HandleClickOrTap(event); HandleClickOrTap(event);
......
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