Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / ui / views / bookmarks / bookmark_menu_controller_views.h
blob9c7f07e4b104df957ca555ef4c070452257d3c14
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 BookmarkNode;
19 class Browser;
21 namespace content {
22 class PageNavigator;
25 namespace ui {
26 class OSExchangeData;
29 namespace views {
30 class MenuButton;
31 class MenuItemView;
32 class MenuRunner;
33 class Widget;
36 // BookmarkMenuController is responsible for showing a menu of bookmarks,
37 // each item in the menu represents a bookmark.
38 // BookmarkMenuController deletes itself as necessary, although the menu can
39 // be explicitly hidden by way of the Cancel method.
40 class BookmarkMenuController : public BaseBookmarkModelObserver,
41 public views::MenuDelegate {
42 public:
43 // Creates a BookmarkMenuController showing the children of |node| starting
44 // at |start_child_index|.
45 BookmarkMenuController(Browser* browser,
46 content::PageNavigator* page_navigator,
47 views::Widget* parent,
48 const BookmarkNode* node,
49 int start_child_index,
50 bool for_drop);
52 void RunMenuAt(BookmarkBarView* bookmark_bar);
54 void clear_bookmark_bar() {
55 bookmark_bar_ = NULL;
58 // Hides the menu.
59 void Cancel();
61 // Returns the node the menu is showing for.
62 const BookmarkNode* node() const { return node_; }
64 // Returns the menu.
65 views::MenuItemView* menu() const;
67 // Returns the context menu, or NULL if the context menu isn't showing.
68 views::MenuItemView* context_menu() const;
70 // Sets the page navigator.
71 void SetPageNavigator(content::PageNavigator* navigator);
73 void set_observer(BookmarkMenuControllerObserver* observer) {
74 observer_ = observer;
77 // views::MenuDelegate:
78 virtual base::string16 GetTooltipText(int id,
79 const gfx::Point& p) const override;
80 virtual bool IsTriggerableEvent(views::MenuItemView* view,
81 const ui::Event& e) override;
82 virtual void ExecuteCommand(int id, int mouse_event_flags) override;
83 virtual bool ShouldExecuteCommandWithoutClosingMenu(
84 int id,
85 const ui::Event& e) override;
86 virtual bool GetDropFormats(
87 views::MenuItemView* menu,
88 int* formats,
89 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) override;
90 virtual bool AreDropTypesRequired(views::MenuItemView* menu) override;
91 virtual bool CanDrop(views::MenuItemView* menu,
92 const ui::OSExchangeData& data) override;
93 virtual int GetDropOperation(views::MenuItemView* item,
94 const ui::DropTargetEvent& event,
95 DropPosition* position) override;
96 virtual int OnPerformDrop(views::MenuItemView* menu,
97 DropPosition position,
98 const ui::DropTargetEvent& event) override;
99 virtual bool ShowContextMenu(views::MenuItemView* source,
100 int id,
101 const gfx::Point& p,
102 ui::MenuSourceType source_type) override;
103 virtual void DropMenuClosed(views::MenuItemView* menu) override;
104 virtual bool CanDrag(views::MenuItemView* menu) override;
105 virtual void WriteDragData(views::MenuItemView* sender,
106 ui::OSExchangeData* data) override;
107 virtual int GetDragOperations(views::MenuItemView* sender) override;
108 virtual views::MenuItemView* GetSiblingMenu(
109 views::MenuItemView* menu,
110 const gfx::Point& screen_point,
111 views::MenuAnchorPosition* anchor,
112 bool* has_mnemonics,
113 views::MenuButton** button) override;
114 virtual int GetMaxWidthForMenu(views::MenuItemView* view) override;
116 // BaseBookmarkModelObserver:
117 virtual void BookmarkModelChanged() override;
119 private:
120 // BookmarkMenuController deletes itself as necessary.
121 virtual ~BookmarkMenuController();
123 scoped_ptr<views::MenuRunner> menu_runner_;
125 scoped_ptr<BookmarkMenuDelegate> menu_delegate_;
127 // The node we're showing the contents of.
128 const BookmarkNode* node_;
130 // Data for the drop.
131 bookmarks::BookmarkNodeData drop_data_;
133 // The observer, may be null.
134 BookmarkMenuControllerObserver* observer_;
136 // Is the menu being shown for a drop?
137 bool for_drop_;
139 // The bookmark bar. This is only non-null if we're showing a menu item for a
140 // folder on the bookmark bar and not for drop, or if the BookmarkBarView has
141 // been destroyed before the menu.
142 BookmarkBarView* bookmark_bar_;
144 DISALLOW_COPY_AND_ASSIGN(BookmarkMenuController);
147 #endif // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_