OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLLER_
H_ | 5 #ifndef CHROME_BROWSER_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLLER_
H_ |
6 #define CHROME_BROWSER_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLLER_
H_ | 6 #define CHROME_BROWSER_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLLER_
H_ |
7 | 7 |
| 8 #include <set> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "views/controls/menu/menu_delegate.h" | 11 #include "views/controls/menu/menu_delegate.h" |
11 | 12 |
12 class BrowserActionsContainer; | 13 class BrowserActionsContainer; |
13 class BrowserActionView; | 14 class BrowserActionView; |
14 class ExtensionActionContextMenu; | 15 class ExtensionActionContextMenu; |
15 | 16 |
| 17 // This class handles the overflow menu for browser actions (showing the menu, |
| 18 // drag and drop, etc). This class manages its own lifetime. |
16 class BrowserActionOverflowMenuController : public views::MenuDelegate { | 19 class BrowserActionOverflowMenuController : public views::MenuDelegate { |
17 public: | 20 public: |
| 21 // The observer is notified prior to the menu being deleted. |
| 22 class Observer { |
| 23 public: |
| 24 virtual void NotifyMenuDeleted( |
| 25 BrowserActionOverflowMenuController* controller) = 0; |
| 26 }; |
| 27 |
18 BrowserActionOverflowMenuController( | 28 BrowserActionOverflowMenuController( |
19 BrowserActionsContainer* owner, | 29 BrowserActionsContainer* owner, |
20 views::MenuButton* menu_button, | 30 views::MenuButton* menu_button, |
21 const std::vector<BrowserActionView*>& views, | 31 const std::vector<BrowserActionView*>& views, |
22 int start_index); | 32 int start_index); |
23 virtual ~BrowserActionOverflowMenuController(); | 33 |
| 34 void set_observer(Observer* observer) { observer_ = observer; } |
24 | 35 |
25 // Shows the overflow menu. | 36 // Shows the overflow menu. |
26 bool RunMenu(gfx::NativeWindow window); | 37 bool RunMenu(gfx::NativeWindow window, bool for_drop); |
27 | 38 |
28 // Closes the overflow menu (and its context menu if open as well). | 39 // Closes the overflow menu (and its context menu if open as well). |
29 void CancelMenu(); | 40 void CancelMenu(); |
30 | 41 |
31 // Overridden from views::MenuDelegate: | 42 // Overridden from views::MenuDelegate: |
32 virtual void ExecuteCommand(int id); | 43 virtual void ExecuteCommand(int id); |
33 virtual bool ShowContextMenu(views::MenuItemView* source, | 44 virtual bool ShowContextMenu(views::MenuItemView* source, |
34 int id, | 45 int id, |
35 int x, | 46 int x, |
36 int y, | 47 int y, |
37 bool is_mouse_gesture); | 48 bool is_mouse_gesture); |
| 49 virtual void DropMenuClosed(views::MenuItemView* menu); |
| 50 // These drag functions offer support for dragging icons into the overflow |
| 51 // menu. |
| 52 virtual bool GetDropFormats( |
| 53 views::MenuItemView* menu, |
| 54 int* formats, |
| 55 std::set<OSExchangeData::CustomFormat>* custom_formats); |
| 56 virtual bool AreDropTypesRequired(views::MenuItemView* menu); |
| 57 virtual bool CanDrop(views::MenuItemView* menu, const OSExchangeData& data); |
| 58 virtual int GetDropOperation(views::MenuItemView* item, |
| 59 const views::DropTargetEvent& event, |
| 60 DropPosition* position); |
| 61 virtual int OnPerformDrop(views::MenuItemView* menu, |
| 62 DropPosition position, |
| 63 const views::DropTargetEvent& event); |
| 64 // These three drag functions offer support for dragging icons out of the |
| 65 // overflow menu. |
| 66 virtual bool CanDrag(views::MenuItemView* menu); |
| 67 virtual void WriteDragData(views::MenuItemView* sender, OSExchangeData* data); |
| 68 virtual int GetDragOperations(views::MenuItemView* sender); |
| 69 |
38 | 70 |
39 private: | 71 private: |
| 72 // This class manages its own lifetime. |
| 73 virtual ~BrowserActionOverflowMenuController(); |
| 74 |
| 75 // Converts a menu item |id| into a BrowserActionView by adding the |id| value |
| 76 // to the number of visible views (according to the container owner). If |
| 77 // |index| is specified, it will point to the absolute index of the view. |
| 78 BrowserActionView* ViewForId(int id, size_t* index); |
| 79 |
40 // A pointer to the browser action container that owns the overflow menu. | 80 // A pointer to the browser action container that owns the overflow menu. |
41 BrowserActionsContainer* owner_; | 81 BrowserActionsContainer* owner_; |
42 | 82 |
| 83 // The observer, may be null. |
| 84 Observer* observer_; |
| 85 |
43 // A pointer to the overflow menu button that we are showing the menu for. | 86 // A pointer to the overflow menu button that we are showing the menu for. |
44 views::MenuButton* menu_button_; | 87 views::MenuButton* menu_button_; |
45 | 88 |
46 // The overflow menu for the menu button. | 89 // The overflow menu for the menu button. |
47 scoped_ptr<views::MenuItemView> menu_; | 90 scoped_ptr<views::MenuItemView> menu_; |
48 | 91 |
49 // The context menu (when you right click a menu item in the overflow menu). | 92 // The context menu (when you right click a menu item in the overflow menu). |
50 scoped_ptr<ExtensionActionContextMenu> context_menu_; | 93 scoped_ptr<ExtensionActionContextMenu> context_menu_; |
51 | 94 |
52 // The views vector of all the browser actions the container knows about. We | 95 // The views vector of all the browser actions the container knows about. We |
53 // won't show all items, just the one starting at |start_index| and above. | 96 // won't show all items, just the one starting at |start_index| and above. |
54 const std::vector<BrowserActionView*>* views_; | 97 const std::vector<BrowserActionView*>* views_; |
55 | 98 |
56 // The index into the BrowserActionView vector, indicating where to start | 99 // The index into the BrowserActionView vector, indicating where to start |
57 // picking browser actions to draw. | 100 // picking browser actions to draw. |
58 int start_index_; | 101 int start_index_; |
59 | 102 |
| 103 // Whether this controller is being used for drop. |
| 104 bool for_drop_; |
| 105 |
60 DISALLOW_COPY_AND_ASSIGN(BrowserActionOverflowMenuController); | 106 DISALLOW_COPY_AND_ASSIGN(BrowserActionOverflowMenuController); |
61 }; | 107 }; |
62 | 108 |
63 #endif // CHROME_BROWSER_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLL
ER_H_ | 109 #endif // CHROME_BROWSER_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLL
ER_H_ |
OLD | NEW |