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

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.h

Issue 7054020: Refactors code for showing bookmark menus so that it can be used by (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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) 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_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_ 5 #ifndef CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_
6 #define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_ 6 #define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map>
10 #include <set> 9 #include <set>
11 10
12 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" 11 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
13 #include "chrome/browser/bookmarks/bookmark_node_data.h" 12 #include "chrome/browser/bookmarks/bookmark_node_data.h"
14 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h"
15 #include "ui/gfx/native_widget_types.h" 13 #include "ui/gfx/native_widget_types.h"
16 #include "views/controls/menu/menu_delegate.h" 14 #include "views/controls/menu/menu_delegate.h"
17 #include "views/controls/menu/menu_item_view.h" 15 #include "views/controls/menu/menu_item_view.h"
18 16
19 class BookmarkBarView; 17 class BookmarkBarView;
18 class BookmarkMenuDelegate;
20 class BookmarkNode; 19 class BookmarkNode;
21 class Browser;
22 class PageNavigator; 20 class PageNavigator;
23 class Profile; 21 class Profile;
24 22
25 namespace gfx { 23 namespace gfx {
26 class Rect; 24 class Rect;
27 } // namespace gfx 25 } // namespace gfx
28 26
29 namespace ui { 27 namespace ui {
30 class OSExchangeData; 28 class OSExchangeData;
31 } // namespace ui 29 } // namespace ui
32 30
33 namespace views { 31 namespace views {
34 class MenuButton; 32 class MenuButton;
35 } // namespace views 33 } // namespace views
36 34
37 // BookmarkMenuController is responsible for showing a menu of bookmarks, 35 // BookmarkMenuController is responsible for showing a menu of bookmarks,
38 // each item in the menu represents a bookmark. 36 // each item in the menu represents a bookmark.
39 // BookmarkMenuController deletes itself as necessary, although the menu can 37 // BookmarkMenuController deletes itself as necessary, although the menu can
40 // be explicitly hidden by way of the Cancel method. 38 // be explicitly hidden by way of the Cancel method.
41 class BookmarkMenuController : public BaseBookmarkModelObserver, 39 class BookmarkMenuController : public BaseBookmarkModelObserver,
42 public views::MenuDelegate, 40 public views::MenuDelegate {
43 public BookmarkContextMenuObserver {
44 public: 41 public:
45 // The observer is notified prior to the menu being deleted. 42 // The observer is notified prior to the menu being deleted.
46 class Observer { 43 class Observer {
47 public: 44 public:
48 virtual void BookmarkMenuDeleted(BookmarkMenuController* controller) = 0; 45 virtual void BookmarkMenuDeleted(BookmarkMenuController* controller) = 0;
49 46
50 protected: 47 protected:
51 virtual ~Observer() {} 48 virtual ~Observer() {}
52 }; 49 };
53 50
54 // Creates a BookmarkMenuController showing the children of |node| starting 51 // Creates a BookmarkMenuController showing the children of |node| starting
55 // at index |start_child_index|. 52 // at |start_child_index|.
56 BookmarkMenuController(Browser* browser, 53 BookmarkMenuController(Profile* profile,
57 Profile* profile,
58 PageNavigator* page_navigator, 54 PageNavigator* page_navigator,
59 gfx::NativeWindow parent, 55 gfx::NativeWindow parent,
60 const BookmarkNode* node, 56 const BookmarkNode* node,
61 int start_child_index); 57 int start_child_index);
62 58
63 void RunMenuAt(BookmarkBarView* bookmark_bar, bool for_drop); 59 void RunMenuAt(BookmarkBarView* bookmark_bar, bool for_drop);
64 60
65 // Shows the menu. 61 // Shows the menu.
66 void RunMenuAt(views::MenuButton* button, 62 void RunMenuAt(views::MenuButton* button,
67 views::MenuItemView::AnchorPosition position, 63 views::MenuItemView::AnchorPosition position,
68 bool for_drop); 64 bool for_drop);
69 65
70 // Hides the menu. 66 // Hides the menu.
71 void Cancel(); 67 void Cancel();
72 68
73 // Returns the node the menu is showing for. 69 // Returns the node the menu is showing for.
74 const BookmarkNode* node() const { return node_; } 70 const BookmarkNode* node() const { return node_; }
75 71
76 // Returns the menu. 72 // Returns the menu.
77 views::MenuItemView* menu() const { return menu_; } 73 views::MenuItemView* menu() const;
78 74
79 // Returns the context menu, or NULL if the context menu isn't showing. 75 // Returns the context menu, or NULL if the context menu isn't showing.
80 views::MenuItemView* context_menu() const { 76 views::MenuItemView* context_menu() const;
81 return context_menu_.get() ? context_menu_->menu() : NULL;
82 }
83 77
84 void set_observer(Observer* observer) { observer_ = observer; } 78 void set_observer(Observer* observer) { observer_ = observer; }
85 79
86 // MenuDelegate methods. 80 // MenuDelegate methods.
87 virtual std::wstring GetTooltipText(int id, const gfx::Point& p); 81 virtual std::wstring GetTooltipText(int id, const gfx::Point& p);
88 virtual bool IsTriggerableEvent(views::MenuItemView* view, 82 virtual bool IsTriggerableEvent(views::MenuItemView* view,
89 const views::MouseEvent& e); 83 const views::MouseEvent& e);
90 virtual void ExecuteCommand(int id, int mouse_event_flags); 84 virtual void ExecuteCommand(int id, int mouse_event_flags);
91 virtual bool GetDropFormats( 85 virtual bool GetDropFormats(
92 views::MenuItemView* menu, 86 views::MenuItemView* menu,
(...skipping 20 matching lines...) Expand all
113 virtual views::MenuItemView* GetSiblingMenu( 107 virtual views::MenuItemView* GetSiblingMenu(
114 views::MenuItemView* menu, 108 views::MenuItemView* menu,
115 const gfx::Point& screen_point, 109 const gfx::Point& screen_point,
116 views::MenuItemView::AnchorPosition* anchor, 110 views::MenuItemView::AnchorPosition* anchor,
117 bool* has_mnemonics, 111 bool* has_mnemonics,
118 views::MenuButton** button); 112 views::MenuButton** button);
119 virtual int GetMaxWidthForMenu(views::MenuItemView* view); 113 virtual int GetMaxWidthForMenu(views::MenuItemView* view);
120 114
121 // BookmarkModelObserver methods. 115 // BookmarkModelObserver methods.
122 virtual void BookmarkModelChanged(); 116 virtual void BookmarkModelChanged();
123 virtual void BookmarkNodeFaviconLoaded(BookmarkModel* model,
124 const BookmarkNode* node);
125
126 // BookmarkContextMenu::Observer methods.
127 virtual void WillRemoveBookmarks(
128 const std::vector<const BookmarkNode*>& bookmarks);
129 virtual void DidRemoveBookmarks();
130 117
131 private: 118 private:
132 typedef std::map<const BookmarkNode*, int> NodeToMenuIDMap;
133
134 // BookmarkMenuController deletes itself as necessary. 119 // BookmarkMenuController deletes itself as necessary.
135 virtual ~BookmarkMenuController(); 120 virtual ~BookmarkMenuController();
136 121
137 // Creates a menu and adds it to node_to_menu_id_map_. This uses 122 scoped_ptr<BookmarkMenuDelegate> menu_delegate_;
138 // BuildMenu to recursively populate the menu.
139 views::MenuItemView* CreateMenu(const BookmarkNode* parent,
140 int start_child_index);
141
142 // Creates an entry in menu for each child node of |parent| starting at
143 // |start_child_index|.
144 void BuildMenu(const BookmarkNode* parent,
145 int start_child_index,
146 views::MenuItemView* menu,
147 int* next_menu_id);
148
149 // Returns the menu whose id is |id|.
150 views::MenuItemView* GetMenuByID(int id);
151
152 // Does the work of processing WillRemoveBookmarks. On exit the set of removed
153 // menus is added to |removed_menus|. It's up to the caller to delete the
154 // the menus added to |removed_menus|.
155 void WillRemoveBookmarksImpl(
156 const std::vector<const BookmarkNode*>& bookmarks,
157 std::set<views::MenuItemView*>* removed_menus);
158
159 Browser* browser_;
160
161 Profile* profile_;
162
163 PageNavigator* page_navigator_;
164
165 // Parent of menus.
166 gfx::NativeWindow parent_;
167 123
168 // The node we're showing the contents of. 124 // The node we're showing the contents of.
169 const BookmarkNode* node_; 125 const BookmarkNode* node_;
170 126
171 // Maps from menu id to BookmarkNode.
172 std::map<int, const BookmarkNode*> menu_id_to_node_map_;
173
174 // Mapping from node to menu id. This only contains entries for nodes of type
175 // URL.
176 NodeToMenuIDMap node_to_menu_id_map_;
177
178 // Current menu.
179 views::MenuItemView* menu_;
180
181 // Data for the drop. 127 // Data for the drop.
182 BookmarkNodeData drop_data_; 128 BookmarkNodeData drop_data_;
183 129
184 // Used when a context menu is shown.
185 scoped_ptr<BookmarkContextMenu> context_menu_;
186
187 // The observer, may be null. 130 // The observer, may be null.
188 Observer* observer_; 131 Observer* observer_;
189 132
190 // Is the menu being shown for a drop? 133 // Is the menu being shown for a drop?
191 bool for_drop_; 134 bool for_drop_;
192 135
193 // The bookmark bar. This is only non-null if we're showing a menu item 136 // The bookmark bar. This is only non-null if we're showing a menu item
194 // for a folder on the bookmark bar and not for drop. 137 // for a folder on the bookmark bar and not for drop.
195 BookmarkBarView* bookmark_bar_; 138 BookmarkBarView* bookmark_bar_;
196 139
197 typedef std::map<const BookmarkNode*, views::MenuItemView*> NodeToMenuMap;
198 NodeToMenuMap node_to_menu_map_;
199
200 // ID of the next menu item.
201 int next_menu_id_;
202
203 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuController); 140 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuController);
204 }; 141 };
205 142
206 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_ 143 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698