OLD | NEW |
| (Empty) |
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_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLL
ER_H_ | |
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLL
ER_H_ | |
7 | |
8 #include <set> | |
9 #include <vector> | |
10 | |
11 #include "base/compiler_specific.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/memory/scoped_vector.h" | |
14 #include "base/sequenced_task_runner_helpers.h" | |
15 #include "ui/views/controls/menu/menu_delegate.h" | |
16 | |
17 class Browser; | |
18 class BrowserActionsContainer; | |
19 class BrowserActionView; | |
20 class IconUpdater; | |
21 | |
22 namespace views { | |
23 class MenuRunner; | |
24 class Widget; | |
25 } | |
26 | |
27 // This class handles the overflow menu for browser actions (showing the menu, | |
28 // drag and drop, etc). This class manages its own lifetime. | |
29 class BrowserActionOverflowMenuController : public views::MenuDelegate { | |
30 public: | |
31 // The observer is notified prior to the menu being deleted. | |
32 class Observer { | |
33 public: | |
34 virtual void NotifyMenuDeleted( | |
35 BrowserActionOverflowMenuController* controller) = 0; | |
36 }; | |
37 | |
38 BrowserActionOverflowMenuController( | |
39 BrowserActionsContainer* owner, | |
40 Browser* browser, | |
41 views::MenuButton* menu_button, | |
42 const std::vector<BrowserActionView*>& views, | |
43 int start_index, | |
44 bool for_drop); | |
45 | |
46 void set_observer(Observer* observer) { observer_ = observer; } | |
47 | |
48 // Shows the overflow menu. | |
49 bool RunMenu(views::Widget* widget); | |
50 | |
51 // Closes the overflow menu (and its context menu if open as well). | |
52 void CancelMenu(); | |
53 | |
54 // Notify the menu that the associated BrowserActionViews have been deleted. | |
55 void NotifyBrowserActionViewsDeleting(); | |
56 | |
57 // Overridden from views::MenuDelegate: | |
58 virtual bool IsCommandEnabled(int id) const OVERRIDE; | |
59 virtual void ExecuteCommand(int id) OVERRIDE; | |
60 virtual bool ShowContextMenu(views::MenuItemView* source, | |
61 int id, | |
62 const gfx::Point& p, | |
63 ui::MenuSourceType source_type) OVERRIDE; | |
64 virtual void DropMenuClosed(views::MenuItemView* menu) OVERRIDE; | |
65 // These drag functions offer support for dragging icons into the overflow | |
66 // menu. | |
67 virtual bool GetDropFormats( | |
68 views::MenuItemView* menu, | |
69 int* formats, | |
70 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE; | |
71 virtual bool AreDropTypesRequired(views::MenuItemView* menu) OVERRIDE; | |
72 virtual bool CanDrop(views::MenuItemView* menu, | |
73 const ui::OSExchangeData& data) OVERRIDE; | |
74 virtual int GetDropOperation(views::MenuItemView* item, | |
75 const ui::DropTargetEvent& event, | |
76 DropPosition* position) OVERRIDE; | |
77 virtual int OnPerformDrop(views::MenuItemView* menu, | |
78 DropPosition position, | |
79 const ui::DropTargetEvent& event) OVERRIDE; | |
80 // These three drag functions offer support for dragging icons out of the | |
81 // overflow menu. | |
82 virtual bool CanDrag(views::MenuItemView* menu) OVERRIDE; | |
83 virtual void WriteDragData(views::MenuItemView* sender, | |
84 ui::OSExchangeData* data) OVERRIDE; | |
85 virtual int GetDragOperations(views::MenuItemView* sender) OVERRIDE; | |
86 | |
87 private: | |
88 // This class manages its own lifetime. | |
89 virtual ~BrowserActionOverflowMenuController(); | |
90 | |
91 // Returns the offset into |views_| for the given |id|. | |
92 size_t IndexForId(int id) const; | |
93 | |
94 // A pointer to the browser action container that owns the overflow menu. | |
95 BrowserActionsContainer* owner_; | |
96 | |
97 Browser* browser_; | |
98 | |
99 // The observer, may be null. | |
100 Observer* observer_; | |
101 | |
102 // A pointer to the overflow menu button that we are showing the menu for. | |
103 views::MenuButton* menu_button_; | |
104 | |
105 // The overflow menu for the menu button. Owned by |menu_runner_|. | |
106 views::MenuItemView* menu_; | |
107 | |
108 // Resposible for running the menu. | |
109 scoped_ptr<views::MenuRunner> menu_runner_; | |
110 | |
111 // The views vector of all the browser actions the container knows about. We | |
112 // won't show all items, just the one starting at |start_index| and above. | |
113 // Owned by |owner_|. | |
114 const std::vector<BrowserActionView*>& views_; | |
115 | |
116 // The index into the BrowserActionView vector, indicating where to start | |
117 // picking browser actions to draw. | |
118 int start_index_; | |
119 | |
120 // Whether this controller is being used for drop. | |
121 bool for_drop_; | |
122 | |
123 // The vector keeps all icon updaters associated with menu item views in the | |
124 // controller. The icon updater will update the menu item view's icon when | |
125 // the browser action view's icon has been updated. | |
126 ScopedVector<IconUpdater> icon_updaters_; | |
127 | |
128 friend class base::DeleteHelper<BrowserActionOverflowMenuController>; | |
129 | |
130 DISALLOW_COPY_AND_ASSIGN(BrowserActionOverflowMenuController); | |
131 }; | |
132 | |
133 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTR
OLLER_H_ | |
OLD | NEW |