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 virtual ~EncodingMenuModel();
34 // Overridden from ui::SimpleMenuModel::Delegate:
35 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
36 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
37 virtual bool GetAcceleratorForCommandId(
39 ui::Accelerator* accelerator) OVERRIDE;
40 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
45 Browser* browser_; // weak
47 DISALLOW_COPY_AND_ASSIGN(EncodingMenuModel);
50 // A menu model that builds the contents of the zoom menu.
51 class ZoomMenuModel : public ui::SimpleMenuModel {
53 explicit ZoomMenuModel(ui::SimpleMenuModel::Delegate* delegate);
54 virtual ~ZoomMenuModel();
59 DISALLOW_COPY_AND_ASSIGN(ZoomMenuModel);
62 class ToolsMenuModel : public ui::SimpleMenuModel {
64 ToolsMenuModel(ui::SimpleMenuModel::Delegate* delegate, Browser* browser);
65 virtual ~ToolsMenuModel();
68 void Build(Browser* browser);
70 scoped_ptr<EncodingMenuModel> encoding_menu_model_;
72 DISALLOW_COPY_AND_ASSIGN(ToolsMenuModel);
75 // A menu model that builds the contents of the wrench menu.
76 class WrenchMenuModel : public ui::SimpleMenuModel,
77 public ui::SimpleMenuModel::Delegate,
78 public ui::ButtonMenuItemModel::Delegate,
79 public TabStripModelObserver,
80 public content::NotificationObserver {
82 // Range of command ID's to use for the items representing bookmarks in the
83 // bookmark menu, must not overlap with that for recent tabs submenu.
84 static const int kMinBookmarkCommandId = 1;
85 static const int kMaxBookmarkCommandId = 1000;
87 // Range of command ID's to use for the items in the recent tabs submenu, must
88 // not overlap with that for bookmarks.
89 static const int kMinRecentTabsCommandId = 1001;
90 static const int kMaxRecentTabsCommandId = 1200;
92 // TODO: remove |is_new_menu|.
93 WrenchMenuModel(ui::AcceleratorProvider* provider,
96 virtual ~WrenchMenuModel();
98 // Overridden for ButtonMenuItemModel::Delegate:
99 virtual bool DoesCommandIdDismissMenu(int command_id) const OVERRIDE;
101 // Overridden for both ButtonMenuItemModel::Delegate and SimpleMenuModel:
102 virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE;
103 virtual base::string16 GetLabelForCommandId(int command_id) const OVERRIDE;
104 virtual bool GetIconForCommandId(int command_id,
105 gfx::Image* icon) const OVERRIDE;
106 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
107 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
108 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
109 virtual bool IsCommandIdVisible(int command_id) const OVERRIDE;
110 virtual bool GetAcceleratorForCommandId(
112 ui::Accelerator* accelerator) OVERRIDE;
114 // Overridden from TabStripModelObserver:
115 virtual void ActiveTabChanged(content::WebContents* old_contents,
116 content::WebContents* new_contents,
118 int reason) OVERRIDE;
119 virtual void TabReplacedAt(TabStripModel* tab_strip_model,
120 content::WebContents* old_contents,
121 content::WebContents* new_contents,
123 virtual void TabStripModelDeleted() OVERRIDE;
125 // Overridden from content::NotificationObserver:
126 virtual void Observe(int type,
127 const content::NotificationSource& source,
128 const content::NotificationDetails& details) OVERRIDE;
131 Browser* browser() const { return browser_; }
133 BookmarkSubMenuModel* bookmark_sub_menu_model() const {
134 return bookmark_sub_menu_model_.get();
137 // Calculates |zoom_label_| in response to a zoom change.
138 void UpdateZoomControls();
141 // Testing constructor used for mocking.
142 friend class ::MockWrenchMenuModel;
145 void Build(bool is_new_menu);
147 void AddGlobalErrorMenuItems();
149 // Appends everything needed for the clipboard menu: a menu break, the
150 // clipboard menu content and the finalizing menu break. If the last break
151 // is not needed it can be suppressed by setting |new_menu|
153 void CreateCutCopyPasteMenu(bool new_menu);
155 // Appends everything needed for the zoom menu: a menu break, then the zoom
156 // menu content and then another menu break. If the new menu type is used,
157 // |new_menu| should be set to true.
158 void CreateZoomMenu(bool new_menu);
160 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
162 bool ShouldShowNewIncognitoWindowMenuItem();
164 // Models for the special menu items with buttons.
165 scoped_ptr<ui::ButtonMenuItemModel> edit_menu_item_model_;
166 scoped_ptr<ui::ButtonMenuItemModel> zoom_menu_item_model_;
168 // Label of the zoom label in the zoom menu item.
169 base::string16 zoom_label_;
172 scoped_ptr<ToolsMenuModel> tools_menu_model_;
175 scoped_ptr<BookmarkSubMenuModel> bookmark_sub_menu_model_;
177 // Recent Tabs submenu.
178 scoped_ptr<RecentTabsSubMenuModel> recent_tabs_sub_menu_model_;
180 ui::AcceleratorProvider* provider_; // weak
182 Browser* browser_; // weak
183 TabStripModel* tab_strip_model_; // weak
185 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
186 content::NotificationRegistrar registrar_;
188 DISALLOW_COPY_AND_ASSIGN(WrenchMenuModel);
191 #endif // CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_