1 // Copyright (c) 2011 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_UI_VIEWS_BOOKMARKS_BOOKMARK_CONTEXT_MENU_H_ 6 #define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_CONTEXT_MENU_H_ 7 8 #include "base/compiler_specific.h" 9 #include "chrome/browser/ui/bookmarks/bookmark_context_menu_controller.h" 10 #include "ui/views/controls/menu/menu_delegate.h" 11 12 class Browser; 13 14 namespace views { 15 class MenuRunner; 16 class Widget; 17 } 18 19 // Observer for the BookmarkContextMenu. 20 class BookmarkContextMenuObserver { 21 public: 22 // Invoked before the specified items are removed from the bookmark model. 23 virtual void WillRemoveBookmarks( 24 const std::vector<const BookmarkNode*>& bookmarks) = 0; 25 26 // Invoked after the items have been removed from the model. 27 virtual void DidRemoveBookmarks() = 0; 28 29 protected: 30 virtual ~BookmarkContextMenuObserver() {} 31 }; 32 33 class BookmarkContextMenu : public BookmarkContextMenuControllerDelegate, 34 public views::MenuDelegate { 35 public: 36 // |browser| is used to open the bookmark manager, and is NULL in tests. 37 BookmarkContextMenu( 38 views::Widget* parent_widget, 39 Browser* browser, 40 Profile* profile, 41 content::PageNavigator* page_navigator, 42 const BookmarkNode* parent, 43 const std::vector<const BookmarkNode*>& selection, 44 bool close_on_remove); 45 virtual ~BookmarkContextMenu(); 46 47 // Shows the context menu at the specified point. 48 void RunMenuAt(const gfx::Point& point, 49 ui::MenuSourceType source_type); 50 51 views::MenuItemView* menu() const { return menu_; } 52 53 void set_observer(BookmarkContextMenuObserver* observer) { 54 observer_ = observer; 55 } 56 57 // Sets the PageNavigator. 58 void SetPageNavigator(content::PageNavigator* navigator); 59 60 // Overridden from views::MenuDelegate: 61 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; 62 virtual bool IsItemChecked(int command_id) const OVERRIDE; 63 virtual bool IsCommandEnabled(int command_id) const OVERRIDE; 64 virtual bool ShouldCloseAllMenusOnExecute(int id) OVERRIDE; 65 66 // Overridden from BookmarkContextMenuControllerDelegate: 67 virtual void CloseMenu() OVERRIDE; 68 virtual void WillExecuteCommand( 69 int command_id, 70 const std::vector<const BookmarkNode*>& bookmarks) OVERRIDE; 71 virtual void DidExecuteCommand(int command_id) OVERRIDE; 72 73 private: 74 scoped_ptr<BookmarkContextMenuController> controller_; 75 76 // The parent of dialog boxes opened from the context menu. 77 views::Widget* parent_widget_; 78 79 // The menu itself. This is owned by |menu_runner_|. 80 views::MenuItemView* menu_; 81 82 // Responsible for running the menu. 83 scoped_ptr<views::MenuRunner> menu_runner_; 84 85 // The node we're showing the menu for. 86 const BookmarkNode* parent_node_; 87 88 BookmarkContextMenuObserver* observer_; 89 90 // Should the menu close when a node is removed. 91 bool close_on_remove_; 92 93 DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenu); 94 }; 95 96 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_CONTEXT_MENU_H_ 97