bookmark_context_menu.h revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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 12class Browser; 13 14namespace views { 15class MenuRunner; 16class Widget; 17} 18 19// Observer for the BookmarkContextMenu. 20class 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 33class 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 IsCommandVisible(int command_id) const OVERRIDE; 65 virtual bool ShouldCloseAllMenusOnExecute(int id) OVERRIDE; 66 67 // Overridden from BookmarkContextMenuControllerDelegate: 68 virtual void CloseMenu() OVERRIDE; 69 virtual void WillExecuteCommand( 70 int command_id, 71 const std::vector<const BookmarkNode*>& bookmarks) OVERRIDE; 72 virtual void DidExecuteCommand(int command_id) OVERRIDE; 73 74 private: 75 scoped_ptr<BookmarkContextMenuController> controller_; 76 77 // The parent of dialog boxes opened from the context menu. 78 views::Widget* parent_widget_; 79 80 // The menu itself. This is owned by |menu_runner_|. 81 views::MenuItemView* menu_; 82 83 // Responsible for running the menu. 84 scoped_ptr<views::MenuRunner> menu_runner_; 85 86 BookmarkContextMenuObserver* observer_; 87 88 // Should the menu close when a node is removed. 89 bool close_on_remove_; 90 91 DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenu); 92}; 93 94#endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_CONTEXT_MENU_H_ 95