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_TOOLBAR_WRENCH_MENU_MODEL_H_ | 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_APP_MENU_MODEL_H_ |
6 #define CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_ | 6 #define CHROME_BROWSER_UI_TOOLBAR_APP_MENU_MODEL_H_ |
7 | 7 |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
11 #include "base/timer/elapsed_timer.h" | 12 #include "base/timer/elapsed_timer.h" |
12 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
13 #include "content/public/browser/host_zoom_map.h" | 14 #include "content/public/browser/host_zoom_map.h" |
14 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
16 #include "ui/base/accelerators/accelerator.h" | 17 #include "ui/base/accelerators/accelerator.h" |
17 #include "ui/base/models/button_menu_item_model.h" | 18 #include "ui/base/models/button_menu_item_model.h" |
18 #include "ui/base/models/simple_menu_model.h" | 19 #include "ui/base/models/simple_menu_model.h" |
19 | 20 |
20 class BookmarkSubMenuModel; | 21 class BookmarkSubMenuModel; |
21 class Browser; | 22 class Browser; |
22 class RecentTabsSubMenuModel; | 23 class RecentTabsSubMenuModel; |
23 | 24 |
24 namespace { | 25 namespace { |
25 class MockWrenchMenuModel; | 26 class MockAppMenuModel; |
26 } // namespace | 27 } // namespace |
27 | 28 |
28 enum WrenchMenuAction { | 29 enum AppMenuAction { |
29 MENU_ACTION_NEW_TAB = 0, | 30 MENU_ACTION_NEW_TAB = 0, |
30 MENU_ACTION_NEW_WINDOW, | 31 MENU_ACTION_NEW_WINDOW, |
31 MENU_ACTION_NEW_INCOGNITO_WINDOW, | 32 MENU_ACTION_NEW_INCOGNITO_WINDOW, |
32 MENU_ACTION_SHOW_BOOKMARK_BAR, | 33 MENU_ACTION_SHOW_BOOKMARK_BAR, |
33 MENU_ACTION_SHOW_BOOKMARK_MANAGER, | 34 MENU_ACTION_SHOW_BOOKMARK_MANAGER, |
34 MENU_ACTION_IMPORT_SETTINGS, | 35 MENU_ACTION_IMPORT_SETTINGS, |
35 MENU_ACTION_BOOKMARK_PAGE, | 36 MENU_ACTION_BOOKMARK_PAGE, |
36 MENU_ACTION_BOOKMARK_ALL_TABS, | 37 MENU_ACTION_BOOKMARK_ALL_TABS, |
37 MENU_ACTION_PIN_TO_START_SCREEN, | 38 MENU_ACTION_PIN_TO_START_SCREEN, |
38 MENU_ACTION_RESTORE_TAB, | 39 MENU_ACTION_RESTORE_TAB, |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 ~ToolsMenuModel() override; | 114 ~ToolsMenuModel() override; |
114 | 115 |
115 private: | 116 private: |
116 void Build(Browser* browser); | 117 void Build(Browser* browser); |
117 | 118 |
118 scoped_ptr<EncodingMenuModel> encoding_menu_model_; | 119 scoped_ptr<EncodingMenuModel> encoding_menu_model_; |
119 | 120 |
120 DISALLOW_COPY_AND_ASSIGN(ToolsMenuModel); | 121 DISALLOW_COPY_AND_ASSIGN(ToolsMenuModel); |
121 }; | 122 }; |
122 | 123 |
123 // A menu model that builds the contents of the wrench menu. | 124 // A menu model that builds the contents of the app menu. |
124 class WrenchMenuModel : public ui::SimpleMenuModel, | 125 class AppMenuModel : public ui::SimpleMenuModel, |
125 public ui::SimpleMenuModel::Delegate, | 126 public ui::SimpleMenuModel::Delegate, |
126 public ui::ButtonMenuItemModel::Delegate, | 127 public ui::ButtonMenuItemModel::Delegate, |
127 public TabStripModelObserver, | 128 public TabStripModelObserver, |
128 public content::NotificationObserver { | 129 public content::NotificationObserver { |
129 public: | 130 public: |
130 // Range of command IDs to use for the items in the recent tabs submenu. | 131 // Range of command IDs to use for the items in the recent tabs submenu. |
131 static const int kMinRecentTabsCommandId = 1001; | 132 static const int kMinRecentTabsCommandId = 1001; |
132 static const int kMaxRecentTabsCommandId = 1200; | 133 static const int kMaxRecentTabsCommandId = 1200; |
133 | 134 |
134 WrenchMenuModel(ui::AcceleratorProvider* provider, Browser* browser); | 135 AppMenuModel(ui::AcceleratorProvider* provider, Browser* browser); |
135 ~WrenchMenuModel() override; | 136 ~AppMenuModel() override; |
136 | 137 |
137 // Overridden for ButtonMenuItemModel::Delegate: | 138 // Overridden for ButtonMenuItemModel::Delegate: |
138 bool DoesCommandIdDismissMenu(int command_id) const override; | 139 bool DoesCommandIdDismissMenu(int command_id) const override; |
139 | 140 |
140 // Overridden for both ButtonMenuItemModel::Delegate and SimpleMenuModel: | 141 // Overridden for both ButtonMenuItemModel::Delegate and SimpleMenuModel: |
141 bool IsItemForCommandIdDynamic(int command_id) const override; | 142 bool IsItemForCommandIdDynamic(int command_id) const override; |
142 base::string16 GetLabelForCommandId(int command_id) const override; | 143 base::string16 GetLabelForCommandId(int command_id) const override; |
143 bool GetIconForCommandId(int command_id, gfx::Image* icon) const override; | 144 bool GetIconForCommandId(int command_id, gfx::Image* icon) const override; |
144 void ExecuteCommand(int command_id, int event_flags) override; | 145 void ExecuteCommand(int command_id, int event_flags) override; |
145 bool IsCommandIdChecked(int command_id) const override; | 146 bool IsCommandIdChecked(int command_id) const override; |
(...skipping 23 matching lines...) Expand all Loading... |
169 BookmarkSubMenuModel* bookmark_sub_menu_model() const { | 170 BookmarkSubMenuModel* bookmark_sub_menu_model() const { |
170 return bookmark_sub_menu_model_.get(); | 171 return bookmark_sub_menu_model_.get(); |
171 } | 172 } |
172 | 173 |
173 // Calculates |zoom_label_| in response to a zoom change. | 174 // Calculates |zoom_label_| in response to a zoom change. |
174 void UpdateZoomControls(); | 175 void UpdateZoomControls(); |
175 | 176 |
176 private: | 177 private: |
177 class HelpMenuModel; | 178 class HelpMenuModel; |
178 // Testing constructor used for mocking. | 179 // Testing constructor used for mocking. |
179 friend class ::MockWrenchMenuModel; | 180 friend class ::MockAppMenuModel; |
180 | 181 |
181 WrenchMenuModel(); | 182 AppMenuModel(); |
182 | 183 |
183 void Build(); | 184 void Build(); |
184 | 185 |
185 // Adds actionable global error menu items to the menu. | 186 // Adds actionable global error menu items to the menu. |
186 // Examples: Extension permissions and sign in errors. | 187 // Examples: Extension permissions and sign in errors. |
187 // Returns a boolean indicating whether any menu items were added. | 188 // Returns a boolean indicating whether any menu items were added. |
188 bool AddGlobalErrorMenuItems(); | 189 bool AddGlobalErrorMenuItems(); |
189 | 190 |
190 // Appends everything needed for the clipboard menu: a menu break, the | 191 // Appends everything needed for the clipboard menu: a menu break, the |
191 // clipboard menu content and the finalizing menu break. | 192 // clipboard menu content and the finalizing menu break. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 // Recent Tabs submenu. | 241 // Recent Tabs submenu. |
241 scoped_ptr<RecentTabsSubMenuModel> recent_tabs_sub_menu_model_; | 242 scoped_ptr<RecentTabsSubMenuModel> recent_tabs_sub_menu_model_; |
242 | 243 |
243 ui::AcceleratorProvider* provider_; // weak | 244 ui::AcceleratorProvider* provider_; // weak |
244 | 245 |
245 Browser* browser_; // weak | 246 Browser* browser_; // weak |
246 | 247 |
247 scoped_ptr<content::HostZoomMap::Subscription> browser_zoom_subscription_; | 248 scoped_ptr<content::HostZoomMap::Subscription> browser_zoom_subscription_; |
248 content::NotificationRegistrar registrar_; | 249 content::NotificationRegistrar registrar_; |
249 | 250 |
250 DISALLOW_COPY_AND_ASSIGN(WrenchMenuModel); | 251 DISALLOW_COPY_AND_ASSIGN(AppMenuModel); |
251 }; | 252 }; |
252 | 253 |
253 #endif // CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_ | 254 #endif // CHROME_BROWSER_UI_TOOLBAR_APP_MENU_MODEL_H_ |
OLD | NEW |