Index: ash/shelf/shelf_item_context_menu.cc |
diff --git a/ash/shelf/shelf_item_context_menu.cc b/ash/shelf/shelf_item_context_menu.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0ea4c6359eace53f3cb36980b15cce4650765455 |
--- /dev/null |
+++ b/ash/shelf/shelf_item_context_menu.cc |
@@ -0,0 +1,129 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ash/shelf/shelf_item_context_menu.h" |
+ |
+#include "ash/root_window_controller.h" |
+#include "ash/shelf/shelf_delegate.h" |
+#include "ash/shelf/shelf_widget.h" |
+#include "ash/shelf/shelf_window_watcher_item_delegate.h" |
+#include "ash/shell_delegate.h" |
+#include "grit/ash_strings.h" |
+#include "ui/aura/window.h" |
+#include "ui/base/l10n/l10n_util.h" |
+ |
+#if defined(OS_CHROMEOS) |
+#include "ash/desktop_background/user_wallpaper_delegate.h" |
+#endif |
+ |
+namespace ash { |
+namespace internal { |
+ |
+ShelfItemContextMenu::ShelfItemContextMenu( |
+ ShelfWindowWatcherItemDelegate* item_delegate, |
+ aura::Window* root_window) |
+ : ui::SimpleMenuModel(this), |
+ item_delegate_(item_delegate), |
+ root_window_(root_window), |
+ shell_(Shell::GetInstance()), |
+ shelf_alignment_menu_(root_window) { |
+ Init(); |
+} |
+ |
+ShelfItemContextMenu::~ShelfItemContextMenu() { |
+} |
+ |
+void ShelfItemContextMenu::Init() { |
+ AddItem(MENU_CLOSE, |
+ l10n_util::GetStringUTF16(IDS_ASH_SHELF_CONTEXT_MENU_CLOSE)); |
+ |
+ AddSeparator(ui::NORMAL_SEPARATOR); |
+ |
+ if (!IsFullScreenMode()) { |
+ AddCheckItemWithStringId(MENU_AUTO_HIDE, |
+ IDS_ASH_SHELF_CONTEXT_MENU_AUTO_HIDE); |
+ } |
+ |
+ if (ash::ShelfWidget::ShelfAlignmentAllowed()) { |
+ AddSubMenuWithStringId(MENU_ALIGNMENT_MENU, |
+ IDS_ASH_SHELF_CONTEXT_MENU_POSITION, |
+ &shelf_alignment_menu_); |
+ } |
+ |
+#if defined(OS_CHROMEOS) |
+ AddItem(MENU_CHANGE_WALLPAPER, |
+ l10n_util::GetStringUTF16(IDS_AURA_SET_DESKTOP_WALLPAPER)); |
+#endif |
+} |
+ |
+bool ShelfItemContextMenu::IsCommandIdChecked(int command_id) const { |
+ switch (command_id) { |
+ case MENU_AUTO_HIDE: |
+ return shell_->GetShelfAutoHideBehavior(root_window_) == |
+ SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
+ default: |
+ return false; |
+ } |
+} |
+ |
+bool ShelfItemContextMenu::IsCommandIdEnabled(int command_id) const { |
+ switch (command_id) { |
+ case MENU_CLOSE: |
+ return true; |
+ case MENU_AUTO_HIDE: |
+ return shell_->GetShelfDelegate()-> |
+ CanUserModifyShelfAutoHideBehavior(root_window_); |
+ case MENU_ALIGNMENT_MENU: |
+ return ShelfWidget::ShelfAlignmentAllowed() ? true : false; |
+#if defined(OS_CHROMEOS) |
+ case MENU_CHANGE_WALLPAPER: |
+ return shell_->user_wallpaper_delegate()->CanOpenSetWallpaperPage(); |
+#endif |
+ default: |
+ return false; |
+ } |
+} |
+ |
+bool ShelfItemContextMenu::GetAcceleratorForCommandId( |
+ int command_id, |
+ ui::Accelerator* accelerator) { |
+ return false; |
+} |
+ |
+void ShelfItemContextMenu::ExecuteCommand(int command_id, int event_flags) { |
+ switch (command_id) { |
+ case MENU_CLOSE: |
+ item_delegate_->Close(); |
+ shell_->delegate()->RecordUserMetricsAction( |
+ ash::UMA_CLOSE_THROUGH_CONTEXT_MENU); |
+ break; |
+ case MENU_AUTO_HIDE: |
+ ToggleShelfAutoHideBehavior(); |
+ break; |
+ case MENU_ALIGNMENT_MENU: |
+ break; |
+#if defined(OS_CHROMEOS) |
+ case MENU_CHANGE_WALLPAPER: |
+ shell_->user_wallpaper_delegate()->OpenSetWallpaperPage(); |
+ break; |
+#endif |
+ } |
+} |
+ |
+bool ShelfItemContextMenu::IsFullScreenMode() const { |
+ RootWindowController* controller = GetRootWindowController(root_window_); |
+ return controller && !!controller->GetWindowForFullscreenMode(); |
+} |
+ |
+void ShelfItemContextMenu::ToggleShelfAutoHideBehavior() const { |
+ ShelfAutoHideBehavior behavior = |
+ shell_->GetShelfAutoHideBehavior(root_window_); |
+ behavior = (behavior == SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS) ? |
+ SHELF_AUTO_HIDE_BEHAVIOR_NEVER : |
+ SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
+ shell_->SetShelfAutoHideBehavior(behavior, root_window_); |
+} |
+ |
+} // namespace internal |
+} // namespace ash |