Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / bookmarks / bookmark_menu_controller_views.h
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 "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"
14
15 class BookmarkBarView;
16 class BookmarkMenuControllerObserver;
17 class BookmarkMenuDelegate;
18 class BookmarkNode;
19 class Browser;
20
21 namespace content {
22 class PageNavigator;
23 }
24
25 namespace ui {
26 class OSExchangeData;
27 }
28
29 namespace views {
30 class MenuButton;
31 class MenuItemView;
32 class MenuRunner;
33 class 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.
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
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 base::string16 GetTooltipText(int id,
78                                         const gfx::Point& p) const OVERRIDE;
79   virtual bool IsTriggerableEvent(views::MenuItemView* view,
80                                   const ui::Event& e) OVERRIDE;
81   virtual void ExecuteCommand(int id, int mouse_event_flags) OVERRIDE;
82   virtual bool ShouldExecuteCommandWithoutClosingMenu(
83       int id,
84       const ui::Event& e) OVERRIDE;
85   virtual bool GetDropFormats(
86       views::MenuItemView* menu,
87       int* formats,
88       std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE;
89   virtual bool AreDropTypesRequired(views::MenuItemView* menu) OVERRIDE;
90   virtual bool CanDrop(views::MenuItemView* menu,
91                        const ui::OSExchangeData& data) OVERRIDE;
92   virtual int GetDropOperation(views::MenuItemView* item,
93                                const ui::DropTargetEvent& event,
94                                DropPosition* position) OVERRIDE;
95   virtual int OnPerformDrop(views::MenuItemView* menu,
96                             DropPosition position,
97                             const ui::DropTargetEvent& event) OVERRIDE;
98   virtual bool ShowContextMenu(views::MenuItemView* source,
99                                int id,
100                                const gfx::Point& p,
101                                ui::MenuSourceType source_type) OVERRIDE;
102   virtual void DropMenuClosed(views::MenuItemView* menu) OVERRIDE;
103   virtual bool CanDrag(views::MenuItemView* menu) OVERRIDE;
104   virtual void WriteDragData(views::MenuItemView* sender,
105                              ui::OSExchangeData* data) OVERRIDE;
106   virtual int GetDragOperations(views::MenuItemView* sender) OVERRIDE;
107   virtual views::MenuItemView* GetSiblingMenu(
108       views::MenuItemView* menu,
109       const gfx::Point& screen_point,
110       views::MenuAnchorPosition* anchor,
111       bool* has_mnemonics,
112       views::MenuButton** button) OVERRIDE;
113   virtual int GetMaxWidthForMenu(views::MenuItemView* view) OVERRIDE;
114
115   // BaseBookmarkModelObserver:
116   virtual void BookmarkModelChanged() OVERRIDE;
117
118  private:
119   // BookmarkMenuController deletes itself as necessary.
120   virtual ~BookmarkMenuController();
121
122   scoped_ptr<views::MenuRunner> menu_runner_;
123
124   scoped_ptr<BookmarkMenuDelegate> menu_delegate_;
125
126   // The node we're showing the contents of.
127   const BookmarkNode* node_;
128
129   // Data for the drop.
130   BookmarkNodeData drop_data_;
131
132   // The observer, may be null.
133   BookmarkMenuControllerObserver* observer_;
134
135   // Is the menu being shown for a drop?
136   bool for_drop_;
137
138   // The bookmark bar. This is only non-null if we're showing a menu item for a
139   // folder on the bookmark bar and not for drop, or if the BookmarkBarView has
140   // been destroyed before the menu.
141   BookmarkBarView* bookmark_bar_;
142
143   DISALLOW_COPY_AND_ASSIGN(BookmarkMenuController);
144 };
145
146 #endif  // CHROME_BROWSER_UI_VIEWS_BOOKMARKS_BOOKMARK_MENU_CONTROLLER_VIEWS_H_