| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 14 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" | 13 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" |
| 15 #include "ui/base/models/menu_model.h" | 14 #include "ui/base/models/menu_model.h" |
| 16 #include "views/controls/menu/menu_delegate.h" | 15 #include "views/controls/menu/menu_delegate.h" |
| 17 | 16 |
| 18 class BookmarkMenuDelegate; | 17 class BookmarkMenuDelegate; |
| 19 class Browser; | 18 class Browser; |
| 20 | 19 |
| 21 namespace views { | 20 namespace views { |
| 22 class MenuButton; | 21 class MenuButton; |
| 23 class MenuItemView; | 22 class MenuItemView; |
| 23 class MenuRunner; |
| 24 class View; | 24 class View; |
| 25 } // namespace views | 25 } // namespace views |
| 26 | 26 |
| 27 // WrenchMenu adapts the WrenchMenuModel to view's menu related classes. | 27 // WrenchMenu adapts the WrenchMenuModel to view's menu related classes. |
| 28 class WrenchMenu : public base::RefCounted<WrenchMenu>, | 28 class WrenchMenu : public views::MenuDelegate, |
| 29 public views::MenuDelegate, | |
| 30 public BaseBookmarkModelObserver { | 29 public BaseBookmarkModelObserver { |
| 31 public: | 30 public: |
| 32 explicit WrenchMenu(Browser* browser); | 31 explicit WrenchMenu(Browser* browser); |
| 32 virtual ~WrenchMenu(); |
| 33 | 33 |
| 34 void Init(ui::MenuModel* model); | 34 void Init(ui::MenuModel* model); |
| 35 | 35 |
| 36 // Shows the menu relative to the specified view. | 36 // Shows the menu relative to the specified view. |
| 37 void RunMenu(views::MenuButton* host); | 37 void RunMenu(views::MenuButton* host); |
| 38 | 38 |
| 39 // MenuDelegate overrides: | 39 // MenuDelegate overrides: |
| 40 virtual std::wstring GetTooltipText(int id, const gfx::Point& p) OVERRIDE; | 40 virtual std::wstring GetTooltipText(int id, const gfx::Point& p) OVERRIDE; |
| 41 virtual bool IsTriggerableEvent(views::MenuItemView* menu, | 41 virtual bool IsTriggerableEvent(views::MenuItemView* menu, |
| 42 const views::MouseEvent& e) OVERRIDE; | 42 const views::MouseEvent& e) OVERRIDE; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 65 virtual bool IsItemChecked(int id) const OVERRIDE; | 65 virtual bool IsItemChecked(int id) const OVERRIDE; |
| 66 virtual bool IsCommandEnabled(int id) const OVERRIDE; | 66 virtual bool IsCommandEnabled(int id) const OVERRIDE; |
| 67 virtual void ExecuteCommand(int id, int mouse_event_flags) OVERRIDE; | 67 virtual void ExecuteCommand(int id, int mouse_event_flags) OVERRIDE; |
| 68 virtual bool GetAccelerator(int id, views::Accelerator* accelerator) OVERRIDE; | 68 virtual bool GetAccelerator(int id, views::Accelerator* accelerator) OVERRIDE; |
| 69 virtual void WillShowMenu(views::MenuItemView* menu) OVERRIDE; | 69 virtual void WillShowMenu(views::MenuItemView* menu) OVERRIDE; |
| 70 | 70 |
| 71 // BaseBookmarkModelObserver overrides: | 71 // BaseBookmarkModelObserver overrides: |
| 72 virtual void BookmarkModelChanged() OVERRIDE; | 72 virtual void BookmarkModelChanged() OVERRIDE; |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 friend class base::RefCounted<WrenchMenu>; | |
| 76 | |
| 77 class CutCopyPasteView; | 75 class CutCopyPasteView; |
| 78 class ZoomView; | 76 class ZoomView; |
| 79 | 77 |
| 80 typedef std::pair<ui::MenuModel*,int> Entry; | 78 typedef std::pair<ui::MenuModel*,int> Entry; |
| 81 typedef std::map<int,Entry> IDToEntry; | 79 typedef std::map<int,Entry> IDToEntry; |
| 82 | 80 |
| 83 virtual ~WrenchMenu(); | |
| 84 | |
| 85 // Populates |parent| with all the child menus in |model|. Recursively invokes | 81 // Populates |parent| with all the child menus in |model|. Recursively invokes |
| 86 // |PopulateMenu| for any submenu. |next_id| is incremented for every menu | 82 // |PopulateMenu| for any submenu. |next_id| is incremented for every menu |
| 87 // that is created. | 83 // that is created. |
| 88 void PopulateMenu(views::MenuItemView* parent, | 84 void PopulateMenu(views::MenuItemView* parent, |
| 89 ui::MenuModel* model, | 85 ui::MenuModel* model, |
| 90 int* next_id); | 86 int* next_id); |
| 91 | 87 |
| 92 // Adds a new menu to |parent| to represent the MenuModel/index pair passed | 88 // Adds a new menu to |parent| to represent the MenuModel/index pair passed |
| 93 // in. | 89 // in. |
| 94 views::MenuItemView* AppendMenuItem(views::MenuItemView* parent, | 90 views::MenuItemView* AppendMenuItem(views::MenuItemView* parent, |
| 95 ui::MenuModel* model, | 91 ui::MenuModel* model, |
| 96 int index, | 92 int index, |
| 97 ui::MenuModel::ItemType menu_type, | 93 ui::MenuModel::ItemType menu_type, |
| 98 int* next_id); | 94 int* next_id); |
| 99 | 95 |
| 100 // Invoked from the cut/copy/paste menus. Cancels the current active menu and | 96 // Invoked from the cut/copy/paste menus. Cancels the current active menu and |
| 101 // activates the menu item in |model| at |index|. | 97 // activates the menu item in |model| at |index|. |
| 102 void CancelAndEvaluate(ui::MenuModel* model, int index); | 98 void CancelAndEvaluate(ui::MenuModel* model, int index); |
| 103 | 99 |
| 104 // Creates the bookmark menu if necessary. Does nothing if already created or | 100 // Creates the bookmark menu if necessary. Does nothing if already created or |
| 105 // the bookmark model isn't loaded. | 101 // the bookmark model isn't loaded. |
| 106 void CreateBookmarkMenu(); | 102 void CreateBookmarkMenu(); |
| 107 | 103 |
| 108 // Returns true if |id| identifies a bookmark menu item. | 104 // Returns true if |id| identifies a bookmark menu item. |
| 109 bool is_bookmark_command(int id) const { | 105 bool is_bookmark_command(int id) const { |
| 110 return bookmark_menu_delegate_.get() && id >= first_bookmark_command_id_; | 106 return bookmark_menu_delegate_.get() && id >= first_bookmark_command_id_; |
| 111 } | 107 } |
| 112 | 108 |
| 113 // The views menu. | 109 // The views menu. Owned by |menu_runner_|. |
| 114 scoped_ptr<views::MenuItemView> root_; | 110 views::MenuItemView* root_; |
| 111 |
| 112 scoped_ptr<views::MenuRunner> menu_runner_; |
| 115 | 113 |
| 116 // Maps from the ID as understood by MenuItemView to the model/index pair the | 114 // Maps from the ID as understood by MenuItemView to the model/index pair the |
| 117 // item came from. | 115 // item came from. |
| 118 IDToEntry id_to_entry_; | 116 IDToEntry id_to_entry_; |
| 119 | 117 |
| 120 // Browser the menu is being shown for. | 118 // Browser the menu is being shown for. |
| 121 Browser* browser_; | 119 Browser* browser_; |
| 122 | 120 |
| 123 // |CancelAndEvaluate| sets |selected_menu_model_| and |selected_index_|. | 121 // |CancelAndEvaluate| sets |selected_menu_model_| and |selected_index_|. |
| 124 // If |selected_menu_model_| is non-null after the menu completes | 122 // If |selected_menu_model_| is non-null after the menu completes |
| 125 // ActivatedAt is invoked. This is done so that ActivatedAt isn't invoked | 123 // ActivatedAt is invoked. This is done so that ActivatedAt isn't invoked |
| 126 // while the message loop is nested. | 124 // while the message loop is nested. |
| 127 ui::MenuModel* selected_menu_model_; | 125 ui::MenuModel* selected_menu_model_; |
| 128 int selected_index_; | 126 int selected_index_; |
| 129 | 127 |
| 130 // Used for managing the bookmark menu items. | 128 // Used for managing the bookmark menu items. |
| 131 scoped_ptr<BookmarkMenuDelegate> bookmark_menu_delegate_; | 129 scoped_ptr<BookmarkMenuDelegate> bookmark_menu_delegate_; |
| 132 | 130 |
| 133 // Menu corresponding to IDC_BOOKMARKS_MENU. | 131 // Menu corresponding to IDC_BOOKMARKS_MENU. |
| 134 views::MenuItemView* bookmark_menu_; | 132 views::MenuItemView* bookmark_menu_; |
| 135 | 133 |
| 136 // ID to use for the items representing bookmarks in the bookmark menu. | 134 // ID to use for the items representing bookmarks in the bookmark menu. |
| 137 int first_bookmark_command_id_; | 135 int first_bookmark_command_id_; |
| 138 | 136 |
| 139 DISALLOW_COPY_AND_ASSIGN(WrenchMenu); | 137 DISALLOW_COPY_AND_ASSIGN(WrenchMenu); |
| 140 }; | 138 }; |
| 141 | 139 |
| 142 #endif // CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_ | 140 #endif // CHROME_BROWSER_UI_VIEWS_WRENCH_MENU_H_ |
| OLD | NEW |