Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / views / bookmarks / bookmark_menu_controller_views.h
blob5c7800834b5883d5dc8a0f991254d17a6fb280ad
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_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_
6 #define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_
8 #include <set>
10 #include "base/compiler_specific.h"
11 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
12 #include "components/bookmarks/browser/bookmark_node_data.h"
13 #include "ui/views/controls/menu/menu_delegate.h"
15 class BookmarkBarView;
16 class BookmarkMenuControllerObserver;
17 class BookmarkMenuDelegate;
18 class Browser;
20 namespace bookmarks {
21 class BookmarkNode;
24 namespace content {
25 class PageNavigator;
28 namespace ui {
29 class OSExchangeData;
32 namespace views {
33 class MenuButton;
34 class MenuItemView;
35 class MenuRunner;
36 class Widget;
39 // BookmarkMenuController is responsible for showing a menu of bookmarks,
40 // each item in the menu represents a bookmark.
41 // BookmarkMenuController deletes itself as necessary, although the menu can
42 // be explicitly hidden by way of the Cancel method.
43 class BookmarkMenuController : public bookmarks::BaseBookmarkModelObserver,
44 public views::MenuDelegate {
45 public:
46 // Creates a BookmarkMenuController showing the children of |node| starting
47 // at |start_child_index|.
48 BookmarkMenuController(Browser* browser,
49 content::PageNavigator* page_navigator,
50 views::Widget* parent,
51 const bookmarks::BookmarkNode* node,
52 int start_child_index,
53 bool for_drop);
55 void RunMenuAt(BookmarkBarView* bookmark_bar);
57 void clear_bookmark_bar() {
58 bookmark_bar_ = NULL;
61 // Hides the menu.
62 void Cancel();
64 // Returns the node the menu is showing for.
65 const bookmarks::BookmarkNode* node() const { return node_; }
67 // Returns the menu.
68 views::MenuItemView* menu() const;
70 // Returns the context menu, or NULL if the context menu isn't showing.
71 views::MenuItemView* context_menu() const;
73 // Sets the page navigator.
74 void SetPageNavigator(content::PageNavigator* navigator);
76 void set_observer(BookmarkMenuControllerObserver* observer) {
77 observer_ = observer;
80 // views::MenuDelegate:
81 base::string16 GetTooltipText(int id, const gfx::Point& p) const override;
82 bool IsTriggerableEvent(views::MenuItemView* view,
83 const ui::Event& e) override;
84 void ExecuteCommand(int id, int mouse_event_flags) override;
85 bool ShouldExecuteCommandWithoutClosingMenu(int id,
86 const ui::Event& e) override;
87 bool GetDropFormats(
88 views::MenuItemView* menu,
89 int* formats,
90 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) override;
91 bool AreDropTypesRequired(views::MenuItemView* menu) override;
92 bool CanDrop(views::MenuItemView* menu,
93 const ui::OSExchangeData& data) override;
94 int GetDropOperation(views::MenuItemView* item,
95 const ui::DropTargetEvent& event,
96 DropPosition* position) override;
97 int OnPerformDrop(views::MenuItemView* menu,
98 DropPosition position,
99 const ui::DropTargetEvent& event) override;
100 bool ShowContextMenu(views::MenuItemView* source,
101 int id,
102 const gfx::Point& p,
103 ui::MenuSourceType source_type) override;
104 void DropMenuClosed(views::MenuItemView* menu) override;
105 bool CanDrag(views::MenuItemView* menu) override;
106 void WriteDragData(views::MenuItemView* sender,
107 ui::OSExchangeData* data) override;
108 int GetDragOperations(views::MenuItemView* sender) override;
109 views::MenuItemView* GetSiblingMenu(views::MenuItemView* menu,
110 const gfx::Point& screen_point,
111 views::MenuAnchorPosition* anchor,
112 bool* has_mnemonics,
113 views::MenuButton** button) override;
114 int GetMaxWidthForMenu(views::MenuItemView* view) override;
115 void WillShowMenu(views::MenuItemView* menu) override;
117 // bookmarks::BaseBookmarkModelObserver:
118 void BookmarkModelChanged() override;
120 private:
121 // BookmarkMenuController deletes itself as necessary.
122 ~BookmarkMenuController() override;
124 scoped_ptr<views::MenuRunner> menu_runner_;
126 scoped_ptr<BookmarkMenuDelegate> menu_delegate_;
128 // The node we're showing the contents of.
129 const bookmarks::BookmarkNode* node_;
131 // Data for the drop.
132 bookmarks::BookmarkNodeData drop_data_;
134 // The observer, may be null.
135 BookmarkMenuControllerObserver* observer_;
137 // Is the menu being shown for a drop?
138 bool for_drop_;
140 // The bookmark bar. This is only non-null if we're showing a menu item for a
141 // folder on the bookmark bar and not for drop, or if the BookmarkBarView has
142 // been destroyed before the menu.
143 BookmarkBarView* bookmark_bar_;
145 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuController);
148 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_