browser_action_overflow_menu_controller.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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. 4 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_ 7 8#include <set> 9#include <vector> 10 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" 15 16class Browser; 17class BrowserActionsContainer; 18class BrowserActionView; 19 20namespace views { 21class MenuRunner; 22class Widget; 23} 24 25// This class handles the overflow menu for browser actions (showing the menu, 26// drag and drop, etc). This class manages its own lifetime. 27class 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; 34 }; 35 36 BrowserActionOverflowMenuController( 37 BrowserActionsContainer* owner, 38 Browser* browser, 39 views::MenuButton* menu_button, 40 const std::vector<BrowserActionView*>& views, 41 int start_index); 42 43 void set_observer(Observer* observer) { observer_ = observer; } 44 45 // Shows the overflow menu. 46 bool RunMenu(views::Widget* widget, bool for_drop); 47 48 // Closes the overflow menu (and its context menu if open as well). 49 void CancelMenu(); 50 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; 80 81 private: 82 // This class manages its own lifetime. 83 virtual ~BrowserActionOverflowMenuController(); 84 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); 89 90 // A pointer to the browser action container that owns the overflow menu. 91 BrowserActionsContainer* owner_; 92 93 Browser* browser_; 94 95 // The observer, may be null. 96 Observer* observer_; 97 98 // A pointer to the overflow menu button that we are showing the menu for. 99 views::MenuButton* menu_button_; 100 101 // The overflow menu for the menu button. Owned by |menu_runner_|. 102 views::MenuItemView* menu_; 103 104 // Resposible for running the menu. 105 scoped_ptr<views::MenuRunner> menu_runner_; 106 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_; 110 111 // The index into the BrowserActionView vector, indicating where to start 112 // picking browser actions to draw. 113 int start_index_; 114 115 // Whether this controller is being used for drop. 116 bool for_drop_; 117 118 friend class base::DeleteHelper<BrowserActionOverflowMenuController>; 119 120 DISALLOW_COPY_AND_ASSIGN(BrowserActionOverflowMenuController); 121}; 122 123#endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLLER_H_ 124