OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_CONTEXT_MENU_H_ | 5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_CONTEXT_MENU_H_ |
6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_CONTEXT_MENU_H_ | 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_CONTEXT_MENU_H_ |
7 | 7 |
8 #include "ash/public/cpp/shelf_item.h" | 8 #include "ash/public/cpp/shelf_item.h" |
9 #include "ash/shelf/shelf_alignment_menu.h" | 9 #include "ash/shelf/shelf_alignment_menu.h" |
10 #include "base/gtest_prod_util.h" | |
11 #include "base/macros.h" | 10 #include "base/macros.h" |
12 #include "ui/base/models/simple_menu_model.h" | 11 #include "ui/base/models/simple_menu_model.h" |
13 | 12 |
14 class ChromeLauncherControllerImpl; | 13 class ChromeLauncherControllerImpl; |
15 | 14 |
16 namespace ash { | 15 namespace ash { |
17 class WmShelf; | 16 class WmShelf; |
18 } | 17 } |
19 | 18 |
20 // Base class for context menu which is shown for a regular extension item in | 19 // Base class for context menu which is shown for a regular extension item in |
21 // the shelf, or for an ARC app item in the shelf, or shown when right click | 20 // the shelf, or for an ARC app item in the shelf, or shown when right click |
22 // on desktop shell. | 21 // on desktop shell. |
23 class LauncherContextMenu : public ui::SimpleMenuModel, | 22 class LauncherContextMenu : public ui::SimpleMenuModel, |
24 public ui::SimpleMenuModel::Delegate { | 23 public ui::SimpleMenuModel::Delegate { |
25 public: | 24 public: |
26 ~LauncherContextMenu() override; | 25 // Menu item command ids, used by subclasses and tests. |
27 | |
28 // Static function to create contextmenu instance. | |
29 static LauncherContextMenu* Create(ChromeLauncherControllerImpl* controller, | |
30 const ash::ShelfItem* item, | |
31 ash::WmShelf* wm_shelf); | |
32 | |
33 // ui::SimpleMenuModel::Delegate overrides: | |
34 bool IsItemForCommandIdDynamic(int command_id) const override; | |
35 base::string16 GetLabelForCommandId(int command_id) const override; | |
36 bool IsCommandIdChecked(int command_id) const override; | |
37 bool IsCommandIdEnabled(int command_id) const override; | |
38 void ExecuteCommand(int command_id, int event_flags) override; | |
39 | |
40 protected: | |
41 enum MenuItem { | 26 enum MenuItem { |
42 MENU_OPEN_NEW, | 27 MENU_OPEN_NEW, |
43 MENU_CLOSE, | 28 MENU_CLOSE, |
44 MENU_PIN, | 29 MENU_PIN, |
45 LAUNCH_TYPE_PINNED_TAB, | 30 LAUNCH_TYPE_PINNED_TAB, |
46 LAUNCH_TYPE_REGULAR_TAB, | 31 LAUNCH_TYPE_REGULAR_TAB, |
47 LAUNCH_TYPE_FULLSCREEN, | 32 LAUNCH_TYPE_FULLSCREEN, |
48 LAUNCH_TYPE_WINDOW, | 33 LAUNCH_TYPE_WINDOW, |
49 MENU_AUTO_HIDE, | 34 MENU_AUTO_HIDE, |
50 MENU_NEW_WINDOW, | 35 MENU_NEW_WINDOW, |
51 MENU_NEW_INCOGNITO_WINDOW, | 36 MENU_NEW_INCOGNITO_WINDOW, |
52 MENU_ALIGNMENT_MENU, | 37 MENU_ALIGNMENT_MENU, |
53 MENU_CHANGE_WALLPAPER, | 38 MENU_CHANGE_WALLPAPER, |
54 MENU_ITEM_COUNT | 39 MENU_ITEM_COUNT |
55 }; | 40 }; |
56 | 41 |
| 42 ~LauncherContextMenu() override; |
| 43 |
| 44 // Static function to create contextmenu instance. |
| 45 static LauncherContextMenu* Create(ChromeLauncherControllerImpl* controller, |
| 46 const ash::ShelfItem* item, |
| 47 ash::WmShelf* wm_shelf); |
| 48 |
| 49 // ui::SimpleMenuModel::Delegate overrides: |
| 50 bool IsItemForCommandIdDynamic(int command_id) const override; |
| 51 base::string16 GetLabelForCommandId(int command_id) const override; |
| 52 bool IsCommandIdChecked(int command_id) const override; |
| 53 bool IsCommandIdEnabled(int command_id) const override; |
| 54 void ExecuteCommand(int command_id, int event_flags) override; |
| 55 |
| 56 protected: |
57 LauncherContextMenu(ChromeLauncherControllerImpl* controller, | 57 LauncherContextMenu(ChromeLauncherControllerImpl* controller, |
58 const ash::ShelfItem* item, | 58 const ash::ShelfItem* item, |
59 ash::WmShelf* wm_shelf); | 59 ash::WmShelf* wm_shelf); |
60 ChromeLauncherControllerImpl* controller() const { return controller_; } | 60 ChromeLauncherControllerImpl* controller() const { return controller_; } |
61 | 61 |
62 const ash::ShelfItem& item() const { return item_; } | 62 const ash::ShelfItem& item() const { return item_; } |
63 | 63 |
64 // Add menu item for pin/unpin. | 64 // Add menu item for pin/unpin. |
65 void AddPinMenu(); | 65 void AddPinMenu(); |
66 | 66 |
67 // Add common shelf options items, e.g. autohide mode, alignment and | 67 // Add common shelf options items, e.g. autohide, alignment, and wallpaper. |
68 // setting wallpaper. | |
69 void AddShelfOptionsMenu(); | 68 void AddShelfOptionsMenu(); |
70 | 69 |
71 // Helper method to execute common commands. Returns true if handled. | 70 // Helper method to execute common commands. Returns true if handled. |
72 bool ExecuteCommonCommand(int command_id, int event_flags); | 71 bool ExecuteCommonCommand(int command_id, int event_flags); |
73 | 72 |
74 private: | 73 private: |
75 FRIEND_TEST_ALL_PREFIXES( | |
76 LauncherContextMenuTest, | |
77 NewIncognitoWindowMenuIsDisabledWhenIncognitoModeOff); | |
78 FRIEND_TEST_ALL_PREFIXES(LauncherContextMenuTest, | |
79 NewWindowMenuIsDisabledWhenIncognitoModeForced); | |
80 FRIEND_TEST_ALL_PREFIXES(LauncherContextMenuTest, | |
81 AutoHideOptionInMaximizedMode); | |
82 FRIEND_TEST_ALL_PREFIXES(LauncherContextMenuTest, | |
83 DesktopShellLauncherContextMenuItemCheck); | |
84 FRIEND_TEST_ALL_PREFIXES(LauncherContextMenuTest, | |
85 ArcLauncherContextMenuItemCheck); | |
86 FRIEND_TEST_ALL_PREFIXES(LauncherContextMenuTest, | |
87 DesktopShellLauncherContextMenuVerifyCloseItem); | |
88 FRIEND_TEST_ALL_PREFIXES(LauncherContextMenuTest, | |
89 AutohideShelfOptionOnExternalDisplay); | |
90 FRIEND_TEST_ALL_PREFIXES(ShelfAppBrowserTest, | |
91 LauncherContextMenuVerifyCloseItemAppearance); | |
92 | |
93 ChromeLauncherControllerImpl* controller_; | 74 ChromeLauncherControllerImpl* controller_; |
94 | 75 |
95 ash::ShelfItem item_; | 76 ash::ShelfItem item_; |
96 | 77 |
97 ash::ShelfAlignmentMenu shelf_alignment_menu_; | 78 ash::ShelfAlignmentMenu shelf_alignment_menu_; |
98 | 79 |
99 ash::WmShelf* wm_shelf_; | 80 ash::WmShelf* wm_shelf_; |
100 | 81 |
101 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenu); | 82 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenu); |
102 }; | 83 }; |
103 | 84 |
104 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_CONTEXT_MENU_H_ | 85 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_CONTEXT_MENU_H_ |
OLD | NEW |