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/sequenced_task_runner_helpers.h"
14 #include "ui/views/controls/menu/menu_delegate.h"
17 class BrowserActionsContainer
;
18 class BrowserActionView
;
25 // This class handles the overflow menu for browser actions (showing the menu,
26 // drag and drop, etc). This class manages its own lifetime.
27 class BrowserActionOverflowMenuController
: public views::MenuDelegate
{
29 // The observer is notified prior to the menu being deleted.
32 virtual void NotifyMenuDeleted(
33 BrowserActionOverflowMenuController
* controller
) = 0;
36 BrowserActionOverflowMenuController(
37 BrowserActionsContainer
* owner
,
39 views::MenuButton
* menu_button
,
40 const std::vector
<BrowserActionView
*>& views
,
43 void set_observer(Observer
* observer
) { observer_
= observer
; }
45 // Shows the overflow menu.
46 bool RunMenu(views::Widget
* widget
, bool for_drop
);
48 // Closes the overflow menu (and its context menu if open as well).
51 // Overridden from views::MenuDelegate:
52 virtual bool IsCommandEnabled(int id
) const OVERRIDE
;
53 virtual void ExecuteCommand(int id
) OVERRIDE
;
54 virtual bool ShowContextMenu(views::MenuItemView
* source
,
57 ui::MenuSourceType source_type
) OVERRIDE
;
58 virtual void DropMenuClosed(views::MenuItemView
* menu
) OVERRIDE
;
59 // These drag functions offer support for dragging icons into the overflow
61 virtual bool GetDropFormats(
62 views::MenuItemView
* menu
,
64 std::set
<ui::OSExchangeData::CustomFormat
>* custom_formats
) OVERRIDE
;
65 virtual bool AreDropTypesRequired(views::MenuItemView
* menu
) OVERRIDE
;
66 virtual bool CanDrop(views::MenuItemView
* menu
,
67 const ui::OSExchangeData
& data
) OVERRIDE
;
68 virtual int GetDropOperation(views::MenuItemView
* item
,
69 const ui::DropTargetEvent
& event
,
70 DropPosition
* position
) OVERRIDE
;
71 virtual int OnPerformDrop(views::MenuItemView
* menu
,
72 DropPosition position
,
73 const ui::DropTargetEvent
& event
) OVERRIDE
;
74 // These three drag functions offer support for dragging icons out of the
76 virtual bool CanDrag(views::MenuItemView
* menu
) OVERRIDE
;
77 virtual void WriteDragData(views::MenuItemView
* sender
,
78 ui::OSExchangeData
* data
) OVERRIDE
;
79 virtual int GetDragOperations(views::MenuItemView
* sender
) OVERRIDE
;
82 // This class manages its own lifetime.
83 virtual ~BrowserActionOverflowMenuController();
85 // Converts a menu item |id| into a BrowserActionView by adding the |id| value
86 // to the number of visible views (according to the container owner). If
87 // |index| is specified, it will point to the absolute index of the view.
88 BrowserActionView
* ViewForId(int id
, size_t* index
);
90 // A pointer to the browser action container that owns the overflow menu.
91 BrowserActionsContainer
* owner_
;
95 // The observer, may be null.
98 // A pointer to the overflow menu button that we are showing the menu for.
99 views::MenuButton
* menu_button_
;
101 // The overflow menu for the menu button. Owned by |menu_runner_|.
102 views::MenuItemView
* menu_
;
104 // Resposible for running the menu.
105 scoped_ptr
<views::MenuRunner
> menu_runner_
;
107 // The views vector of all the browser actions the container knows about. We
108 // won't show all items, just the one starting at |start_index| and above.
109 const std::vector
<BrowserActionView
*>* views_
;
111 // The index into the BrowserActionView vector, indicating where to start
112 // picking browser actions to draw.
115 // Whether this controller is being used for drop.
118 friend class base::DeleteHelper
<BrowserActionOverflowMenuController
>;
120 DISALLOW_COPY_AND_ASSIGN(BrowserActionOverflowMenuController
);
123 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLLER_H_