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_BOOKMARKS_BOOKMARK_MENU_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_DELEGATE_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_DELEGATE_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_DELEGATE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "chrome/browser/bookmarks/bookmark_stats.h" | 12 #include "chrome/browser/bookmarks/bookmark_stats.h" |
13 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" | 13 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" |
14 #include "components/bookmarks/browser/base_bookmark_model_observer.h" | 14 #include "components/bookmarks/browser/base_bookmark_model_observer.h" |
15 #include "components/bookmarks/browser/bookmark_node_data.h" | 15 #include "components/bookmarks/browser/bookmark_node_data.h" |
16 #include "ui/views/controls/menu/menu_delegate.h" | 16 #include "ui/views/controls/menu/menu_delegate.h" |
17 | 17 |
18 class BookmarkNode; | |
19 class Browser; | 18 class Browser; |
20 class ChromeBookmarkClient; | 19 class ChromeBookmarkClient; |
21 class Profile; | 20 class Profile; |
22 | 21 |
23 namespace content { | 22 namespace content { |
24 class PageNavigator; | 23 class PageNavigator; |
25 } | 24 } |
26 | 25 |
27 namespace ui { | 26 namespace ui { |
28 class OSExchangeData; | 27 class OSExchangeData; |
(...skipping 25 matching lines...) Expand all Loading... |
54 BookmarkMenuDelegate(Browser* browser, | 53 BookmarkMenuDelegate(Browser* browser, |
55 content::PageNavigator* navigator, | 54 content::PageNavigator* navigator, |
56 views::Widget* parent, | 55 views::Widget* parent, |
57 int first_menu_id, | 56 int first_menu_id, |
58 int max_menu_id); | 57 int max_menu_id); |
59 ~BookmarkMenuDelegate() override; | 58 ~BookmarkMenuDelegate() override; |
60 | 59 |
61 // Creates the menus from the model. | 60 // Creates the menus from the model. |
62 void Init(views::MenuDelegate* real_delegate, | 61 void Init(views::MenuDelegate* real_delegate, |
63 views::MenuItemView* parent, | 62 views::MenuItemView* parent, |
64 const BookmarkNode* node, | 63 const bookmarks::BookmarkNode* node, |
65 int start_child_index, | 64 int start_child_index, |
66 ShowOptions show_options, | 65 ShowOptions show_options, |
67 BookmarkLaunchLocation location); | 66 BookmarkLaunchLocation location); |
68 | 67 |
69 // Sets the PageNavigator. | 68 // Sets the PageNavigator. |
70 void SetPageNavigator(content::PageNavigator* navigator); | 69 void SetPageNavigator(content::PageNavigator* navigator); |
71 | 70 |
72 // Returns the id given to the next menu. | 71 // Returns the id given to the next menu. |
73 int next_menu_id() const { return next_menu_id_; } | 72 int next_menu_id() const { return next_menu_id_; } |
74 | 73 |
75 // Makes the menu for |node| the active menu. |start_index| is the index of | 74 // Makes the menu for |node| the active menu. |start_index| is the index of |
76 // the first child of |node| to show in the menu. | 75 // the first child of |node| to show in the menu. |
77 void SetActiveMenu(const BookmarkNode* node, int start_index); | 76 void SetActiveMenu(const bookmarks::BookmarkNode* node, int start_index); |
78 | 77 |
79 bookmarks::BookmarkModel* GetBookmarkModel(); | 78 bookmarks::BookmarkModel* GetBookmarkModel(); |
80 ChromeBookmarkClient* GetChromeBookmarkClient(); | 79 ChromeBookmarkClient* GetChromeBookmarkClient(); |
81 | 80 |
82 // Returns the menu. | 81 // Returns the menu. |
83 views::MenuItemView* menu() { return menu_; } | 82 views::MenuItemView* menu() { return menu_; } |
84 | 83 |
85 // Returns the context menu, or NULL if the context menu isn't showing. | 84 // Returns the context menu, or NULL if the context menu isn't showing. |
86 views::MenuItemView* context_menu() { | 85 views::MenuItemView* context_menu() { |
87 return context_menu_.get() ? context_menu_->menu() : NULL; | 86 return context_menu_.get() ? context_menu_->menu() : NULL; |
(...skipping 29 matching lines...) Expand all Loading... |
117 const gfx::Point& p, | 116 const gfx::Point& p, |
118 ui::MenuSourceType source_type); | 117 ui::MenuSourceType source_type); |
119 bool CanDrag(views::MenuItemView* menu); | 118 bool CanDrag(views::MenuItemView* menu); |
120 void WriteDragData(views::MenuItemView* sender, ui::OSExchangeData* data); | 119 void WriteDragData(views::MenuItemView* sender, ui::OSExchangeData* data); |
121 int GetDragOperations(views::MenuItemView* sender); | 120 int GetDragOperations(views::MenuItemView* sender); |
122 int GetMaxWidthForMenu(views::MenuItemView* menu); | 121 int GetMaxWidthForMenu(views::MenuItemView* menu); |
123 | 122 |
124 // BookmarkModelObserver methods. | 123 // BookmarkModelObserver methods. |
125 void BookmarkModelChanged() override; | 124 void BookmarkModelChanged() override; |
126 void BookmarkNodeFaviconChanged(bookmarks::BookmarkModel* model, | 125 void BookmarkNodeFaviconChanged(bookmarks::BookmarkModel* model, |
127 const BookmarkNode* node) override; | 126 const bookmarks::BookmarkNode* node) override; |
128 | 127 |
129 // BookmarkContextMenu::Observer methods. | 128 // BookmarkContextMenu::Observer methods. |
130 void WillRemoveBookmarks( | 129 void WillRemoveBookmarks( |
131 const std::vector<const BookmarkNode*>& bookmarks) override; | 130 const std::vector<const bookmarks::BookmarkNode*>& bookmarks) override; |
132 void DidRemoveBookmarks() override; | 131 void DidRemoveBookmarks() override; |
133 | 132 |
134 private: | 133 private: |
135 typedef std::map<int, const BookmarkNode*> MenuIDToNodeMap; | 134 typedef std::map<int, const bookmarks::BookmarkNode*> MenuIDToNodeMap; |
136 typedef std::map<const BookmarkNode*, views::MenuItemView*> NodeToMenuMap; | 135 typedef std::map<const bookmarks::BookmarkNode*, views::MenuItemView*> |
| 136 NodeToMenuMap; |
137 | 137 |
138 // Creates a menu. This uses BuildMenu() to recursively populate the menu. | 138 // Creates a menu. This uses BuildMenu() to recursively populate the menu. |
139 views::MenuItemView* CreateMenu(const BookmarkNode* parent, | 139 views::MenuItemView* CreateMenu(const bookmarks::BookmarkNode* parent, |
140 int start_child_index, | 140 int start_child_index, |
141 ShowOptions show_options); | 141 ShowOptions show_options); |
142 | 142 |
143 // Invokes BuildMenuForPermanentNode() for the permanent nodes (excluding | 143 // Invokes BuildMenuForPermanentNode() for the permanent nodes (excluding |
144 // 'other bookmarks' folder). | 144 // 'other bookmarks' folder). |
145 void BuildMenusForPermanentNodes(views::MenuItemView* menu, | 145 void BuildMenusForPermanentNodes(views::MenuItemView* menu, |
146 int* next_menu_id); | 146 int* next_menu_id); |
147 | 147 |
148 // If |node| has children a new menu is created and added to |menu| to | 148 // If |node| has children a new menu is created and added to |menu| to |
149 // represent it. If |node| is not empty and |added_separator| is false, a | 149 // represent it. If |node| is not empty and |added_separator| is false, a |
150 // separator is added before the new menu items and |added_separator| is set | 150 // separator is added before the new menu items and |added_separator| is set |
151 // to true. | 151 // to true. |
152 void BuildMenuForPermanentNode(const BookmarkNode* node, | 152 void BuildMenuForPermanentNode(const bookmarks::BookmarkNode* node, |
153 int icon_resource_id, | 153 int icon_resource_id, |
154 views::MenuItemView* menu, | 154 views::MenuItemView* menu, |
155 int* next_menu_id, | 155 int* next_menu_id, |
156 bool* added_separator); | 156 bool* added_separator); |
157 | 157 |
158 void BuildMenuForManagedNode(views::MenuItemView* menu, | 158 void BuildMenuForManagedNode(views::MenuItemView* menu, |
159 int* next_menu_id); | 159 int* next_menu_id); |
160 | 160 |
161 // Creates an entry in menu for each child node of |parent| starting at | 161 // Creates an entry in menu for each child node of |parent| starting at |
162 // |start_child_index|. | 162 // |start_child_index|. |
163 void BuildMenu(const BookmarkNode* parent, | 163 void BuildMenu(const bookmarks::BookmarkNode* parent, |
164 int start_child_index, | 164 int start_child_index, |
165 views::MenuItemView* menu, | 165 views::MenuItemView* menu, |
166 int* next_menu_id); | 166 int* next_menu_id); |
167 | 167 |
168 // Returns true if |menu_id_| is outside the range of minimum and maximum menu | 168 // Returns true if |menu_id_| is outside the range of minimum and maximum menu |
169 // ID's allowed. | 169 // ID's allowed. |
170 bool IsOutsideMenuIdRange(int menu_id) const; | 170 bool IsOutsideMenuIdRange(int menu_id) const; |
171 | 171 |
172 Browser* browser_; | 172 Browser* browser_; |
173 Profile* profile_; | 173 Profile* profile_; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // Is the model being changed? | 207 // Is the model being changed? |
208 bool is_mutating_model_; | 208 bool is_mutating_model_; |
209 | 209 |
210 // The location where this bookmark menu will be displayed (for UMA). | 210 // The location where this bookmark menu will be displayed (for UMA). |
211 BookmarkLaunchLocation location_; | 211 BookmarkLaunchLocation location_; |
212 | 212 |
213 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuDelegate); | 213 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuDelegate); |
214 }; | 214 }; |
215 | 215 |
216 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_DELEGATE_H_ | 216 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_DELEGATE_H_ |
OLD | NEW |