Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / bookmarks / bookmark_context_menu_controller.h
blobe3b42fe8ab6563d4f67367d3db08b31c31cf3e6a
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.
5 #ifndef CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
13 #include "ui/base/models/simple_menu_model.h"
14 #include "ui/gfx/native_widget_types.h"
16 class Browser;
17 class Profile;
19 namespace content {
20 class PageNavigator;
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() {}
29 // Closes the bookmark context menu.
30 virtual void CloseMenu() = 0;
32 // Sent before any command from the menu is executed.
33 virtual void WillExecuteCommand(
34 int command_id,
35 const std::vector<const bookmarks::BookmarkNode*>& bookmarks) {}
37 // Sent after any command from the menu is executed.
38 virtual void DidExecuteCommand(int command_id) {}
41 // BookmarkContextMenuController creates and manages state for the context menu
42 // shown for any bookmark item.
43 class BookmarkContextMenuController
44 : public bookmarks::BaseBookmarkModelObserver,
45 public ui::SimpleMenuModel::Delegate {
46 public:
47 // Creates the bookmark context menu.
48 // |browser| is used to open the bookmark manager and is NULL in tests.
49 // |profile| is used for opening urls as well as enabling 'open incognito'.
50 // |navigator| is used if |browser| is null, and is provided for testing.
51 // |parent| is the parent for newly created nodes if |selection| is empty.
52 // |selection| is the nodes the context menu operates on and may be empty.
53 BookmarkContextMenuController(
54 gfx::NativeWindow parent_window,
55 BookmarkContextMenuControllerDelegate* delegate,
56 Browser* browser,
57 Profile* profile,
58 content::PageNavigator* navigator,
59 const bookmarks::BookmarkNode* parent,
60 const std::vector<const bookmarks::BookmarkNode*>& selection);
61 ~BookmarkContextMenuController() override;
63 ui::SimpleMenuModel* menu_model() { return menu_model_.get(); }
65 // ui::SimpleMenuModel::Delegate implementation:
66 bool IsCommandIdChecked(int command_id) const override;
67 bool IsCommandIdEnabled(int command_id) const override;
68 bool IsCommandIdVisible(int command_id) const override;
69 bool GetAcceleratorForCommandId(int command_id,
70 ui::Accelerator* accelerator) override;
71 void ExecuteCommand(int command_id, int event_flags) override;
72 bool IsItemForCommandIdDynamic(int command_id) const override;
73 base::string16 GetLabelForCommandId(int command_id) const override;
75 void set_navigator(content::PageNavigator* navigator) {
76 navigator_ = navigator;
79 private:
80 void BuildMenu();
82 // Adds a IDC_* style command to the menu with a localized string.
83 void AddItem(int id, int localization_id);
84 // Adds a separator to the menu.
85 void AddSeparator();
86 // Adds a checkable item to the menu.
87 void AddCheckboxItem(int id, int localization_id);
89 // Overridden from bookmarks::BaseBookmarkModelObserver:
90 // Any change to the model results in closing the menu.
91 void BookmarkModelChanged() override;
93 gfx::NativeWindow parent_window_;
94 BookmarkContextMenuControllerDelegate* delegate_;
95 Browser* browser_;
96 Profile* profile_;
97 content::PageNavigator* navigator_;
98 const bookmarks::BookmarkNode* parent_;
99 std::vector<const bookmarks::BookmarkNode*> selection_;
100 bookmarks::BookmarkModel* model_;
101 scoped_ptr<ui::SimpleMenuModel> menu_model_;
103 DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuController);
106 #endif // CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_