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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_
8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
11 #include "content/public/browser/host_zoom_map.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "ui/base/accelerators/accelerator.h"
15 #include "ui/base/models/button_menu_item_model.h"
16 #include "ui/base/models/simple_menu_model.h"
18 class BookmarkSubMenuModel;
20 class RecentTabsSubMenuModel;
24 class MockWrenchMenuModel;
27 // A menu model that builds the contents of an encoding menu.
28 class EncodingMenuModel : public ui::SimpleMenuModel,
29 public ui::SimpleMenuModel::Delegate {
31 explicit EncodingMenuModel(Browser* browser);
32 ~EncodingMenuModel() override;
34 // Overridden from ui::SimpleMenuModel::Delegate:
35 bool IsCommandIdChecked(int command_id) const override;
36 bool IsCommandIdEnabled(int command_id) const override;
37 bool GetAcceleratorForCommandId(int command_id,
38 ui::Accelerator* accelerator) override;
39 void ExecuteCommand(int command_id, int event_flags) override;
44 Browser* browser_; // weak
46 DISALLOW_COPY_AND_ASSIGN(EncodingMenuModel);
49 // A menu model that builds the contents of the zoom menu.
50 class ZoomMenuModel : public ui::SimpleMenuModel {
52 explicit ZoomMenuModel(ui::SimpleMenuModel::Delegate* delegate);
53 ~ZoomMenuModel() override;
58 DISALLOW_COPY_AND_ASSIGN(ZoomMenuModel);
61 class ToolsMenuModel : public ui::SimpleMenuModel {
63 ToolsMenuModel(ui::SimpleMenuModel::Delegate* delegate, Browser* browser);
64 ~ToolsMenuModel() override;
67 void Build(Browser* browser);
69 scoped_ptr<EncodingMenuModel> encoding_menu_model_;
71 DISALLOW_COPY_AND_ASSIGN(ToolsMenuModel);
74 // A menu model that builds the contents of the wrench menu.
75 class WrenchMenuModel : public ui::SimpleMenuModel,
76 public ui::SimpleMenuModel::Delegate,
77 public ui::ButtonMenuItemModel::Delegate,
78 public TabStripModelObserver,
79 public content::NotificationObserver {
81 // Range of command ID's to use for the items representing bookmarks in the
82 // bookmark menu, must not overlap with that for recent tabs submenu.
83 static const int kMinBookmarkCommandId = 1;
84 static const int kMaxBookmarkCommandId = 1000;
86 // Range of command ID's to use for the items in the recent tabs submenu, must
87 // not overlap with that for bookmarks.
88 static const int kMinRecentTabsCommandId = 1001;
89 static const int kMaxRecentTabsCommandId = 1200;
91 WrenchMenuModel(ui::AcceleratorProvider* provider, Browser* browser);
92 ~WrenchMenuModel() override;
94 // Overridden for ButtonMenuItemModel::Delegate:
95 bool DoesCommandIdDismissMenu(int command_id) const override;
97 // Overridden for both ButtonMenuItemModel::Delegate and SimpleMenuModel:
98 bool IsItemForCommandIdDynamic(int command_id) const override;
99 base::string16 GetLabelForCommandId(int command_id) const override;
100 bool GetIconForCommandId(int command_id, gfx::Image* icon) const override;
101 void ExecuteCommand(int command_id, int event_flags) override;
102 bool IsCommandIdChecked(int command_id) const override;
103 bool IsCommandIdEnabled(int command_id) const override;
104 bool IsCommandIdVisible(int command_id) const override;
105 bool GetAcceleratorForCommandId(int command_id,
106 ui::Accelerator* accelerator) override;
108 // Overridden from TabStripModelObserver:
109 void ActiveTabChanged(content::WebContents* old_contents,
110 content::WebContents* new_contents,
112 int reason) override;
113 void TabReplacedAt(TabStripModel* tab_strip_model,
114 content::WebContents* old_contents,
115 content::WebContents* new_contents,
117 void TabStripModelDeleted() override;
119 // Overridden from content::NotificationObserver:
120 void Observe(int type,
121 const content::NotificationSource& source,
122 const content::NotificationDetails& details) override;
125 Browser* browser() const { return browser_; }
127 BookmarkSubMenuModel* bookmark_sub_menu_model() const {
128 return bookmark_sub_menu_model_.get();
131 // Calculates |zoom_label_| in response to a zoom change.
132 void UpdateZoomControls();
136 // Testing constructor used for mocking.
137 friend class ::MockWrenchMenuModel;
143 void AddGlobalErrorMenuItems();
145 // Appends everything needed for the clipboard menu: a menu break, the
146 // clipboard menu content and the finalizing menu break.
147 void CreateCutCopyPasteMenu();
149 // Add a menu item for the extension icons.
150 void CreateExtensionToolbarOverflowMenu();
152 // Appends everything needed for the zoom menu: a menu break, then the zoom
153 // menu content and then another menu break.
154 void CreateZoomMenu();
156 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
158 bool ShouldShowNewIncognitoWindowMenuItem();
160 // Models for the special menu items with buttons.
161 scoped_ptr<ui::ButtonMenuItemModel> edit_menu_item_model_;
162 scoped_ptr<ui::ButtonMenuItemModel> zoom_menu_item_model_;
164 // Label of the zoom label in the zoom menu item.
165 base::string16 zoom_label_;
167 #if defined(GOOGLE_CHROME_BUILD)
169 scoped_ptr<HelpMenuModel> help_menu_model_;
173 scoped_ptr<ToolsMenuModel> tools_menu_model_;
176 scoped_ptr<BookmarkSubMenuModel> bookmark_sub_menu_model_;
178 // Recent Tabs submenu.
179 scoped_ptr<RecentTabsSubMenuModel> recent_tabs_sub_menu_model_;
181 ui::AcceleratorProvider* provider_; // weak
183 Browser* browser_; // weak
184 TabStripModel* tab_strip_model_; // weak
186 scoped_ptr<content::HostZoomMap::Subscription> content_zoom_subscription_;
187 scoped_ptr<content::HostZoomMap::Subscription> browser_zoom_subscription_;
188 content::NotificationRegistrar registrar_;
190 DISALLOW_COPY_AND_ASSIGN(WrenchMenuModel);
193 #endif // CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_