| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_ | |
| 6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" | |
| 13 #include "ui/base/models/simple_menu_model.h" | |
| 14 #include "ui/gfx/native_widget_types.h" | |
| 15 | |
| 16 class Browser; | |
| 17 class Profile; | |
| 18 | |
| 19 namespace content { | |
| 20 class PageNavigator; | |
| 21 } | |
| 22 | |
| 23 // An interface implemented by an object that performs actions on the actual | |
| 24 // menu for the controller. | |
| 25 class BookmarkContextMenuControllerDelegate { | |
| 26 public: | |
| 27 virtual ~BookmarkContextMenuControllerDelegate() {} | |
| 28 | |
| 29 // Closes the bookmark context menu. | |
| 30 virtual void CloseMenu() = 0; | |
| 31 | |
| 32 // Sent before any command from the menu is executed. | |
| 33 virtual void WillExecuteCommand() {} | |
| 34 | |
| 35 // Sent after any command from the menu is executed. | |
| 36 virtual void DidExecuteCommand() {} | |
| 37 }; | |
| 38 | |
| 39 // BookmarkContextMenuController creates and manages state for the context menu | |
| 40 // shown for any bookmark item. | |
| 41 class BookmarkContextMenuController : public BaseBookmarkModelObserver, | |
| 42 public ui::SimpleMenuModel::Delegate { | |
| 43 public: | |
| 44 // Creates the bookmark context menu. | |
| 45 // |browser| is used to open the bookmark manager and is NULL in tests. | |
| 46 // |profile| is used for opening urls as well as enabling 'open incognito'. | |
| 47 // |navigator| is used if |browser| is null, and is provided for testing. | |
| 48 // |parent| is the parent for newly created nodes if |selection| is empty. | |
| 49 // |selection| is the nodes the context menu operates on and may be empty. | |
| 50 BookmarkContextMenuController( | |
| 51 gfx::NativeWindow parent_window, | |
| 52 BookmarkContextMenuControllerDelegate* delegate, | |
| 53 Browser* browser, | |
| 54 Profile* profile, | |
| 55 content::PageNavigator* navigator, | |
| 56 const BookmarkNode* parent, | |
| 57 const std::vector<const BookmarkNode*>& selection); | |
| 58 virtual ~BookmarkContextMenuController(); | |
| 59 | |
| 60 void BuildMenu(); | |
| 61 | |
| 62 ui::SimpleMenuModel* menu_model() const { return menu_model_.get(); } | |
| 63 | |
| 64 // ui::SimpleMenuModel::Delegate implementation: | |
| 65 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | |
| 66 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | |
| 67 virtual bool GetAcceleratorForCommandId( | |
| 68 int command_id, | |
| 69 ui::Accelerator* accelerator) OVERRIDE; | |
| 70 virtual void ExecuteCommand(int command_id) OVERRIDE; | |
| 71 | |
| 72 // Accessors: | |
| 73 Profile* profile() const { return profile_; } | |
| 74 content::PageNavigator* navigator() const { return navigator_; } | |
| 75 | |
| 76 private: | |
| 77 // Adds a IDC_* style command to the menu with a localized string. | |
| 78 void AddItem(int id, int localization_id); | |
| 79 // Adds a separator to the menu. | |
| 80 void AddSeparator(); | |
| 81 // Adds a checkable item to the menu. | |
| 82 void AddCheckboxItem(int id, int localization_id); | |
| 83 | |
| 84 // Overridden from BaseBookmarkModelObserver: | |
| 85 // Any change to the model results in closing the menu. | |
| 86 virtual void BookmarkModelChanged() OVERRIDE; | |
| 87 | |
| 88 // Returns true if selection_ has at least one bookmark of type url. | |
| 89 bool HasURLs() const; | |
| 90 | |
| 91 gfx::NativeWindow parent_window_; | |
| 92 BookmarkContextMenuControllerDelegate* delegate_; | |
| 93 Browser* browser_; | |
| 94 Profile* profile_; | |
| 95 content::PageNavigator* navigator_; | |
| 96 const BookmarkNode* parent_; | |
| 97 std::vector<const BookmarkNode*> selection_; | |
| 98 BookmarkModel* model_; | |
| 99 scoped_ptr<ui::SimpleMenuModel> menu_model_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuController); | |
| 102 }; | |
| 103 | |
| 104 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_ | |
| OLD | NEW |