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_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 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 bool IsShowing(); | 52 bool IsShowing(); |
53 | 53 |
54 const views::MenuConfig& GetMenuConfig() const; | 54 const views::MenuConfig& GetMenuConfig() const; |
55 | 55 |
56 bool use_new_menu() const { return use_new_menu_; } | 56 bool use_new_menu() const { return use_new_menu_; } |
57 | 57 |
58 void AddObserver(WrenchMenuObserver* observer); | 58 void AddObserver(WrenchMenuObserver* observer); |
59 void RemoveObserver(WrenchMenuObserver* observer); | 59 void RemoveObserver(WrenchMenuObserver* observer); |
60 | 60 |
61 // MenuDelegate overrides: | 61 // MenuDelegate overrides: |
62 virtual const gfx::Font* GetLabelFont(int command_id) const OVERRIDE; | 62 virtual const gfx::Font* GetLabelFont(int index) const OVERRIDE; |
63 virtual bool GetForegroundColor(int command_id, | 63 virtual bool GetForegroundColor(int command_id, |
64 bool is_hovered, | 64 bool is_hovered, |
65 SkColor* override_color) const OVERRIDE; | 65 SkColor* override_color) const OVERRIDE; |
66 virtual string16 GetTooltipText(int command_id, | 66 virtual string16 GetTooltipText(int id, const gfx::Point& p) const OVERRIDE; |
67 const gfx::Point& p) const OVERRIDE; | |
68 virtual bool IsTriggerableEvent(views::MenuItemView* menu, | 67 virtual bool IsTriggerableEvent(views::MenuItemView* menu, |
69 const ui::Event& e) OVERRIDE; | 68 const ui::Event& e) OVERRIDE; |
70 virtual bool GetDropFormats( | 69 virtual bool GetDropFormats( |
71 views::MenuItemView* menu, | 70 views::MenuItemView* menu, |
72 int* formats, | 71 int* formats, |
73 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE; | 72 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE; |
74 virtual bool AreDropTypesRequired(views::MenuItemView* menu) OVERRIDE; | 73 virtual bool AreDropTypesRequired(views::MenuItemView* menu) OVERRIDE; |
75 virtual bool CanDrop(views::MenuItemView* menu, | 74 virtual bool CanDrop(views::MenuItemView* menu, |
76 const ui::OSExchangeData& data) OVERRIDE; | 75 const ui::OSExchangeData& data) OVERRIDE; |
77 virtual int GetDropOperation(views::MenuItemView* item, | 76 virtual int GetDropOperation(views::MenuItemView* item, |
78 const ui::DropTargetEvent& event, | 77 const ui::DropTargetEvent& event, |
79 DropPosition* position) OVERRIDE; | 78 DropPosition* position) OVERRIDE; |
80 virtual int OnPerformDrop(views::MenuItemView* menu, | 79 virtual int OnPerformDrop(views::MenuItemView* menu, |
81 DropPosition position, | 80 DropPosition position, |
82 const ui::DropTargetEvent& event) OVERRIDE; | 81 const ui::DropTargetEvent& event) OVERRIDE; |
83 virtual bool ShowContextMenu(views::MenuItemView* source, | 82 virtual bool ShowContextMenu(views::MenuItemView* source, |
84 int command_id, | 83 int id, |
85 const gfx::Point& p, | 84 const gfx::Point& p, |
86 ui::MenuSourceType source_type) OVERRIDE; | 85 ui::MenuSourceType source_type) OVERRIDE; |
87 virtual bool CanDrag(views::MenuItemView* menu) OVERRIDE; | 86 virtual bool CanDrag(views::MenuItemView* menu) OVERRIDE; |
88 virtual void WriteDragData(views::MenuItemView* sender, | 87 virtual void WriteDragData(views::MenuItemView* sender, |
89 ui::OSExchangeData* data) OVERRIDE; | 88 ui::OSExchangeData* data) OVERRIDE; |
90 virtual int GetDragOperations(views::MenuItemView* sender) OVERRIDE; | 89 virtual int GetDragOperations(views::MenuItemView* sender) OVERRIDE; |
91 virtual int GetMaxWidthForMenu(views::MenuItemView* menu) OVERRIDE; | 90 virtual int GetMaxWidthForMenu(views::MenuItemView* menu) OVERRIDE; |
92 virtual bool IsItemChecked(int command_id) const OVERRIDE; | 91 virtual bool IsItemChecked(int id) const OVERRIDE; |
93 virtual bool IsCommandEnabled(int command_id) const OVERRIDE; | 92 virtual bool IsCommandEnabled(int id) const OVERRIDE; |
94 virtual void ExecuteCommand(int command_id, int mouse_event_flags) OVERRIDE; | 93 virtual void ExecuteCommand(int id, int mouse_event_flags) OVERRIDE; |
95 virtual bool GetAccelerator(int command_id, | 94 virtual bool GetAccelerator(int id, ui::Accelerator* accelerator) OVERRIDE; |
96 ui::Accelerator* accelerator) OVERRIDE; | |
97 virtual void WillShowMenu(views::MenuItemView* menu) OVERRIDE; | 95 virtual void WillShowMenu(views::MenuItemView* menu) OVERRIDE; |
98 virtual void WillHideMenu(views::MenuItemView* menu) OVERRIDE; | 96 virtual void WillHideMenu(views::MenuItemView* menu) OVERRIDE; |
99 | 97 |
100 // BaseBookmarkModelObserver overrides: | 98 // BaseBookmarkModelObserver overrides: |
101 virtual void BookmarkModelChanged() OVERRIDE; | 99 virtual void BookmarkModelChanged() OVERRIDE; |
102 | 100 |
103 // content::NotificationObserver overrides: | 101 // content::NotificationObserver overrides: |
104 virtual void Observe(int type, | 102 virtual void Observe(int type, |
105 const content::NotificationSource& source, | 103 const content::NotificationSource& source, |
106 const content::NotificationDetails& details) OVERRIDE; | 104 const content::NotificationDetails& details) OVERRIDE; |
107 | 105 |
108 private: | 106 private: |
109 class CutCopyPasteView; | 107 class CutCopyPasteView; |
110 class RecentTabsMenuModelDelegate; | 108 class RecentTabsMenuModelDelegate; |
111 class ZoomView; | 109 class ZoomView; |
112 | 110 |
113 typedef std::pair<ui::MenuModel*,int> Entry; | 111 typedef std::pair<ui::MenuModel*,int> Entry; |
114 typedef std::map<int,Entry> CommandIDToEntry; | 112 typedef std::map<int,Entry> IDToEntry; |
115 | 113 |
116 const ui::NativeTheme* GetNativeTheme() const; | 114 const ui::NativeTheme* GetNativeTheme() const; |
117 | 115 |
118 // Populates |parent| with all the child menus in |model|. Recursively invokes | 116 // Populates |parent| with all the child menus in |model|. Recursively invokes |
119 // |PopulateMenu| for any submenu. | 117 // |PopulateMenu| for any submenu. |next_id| is incremented for every menu |
| 118 // that is created. |
120 void PopulateMenu(views::MenuItemView* parent, | 119 void PopulateMenu(views::MenuItemView* parent, |
121 ui::MenuModel* model); | 120 ui::MenuModel* model, |
| 121 int* next_id); |
122 | 122 |
123 // Adds a new menu to |parent| to represent the MenuModel/index pair passed | 123 // Adds a new menu to |parent| to represent the MenuModel/index pair passed |
124 // in. The returned item's MenuItemView::GetCommand() is the same as that of | 124 // in. |
125 // |model|->GetCommandIdAt(|index|). | |
126 // Fur button containing menu items a |height| override can be specified with | 125 // Fur button containing menu items a |height| override can be specified with |
127 // a number bigger then 0. | 126 // a number bigger then 0. |
128 views::MenuItemView* AppendMenuItem(views::MenuItemView* parent, | 127 views::MenuItemView* AppendMenuItem(views::MenuItemView* parent, |
129 ui::MenuModel* model, | 128 ui::MenuModel* model, |
130 int index, | 129 int index, |
131 ui::MenuModel::ItemType menu_type, | 130 ui::MenuModel::ItemType menu_type, |
| 131 int* next_id, |
132 int height); | 132 int height); |
133 | 133 |
134 // Invoked from the cut/copy/paste menus. Cancels the current active menu and | 134 // Invoked from the cut/copy/paste menus. Cancels the current active menu and |
135 // activates the menu item in |model| at |index|. | 135 // activates the menu item in |model| at |index|. |
136 void CancelAndEvaluate(ui::MenuModel* model, int index); | 136 void CancelAndEvaluate(ui::MenuModel* model, int index); |
137 | 137 |
138 // Creates the bookmark menu if necessary. Does nothing if already created or | 138 // Creates the bookmark menu if necessary. Does nothing if already created or |
139 // the bookmark model isn't loaded. | 139 // the bookmark model isn't loaded. |
140 void CreateBookmarkMenu(); | 140 void CreateBookmarkMenu(); |
141 | 141 |
142 // Returns the index of the MenuModel/index pair representing the |command_id| | 142 // Returns true if |id| identifies a bookmark menu item. |
143 // in |command_id_to_entry_|. | 143 bool is_bookmark_command(int id) const { |
144 int ModelIndexFromCommandId(int command_id) const; | 144 return bookmark_menu_delegate_.get() && id >= first_bookmark_command_id_; |
| 145 } |
| 146 |
| 147 // Returns true if |id| identifies a recent tabs menu item. |
| 148 bool is_recent_tabs_command(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 } |
145 | 153 |
146 // The views menu. Owned by |menu_runner_|. | 154 // The views menu. Owned by |menu_runner_|. |
147 views::MenuItemView* root_; | 155 views::MenuItemView* root_; |
148 | 156 |
149 scoped_ptr<views::MenuRunner> menu_runner_; | 157 scoped_ptr<views::MenuRunner> menu_runner_; |
150 | 158 |
151 // Maps from the command ID in model to the model/index pair the item came | 159 // Maps from the ID as understood by MenuItemView to the model/index pair the |
152 // from. | 160 // item came from. |
153 CommandIDToEntry command_id_to_entry_; | 161 IDToEntry id_to_entry_; |
154 | 162 |
155 // Browser the menu is being shown for. | 163 // Browser the menu is being shown for. |
156 Browser* browser_; | 164 Browser* browser_; |
157 | 165 |
158 // |CancelAndEvaluate| sets |selected_menu_model_| and |selected_index_|. | 166 // |CancelAndEvaluate| sets |selected_menu_model_| and |selected_index_|. |
159 // If |selected_menu_model_| is non-null after the menu completes | 167 // If |selected_menu_model_| is non-null after the menu completes |
160 // ActivatedAt is invoked. This is done so that ActivatedAt isn't invoked | 168 // ActivatedAt is invoked. This is done so that ActivatedAt isn't invoked |
161 // while the message loop is nested. | 169 // while the message loop is nested. |
162 ui::MenuModel* selected_menu_model_; | 170 ui::MenuModel* selected_menu_model_; |
163 int selected_index_; | 171 int selected_index_; |
164 | 172 |
165 // Used for managing the bookmark menu items. | 173 // Used for managing the bookmark menu items. |
166 scoped_ptr<BookmarkMenuDelegate> bookmark_menu_delegate_; | 174 scoped_ptr<BookmarkMenuDelegate> bookmark_menu_delegate_; |
167 | 175 |
168 // Menu corresponding to IDC_BOOKMARKS_MENU. | 176 // Menu corresponding to IDC_BOOKMARKS_MENU. |
169 views::MenuItemView* bookmark_menu_; | 177 views::MenuItemView* bookmark_menu_; |
170 | 178 |
171 // Menu corresponding to IDC_FEEDBACK. | 179 // Menu corresponding to IDC_FEEDBACK. |
172 views::MenuItemView* feedback_menu_item_; | 180 views::MenuItemView* feedback_menu_item_; |
173 | 181 |
174 // Used for managing "Recent tabs" menu items. | 182 // Used for managing "Recent tabs" menu items. |
175 scoped_ptr<RecentTabsMenuModelDelegate> recent_tabs_menu_model_delegate_; | 183 scoped_ptr<RecentTabsMenuModelDelegate> recent_tabs_menu_model_delegate_; |
176 | 184 |
| 185 // First ID to use for the items representing bookmarks in the bookmark menu. |
| 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_; |
| 191 |
177 content::NotificationRegistrar registrar_; | 192 content::NotificationRegistrar registrar_; |
178 | 193 |
179 const bool use_new_menu_; | 194 const bool use_new_menu_; |
180 | 195 |
181 const bool supports_new_separators_; | 196 const bool supports_new_separators_; |
182 | 197 |
183 ObserverList<WrenchMenuObserver> observer_list_; | 198 ObserverList<WrenchMenuObserver> observer_list_; |
184 | 199 |
185 DISALLOW_COPY_AND_ASSIGN(WrenchMenu); | 200 DISALLOW_COPY_AND_ASSIGN(WrenchMenu); |
186 }; | 201 }; |
187 | 202 |
188 #endif // CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_ | 203 #endif // CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_ |
OLD | NEW |