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