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
;
28 // This class handles the overflow menu for browser actions (showing the menu,
29 // drag and drop, etc). This class manages its own lifetime.
30 class BrowserActionOverflowMenuController
: public views::MenuDelegate
{
32 // The observer is notified prior to the menu being deleted.
35 virtual void NotifyMenuDeleted(
36 BrowserActionOverflowMenuController
* controller
) = 0;
39 BrowserActionOverflowMenuController(
40 BrowserActionsContainer
* owner
,
42 views::MenuButton
* menu_button
,
43 const std::vector
<BrowserActionView
*>& views
,
46 void set_observer(Observer
* observer
) { observer_
= observer
; }
48 // Shows the overflow menu.
49 bool RunMenu(views::Widget
* widget
, bool for_drop
);
51 // Closes the overflow menu (and its context menu if open as well).
54 // Overridden from views::MenuDelegate:
55 virtual bool IsCommandEnabled(int id
) const OVERRIDE
;
56 virtual void ExecuteCommand(int id
) OVERRIDE
;
57 virtual bool ShowContextMenu(views::MenuItemView
* source
,
60 ui::MenuSourceType source_type
) OVERRIDE
;
61 virtual void DropMenuClosed(views::MenuItemView
* menu
) OVERRIDE
;
62 // These drag functions offer support for dragging icons into the overflow
64 virtual bool GetDropFormats(
65 views::MenuItemView
* menu
,
67 std::set
<ui::OSExchangeData::CustomFormat
>* custom_formats
) OVERRIDE
;
68 virtual bool AreDropTypesRequired(views::MenuItemView
* menu
) OVERRIDE
;
69 virtual bool CanDrop(views::MenuItemView
* menu
,
70 const ui::OSExchangeData
& data
) OVERRIDE
;
71 virtual int GetDropOperation(views::MenuItemView
* item
,
72 const ui::DropTargetEvent
& event
,
73 DropPosition
* position
) OVERRIDE
;
74 virtual int OnPerformDrop(views::MenuItemView
* menu
,
75 DropPosition position
,
76 const ui::DropTargetEvent
& event
) OVERRIDE
;
77 // These three drag functions offer support for dragging icons out of the
79 virtual bool CanDrag(views::MenuItemView
* menu
) OVERRIDE
;
80 virtual void WriteDragData(views::MenuItemView
* sender
,
81 ui::OSExchangeData
* data
) OVERRIDE
;
82 virtual int GetDragOperations(views::MenuItemView
* sender
) OVERRIDE
;
85 // This class manages its own lifetime.
86 virtual ~BrowserActionOverflowMenuController();
88 // Converts a menu item |id| into a BrowserActionView by adding the |id| value
89 // to the number of visible views (according to the container owner). If
90 // |index| is specified, it will point to the absolute index of the view.
91 BrowserActionView
* ViewForId(int id
, size_t* index
);
93 // A pointer to the browser action container that owns the overflow menu.
94 BrowserActionsContainer
* owner_
;
98 // The observer, may be null.
101 // A pointer to the overflow menu button that we are showing the menu for.
102 views::MenuButton
* menu_button_
;
104 // The overflow menu for the menu button. Owned by |menu_runner_|.
105 views::MenuItemView
* menu_
;
107 // Resposible for running the menu.
108 scoped_ptr
<views::MenuRunner
> menu_runner_
;
110 // The views vector of all the browser actions the container knows about. We
111 // won't show all items, just the one starting at |start_index| and above.
112 const std::vector
<BrowserActionView
*>* views_
;
114 // The index into the BrowserActionView vector, indicating where to start
115 // picking browser actions to draw.
118 // Whether this controller is being used for drop.
121 // The vector keeps all icon updaters associated with menu item views in the
122 // controller. The icon updater will update the menu item view's icon when
123 // the browser action view's icon has been updated.
124 ScopedVector
<IconUpdater
> icon_updaters_
;
126 friend class base::DeleteHelper
<BrowserActionOverflowMenuController
>;
128 DISALLOW_COPY_AND_ASSIGN(BrowserActionOverflowMenuController
);
131 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLLER_H_