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_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 virtual void DidExecuteCommand(int command_id) {} | 39 virtual void DidExecuteCommand(int command_id) {} |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 // BookmarkContextMenuController creates and manages state for the context menu | 42 // BookmarkContextMenuController creates and manages state for the context menu |
| 43 // shown for any bookmark item. | 43 // shown for any bookmark item. |
| 44 class BookmarkContextMenuController | 44 class BookmarkContextMenuController |
| 45 : public bookmarks::BaseBookmarkModelObserver, | 45 : public bookmarks::BaseBookmarkModelObserver, |
| 46 public ui::SimpleMenuModel::Delegate { | 46 public ui::SimpleMenuModel::Delegate { |
| 47 public: | 47 public: |
| 48 // Creates the bookmark context menu. | 48 // Creates the bookmark context menu. |
| 49 // |browser| is used to open the bookmark manager and is NULL in tests. | 49 // |browser| is used to open the bookmark manager and is nullptr in tests. |
|
Peter Kasting
2017/04/14 19:04:40
Nit: In comments, just say "null" in lowercase.
Paezagon
2017/04/14 19:52:34
Done.
| |
| 50 // |profile| is used for opening urls as well as enabling 'open incognito'. | 50 // |profile| is used for opening urls as well as enabling 'open incognito'. |
| 51 // |navigator| is used if |browser| is null, and is provided for testing. | 51 // |navigator| is used if |browser| is null, and is provided for testing. |
| 52 // |parent| is the parent for newly created nodes if |selection| is empty. | 52 // |parent| is the parent for newly created nodes if |selection| is empty. |
| 53 // |selection| is the nodes the context menu operates on and may be empty. | 53 // |selection| is the nodes the context menu operates on and may be empty. |
| 54 BookmarkContextMenuController( | 54 BookmarkContextMenuController( |
| 55 gfx::NativeWindow parent_window, | 55 gfx::NativeWindow parent_window, |
| 56 BookmarkContextMenuControllerDelegate* delegate, | 56 BookmarkContextMenuControllerDelegate* delegate, |
| 57 Browser* browser, | 57 Browser* browser, |
| 58 Profile* profile, | 58 Profile* profile, |
| 59 content::PageNavigator* navigator, | 59 content::PageNavigator* navigator, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 71 bool IsItemForCommandIdDynamic(int command_id) const override; | 71 bool IsItemForCommandIdDynamic(int command_id) const override; |
| 72 base::string16 GetLabelForCommandId(int command_id) const override; | 72 base::string16 GetLabelForCommandId(int command_id) const override; |
| 73 | 73 |
| 74 void set_navigator(content::PageNavigator* navigator) { | 74 void set_navigator(content::PageNavigator* navigator) { |
| 75 navigator_ = navigator; | 75 navigator_ = navigator; |
| 76 } | 76 } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 void BuildMenu(); | 79 void BuildMenu(); |
| 80 | 80 |
| 81 // Adds a IDC_* style command to the menu with a string16. | |
| 82 void AddItem(int id, const base::string16 str); | |
| 81 // Adds a IDC_* style command to the menu with a localized string. | 83 // Adds a IDC_* style command to the menu with a localized string. |
| 82 void AddItem(int id, int localization_id); | 84 void AddItem(int id, int localization_id); |
| 83 // Adds a separator to the menu. | 85 // Adds a separator to the menu. |
| 84 void AddSeparator(); | 86 void AddSeparator(); |
| 85 // Adds a checkable item to the menu. | 87 // Adds a checkable item to the menu. |
| 86 void AddCheckboxItem(int id, int localization_id); | 88 void AddCheckboxItem(int id, int localization_id); |
| 87 | 89 |
| 88 // Overridden from bookmarks::BaseBookmarkModelObserver: | 90 // Overridden from bookmarks::BaseBookmarkModelObserver: |
| 89 // Any change to the model results in closing the menu. | 91 // Any change to the model results in closing the menu. |
| 90 void BookmarkModelChanged() override; | 92 void BookmarkModelChanged() override; |
| 91 | 93 |
| 92 gfx::NativeWindow parent_window_; | 94 gfx::NativeWindow parent_window_; |
| 93 BookmarkContextMenuControllerDelegate* delegate_; | 95 BookmarkContextMenuControllerDelegate* delegate_; |
| 94 Browser* browser_; | 96 Browser* browser_; |
| 95 Profile* profile_; | 97 Profile* profile_; |
| 96 content::PageNavigator* navigator_; | 98 content::PageNavigator* navigator_; |
| 97 const bookmarks::BookmarkNode* parent_; | 99 const bookmarks::BookmarkNode* parent_; |
| 98 std::vector<const bookmarks::BookmarkNode*> selection_; | 100 std::vector<const bookmarks::BookmarkNode*> selection_; |
| 99 bookmarks::BookmarkModel* model_; | 101 bookmarks::BookmarkModel* model_; |
| 100 std::unique_ptr<ui::SimpleMenuModel> menu_model_; | 102 std::unique_ptr<ui::SimpleMenuModel> menu_model_; |
| 101 // Used to detect deletion of |this| executing a command. | 103 // Used to detect deletion of |this| executing a command. |
| 102 base::WeakPtrFactory<BookmarkContextMenuController> weak_factory_; | 104 base::WeakPtrFactory<BookmarkContextMenuController> weak_factory_; |
| 103 | 105 |
| 104 DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuController); | 106 DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuController); |
| 105 }; | 107 }; |
| 106 | 108 |
| 107 #endif // CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_ | 109 #endif // CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_ |
| OLD | NEW |