| OLD | NEW |
| 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/shelf_model.h" | 10 #include "ash/common/shelf/shelf_model.h" |
| 11 #include "ash/common/shelf/wm_shelf.h" | 11 #include "ash/common/shelf/wm_shelf.h" |
| 12 #include "ash/common/strings/grit/ash_strings.h" | 12 #include "ash/common/strings/grit/ash_strings.h" |
| 13 #include "ash/common/wallpaper/wallpaper_delegate.h" | 13 #include "ash/common/wallpaper/wallpaper_delegate.h" |
| 14 #include "ash/common/wm_shell.h" | 14 #include "ash/common/wm_shell.h" |
| 15 #include "ash/common/wm_window.h" | 15 #include "ash/common/wm_window.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 17 #include "chrome/browser/fullscreen.h" | 18 #include "chrome/browser/fullscreen.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 20 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 20 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 21 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 21 #include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h" | 22 #include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h" |
| 22 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" | 23 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" |
| 23 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" | 24 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" |
| 24 #include "chrome/browser/ui/ash/launcher/desktop_shell_launcher_context_menu.h" | 25 #include "chrome/browser/ui/ash/launcher/desktop_shell_launcher_context_menu.h" |
| 25 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h" | 26 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h" |
| 26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
| 28 #include "components/prefs/pref_service.h" | 29 #include "components/prefs/pref_service.h" |
| 29 #include "content/public/common/context_menu_params.h" | 30 #include "content/public/common/context_menu_params.h" |
| 30 | 31 |
| 31 #if defined(OS_CHROMEOS) | |
| 32 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | |
| 33 #endif // defined(OS_CHROMEOS) | |
| 34 | |
| 35 namespace { | 32 namespace { |
| 36 | 33 |
| 37 // Returns true if the user can modify the |shelf|'s auto-hide behavior. | 34 // Returns true if the user can modify the |shelf|'s auto-hide behavior. |
| 38 bool CanUserModifyShelfAutoHideBehavior(const Profile* profile) { | 35 bool CanUserModifyShelfAutoHideBehavior(const Profile* profile) { |
| 39 const std::string& pref = prefs::kShelfAutoHideBehaviorLocal; | 36 const std::string& pref = prefs::kShelfAutoHideBehaviorLocal; |
| 40 return profile->GetPrefs()->FindPreference(pref)->IsUserModifiable(); | 37 return profile->GetPrefs()->FindPreference(pref)->IsUserModifiable(); |
| 41 } | 38 } |
| 42 | 39 |
| 43 } // namespace | 40 } // namespace |
| 44 | 41 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 67 const ash::ShelfItem* item, | 64 const ash::ShelfItem* item, |
| 68 ash::WmShelf* wm_shelf) | 65 ash::WmShelf* wm_shelf) |
| 69 : ui::SimpleMenuModel(nullptr), | 66 : ui::SimpleMenuModel(nullptr), |
| 70 controller_(controller), | 67 controller_(controller), |
| 71 item_(item ? *item : ash::ShelfItem()), | 68 item_(item ? *item : ash::ShelfItem()), |
| 72 shelf_alignment_menu_(wm_shelf), | 69 shelf_alignment_menu_(wm_shelf), |
| 73 wm_shelf_(wm_shelf) { | 70 wm_shelf_(wm_shelf) { |
| 74 set_delegate(this); | 71 set_delegate(this); |
| 75 } | 72 } |
| 76 | 73 |
| 77 LauncherContextMenu::~LauncherContextMenu() { | 74 LauncherContextMenu::~LauncherContextMenu() {} |
| 78 } | |
| 79 | 75 |
| 80 bool LauncherContextMenu::IsItemForCommandIdDynamic(int command_id) const { | 76 bool LauncherContextMenu::IsItemForCommandIdDynamic(int command_id) const { |
| 81 return false; | 77 return false; |
| 82 } | 78 } |
| 83 | 79 |
| 84 base::string16 LauncherContextMenu::GetLabelForCommandId(int command_id) const { | 80 base::string16 LauncherContextMenu::GetLabelForCommandId(int command_id) const { |
| 85 NOTREACHED(); | 81 NOTREACHED(); |
| 86 return base::string16(); | 82 return base::string16(); |
| 87 } | 83 } |
| 88 | 84 |
| 89 bool LauncherContextMenu::IsCommandIdChecked(int command_id) const { | 85 bool LauncherContextMenu::IsCommandIdChecked(int command_id) const { |
| 90 if (command_id == MENU_AUTO_HIDE) { | 86 if (command_id == MENU_AUTO_HIDE) { |
| 91 return wm_shelf_->auto_hide_behavior() == | 87 return wm_shelf_->auto_hide_behavior() == |
| 92 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; | 88 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
| 93 } | 89 } |
| 94 DCHECK(command_id < MENU_ITEM_COUNT); | 90 DCHECK(command_id < MENU_ITEM_COUNT); |
| 95 return false; | 91 return false; |
| 96 } | 92 } |
| 97 | 93 |
| 98 bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const { | 94 bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const { |
| 99 switch (command_id) { | 95 switch (command_id) { |
| 100 case MENU_PIN: | 96 case MENU_PIN: |
| 101 return controller_->IsPinnable(item_.id); | 97 // Users cannot modify the pinned state of apps pinned by policy. |
| 98 return !item_.pinned_by_policy && (item_.type == ash::TYPE_APP_SHORTCUT || |
| 99 item_.type == ash::TYPE_APP); |
| 102 case MENU_CHANGE_WALLPAPER: | 100 case MENU_CHANGE_WALLPAPER: |
| 103 #if defined(OS_CHROMEOS) | |
| 104 return ash::WmShell::Get() | 101 return ash::WmShell::Get() |
| 105 ->wallpaper_delegate() | 102 ->wallpaper_delegate() |
| 106 ->CanOpenSetWallpaperPage(); | 103 ->CanOpenSetWallpaperPage(); |
| 107 #else | |
| 108 return false; | |
| 109 #endif // defined(OS_CHROMEOS) | |
| 110 case MENU_AUTO_HIDE: | 104 case MENU_AUTO_HIDE: |
| 111 return CanUserModifyShelfAutoHideBehavior(controller_->profile()); | 105 return CanUserModifyShelfAutoHideBehavior(controller_->profile()); |
| 112 default: | 106 default: |
| 113 DCHECK(command_id < MENU_ITEM_COUNT); | 107 DCHECK(command_id < MENU_ITEM_COUNT); |
| 114 return true; | 108 return true; |
| 115 } | 109 } |
| 116 } | 110 } |
| 117 | 111 |
| 118 void LauncherContextMenu::ExecuteCommand(int command_id, int event_flags) { | 112 void LauncherContextMenu::ExecuteCommand(int command_id, int event_flags) { |
| 119 switch (static_cast<MenuItem>(command_id)) { | 113 switch (static_cast<MenuItem>(command_id)) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 139 case MENU_AUTO_HIDE: | 133 case MENU_AUTO_HIDE: |
| 140 wm_shelf_->SetAutoHideBehavior( | 134 wm_shelf_->SetAutoHideBehavior( |
| 141 wm_shelf_->auto_hide_behavior() == | 135 wm_shelf_->auto_hide_behavior() == |
| 142 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS | 136 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS |
| 143 ? ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER | 137 ? ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER |
| 144 : ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 138 : ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 145 break; | 139 break; |
| 146 case MENU_ALIGNMENT_MENU: | 140 case MENU_ALIGNMENT_MENU: |
| 147 break; | 141 break; |
| 148 case MENU_CHANGE_WALLPAPER: | 142 case MENU_CHANGE_WALLPAPER: |
| 149 #if defined(OS_CHROMEOS) | |
| 150 chromeos::WallpaperManager::Get()->Open(); | 143 chromeos::WallpaperManager::Get()->Open(); |
| 151 #endif // defined(OS_CHROMEOS) | |
| 152 break; | 144 break; |
| 153 default: | 145 default: |
| 154 NOTREACHED(); | 146 NOTREACHED(); |
| 155 } | 147 } |
| 156 } | 148 } |
| 157 | 149 |
| 158 void LauncherContextMenu::AddPinMenu() { | 150 void LauncherContextMenu::AddPinMenu() { |
| 159 // Expect an item with a none zero id to add pin/unpin menu item. | 151 // Expect an item with a none zero id to add pin/unpin menu item. |
| 160 DCHECK(item_.id); | 152 DCHECK(item_.id); |
| 161 int menu_pin_string_id; | 153 int menu_pin_string_id; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 case MENU_PIN: | 199 case MENU_PIN: |
| 208 case MENU_AUTO_HIDE: | 200 case MENU_AUTO_HIDE: |
| 209 case MENU_ALIGNMENT_MENU: | 201 case MENU_ALIGNMENT_MENU: |
| 210 case MENU_CHANGE_WALLPAPER: | 202 case MENU_CHANGE_WALLPAPER: |
| 211 LauncherContextMenu::ExecuteCommand(command_id, event_flags); | 203 LauncherContextMenu::ExecuteCommand(command_id, event_flags); |
| 212 return true; | 204 return true; |
| 213 default: | 205 default: |
| 214 return false; | 206 return false; |
| 215 } | 207 } |
| 216 } | 208 } |
| OLD | NEW |