OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 "chrome/browser/ui/views/ash/launcher/launcher_context_menu.h" | |
6 | |
7 #include "ash/launcher/launcher_context_menu.h" | |
8 #include "ash/shell.h" | |
9 #include "base/command_line.h" | |
10 #include "chrome/browser/extensions/extension_prefs.h" | |
11 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.h" | |
12 #include "chrome/common/chrome_switches.h" | |
13 #include "grit/ash_strings.h" | |
14 #include "grit/generated_resources.h" | |
15 #include "ui/base/l10n/l10n_util.h" | |
16 | |
17 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, | |
18 const ash::LauncherItem* item) | |
19 : ui::SimpleMenuModel(NULL), | |
20 controller_(controller), | |
21 item_(item ? *item : ash::LauncherItem()) { | |
22 set_delegate(this); | |
23 | |
24 if (is_valid_item()) { | |
25 if (item_.type == ash::TYPE_APP_SHORTCUT) { | |
26 DCHECK(controller->IsPinned(item_.id)); | |
27 AddItem( | |
28 MENU_PIN, | |
29 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_UNPIN)); | |
30 // No open actions for pending app shortcut. | |
31 if (item->status != ash::STATUS_IS_PENDING) { | |
32 AddSeparator(); | |
33 AddCheckItemWithStringId( | |
34 LAUNCH_TYPE_REGULAR_TAB, | |
35 IDS_APP_CONTEXT_MENU_OPEN_REGULAR); | |
36 AddCheckItemWithStringId( | |
37 LAUNCH_TYPE_PINNED_TAB, | |
38 IDS_APP_CONTEXT_MENU_OPEN_PINNED); | |
39 AddCheckItemWithStringId( | |
40 LAUNCH_TYPE_WINDOW, | |
41 IDS_APP_CONTEXT_MENU_OPEN_WINDOW); | |
42 // Even though the launch type is Full Screen it is more accurately | |
43 // described as Maximized in Ash. | |
44 AddCheckItemWithStringId( | |
45 LAUNCH_TYPE_FULLSCREEN, | |
46 IDS_APP_CONTEXT_MENU_OPEN_MAXIMIZED); | |
47 } | |
48 } else if (item_.type == ash::TYPE_BROWSER_SHORTCUT) { | |
49 AddItem(MENU_NEW_WINDOW, | |
50 l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_WINDOW)); | |
51 if (!controller_->IsLoggedInAsGuest()) { | |
52 AddItem(MENU_NEW_INCOGNITO_WINDOW, | |
53 l10n_util::GetStringUTF16(IDS_LAUNCHER_NEW_INCOGNITO_WINDOW)); | |
54 } | |
55 } else { | |
56 AddItem(MENU_OPEN, controller->GetTitle(item_)); | |
57 if (item_.type == ash::TYPE_PLATFORM_APP) { | |
58 AddItem( | |
59 MENU_PIN, | |
60 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_PIN)); | |
61 } | |
62 if (controller->IsOpen(item_.id)) { | |
63 AddItem(MENU_CLOSE, | |
64 l10n_util::GetStringUTF16(IDS_LAUNCHER_CONTEXT_MENU_CLOSE)); | |
65 } | |
66 } | |
67 AddSeparator(); | |
68 } | |
69 AddCheckItemWithStringId( | |
70 MENU_AUTO_HIDE, ash::LauncherContextMenu::GetAutoHideResourceStringId()); | |
71 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
72 switches::kShowLauncherAlignmentMenu)) { | |
73 AddSubMenuWithStringId(MENU_ALIGNMENT_MENU, | |
74 IDS_AURA_LAUNCHER_CONTEXT_MENU_POSITION, | |
75 &alignment_menu_); | |
76 } | |
77 } | |
78 | |
79 LauncherContextMenu::~LauncherContextMenu() { | |
80 } | |
81 | |
82 bool LauncherContextMenu::IsCommandIdChecked(int command_id) const { | |
83 switch (command_id) { | |
84 case LAUNCH_TYPE_PINNED_TAB: | |
85 return controller_->GetLaunchType(item_.id) == | |
86 extensions::ExtensionPrefs::LAUNCH_PINNED; | |
87 case LAUNCH_TYPE_REGULAR_TAB: | |
88 return controller_->GetLaunchType(item_.id) == | |
89 extensions::ExtensionPrefs::LAUNCH_REGULAR; | |
90 case LAUNCH_TYPE_WINDOW: | |
91 return controller_->GetLaunchType(item_.id) == | |
92 extensions::ExtensionPrefs::LAUNCH_WINDOW; | |
93 case LAUNCH_TYPE_FULLSCREEN: | |
94 return controller_->GetLaunchType(item_.id) == | |
95 extensions::ExtensionPrefs::LAUNCH_FULLSCREEN; | |
96 case MENU_AUTO_HIDE: | |
97 return ash::LauncherContextMenu::IsAutoHideMenuHideChecked(); | |
98 default: | |
99 return false; | |
100 } | |
101 } | |
102 | |
103 bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const { | |
104 switch (command_id) { | |
105 case MENU_PIN: | |
106 return item_.type == ash::TYPE_PLATFORM_APP || | |
107 controller_->IsPinnable(item_.id); | |
108 default: | |
109 return true; | |
110 } | |
111 } | |
112 | |
113 bool LauncherContextMenu::GetAcceleratorForCommandId( | |
114 int command_id, | |
115 ui::Accelerator* accelerator) { | |
116 return false; | |
117 } | |
118 | |
119 void LauncherContextMenu::ExecuteCommand(int command_id) { | |
120 switch (static_cast<MenuItem>(command_id)) { | |
121 case MENU_OPEN: | |
122 controller_->Open(item_.id, ui::EF_NONE); | |
123 break; | |
124 case MENU_CLOSE: | |
125 controller_->Close(item_.id); | |
126 break; | |
127 case MENU_PIN: | |
128 controller_->TogglePinned(item_.id); | |
129 break; | |
130 case LAUNCH_TYPE_PINNED_TAB: | |
131 controller_->SetLaunchType(item_.id, | |
132 extensions::ExtensionPrefs::LAUNCH_PINNED); | |
133 break; | |
134 case LAUNCH_TYPE_REGULAR_TAB: | |
135 controller_->SetLaunchType(item_.id, | |
136 extensions::ExtensionPrefs::LAUNCH_REGULAR); | |
137 break; | |
138 case LAUNCH_TYPE_WINDOW: | |
139 controller_->SetLaunchType(item_.id, | |
140 extensions::ExtensionPrefs::LAUNCH_WINDOW); | |
141 break; | |
142 case LAUNCH_TYPE_FULLSCREEN: | |
143 controller_->SetLaunchType(item_.id, | |
144 extensions::ExtensionPrefs::LAUNCH_FULLSCREEN); | |
145 break; | |
146 case MENU_AUTO_HIDE: | |
147 controller_->SetAutoHideBehavior( | |
148 ash::LauncherContextMenu::GetToggledAutoHideBehavior()); | |
149 break; | |
150 case MENU_NEW_WINDOW: | |
151 controller_->CreateNewWindow(); | |
152 break; | |
153 case MENU_NEW_INCOGNITO_WINDOW: | |
154 controller_->CreateNewIncognitoWindow(); | |
155 break; | |
156 case MENU_ALIGNMENT_MENU: | |
157 break; | |
158 } | |
159 } | |
OLD | NEW |