Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / bookmarks / bookmark_context_menu_controller.h
blobb2d14af6824d6d85d10fa78c4f6a85480a913a42
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 "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"
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 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 : public BaseBookmarkModelObserver,
44 public ui::SimpleMenuModel::Delegate {
45 public:
46 // Creates the bookmark context menu.
47 // |browser| is used to open the bookmark manager and is NULL in tests.
48 // |profile| is used for opening urls as well as enabling 'open incognito'.
49 // |navigator| is used if |browser| is null, and is provided for testing.
50 // |parent| is the parent for newly created nodes if |selection| is empty.
51 // |selection| is the nodes the context menu operates on and may be empty.
52 BookmarkContextMenuController(
53 gfx::NativeWindow parent_window,
54 BookmarkContextMenuControllerDelegate* delegate,
55 Browser* browser,
56 Profile* profile,
57 content::PageNavigator* navigator,
58 const BookmarkNode* parent,
59 const std::vector<const BookmarkNode*>& selection);
60 virtual ~BookmarkContextMenuController();
62 ui::SimpleMenuModel* menu_model() { return menu_model_.get(); }
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, int event_flags) OVERRIDE;
71 virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE;
72 virtual base::string16 GetLabelForCommandId(int command_id) const OVERRIDE;
74 void set_navigator(content::PageNavigator* navigator) {
75 navigator_ = navigator;
78 private:
79 // A hook so that platform-specific implementations can report which commands
80 // are enabled. Returns true if |enabled| was set by the platform-specific
81 // implementation.
82 bool IsPlatformCommandIdEnabled(int command_id, bool* enabled) const;
84 // A hook to execute platform-specific commands. Returns true if the command
85 // has been handled and should no longer be processed.
86 bool ExecutePlatformCommand(int command_id, int event_flags);
88 void BuildMenu();
90 // Adds a IDC_* style command to the menu with a localized string.
91 void AddItem(int id, int localization_id);
92 // Adds a separator to the menu.
93 void AddSeparator();
94 // Adds a checkable item to the menu.
95 void AddCheckboxItem(int id, int localization_id);
97 // Overridden from BaseBookmarkModelObserver:
98 // Any change to the model results in closing the menu.
99 virtual void BookmarkModelChanged() OVERRIDE;
101 gfx::NativeWindow parent_window_;
102 BookmarkContextMenuControllerDelegate* delegate_;
103 Browser* browser_;
104 Profile* profile_;
105 content::PageNavigator* navigator_;
106 const BookmarkNode* parent_;
107 std::vector<const BookmarkNode*> selection_;
108 BookmarkModel* model_;
109 scoped_ptr<ui::SimpleMenuModel> menu_model_;
111 DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuController);
114 #endif // CHROME_BROWSER_UI_BOOKMARKS_BOOKMARK_CONTEXT_MENU_CONTROLLER_H_