| 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/wm_shelf.h" |
| 10 #include "ash/desktop_background/user_wallpaper_delegate.h" | 11 #include "ash/desktop_background/user_wallpaper_delegate.h" |
| 11 #include "ash/metrics/user_metrics_recorder.h" | 12 #include "ash/metrics/user_metrics_recorder.h" |
| 12 #include "ash/shelf/shelf.h" | 13 #include "ash/shelf/shelf_widget.h" |
| 13 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "chrome/browser/fullscreen.h" | 16 #include "chrome/browser/fullscreen.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #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" |
| 18 #include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h" | 19 #include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h" |
| 19 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 20 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 20 #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" |
| 21 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h" | 22 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h" |
| 22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 33 const std::string& pref = prefs::kShelfAutoHideBehaviorLocal; | 34 const std::string& pref = prefs::kShelfAutoHideBehaviorLocal; |
| 34 return profile->GetPrefs()->FindPreference(pref)->IsUserModifiable(); | 35 return profile->GetPrefs()->FindPreference(pref)->IsUserModifiable(); |
| 35 } | 36 } |
| 36 | 37 |
| 37 } // namespace | 38 } // namespace |
| 38 | 39 |
| 39 // static | 40 // static |
| 40 LauncherContextMenu* LauncherContextMenu::Create( | 41 LauncherContextMenu* LauncherContextMenu::Create( |
| 41 ChromeLauncherController* controller, | 42 ChromeLauncherController* controller, |
| 42 const ash::ShelfItem* item, | 43 const ash::ShelfItem* item, |
| 43 ash::Shelf* shelf) { | 44 ash::WmShelf* wm_shelf) { |
| 44 DCHECK(controller); | 45 DCHECK(controller); |
| 45 DCHECK(shelf); | 46 DCHECK(wm_shelf); |
| 46 // Create DesktopShellLauncherContextMenu if no item is selected. | 47 // Create DesktopShellLauncherContextMenu if no item is selected. |
| 47 if (!item || item->id == 0) | 48 if (!item || item->id == 0) |
| 48 return new DesktopShellLauncherContextMenu(controller, item, shelf); | 49 return new DesktopShellLauncherContextMenu(controller, item, wm_shelf); |
| 49 | 50 |
| 50 // Create ArcLauncherContextMenu if the item is an Arc app. | 51 // Create ArcLauncherContextMenu if the item is an Arc app. |
| 51 const std::string& app_id = controller->GetAppIDForShelfID(item->id); | 52 const std::string& app_id = controller->GetAppIDForShelfID(item->id); |
| 52 ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(controller->profile()); | 53 ArcAppListPrefs* arc_prefs = ArcAppListPrefs::Get(controller->profile()); |
| 53 if (arc_prefs && arc_prefs->IsRegistered(app_id)) | 54 if (arc_prefs && arc_prefs->IsRegistered(app_id)) |
| 54 return new ArcLauncherContextMenu(controller, item, shelf); | 55 return new ArcLauncherContextMenu(controller, item, wm_shelf); |
| 55 | 56 |
| 56 // Create ExtensionLauncherContextMenu for the item. | 57 // Create ExtensionLauncherContextMenu for the item. |
| 57 return new ExtensionLauncherContextMenu(controller, item, shelf); | 58 return new ExtensionLauncherContextMenu(controller, item, wm_shelf); |
| 58 } | 59 } |
| 59 | 60 |
| 60 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, | 61 LauncherContextMenu::LauncherContextMenu(ChromeLauncherController* controller, |
| 61 const ash::ShelfItem* item, | 62 const ash::ShelfItem* item, |
| 62 ash::Shelf* shelf) | 63 ash::WmShelf* wm_shelf) |
| 63 : ui::SimpleMenuModel(nullptr), | 64 : ui::SimpleMenuModel(nullptr), |
| 64 controller_(controller), | 65 controller_(controller), |
| 65 item_(item ? *item : ash::ShelfItem()), | 66 item_(item ? *item : ash::ShelfItem()), |
| 66 shelf_alignment_menu_(shelf), | 67 shelf_alignment_menu_(wm_shelf), |
| 67 shelf_(shelf) { | 68 wm_shelf_(wm_shelf) { |
| 68 set_delegate(this); | 69 set_delegate(this); |
| 69 } | 70 } |
| 70 | 71 |
| 71 LauncherContextMenu::~LauncherContextMenu() { | 72 LauncherContextMenu::~LauncherContextMenu() { |
| 72 } | 73 } |
| 73 | 74 |
| 74 bool LauncherContextMenu::IsItemForCommandIdDynamic(int command_id) const { | 75 bool LauncherContextMenu::IsItemForCommandIdDynamic(int command_id) const { |
| 75 return false; | 76 return false; |
| 76 } | 77 } |
| 77 | 78 |
| 78 base::string16 LauncherContextMenu::GetLabelForCommandId(int command_id) const { | 79 base::string16 LauncherContextMenu::GetLabelForCommandId(int command_id) const { |
| 79 NOTREACHED(); | 80 NOTREACHED(); |
| 80 return base::string16(); | 81 return base::string16(); |
| 81 } | 82 } |
| 82 | 83 |
| 83 bool LauncherContextMenu::IsCommandIdChecked(int command_id) const { | 84 bool LauncherContextMenu::IsCommandIdChecked(int command_id) const { |
| 84 if (command_id == MENU_AUTO_HIDE) | 85 if (command_id == MENU_AUTO_HIDE) { |
| 85 return shelf_->auto_hide_behavior() == ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; | 86 return wm_shelf_->GetAutoHideBehavior() == |
| 87 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
| 88 } |
| 86 DCHECK(command_id < MENU_ITEM_COUNT); | 89 DCHECK(command_id < MENU_ITEM_COUNT); |
| 87 return false; | 90 return false; |
| 88 } | 91 } |
| 89 | 92 |
| 90 bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const { | 93 bool LauncherContextMenu::IsCommandIdEnabled(int command_id) const { |
| 91 switch (command_id) { | 94 switch (command_id) { |
| 92 case MENU_PIN: | 95 case MENU_PIN: |
| 93 return controller_->IsPinnable(item_.id); | 96 return controller_->IsPinnable(item_.id); |
| 94 case MENU_CHANGE_WALLPAPER: | 97 case MENU_CHANGE_WALLPAPER: |
| 95 return ash::Shell::GetInstance() | 98 return ash::Shell::GetInstance() |
| (...skipping 30 matching lines...) Expand all Loading... |
| 126 // TODO(simonhong): Use ShelfItemDelegate::Close(). | 129 // TODO(simonhong): Use ShelfItemDelegate::Close(). |
| 127 controller_->Close(item_.id); | 130 controller_->Close(item_.id); |
| 128 } | 131 } |
| 129 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 132 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 130 ash::UMA_CLOSE_THROUGH_CONTEXT_MENU); | 133 ash::UMA_CLOSE_THROUGH_CONTEXT_MENU); |
| 131 break; | 134 break; |
| 132 case MENU_PIN: | 135 case MENU_PIN: |
| 133 controller_->TogglePinned(item_.id); | 136 controller_->TogglePinned(item_.id); |
| 134 break; | 137 break; |
| 135 case MENU_AUTO_HIDE: | 138 case MENU_AUTO_HIDE: |
| 136 shelf_->SetAutoHideBehavior(shelf_->auto_hide_behavior() == | 139 wm_shelf_->SetAutoHideBehavior( |
| 137 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS | 140 wm_shelf_->GetAutoHideBehavior() == |
| 138 ? ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER | 141 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS |
| 139 : ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 142 ? ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER |
| 143 : ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 140 break; | 144 break; |
| 141 case MENU_ALIGNMENT_MENU: | 145 case MENU_ALIGNMENT_MENU: |
| 142 break; | 146 break; |
| 143 case MENU_CHANGE_WALLPAPER: | 147 case MENU_CHANGE_WALLPAPER: |
| 144 ash::Shell::GetInstance()->user_wallpaper_delegate()-> | 148 ash::Shell::GetInstance()->user_wallpaper_delegate()-> |
| 145 OpenSetWallpaperPage(); | 149 OpenSetWallpaperPage(); |
| 146 break; | 150 break; |
| 147 default: | 151 default: |
| 148 NOTREACHED(); | 152 NOTREACHED(); |
| 149 } | 153 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 case MENU_PIN: | 204 case MENU_PIN: |
| 201 case MENU_AUTO_HIDE: | 205 case MENU_AUTO_HIDE: |
| 202 case MENU_ALIGNMENT_MENU: | 206 case MENU_ALIGNMENT_MENU: |
| 203 case MENU_CHANGE_WALLPAPER: | 207 case MENU_CHANGE_WALLPAPER: |
| 204 LauncherContextMenu::ExecuteCommand(command_id, event_flags); | 208 LauncherContextMenu::ExecuteCommand(command_id, event_flags); |
| 205 return true; | 209 return true; |
| 206 default: | 210 default: |
| 207 return false; | 211 return false; |
| 208 } | 212 } |
| 209 } | 213 } |
| OLD | NEW |