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

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

Issue 1857213004: Refactor of LauncherContextMenu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits update Created 4 years, 8 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 (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/shelf/shelf_alignment_menu.h" 8 #include "ash/shelf/shelf_alignment_menu.h"
9 #include "ash/shelf/shelf_item_types.h" 9 #include "ash/shelf/shelf_item_types.h"
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "ui/base/models/simple_menu_model.h" 12 #include "ui/base/models/simple_menu_model.h"
14 13
15 class ChromeLauncherController; 14 class ChromeLauncherController;
16 15
17 namespace extensions { 16 namespace ash {
18 class ContextMenuMatcher; 17 class Shelf;
19 } 18 }
20 19
21 // Context menu shown for the ash shell desktop, or for an item in the shelf. 20 // 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
22 // on desktop shell.
22 class LauncherContextMenu : public ui::SimpleMenuModel, 23 class LauncherContextMenu : public ui::SimpleMenuModel,
23 public ui::SimpleMenuModel::Delegate { 24 public ui::SimpleMenuModel::Delegate {
24 public: 25 public:
25 LauncherContextMenu(ChromeLauncherController* controller,
26 const ash::ShelfItem* item,
27 ash::Shelf* shelf);
28 ~LauncherContextMenu() override; 26 ~LauncherContextMenu() override;
29 27
30 void Init(); 28 // Static function to create contextmenu instance.
29 static LauncherContextMenu* Create(ChromeLauncherController* controller,
30 const ash::ShelfItem* item,
31 ash::Shelf* shelf);
31 32
32 // ui::SimpleMenuModel::Delegate overrides: 33 // ui::SimpleMenuModel::Delegate overrides:
33 bool IsItemForCommandIdDynamic(int command_id) const override; 34 bool IsItemForCommandIdDynamic(int command_id) const override;
34 base::string16 GetLabelForCommandId(int command_id) const override; 35 base::string16 GetLabelForCommandId(int command_id) const override;
35 bool IsCommandIdChecked(int command_id) const override; 36 bool IsCommandIdChecked(int command_id) const override;
36 bool IsCommandIdEnabled(int command_id) const override; 37 bool IsCommandIdEnabled(int command_id) const override;
37 bool GetAcceleratorForCommandId(int command_id, 38 bool GetAcceleratorForCommandId(int command_id,
38 ui::Accelerator* accelerator) override; 39 ui::Accelerator* accelerator) override;
39 void ExecuteCommand(int command_id, int event_flags) override; 40 void ExecuteCommand(int command_id, int event_flags) override;
40 41
41 private: 42 protected:
42 FRIEND_TEST_ALL_PREFIXES(
43 LauncherContextMenuTest,
44 NewIncognitoWindowMenuIsDisabledWhenIncognitoModeOff);
45 FRIEND_TEST_ALL_PREFIXES(
46 LauncherContextMenuTest,
47 NewWindowMenuIsDisabledWhenIncognitoModeForced);
48 FRIEND_TEST_ALL_PREFIXES(
49 LauncherContextMenuTest,
50 AutoHideOptionInMaximizedMode);
51
52 enum MenuItem { 43 enum MenuItem {
53 MENU_OPEN_NEW, 44 MENU_OPEN_NEW,
54 MENU_CLOSE, 45 MENU_CLOSE,
55 MENU_PIN, 46 MENU_PIN,
56 LAUNCH_TYPE_PINNED_TAB, 47 LAUNCH_TYPE_PINNED_TAB,
57 LAUNCH_TYPE_REGULAR_TAB, 48 LAUNCH_TYPE_REGULAR_TAB,
58 LAUNCH_TYPE_FULLSCREEN, 49 LAUNCH_TYPE_FULLSCREEN,
59 LAUNCH_TYPE_WINDOW, 50 LAUNCH_TYPE_WINDOW,
60 MENU_AUTO_HIDE, 51 MENU_AUTO_HIDE,
61 MENU_NEW_WINDOW, 52 MENU_NEW_WINDOW,
62 MENU_NEW_INCOGNITO_WINDOW, 53 MENU_NEW_INCOGNITO_WINDOW,
63 MENU_ALIGNMENT_MENU, 54 MENU_ALIGNMENT_MENU,
64 MENU_CHANGE_WALLPAPER, 55 MENU_CHANGE_WALLPAPER,
65 MENU_ITEM_COUNT 56 MENU_ITEM_COUNT
66 }; 57 };
67 58
59 LauncherContextMenu(ChromeLauncherController* controller,
60 const ash::ShelfItem* item,
61 ash::Shelf* shelf);
62 ChromeLauncherController* controller() const { return controller_; }
63
64 const ash::ShelfItem& item() const { return item_; }
65
66 ash::Shelf* shelf() const { return shelf_; }
67
68 // Add menu item for pin/unpin.
69 void AddPinMenu();
70
71 // Add common shelf options items, e.g. autohide mode, alignment and
72 // setting wallpaper.
73 void AddShelfOptionsMenu();
74
75 // Helper method to execute common commands. Returns true if handled.
76 bool ExecuteCommonCommand(int command_id, int event_flags);
77
78 private:
79 FRIEND_TEST_ALL_PREFIXES(
80 LauncherContextMenuTest,
81 NewIncognitoWindowMenuIsDisabledWhenIncognitoModeOff);
82 FRIEND_TEST_ALL_PREFIXES(LauncherContextMenuTest,
83 NewWindowMenuIsDisabledWhenIncognitoModeForced);
84 FRIEND_TEST_ALL_PREFIXES(LauncherContextMenuTest,
85 AutoHideOptionInMaximizedMode);
86 FRIEND_TEST_ALL_PREFIXES(LauncherContextMenuTest,
87 DesktopShellLauncherContextMenuItemCheck);
88 FRIEND_TEST_ALL_PREFIXES(LauncherContextMenuTest,
89 ArcLauncherContextMenuItemCheck);
90
68 ChromeLauncherController* controller_; 91 ChromeLauncherController* controller_;
69 92
70 ash::ShelfItem item_; 93 ash::ShelfItem item_;
71 94
72 ash::ShelfAlignmentMenu shelf_alignment_menu_; 95 ash::ShelfAlignmentMenu shelf_alignment_menu_;
73 96
74 scoped_ptr<extensions::ContextMenuMatcher> extension_items_;
75
76 ash::Shelf* shelf_; 97 ash::Shelf* shelf_;
77 98
78 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenu); 99 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenu);
79 }; 100 };
80 101
81 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_CONTEXT_MENU_H_ 102 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_CONTEXT_MENU_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698