bookmark_menu_controller_views.h revision 424c4d7b64af9d0d8fd9624f381f469654d5e3d2
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.
4
5#ifndef CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_
6#define CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_
7
8#include <set>
9
10#include "base/compiler_specific.h"
11#include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
12#include "chrome/browser/bookmarks/bookmark_node_data.h"
13#include "ui/views/controls/menu/menu_delegate.h"
14#include "ui/views/controls/menu/menu_item_view.h"
15
16class BookmarkBarView;
17class BookmarkMenuControllerObserver;
18class BookmarkMenuDelegate;
19class BookmarkNode;
20class Browser;
21
22namespace content {
23class PageNavigator;
24}
25
26namespace ui {
27class OSExchangeData;
28}
29
30namespace views {
31class MenuButton;
32class MenuRunner;
33class Widget;
34}
35
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.
40class 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
51  void RunMenuAt(BookmarkBarView* bookmark_bar, bool for_drop);
52
53  void clear_bookmark_bar() {
54    bookmark_bar_ = NULL;
55  }
56
57  // Hides the menu.
58  void Cancel();
59
60  // Returns the node the menu is showing for.
61  const BookmarkNode* node() const { return node_; }
62
63  // Returns the menu.
64  views::MenuItemView* menu() const;
65
66  // Returns the context menu, or NULL if the context menu isn't showing.
67  views::MenuItemView* context_menu() const;
68
69  // Sets the page navigator.
70  void SetPageNavigator(content::PageNavigator* navigator);
71
72  void set_observer(BookmarkMenuControllerObserver* observer) {
73    observer_ = observer;
74  }
75
76  // views::MenuDelegate:
77  virtual string16 GetTooltipText(int id, const gfx::Point& p) const OVERRIDE;
78  virtual bool IsTriggerableEvent(views::MenuItemView* view,
79                                  const ui::Event& e) OVERRIDE;
80  virtual void ExecuteCommand(int id, int mouse_event_flags) OVERRIDE;
81  virtual bool ShouldExecuteCommandWithoutClosingMenu(
82      int id,
83      const ui::Event& e) OVERRIDE;
84  virtual bool GetDropFormats(
85      views::MenuItemView* menu,
86      int* formats,
87      std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE;
88  virtual bool AreDropTypesRequired(views::MenuItemView* menu) OVERRIDE;
89  virtual bool CanDrop(views::MenuItemView* menu,
90                       const ui::OSExchangeData& data) OVERRIDE;
91  virtual int GetDropOperation(views::MenuItemView* item,
92                               const ui::DropTargetEvent& event,
93                               DropPosition* position) OVERRIDE;
94  virtual int OnPerformDrop(views::MenuItemView* menu,
95                            DropPosition position,
96                            const ui::DropTargetEvent& event) OVERRIDE;
97  virtual bool ShowContextMenu(views::MenuItemView* source,
98                               int id,
99                               const gfx::Point& p,
100                               ui::MenuSourceType source_type) OVERRIDE;
101  virtual void DropMenuClosed(views::MenuItemView* menu) OVERRIDE;
102  virtual bool CanDrag(views::MenuItemView* menu) OVERRIDE;
103  virtual void WriteDragData(views::MenuItemView* sender,
104                             ui::OSExchangeData* data) OVERRIDE;
105  virtual int GetDragOperations(views::MenuItemView* sender) OVERRIDE;
106  virtual views::MenuItemView* GetSiblingMenu(
107      views::MenuItemView* menu,
108      const gfx::Point& screen_point,
109      views::MenuItemView::AnchorPosition* anchor,
110      bool* has_mnemonics,
111      views::MenuButton** button) OVERRIDE;
112  virtual int GetMaxWidthForMenu(views::MenuItemView* view) OVERRIDE;
113
114  // BaseBookmarkModelObserver:
115  virtual void BookmarkModelChanged() OVERRIDE;
116
117 private:
118  // BookmarkMenuController deletes itself as necessary.
119  virtual ~BookmarkMenuController();
120
121  scoped_ptr<views::MenuRunner> menu_runner_;
122
123  scoped_ptr<BookmarkMenuDelegate> menu_delegate_;
124
125  // The node we're showing the contents of.
126  const BookmarkNode* node_;
127
128  // Data for the drop.
129  BookmarkNodeData drop_data_;
130
131  // The observer, may be null.
132  BookmarkMenuControllerObserver* observer_;
133
134  // Is the menu being shown for a drop?
135  bool for_drop_;
136
137  // The bookmark bar. This is only non-null if we're showing a menu item for a
138  // folder on the bookmark bar and not for drop, or if the BookmarkBarView has
139  // been destroyed before the menu.
140  BookmarkBarView* bookmark_bar_;
141
142  DISALLOW_COPY_AND_ASSIGN(BookmarkMenuController);
143};
144
145#endif  // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_
146