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

Side by Side Diff: chrome/browser/ui/ash/launcher/launcher_context_menu.cc

Issue 2052013002: Adding ChromeLauncherController interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome_launcher_smaller_api
Patch Set: Rebase Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" 5 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/common/session/session_state_delegate.h" 9 #include "ash/common/session/session_state_delegate.h"
10 #include "ash/common/shelf/wm_shelf.h" 10 #include "ash/common/shelf/wm_shelf.h"
11 #include "ash/desktop_background/user_wallpaper_delegate.h" 11 #include "ash/desktop_background/user_wallpaper_delegate.h"
12 #include "ash/metrics/user_metrics_recorder.h" 12 #include "ash/metrics/user_metrics_recorder.h"
13 #include "ash/shelf/shelf_widget.h" 13 #include "ash/shelf/shelf_widget.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "chrome/browser/fullscreen.h" 16 #include "chrome/browser/fullscreen.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 18 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
19 #include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h" 19 #include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h"
20 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 20 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h"
21 #include "chrome/browser/ui/ash/launcher/desktop_shell_launcher_context_menu.h" 21 #include "chrome/browser/ui/ash/launcher/desktop_shell_launcher_context_menu.h"
22 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h" 22 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chrome/grit/generated_resources.h" 24 #include "chrome/grit/generated_resources.h"
25 #include "components/prefs/pref_service.h" 25 #include "components/prefs/pref_service.h"
26 #include "content/public/common/context_menu_params.h" 26 #include "content/public/common/context_menu_params.h"
27 #include "grit/ash_strings.h" 27 #include "grit/ash_strings.h"
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
29 29
30 namespace { 30 namespace {
31 31
32 // Returns true if the user can modify the |shelf|'s auto-hide behavior. 32 // Returns true if the user can modify the |shelf|'s auto-hide behavior.
33 bool CanUserModifyShelfAutoHideBehavior(const Profile* profile) { 33 bool CanUserModifyShelfAutoHideBehavior(const Profile* profile) {
34 const std::string& pref = prefs::kShelfAutoHideBehaviorLocal; 34 const std::string& pref = prefs::kShelfAutoHideBehaviorLocal;
35 return profile->GetPrefs()->FindPreference(pref)->IsUserModifiable(); 35 return profile->GetPrefs()->FindPreference(pref)->IsUserModifiable();
36 } 36 }
37 37
38 } // namespace 38 } // namespace
39 39
40 // static 40 // static
41 LauncherContextMenu* LauncherContextMenu::Create( 41 LauncherContextMenu* LauncherContextMenu::Create(
42 ChromeLauncherController* controller, 42 ChromeLauncherControllerImpl* controller,
43 const ash::ShelfItem* item, 43 const ash::ShelfItem* item,
44 ash::WmShelf* wm_shelf) { 44 ash::WmShelf* wm_shelf) {
45 DCHECK(controller); 45 DCHECK(controller);
46 DCHECK(wm_shelf); 46 DCHECK(wm_shelf);
47 // Create DesktopShellLauncherContextMenu if no item is selected. 47 // Create DesktopShellLauncherContextMenu if no item is selected.
48 if (!item || item->id == 0) 48 if (!item || item->id == 0)
49 return new DesktopShellLauncherContextMenu(controller, item, wm_shelf); 49 return new DesktopShellLauncherContextMenu(controller, item, wm_shelf);
50 50
51 // Create ArcLauncherContextMenu if the item is an Arc app. 51 // Create ArcLauncherContextMenu if the item is an Arc app.
52 const std::string& app_id = controller->GetAppIDForShelfID(item->id); 52 const std::string& app_id = controller->GetAppIDForShelfID(item->id);
53 ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(controller->profile()); 53 ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(controller->GetProfile());
54 if (arc_prefs && arc_prefs->IsRegistered(app_id)) 54 if (arc_prefs && arc_prefs->IsRegistered(app_id))
55 return new ArcLauncherContextMenu(controller, item, wm_shelf); 55 return new ArcLauncherContextMenu(controller, item, wm_shelf);
56 56
57 // Create ExtensionLauncherContextMenu for the item. 57 // Create ExtensionLauncherContextMenu for the item.
58 return new ExtensionLauncherContextMenu(controller, item, wm_shelf); 58 return new ExtensionLauncherContextMenu(controller, item, wm_shelf);
59 } 59 }
60 60
61 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, 61 LauncherContextMenu::LauncherContextMenu(
62 const ash::ShelfItem* item, 62 ChromeLauncherControllerImpl* controller,
63 ash::WmShelf* wm_shelf) 63 const ash::ShelfItem* item,
64 ash::WmShelf* wm_shelf)
64 : ui::SimpleMenuModel(nullptr), 65 : ui::SimpleMenuModel(nullptr),
65 controller_(controller), 66 controller_(controller),
66 item_(item ? *item : ash::ShelfItem()), 67 item_(item ? *item : ash::ShelfItem()),
67 shelf_alignment_menu_(wm_shelf), 68 shelf_alignment_menu_(wm_shelf),
68 wm_shelf_(wm_shelf) { 69 wm_shelf_(wm_shelf) {
69 set_delegate(this); 70 set_delegate(this);
70 } 71 }
71 72
72 LauncherContextMenu::~LauncherContextMenu() { 73 LauncherContextMenu::~LauncherContextMenu() {
73 } 74 }
(...skipping 18 matching lines...) Expand all
92 93
93 bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const { 94 bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const {
94 switch (command_id) { 95 switch (command_id) {
95 case MENU_PIN: 96 case MENU_PIN:
96 return controller_->IsPinnable(item_.id); 97 return controller_->IsPinnable(item_.id);
97 case MENU_CHANGE_WALLPAPER: 98 case MENU_CHANGE_WALLPAPER:
98 return ash::Shell::GetInstance() 99 return ash::Shell::GetInstance()
99 ->user_wallpaper_delegate() 100 ->user_wallpaper_delegate()
100 ->CanOpenSetWallpaperPage(); 101 ->CanOpenSetWallpaperPage();
101 case MENU_AUTO_HIDE: 102 case MENU_AUTO_HIDE:
102 return CanUserModifyShelfAutoHideBehavior(controller_->profile()); 103 return CanUserModifyShelfAutoHideBehavior(controller_->GetProfile());
103 default: 104 default:
104 DCHECK(command_id < MENU_ITEM_COUNT); 105 DCHECK(command_id < MENU_ITEM_COUNT);
105 return true; 106 return true;
106 } 107 }
107 } 108 }
108 109
109 bool LauncherContextMenu::GetAcceleratorForCommandId( 110 bool LauncherContextMenu::GetAcceleratorForCommandId(
110 int command_id, 111 int command_id,
111 ui::Accelerator* accelerator) { 112 ui::Accelerator* accelerator) {
112 return false; 113 return false;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 176 }
176 AddItemWithStringId(MENU_PIN, menu_pin_string_id); 177 AddItemWithStringId(MENU_PIN, menu_pin_string_id);
177 } 178 }
178 179
179 void LauncherContextMenu::AddShelfOptionsMenu() { 180 void LauncherContextMenu::AddShelfOptionsMenu() {
180 // In fullscreen, the launcher is either hidden or autohidden depending 181 // In fullscreen, the launcher is either hidden or autohidden depending
181 // on thethe type of fullscreen. Do not show the auto-hide menu item while in 182 // on thethe type of fullscreen. Do not show the auto-hide menu item while in
182 // while in fullscreen because it is confusing when the preference appears 183 // while in fullscreen because it is confusing when the preference appears
183 // not to apply. 184 // not to apply.
184 if (!IsFullScreenMode() && 185 if (!IsFullScreenMode() &&
185 CanUserModifyShelfAutoHideBehavior(controller_->profile())) { 186 CanUserModifyShelfAutoHideBehavior(controller_->GetProfile())) {
186 AddCheckItemWithStringId(MENU_AUTO_HIDE, 187 AddCheckItemWithStringId(MENU_AUTO_HIDE,
187 IDS_ASH_SHELF_CONTEXT_MENU_AUTO_HIDE); 188 IDS_ASH_SHELF_CONTEXT_MENU_AUTO_HIDE);
188 } 189 }
189 if (ash::ShelfWidget::ShelfAlignmentAllowed() && 190 if (ash::ShelfWidget::ShelfAlignmentAllowed() &&
190 !ash::Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) { 191 !ash::Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) {
191 AddSubMenuWithStringId(MENU_ALIGNMENT_MENU, 192 AddSubMenuWithStringId(MENU_ALIGNMENT_MENU,
192 IDS_ASH_SHELF_CONTEXT_MENU_POSITION, 193 IDS_ASH_SHELF_CONTEXT_MENU_POSITION,
193 &shelf_alignment_menu_); 194 &shelf_alignment_menu_);
194 } 195 }
195 if (!controller_->profile()->IsGuestSession()) 196 if (!controller_->GetProfile()->IsGuestSession())
196 AddItemWithStringId(MENU_CHANGE_WALLPAPER, IDS_AURA_SET_DESKTOP_WALLPAPER); 197 AddItemWithStringId(MENU_CHANGE_WALLPAPER, IDS_AURA_SET_DESKTOP_WALLPAPER);
197 } 198 }
198 199
199 bool LauncherContextMenu::ExecuteCommonCommand(int command_id, 200 bool LauncherContextMenu::ExecuteCommonCommand(int command_id,
200 int event_flags) { 201 int event_flags) {
201 switch (command_id) { 202 switch (command_id) {
202 case MENU_OPEN_NEW: 203 case MENU_OPEN_NEW:
203 case MENU_CLOSE: 204 case MENU_CLOSE:
204 case MENU_PIN: 205 case MENU_PIN:
205 case MENU_AUTO_HIDE: 206 case MENU_AUTO_HIDE:
206 case MENU_ALIGNMENT_MENU: 207 case MENU_ALIGNMENT_MENU:
207 case MENU_CHANGE_WALLPAPER: 208 case MENU_CHANGE_WALLPAPER:
208 LauncherContextMenu::ExecuteCommand(command_id, event_flags); 209 LauncherContextMenu::ExecuteCommand(command_id, event_flags);
209 return true; 210 return true;
210 default: 211 default:
211 return false; 212 return false;
212 } 213 }
213 } 214 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698