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

Side by Side Diff: chrome/browser/ui/views/wrench_menu.h

Issue 23530070: backup for dynamic recent tabs submenu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new RecentTabsMenuModelDelegate w/ new intf Created 7 years, 2 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 | Annotate | Revision Log
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_VIEWS_WRENCH_MENU_H_ 5 #ifndef CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_
6 #define CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_ 6 #define CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_
7 7
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/observer_list.h" 12 #include "base/observer_list.h"
13 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" 13 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
14 #include "chrome/browser/ui/views/menu_items_changed_delegate.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/models/menu_model.h" 17 #include "ui/base/models/menu_model.h"
17 #include "ui/views/controls/menu/menu_delegate.h" 18 #include "ui/views/controls/menu/menu_delegate.h"
18 19
19 class BookmarkMenuDelegate; 20 class BookmarkMenuDelegate;
20 class Browser; 21 class Browser;
22 class RecentTabsMenuModelDelegate;
21 class WrenchMenuObserver; 23 class WrenchMenuObserver;
22 24
23 namespace ui { 25 namespace ui {
24 class NativeTheme; 26 class NativeTheme;
25 } 27 }
26 28
27 namespace views { 29 namespace views {
28 class MenuButton; 30 class MenuButton;
29 struct MenuConfig; 31 struct MenuConfig;
30 class MenuItemView; 32 class MenuItemView;
31 class MenuRunner; 33 class MenuRunner;
32 class View; 34 class View;
33 } // namespace views 35 } // namespace views
34 36
35 // WrenchMenu adapts the WrenchMenuModel to view's menu related classes. 37 // WrenchMenu adapts the WrenchMenuModel to view's menu related classes.
36 class WrenchMenu : public views::MenuDelegate, 38 class WrenchMenu : public views::MenuDelegate,
39 public MenuItemsChangedDelegate,
37 public BaseBookmarkModelObserver, 40 public BaseBookmarkModelObserver,
38 public content::NotificationObserver { 41 public content::NotificationObserver {
39 public: 42 public:
40 // TODO: remove |use_new_menu| and |supports_new_separators|. 43 // TODO: remove |use_new_menu| and |supports_new_separators|.
41 WrenchMenu(Browser* browser, 44 WrenchMenu(Browser* browser,
42 bool use_new_menu, 45 bool use_new_menu,
43 bool supports_new_separators); 46 bool supports_new_separators);
44 virtual ~WrenchMenu(); 47 virtual ~WrenchMenu();
45 48
46 void Init(ui::MenuModel* model); 49 void Init(ui::MenuModel* model);
47 50
48 // Shows the menu relative to the specified view. 51 // Shows the menu relative to the specified view.
49 void RunMenu(views::MenuButton* host); 52 void RunMenu(views::MenuButton* host);
50 53
51 // Whether the menu is currently visible to the user. 54 // Whether the menu is currently visible to the user.
52 bool IsShowing(); 55 bool IsShowing();
53 56
54 const views::MenuConfig& GetMenuConfig() const; 57 const views::MenuConfig& GetMenuConfig() const;
55 58
56 bool use_new_menu() const { return use_new_menu_; } 59 bool use_new_menu() const { return use_new_menu_; }
57 60
58 void AddObserver(WrenchMenuObserver* observer); 61 void AddObserver(WrenchMenuObserver* observer);
59 void RemoveObserver(WrenchMenuObserver* observer); 62 void RemoveObserver(WrenchMenuObserver* observer);
60 63
61 // MenuDelegate overrides: 64 // MenuDelegate overrides:
62 virtual const gfx::Font* GetLabelFont(int index) const OVERRIDE; 65 virtual const gfx::Font* GetLabelFont(int id) const OVERRIDE;
63 virtual bool GetForegroundColor(int command_id, 66 virtual bool GetForegroundColor(int command_id,
64 bool is_hovered, 67 bool is_hovered,
65 SkColor* override_color) const OVERRIDE; 68 SkColor* override_color) const OVERRIDE;
66 virtual string16 GetTooltipText(int id, const gfx::Point& p) const OVERRIDE; 69 virtual string16 GetTooltipText(int id, const gfx::Point& p) const OVERRIDE;
67 virtual bool IsTriggerableEvent(views::MenuItemView* menu, 70 virtual bool IsTriggerableEvent(views::MenuItemView* menu,
68 const ui::Event& e) OVERRIDE; 71 const ui::Event& e) OVERRIDE;
69 virtual bool GetDropFormats( 72 virtual bool GetDropFormats(
70 views::MenuItemView* menu, 73 views::MenuItemView* menu,
71 int* formats, 74 int* formats,
72 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE; 75 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE;
(...skipping 15 matching lines...) Expand all
88 ui::OSExchangeData* data) OVERRIDE; 91 ui::OSExchangeData* data) OVERRIDE;
89 virtual int GetDragOperations(views::MenuItemView* sender) OVERRIDE; 92 virtual int GetDragOperations(views::MenuItemView* sender) OVERRIDE;
90 virtual int GetMaxWidthForMenu(views::MenuItemView* menu) OVERRIDE; 93 virtual int GetMaxWidthForMenu(views::MenuItemView* menu) OVERRIDE;
91 virtual bool IsItemChecked(int id) const OVERRIDE; 94 virtual bool IsItemChecked(int id) const OVERRIDE;
92 virtual bool IsCommandEnabled(int id) const OVERRIDE; 95 virtual bool IsCommandEnabled(int id) const OVERRIDE;
93 virtual void ExecuteCommand(int id, int mouse_event_flags) OVERRIDE; 96 virtual void ExecuteCommand(int id, int mouse_event_flags) OVERRIDE;
94 virtual bool GetAccelerator(int id, ui::Accelerator* accelerator) OVERRIDE; 97 virtual bool GetAccelerator(int id, ui::Accelerator* accelerator) OVERRIDE;
95 virtual void WillShowMenu(views::MenuItemView* menu) OVERRIDE; 98 virtual void WillShowMenu(views::MenuItemView* menu) OVERRIDE;
96 virtual void WillHideMenu(views::MenuItemView* menu) OVERRIDE; 99 virtual void WillHideMenu(views::MenuItemView* menu) OVERRIDE;
97 100
101 // MenuItemsChangedDelegate overrides:
102 void OnItemAdded(views::MenuItemView* parent, int menu_index,
103 ui::MenuModel* model, int model_index,
104 int item_id) OVERRIDE;
105 void OnItemRemoved(views::MenuItemView* parent, int menu_index,
106 int item_id) OVERRIDE;
107 virtual void UpdateMapOfMenuItemIdAndModel(
108 ui::MenuModel* model, std::vector<int>& item_ids) OVERRIDE;
109
98 // BaseBookmarkModelObserver overrides: 110 // BaseBookmarkModelObserver overrides:
99 virtual void BookmarkModelChanged() OVERRIDE; 111 virtual void BookmarkModelChanged() OVERRIDE;
100 112
101 // content::NotificationObserver overrides: 113 // content::NotificationObserver overrides:
102 virtual void Observe(int type, 114 virtual void Observe(int type,
103 const content::NotificationSource& source, 115 const content::NotificationSource& source,
104 const content::NotificationDetails& details) OVERRIDE; 116 const content::NotificationDetails& details) OVERRIDE;
105 117
106 private: 118 private:
119 friend class RecentTabsMenuModelDelegate;
120
107 class CutCopyPasteView; 121 class CutCopyPasteView;
108 class RecentTabsMenuModelDelegate;
109 class ZoomView; 122 class ZoomView;
110 123
111 typedef std::pair<ui::MenuModel*,int> Entry; 124 typedef std::pair<ui::MenuModel*,int> Entry;
112 typedef std::map<int,Entry> IDToEntry; 125 typedef std::map<int,Entry> IDToEntry;
113 126
114 const ui::NativeTheme* GetNativeTheme() const; 127 const ui::NativeTheme* GetNativeTheme() const;
115 128
116 // Populates |parent| with all the child menus in |model|. Recursively invokes 129 // Populates |parent| with all the child menus in |model|. Recursively invokes
117 // |PopulateMenu| for any submenu. |next_id| is incremented for every menu 130 // |PopulateMenu| for any submenu. |next_id| is incremented for every menu
118 // that is created. 131 // that is created.
119 void PopulateMenu(views::MenuItemView* parent, 132 void PopulateMenu(views::MenuItemView* parent,
120 ui::MenuModel* model, 133 ui::MenuModel* model,
121 int* next_id); 134 int* next_id);
122 135
123 // Adds a new menu to |parent| to represent the MenuModel/index pair passed 136 // Adds a new menu to |parent| at |menu_index| to represent the
124 // in. 137 // MenuModel/model_index pair passed in.
125 // Fur button containing menu items a |height| override can be specified with 138 // Fur button containing menu items a |height| override can be specified with
126 // a number bigger then 0. 139 // a number bigger then 0.
127 views::MenuItemView* AppendMenuItem(views::MenuItemView* parent, 140 views::MenuItemView* AddMenuItem(views::MenuItemView* parent,
128 ui::MenuModel* model, 141 int menu_index,
129 int index, 142 ui::MenuModel* model,
130 ui::MenuModel::ItemType menu_type, 143 int model_index,
131 int* next_id, 144 ui::MenuModel::ItemType menu_type,
132 int height); 145 int* next_id,
146 int height);
133 147
134 // Invoked from the cut/copy/paste menus. Cancels the current active menu and 148 // Invoked from the cut/copy/paste menus. Cancels the current active menu and
135 // activates the menu item in |model| at |index|. 149 // activates the menu item in |model| at |index|.
136 void CancelAndEvaluate(ui::MenuModel* model, int index); 150 void CancelAndEvaluate(ui::MenuModel* model, int index);
137 151
138 // Creates the bookmark menu if necessary. Does nothing if already created or 152 // Creates the bookmark menu if necessary. Does nothing if already created or
139 // the bookmark model isn't loaded. 153 // the bookmark model isn't loaded.
140 void CreateBookmarkMenu(); 154 void CreateBookmarkMenu();
141 155
142 // Returns true if |id| identifies a bookmark menu item. 156 // Returns true if |id| identifies a bookmark menu item.
143 bool is_bookmark_command(int id) const { 157 bool IsBookmarkCommand(int id) const;
144 return bookmark_menu_delegate_.get() && id >= first_bookmark_command_id_;
145 }
146 158
147 // Returns true if |id| identifies a recent tabs menu item. 159 // Returns true if |id| identifies a recent tabs menu item.
148 bool is_recent_tabs_command(int id) const { 160 bool IsRecentTabsCommand(int id) const;
149 return (recent_tabs_menu_model_delegate_.get() &&
150 id >= first_recent_tabs_command_id_ &&
151 id <= last_recent_tabs_command_id_);
152 }
153 161
154 // The views menu. Owned by |menu_runner_|. 162 // The views menu. Owned by |menu_runner_|.
155 views::MenuItemView* root_; 163 views::MenuItemView* root_;
156 164
157 scoped_ptr<views::MenuRunner> menu_runner_; 165 scoped_ptr<views::MenuRunner> menu_runner_;
158 166
159 // Maps from the ID as understood by MenuItemView to the model/index pair the 167 // Maps from the ID as understood by MenuItemView to the model/index pair the
160 // item came from. 168 // item came from.
161 IDToEntry id_to_entry_; 169 IDToEntry id_to_entry_;
162 170
(...skipping 12 matching lines...) Expand all
175 183
176 // Menu corresponding to IDC_BOOKMARKS_MENU. 184 // Menu corresponding to IDC_BOOKMARKS_MENU.
177 views::MenuItemView* bookmark_menu_; 185 views::MenuItemView* bookmark_menu_;
178 186
179 // Menu corresponding to IDC_FEEDBACK. 187 // Menu corresponding to IDC_FEEDBACK.
180 views::MenuItemView* feedback_menu_item_; 188 views::MenuItemView* feedback_menu_item_;
181 189
182 // Used for managing "Recent tabs" menu items. 190 // Used for managing "Recent tabs" menu items.
183 scoped_ptr<RecentTabsMenuModelDelegate> recent_tabs_menu_model_delegate_; 191 scoped_ptr<RecentTabsMenuModelDelegate> recent_tabs_menu_model_delegate_;
184 192
185 // First ID to use for the items representing bookmarks in the bookmark menu. 193 // ID of the last item in the recent tabs submenu.
186 int first_bookmark_command_id_;
187
188 // First/last IDs to use for the items of the recent tabs sub-menu.
189 int first_recent_tabs_command_id_;
190 int last_recent_tabs_command_id_; 194 int last_recent_tabs_command_id_;
191 195
192 content::NotificationRegistrar registrar_; 196 content::NotificationRegistrar registrar_;
193 197
194 const bool use_new_menu_; 198 const bool use_new_menu_;
195 199
196 const bool supports_new_separators_; 200 const bool supports_new_separators_;
197 201
198 ObserverList<WrenchMenuObserver> observer_list_; 202 ObserverList<WrenchMenuObserver> observer_list_;
199 203
200 DISALLOW_COPY_AND_ASSIGN(WrenchMenu); 204 DISALLOW_COPY_AND_ASSIGN(WrenchMenu);
201 }; 205 };
202 206
203 #endif // CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_ 207 #endif // CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/recent_tabs_menu_model_delegate.cc ('k') | chrome/browser/ui/views/wrench_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698