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_
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
;
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
{
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
,
55 void RunMenuAt(BookmarkBarView
* bookmark_bar
);
57 void clear_bookmark_bar() {
64 // Returns the node the menu is showing for.
65 const bookmarks::BookmarkNode
* node() const { return node_
; }
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
) {
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
;
88 views::MenuItemView
* menu
,
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
,
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
,
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
;
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?
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_