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_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLLER_H_
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"
18 class BrowserActionsContainer;
19 class BrowserActionView;
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 {
31 // The observer is notified prior to the menu being deleted.
34 virtual void NotifyMenuDeleted(
35 BrowserActionOverflowMenuController* controller) = 0;
38 BrowserActionOverflowMenuController(
39 BrowserActionsContainer* owner,
41 views::MenuButton* menu_button,
42 const std::vector<BrowserActionView*>& views,
46 void set_observer(Observer* observer) { observer_ = observer; }
48 // Shows the overflow menu.
49 bool RunMenu(views::Widget* widget);
51 // Closes the overflow menu (and its context menu if open as well).
54 // Notify the menu that the associated BrowserActionViews have been deleted.
55 void NotifyBrowserActionViewsDeleting();
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,
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
67 virtual bool GetDropFormats(
68 views::MenuItemView* menu,
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
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;
88 // This class manages its own lifetime.
89 virtual ~BrowserActionOverflowMenuController();
91 // Returns the offset into |views_| for the given |id|.
92 size_t IndexForId(int id) const;
94 // A pointer to the browser action container that owns the overflow menu.
95 BrowserActionsContainer* owner_;
99 // The observer, may be null.
102 // A pointer to the overflow menu button that we are showing the menu for.
103 views::MenuButton* menu_button_;
105 // The overflow menu for the menu button. Owned by |menu_runner_|.
106 views::MenuItemView* menu_;
108 // Resposible for running the menu.
109 scoped_ptr<views::MenuRunner> menu_runner_;
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_;
116 // The index into the BrowserActionView vector, indicating where to start
117 // picking browser actions to draw.
120 // Whether this controller is being used for drop.
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_;
128 friend class base::DeleteHelper<BrowserActionOverflowMenuController>;
130 DISALLOW_COPY_AND_ASSIGN(BrowserActionOverflowMenuController);
133 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLLER_H_