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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_CONTEXT_MENU_H_
6 #define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_CONTEXT_MENU_H_
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"
19 // Observer for the BookmarkContextMenu.
20 class BookmarkContextMenuObserver {
22 // Invoked before the specified items are removed from the bookmark model.
23 virtual void WillRemoveBookmarks(
24 const std::vector<const BookmarkNode*>& bookmarks) = 0;
26 // Invoked after the items have been removed from the model.
27 virtual void DidRemoveBookmarks() = 0;
30 virtual ~BookmarkContextMenuObserver() {}
33 class BookmarkContextMenu : public BookmarkContextMenuControllerDelegate,
34 public views::MenuDelegate {
36 // |browser| is used to open the bookmark manager, and is NULL in tests.
38 views::Widget* parent_widget,
41 content::PageNavigator* page_navigator,
42 const BookmarkNode* parent,
43 const std::vector<const BookmarkNode*>& selection,
44 bool close_on_remove);
45 virtual ~BookmarkContextMenu();
47 // Shows the context menu at the specified point.
48 void RunMenuAt(const gfx::Point& point,
49 ui::MenuSourceType source_type);
51 views::MenuItemView* menu() const { return menu_; }
53 void set_observer(BookmarkContextMenuObserver* observer) {
57 // Sets the PageNavigator.
58 void SetPageNavigator(content::PageNavigator* navigator);
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;
67 // Overridden from BookmarkContextMenuControllerDelegate:
68 virtual void CloseMenu() OVERRIDE;
69 virtual void WillExecuteCommand(
71 const std::vector<const BookmarkNode*>& bookmarks) OVERRIDE;
72 virtual void DidExecuteCommand(int command_id) OVERRIDE;
75 scoped_ptr<BookmarkContextMenuController> controller_;
77 // The parent of dialog boxes opened from the context menu.
78 views::Widget* parent_widget_;
80 // The menu itself. This is owned by |menu_runner_|.
81 views::MenuItemView* menu_;
83 // Responsible for running the menu.
84 scoped_ptr<views::MenuRunner> menu_runner_;
86 BookmarkContextMenuObserver* observer_;
88 // Should the menu close when a node is removed.
89 bool close_on_remove_;
91 DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenu);
94 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_CONTEXT_MENU_H_