Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / extensions / browser_action_overflow_menu_controller.h
blob15964e499672c793f2e7e5fb6a287e83cefabc33
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_
8 #include <set>
9 #include <vector>
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"
16 class Browser;
17 class BrowserActionsContainer;
18 class BrowserActionView;
20 namespace views {
21 class MenuRunner;
22 class Widget;
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 {
28 public:
29 // The observer is notified prior to the menu being deleted.
30 class Observer {
31 public:
32 virtual void NotifyMenuDeleted(
33 BrowserActionOverflowMenuController* controller) = 0;
36 BrowserActionOverflowMenuController(
37 BrowserActionsContainer* owner,
38 Browser* browser,
39 views::MenuButton* menu_button,
40 const std::vector<BrowserActionView*>& views,
41 int start_index);
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).
49 void CancelMenu();
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,
55 int id,
56 const gfx::Point& p,
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
60 // menu.
61 virtual bool GetDropFormats(
62 views::MenuItemView* menu,
63 int* formats,
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
75 // overflow menu.
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;
81 private:
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_;
93 Browser* browser_;
95 // The observer, may be null.
96 Observer* observer_;
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.
113 int start_index_;
115 // Whether this controller is being used for drop.
116 bool 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_