| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 // than then bookmark bar folder). This only makes sense when showing the | 45 // than then bookmark bar folder). This only makes sense when showing the |
| 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, | |
| 57 int max_menu_id); | |
| 58 ~BookmarkMenuDelegate() override; | 56 ~BookmarkMenuDelegate() override; |
| 59 | 57 |
| 60 // Creates the menus from the model. | 58 // Creates the menus from the model. |
| 61 void Init(views::MenuDelegate* real_delegate, | 59 void Init(views::MenuDelegate* real_delegate, |
| 62 views::MenuItemView* parent, | 60 views::MenuItemView* parent, |
| 63 const bookmarks::BookmarkNode* node, | 61 const bookmarks::BookmarkNode* node, |
| 64 int start_child_index, | 62 int start_child_index, |
| 65 ShowOptions show_options, | 63 ShowOptions show_options, |
| 66 BookmarkLaunchLocation location); | 64 BookmarkLaunchLocation location); |
| 67 | 65 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 views::MenuDelegate::DropPosition position, | 110 views::MenuDelegate::DropPosition position, |
| 113 const ui::DropTargetEvent& event); | 111 const ui::DropTargetEvent& event); |
| 114 bool ShowContextMenu(views::MenuItemView* source, | 112 bool ShowContextMenu(views::MenuItemView* source, |
| 115 int id, | 113 int id, |
| 116 const gfx::Point& p, | 114 const gfx::Point& p, |
| 117 ui::MenuSourceType source_type); | 115 ui::MenuSourceType source_type); |
| 118 bool CanDrag(views::MenuItemView* menu); | 116 bool CanDrag(views::MenuItemView* menu); |
| 119 void WriteDragData(views::MenuItemView* sender, ui::OSExchangeData* data); | 117 void WriteDragData(views::MenuItemView* sender, ui::OSExchangeData* data); |
| 120 int GetDragOperations(views::MenuItemView* sender); | 118 int GetDragOperations(views::MenuItemView* sender); |
| 121 int GetMaxWidthForMenu(views::MenuItemView* menu); | 119 int GetMaxWidthForMenu(views::MenuItemView* menu); |
| 120 void WillShowMenu(views::MenuItemView* menu); |
| 122 | 121 |
| 123 // BookmarkModelObserver methods. | 122 // BookmarkModelObserver methods. |
| 124 void BookmarkModelChanged() override; | 123 void BookmarkModelChanged() override; |
| 125 void BookmarkNodeFaviconChanged(bookmarks::BookmarkModel* model, | 124 void BookmarkNodeFaviconChanged(bookmarks::BookmarkModel* model, |
| 126 const bookmarks::BookmarkNode* node) override; | 125 const bookmarks::BookmarkNode* node) override; |
| 127 | 126 |
| 128 // BookmarkContextMenu::Observer methods. | 127 // BookmarkContextMenu::Observer methods. |
| 129 void WillRemoveBookmarks( | 128 void WillRemoveBookmarks( |
| 130 const std::vector<const bookmarks::BookmarkNode*>& bookmarks) override; | 129 const std::vector<const bookmarks::BookmarkNode*>& bookmarks) override; |
| 131 void DidRemoveBookmarks() override; | 130 void DidRemoveBookmarks() override; |
| 132 | 131 |
| 133 private: | 132 private: |
| 133 friend class BookmarkMenuDelegateTest; |
| 134 |
| 134 typedef std::map<int, const bookmarks::BookmarkNode*> MenuIDToNodeMap; | 135 typedef std::map<int, const bookmarks::BookmarkNode*> MenuIDToNodeMap; |
| 135 typedef std::map<const bookmarks::BookmarkNode*, views::MenuItemView*> | 136 typedef std::map<const bookmarks::BookmarkNode*, views::MenuItemView*> |
| 136 NodeToMenuMap; | 137 NodeToMenuMap; |
| 137 | 138 |
| 138 // Creates a menu. This uses BuildMenu() to recursively populate the menu. | 139 // Creates a menu. This uses BuildMenu() to recursively populate the menu. |
| 139 views::MenuItemView* CreateMenu(const bookmarks::BookmarkNode* parent, | 140 views::MenuItemView* CreateMenu(const bookmarks::BookmarkNode* parent, |
| 140 int start_child_index, | 141 int start_child_index, |
| 141 ShowOptions show_options); | 142 ShowOptions show_options); |
| 142 | 143 |
| 143 // Invokes BuildMenuForPermanentNode() for the permanent nodes (excluding | 144 // Invokes BuildMenuForPermanentNode() for the permanent nodes (excluding |
| 144 // 'other bookmarks' folder). | 145 // 'other bookmarks' folder). |
| 145 void BuildMenusForPermanentNodes(views::MenuItemView* menu, | 146 void BuildMenusForPermanentNodes(views::MenuItemView* menu); |
| 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 bookmarks::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, | |
| 156 bool* added_separator); | 155 bool* added_separator); |
| 157 | 156 |
| 158 void BuildMenuForManagedNode(views::MenuItemView* menu, int* next_menu_id); | 157 void BuildMenuForManagedNode(views::MenuItemView* menu); |
| 159 void BuildMenuForSupervisedNode(views::MenuItemView* menu, int* next_menu_id); | 158 void BuildMenuForSupervisedNode(views::MenuItemView* menu); |
| 160 | 159 |
| 161 // Creates an entry in menu for each child node of |parent| starting at | 160 // Creates an entry in menu for each child node of |parent| starting at |
| 162 // |start_child_index|. | 161 // |start_child_index|. |
| 163 void BuildMenu(const bookmarks::BookmarkNode* parent, | 162 void BuildMenu(const bookmarks::BookmarkNode* parent, |
| 164 int start_child_index, | 163 int start_child_index, |
| 165 views::MenuItemView* menu, | 164 views::MenuItemView* menu); |
| 166 int* next_menu_id); | |
| 167 | 165 |
| 168 // Returns true if |menu_id_| is outside the range of minimum and maximum menu | 166 // Registers the necessary mappings for |menu| and |node|. |
| 169 // ID's allowed. | 167 void AddMenuToMaps(views::MenuItemView* menu, |
| 170 bool IsOutsideMenuIdRange(int menu_id) const; | 168 const bookmarks::BookmarkNode* node); |
| 171 | 169 |
| 172 Browser* browser_; | 170 Browser* browser_; |
| 173 Profile* profile_; | 171 Profile* profile_; |
| 174 | 172 |
| 175 content::PageNavigator* page_navigator_; | 173 content::PageNavigator* page_navigator_; |
| 176 | 174 |
| 177 // Parent of menus. | 175 // Parent of menus. |
| 178 views::Widget* parent_; | 176 views::Widget* parent_; |
| 179 | 177 |
| 180 // Maps from menu id to BookmarkNode. | 178 // Maps from menu id to BookmarkNode. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 191 | 189 |
| 192 // If non-NULL this is the |parent| passed to Init and is NOT owned by us. | 190 // If non-NULL this is the |parent| passed to Init and is NOT owned by us. |
| 193 views::MenuItemView* parent_menu_item_; | 191 views::MenuItemView* parent_menu_item_; |
| 194 | 192 |
| 195 // Maps from node to menu. | 193 // Maps from node to menu. |
| 196 NodeToMenuMap node_to_menu_map_; | 194 NodeToMenuMap node_to_menu_map_; |
| 197 | 195 |
| 198 // ID of the next menu item. | 196 // ID of the next menu item. |
| 199 int next_menu_id_; | 197 int next_menu_id_; |
| 200 | 198 |
| 201 // Minimum and maximum ID's to use for menu items. | |
| 202 const int min_menu_id_; | |
| 203 const int max_menu_id_; | |
| 204 | |
| 205 views::MenuDelegate* real_delegate_; | 199 views::MenuDelegate* real_delegate_; |
| 206 | 200 |
| 207 // Is the model being changed? | 201 // Is the model being changed? |
| 208 bool is_mutating_model_; | 202 bool is_mutating_model_; |
| 209 | 203 |
| 210 // The location where this bookmark menu will be displayed (for UMA). | 204 // The location where this bookmark menu will be displayed (for UMA). |
| 211 BookmarkLaunchLocation location_; | 205 BookmarkLaunchLocation location_; |
| 212 | 206 |
| 213 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuDelegate); | 207 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuDelegate); |
| 214 }; | 208 }; |
| 215 | 209 |
| 216 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_DELEGATE_H_ | 210 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_DELEGATE_H_ |
| OLD | NEW |