Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2376)

Unified Diff: ash/common/wm_root_window_controller.cc

Issue 2336883002: mash: Port context menu code to WmShell and WmRootWindowController. (Closed)
Patch Set: Fix error. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/common/wm_root_window_controller.h ('k') | ash/common/wm_shell.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/common/wm_root_window_controller.cc
diff --git a/ash/common/wm_root_window_controller.cc b/ash/common/wm_root_window_controller.cc
index 52035e7bbfc0b4e7460c004c6e8e22892d8b662e..98e4aefb418599356a61512cd07d7f4dbcd162c5 100644
--- a/ash/common/wm_root_window_controller.cc
+++ b/ash/common/wm_root_window_controller.cc
@@ -5,6 +5,8 @@
#include "ash/common/wm_root_window_controller.h"
#include "ash/common/session/session_state_delegate.h"
+#include "ash/common/shelf/wm_shelf.h"
+#include "ash/common/shell_delegate.h"
#include "ash/common/shell_window_ids.h"
#include "ash/common/wallpaper/wallpaper_delegate.h"
#include "ash/common/wallpaper/wallpaper_widget_controller.h"
@@ -16,6 +18,9 @@
#include "ash/common/wm_shell.h"
#include "ash/common/wm_window.h"
#include "base/memory/ptr_util.h"
+#include "ui/base/models/menu_model.h"
+#include "ui/views/controls/menu/menu_model_adapter.h"
+#include "ui/views/controls/menu/menu_runner.h"
namespace ash {
namespace {
@@ -91,6 +96,33 @@ const WmWindow* WmRootWindowController::GetContainer(int container_id) const {
return root_->GetChildByShellWindowId(container_id);
}
+void WmRootWindowController::ShowContextMenu(
+ const gfx::Point& location_in_screen,
+ ui::MenuSourceType source_type) {
+ ShellDelegate* delegate = WmShell::Get()->delegate();
+ DCHECK(delegate);
+ menu_model_.reset(delegate->CreateContextMenu(GetShelf(), nullptr));
+ if (!menu_model_)
+ return;
+
+ menu_model_adapter_.reset(new views::MenuModelAdapter(
+ menu_model_.get(), base::Bind(&WmRootWindowController::OnMenuClosed,
+ base::Unretained(this))));
+
+ // The wallpaper controller may not be set yet if the user clicked on the
+ // status area before the initial animation completion. See crbug.com/222218
+ if (!wallpaper_widget_controller())
+ return;
+
+ menu_runner_.reset(new views::MenuRunner(
+ menu_model_adapter_->CreateMenu(),
+ views::MenuRunner::CONTEXT_MENU | views::MenuRunner::ASYNC));
+ ignore_result(
+ menu_runner_->RunMenuAt(wallpaper_widget_controller()->widget(), nullptr,
+ gfx::Rect(location_in_screen, gfx::Size()),
+ views::MENU_ANCHOR_TOPLEFT, source_type));
+}
+
void WmRootWindowController::OnInitialWallpaperAnimationStarted() {}
void WmRootWindowController::OnWallpaperAnimationFinished(
@@ -310,4 +342,11 @@ void WmRootWindowController::DeleteWorkspaceController() {
workspace_controller_.reset();
}
+void WmRootWindowController::OnMenuClosed() {
+ menu_runner_.reset();
+ menu_model_adapter_.reset();
+ menu_model_.reset();
+ GetShelf()->UpdateVisibilityState();
+}
+
} // namespace ash
« no previous file with comments | « ash/common/wm_root_window_controller.h ('k') | ash/common/wm_shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698