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

Side by Side Diff: ash/shelf/shelf_item_context_menu.cc

Issue 107163005: [ash] Add TYPE_DIALOG and its item's LauncherContextMenu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/shelf/shelf_item_context_menu.h"
6
7 #include "ash/root_window_controller.h"
8 #include "ash/shelf/shelf_delegate.h"
9 #include "ash/shelf/shelf_widget.h"
10 #include "ash/shelf/shelf_window_watcher_item_delegate.h"
11 #include "ash/shell_delegate.h"
12 #include "grit/ash_strings.h"
13 #include "ui/aura/window.h"
14 #include "ui/base/l10n/l10n_util.h"
15
16 #if defined(OS_CHROMEOS)
17 #include "ash/desktop_background/user_wallpaper_delegate.h"
18 #endif
19
20 namespace ash {
21 namespace internal {
22
23 ShelfItemContextMenu::ShelfItemContextMenu(
24 ShelfWindowWatcherItemDelegate* item_delegate,
25 aura::Window* root_window)
26 : ui::SimpleMenuModel(this),
27 item_delegate_(item_delegate),
28 root_window_(root_window),
29 shell_(Shell::GetInstance()),
30 shelf_alignment_menu_(root_window) {
31 Init();
32 }
33
34 ShelfItemContextMenu::~ShelfItemContextMenu() {
35 }
36
37 void ShelfItemContextMenu::Init() {
38 AddItem(MENU_CLOSE,
39 l10n_util::GetStringUTF16(IDS_ASH_SHELF_CONTEXT_MENU_CLOSE));
40
41 AddSeparator(ui::NORMAL_SEPARATOR);
42
43 if (!IsFullScreenMode()) {
44 AddCheckItemWithStringId(MENU_AUTO_HIDE,
45 IDS_ASH_SHELF_CONTEXT_MENU_AUTO_HIDE);
46 }
47
48 if (ash::ShelfWidget::ShelfAlignmentAllowed()) {
49 AddSubMenuWithStringId(MENU_ALIGNMENT_MENU,
50 IDS_ASH_SHELF_CONTEXT_MENU_POSITION,
51 &shelf_alignment_menu_);
52 }
53
54 #if defined(OS_CHROMEOS)
55 AddItem(MENU_CHANGE_WALLPAPER,
56 l10n_util::GetStringUTF16(IDS_AURA_SET_DESKTOP_WALLPAPER));
57 #endif
58 }
59
60 bool ShelfItemContextMenu::IsCommandIdChecked(int command_id) const {
61 switch (command_id) {
62 case MENU_AUTO_HIDE:
63 return shell_->GetShelfAutoHideBehavior(root_window_) ==
64 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
65 default:
66 return false;
67 }
68 }
69
70 bool ShelfItemContextMenu::IsCommandIdEnabled(int command_id) const {
71 switch (command_id) {
72 case MENU_CLOSE:
73 return true;
74 case MENU_AUTO_HIDE:
75 return shell_->GetShelfDelegate()->
76 CanUserModifyShelfAutoHideBehavior(root_window_);
77 case MENU_ALIGNMENT_MENU:
78 return ShelfWidget::ShelfAlignmentAllowed() ? true : false;
79 #if defined(OS_CHROMEOS)
80 case MENU_CHANGE_WALLPAPER:
81 return shell_->user_wallpaper_delegate()->CanOpenSetWallpaperPage();
82 #endif
83 default:
84 return false;
85 }
86 }
87
88 bool ShelfItemContextMenu::GetAcceleratorForCommandId(
89 int command_id,
90 ui::Accelerator* accelerator) {
91 return false;
92 }
93
94 void ShelfItemContextMenu::ExecuteCommand(int command_id, int event_flags) {
95 switch (command_id) {
96 case MENU_CLOSE:
97 item_delegate_->Close();
98 shell_->delegate()->RecordUserMetricsAction(
99 ash::UMA_CLOSE_THROUGH_CONTEXT_MENU);
100 break;
101 case MENU_AUTO_HIDE:
102 ToggleShelfAutoHideBehavior();
103 break;
104 case MENU_ALIGNMENT_MENU:
105 break;
106 #if defined(OS_CHROMEOS)
107 case MENU_CHANGE_WALLPAPER:
108 shell_->user_wallpaper_delegate()->OpenSetWallpaperPage();
109 break;
110 #endif
111 }
112 }
113
114 bool ShelfItemContextMenu::IsFullScreenMode() const {
115 RootWindowController* controller = GetRootWindowController(root_window_);
116 return controller && !!controller->GetWindowForFullscreenMode();
117 }
118
119 void ShelfItemContextMenu::ToggleShelfAutoHideBehavior() const {
120 ShelfAutoHideBehavior behavior =
121 shell_->GetShelfAutoHideBehavior(root_window_);
122 behavior = (behavior == SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS) ?
123 SHELF_AUTO_HIDE_BEHAVIOR_NEVER :
124 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
125 shell_->SetShelfAutoHideBehavior(behavior, root_window_);
126 }
127
128 } // namespace internal
129 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698