Chromium Code Reviews| 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 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 // contents of the bookmark bar folder. | 46 // contents of the bookmark bar folder. |
| 47 SHOW_PERMANENT_FOLDERS, | 47 SHOW_PERMANENT_FOLDERS, |
| 48 | 48 |
| 49 // Don't show any additional folders. | 49 // Don't show any additional folders. |
| 50 HIDE_PERMANENT_FOLDERS | 50 HIDE_PERMANENT_FOLDERS |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 BookmarkMenuDelegate(Browser* browser, | 53 BookmarkMenuDelegate(Browser* browser, |
| 54 content::PageNavigator* navigator, | 54 content::PageNavigator* navigator, |
| 55 views::Widget* parent, | 55 views::Widget* parent, |
| 56 int first_menu_id); | 56 int first_menu_id, |
| 57 int max_menu_id); | |
| 57 virtual ~BookmarkMenuDelegate(); | 58 virtual ~BookmarkMenuDelegate(); |
| 58 | 59 |
| 59 // Creates the menus from the model. | 60 // Creates the menus from the model. |
| 60 void Init(views::MenuDelegate* real_delegate, | 61 void Init(views::MenuDelegate* real_delegate, |
| 61 views::MenuItemView* parent, | 62 views::MenuItemView* parent, |
| 62 const BookmarkNode* node, | 63 const BookmarkNode* node, |
| 63 int start_child_index, | 64 int start_child_index, |
| 64 ShowOptions show_options, | 65 ShowOptions show_options, |
| 65 BookmarkLaunchLocation location); | 66 BookmarkLaunchLocation location); |
| 66 | 67 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 virtual void BookmarkModelChanged() OVERRIDE; | 123 virtual void BookmarkModelChanged() OVERRIDE; |
| 123 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model, | 124 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model, |
| 124 const BookmarkNode* node) OVERRIDE; | 125 const BookmarkNode* node) OVERRIDE; |
| 125 | 126 |
| 126 // BookmarkContextMenu::Observer methods. | 127 // BookmarkContextMenu::Observer methods. |
| 127 virtual void WillRemoveBookmarks( | 128 virtual void WillRemoveBookmarks( |
| 128 const std::vector<const BookmarkNode*>& bookmarks) OVERRIDE; | 129 const std::vector<const BookmarkNode*>& bookmarks) OVERRIDE; |
| 129 virtual void DidRemoveBookmarks() OVERRIDE; | 130 virtual void DidRemoveBookmarks() OVERRIDE; |
| 130 | 131 |
| 131 private: | 132 private: |
| 133 friend class BookmarkMenuDelegateTest; | |
| 134 FRIEND_TEST_ALL_PREFIXES(BookmarkMenuDelegateTest, MenuIdRange); | |
| 135 | |
| 132 typedef std::map<int, const BookmarkNode*> MenuIDToNodeMap; | 136 typedef std::map<int, const BookmarkNode*> MenuIDToNodeMap; |
| 133 typedef std::map<const BookmarkNode*, views::MenuItemView*> NodeToMenuMap; | 137 typedef std::map<const BookmarkNode*, views::MenuItemView*> NodeToMenuMap; |
| 134 | 138 |
| 135 // Creates a menu. This uses BuildMenu() to recursively populate the menu. | 139 // Creates a menu. This uses BuildMenu() to recursively populate the menu. |
| 136 views::MenuItemView* CreateMenu(const BookmarkNode* parent, | 140 views::MenuItemView* CreateMenu(const BookmarkNode* parent, |
| 137 int start_child_index, | 141 int start_child_index, |
| 138 ShowOptions show_options); | 142 ShowOptions show_options); |
| 139 | 143 |
| 140 // Invokes BuildMenuForPermanentNode() for the permanent nodes (excluding | 144 // Invokes BuildMenuForPermanentNode() for the permanent nodes (excluding |
| 141 // 'other bookmarks' folder). | 145 // 'other bookmarks' folder). |
| 142 void BuildMenusForPermanentNodes(views::MenuItemView* menu, | 146 void BuildMenusForPermanentNodes(views::MenuItemView* menu, |
| 143 int* next_menu_id); | 147 int* next_menu_id); |
| 144 | 148 |
| 145 // If |node| has children a new menu is created and added to |menu| to | 149 // If |node| has children a new menu is created and added to |menu| to |
| 146 // represent it. If |node| is not empty and |added_separator| is false, a | 150 // represent it. If |node| is not empty and |added_separator| is false, a |
| 147 // separator is added before the new menu items and |added_separator| is set | 151 // separator is added before the new menu items and |added_separator| is set |
| 148 // to true. | 152 // to true. |
| 149 void BuildMenuForPermanentNode(const BookmarkNode* node, | 153 void BuildMenuForPermanentNode(const BookmarkNode* node, |
| 150 views::MenuItemView* menu, | 154 views::MenuItemView* menu, |
| 151 int* next_menu_id, | 155 int* next_menu_id, |
| 152 bool* added_separator); | 156 bool* added_separator); |
| 153 | 157 |
| 154 // Creates an entry in menu for each child node of |parent| starting at | 158 // Creates an entry in menu for each child node of |parent| starting at |
| 155 // |start_child_index|. | 159 // |start_child_index|. |
| 156 void BuildMenu(const BookmarkNode* parent, | 160 void BuildMenu(const BookmarkNode* parent, |
| 157 int start_child_index, | 161 int start_child_index, |
| 158 views::MenuItemView* menu, | 162 views::MenuItemView* menu, |
| 159 int* next_menu_id); | 163 int* next_menu_id); |
| 160 | 164 |
| 165 // Returns true if |menu_id_| is outside the range of minimum and maximum menu | |
| 166 // ID's allowed. | |
| 167 bool IsOutsideMenuIdRange(int menu_id) const; | |
| 168 | |
| 161 Browser* browser_; | 169 Browser* browser_; |
| 162 Profile* profile_; | 170 Profile* profile_; |
| 163 | 171 |
| 164 content::PageNavigator* page_navigator_; | 172 content::PageNavigator* page_navigator_; |
| 165 | 173 |
| 166 // Parent of menus. | 174 // Parent of menus. |
| 167 views::Widget* parent_; | 175 views::Widget* parent_; |
| 168 | 176 |
| 169 // Maps from menu id to BookmarkNode. | 177 // Maps from menu id to BookmarkNode. |
| 170 MenuIDToNodeMap menu_id_to_node_map_; | 178 MenuIDToNodeMap menu_id_to_node_map_; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 183 | 191 |
| 184 // If non-NULL this is the |parent| passed to Init and is NOT owned by us. | 192 // If non-NULL this is the |parent| passed to Init and is NOT owned by us. |
| 185 views::MenuItemView* parent_menu_item_; | 193 views::MenuItemView* parent_menu_item_; |
| 186 | 194 |
| 187 // Maps from node to menu. | 195 // Maps from node to menu. |
| 188 NodeToMenuMap node_to_menu_map_; | 196 NodeToMenuMap node_to_menu_map_; |
| 189 | 197 |
| 190 // ID of the next menu item. | 198 // ID of the next menu item. |
| 191 int next_menu_id_; | 199 int next_menu_id_; |
| 192 | 200 |
| 201 // Minimum and maximum ID's to use for menu items. | |
| 202 int min_menu_id_; | |
|
sky
2013/10/08 15:55:04
Make both of these (min/max) const.
| |
| 203 int max_menu_id_; | |
| 204 | |
| 193 views::MenuDelegate* real_delegate_; | 205 views::MenuDelegate* real_delegate_; |
| 194 | 206 |
| 195 // Is the model being changed? | 207 // Is the model being changed? |
| 196 bool is_mutating_model_; | 208 bool is_mutating_model_; |
| 197 | 209 |
| 198 // The location where this bookmark menu will be displayed (for UMA). | 210 // The location where this bookmark menu will be displayed (for UMA). |
| 199 BookmarkLaunchLocation location_; | 211 BookmarkLaunchLocation location_; |
| 200 | 212 |
| 201 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuDelegate); | 213 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuDelegate); |
| 202 }; | 214 }; |
| 203 | 215 |
| 204 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_DELEGATE_H_ | 216 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_DELEGATE_H_ |
| OLD | NEW |