Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / toolbar / wrench_menu_model.h
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.
4
5 #ifndef CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_
7
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"
17
18 class BookmarkSubMenuModel;
19 class Browser;
20 class RecentTabsSubMenuModel;
21 class TabStripModel;
22
23 namespace {
24 class MockWrenchMenuModel;
25 }  // namespace
26
27 // A menu model that builds the contents of an encoding menu.
28 class EncodingMenuModel : public ui::SimpleMenuModel,
29                           public ui::SimpleMenuModel::Delegate {
30  public:
31   explicit EncodingMenuModel(Browser* browser);
32   ~EncodingMenuModel() override;
33
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;
40
41  private:
42   void Build();
43
44   Browser* browser_;  // weak
45
46   DISALLOW_COPY_AND_ASSIGN(EncodingMenuModel);
47 };
48
49 // A menu model that builds the contents of the zoom menu.
50 class ZoomMenuModel : public ui::SimpleMenuModel {
51  public:
52   explicit ZoomMenuModel(ui::SimpleMenuModel::Delegate* delegate);
53   ~ZoomMenuModel() override;
54
55  private:
56   void Build();
57
58   DISALLOW_COPY_AND_ASSIGN(ZoomMenuModel);
59 };
60
61 class ToolsMenuModel : public ui::SimpleMenuModel {
62  public:
63   ToolsMenuModel(ui::SimpleMenuModel::Delegate* delegate, Browser* browser);
64   ~ToolsMenuModel() override;
65
66  private:
67   void Build(Browser* browser);
68
69   scoped_ptr<EncodingMenuModel> encoding_menu_model_;
70
71   DISALLOW_COPY_AND_ASSIGN(ToolsMenuModel);
72 };
73
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 {
80  public:
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;
85
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;
90
91   WrenchMenuModel(ui::AcceleratorProvider* provider, Browser* browser);
92   ~WrenchMenuModel() override;
93
94   // Overridden for ButtonMenuItemModel::Delegate:
95   bool DoesCommandIdDismissMenu(int command_id) const override;
96
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;
107
108   // Overridden from TabStripModelObserver:
109   void ActiveTabChanged(content::WebContents* old_contents,
110                         content::WebContents* new_contents,
111                         int index,
112                         int reason) override;
113   void TabReplacedAt(TabStripModel* tab_strip_model,
114                      content::WebContents* old_contents,
115                      content::WebContents* new_contents,
116                      int index) override;
117   void TabStripModelDeleted() override;
118
119   // Overridden from content::NotificationObserver:
120   void Observe(int type,
121                const content::NotificationSource& source,
122                const content::NotificationDetails& details) override;
123
124   // Getters.
125   Browser* browser() const { return browser_; }
126
127   BookmarkSubMenuModel* bookmark_sub_menu_model() const {
128     return bookmark_sub_menu_model_.get();
129   }
130
131   // Calculates |zoom_label_| in response to a zoom change.
132   void UpdateZoomControls();
133
134  private:
135   class HelpMenuModel;
136   // Testing constructor used for mocking.
137   friend class ::MockWrenchMenuModel;
138
139   WrenchMenuModel();
140
141   void Build();
142
143   void AddGlobalErrorMenuItems();
144
145   // Appends everything needed for the clipboard menu: a menu break, the
146   // clipboard menu content and the finalizing menu break.
147   void CreateCutCopyPasteMenu();
148
149   // Add a menu item for the extension icons.
150   void CreateExtensionToolbarOverflowMenu();
151
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();
155
156   void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
157
158   bool ShouldShowNewIncognitoWindowMenuItem();
159
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_;
163
164   // Label of the zoom label in the zoom menu item.
165   base::string16 zoom_label_;
166
167 #if defined(GOOGLE_CHROME_BUILD)
168   // Help menu.
169   scoped_ptr<HelpMenuModel> help_menu_model_;
170 #endif
171
172   // Tools menu.
173   scoped_ptr<ToolsMenuModel> tools_menu_model_;
174
175   // Bookmark submenu.
176   scoped_ptr<BookmarkSubMenuModel> bookmark_sub_menu_model_;
177
178   // Recent Tabs submenu.
179   scoped_ptr<RecentTabsSubMenuModel> recent_tabs_sub_menu_model_;
180
181   ui::AcceleratorProvider* provider_;  // weak
182
183   Browser* browser_;  // weak
184   TabStripModel* tab_strip_model_; // weak
185
186   scoped_ptr<content::HostZoomMap::Subscription> content_zoom_subscription_;
187   scoped_ptr<content::HostZoomMap::Subscription> browser_zoom_subscription_;
188   content::NotificationRegistrar registrar_;
189
190   DISALLOW_COPY_AND_ASSIGN(WrenchMenuModel);
191 };
192
193 #endif  // CHROME_BROWSER_UI_TOOLBAR_WRENCH_MENU_MODEL_H_