| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLL
ER_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLL
ER_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLL
ER_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTROLL
ER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include "base/macros.h" |
| 9 #include <vector> | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "ui/views/controls/button/menu_button.h" |
| 12 #include "ui/views/controls/button/menu_button_listener.h" |
| 10 | 13 |
| 11 #include "base/compiler_specific.h" | 14 class BrowserActionsContainer; |
| 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" | |
| 16 | 15 |
| 17 class Browser; | 16 // The MenuButton for the chevron in the extension toolbar, which is also |
| 18 class BrowserActionsContainer; | 17 // responsible for showing the legacy (drop-down) overflow menu. |
| 19 class BrowserActionView; | 18 class ChevronMenuButton : public views::MenuButton, |
| 20 class IconUpdater; | 19 public views::MenuButtonListener { |
| 20 public: |
| 21 explicit ChevronMenuButton( |
| 22 BrowserActionsContainer* browser_actions_container); |
| 23 virtual ~ChevronMenuButton(); |
| 21 | 24 |
| 22 namespace views { | 25 // Closes the overflow menu (and any context menu), if it is open. |
| 23 class MenuRunner; | 26 void CloseMenu(); |
| 24 class Widget; | |
| 25 } | |
| 26 | 27 |
| 27 // This class handles the overflow menu for browser actions (showing the menu, | 28 private: |
| 28 // drag and drop, etc). This class manages its own lifetime. | 29 class MenuController; |
| 29 class BrowserActionOverflowMenuController : public views::MenuDelegate { | |
| 30 public: | |
| 31 // The observer is notified prior to the menu being deleted. | |
| 32 class Observer { | |
| 33 public: | |
| 34 virtual void NotifyMenuDeleted( | |
| 35 BrowserActionOverflowMenuController* controller) = 0; | |
| 36 }; | |
| 37 | 30 |
| 38 BrowserActionOverflowMenuController( | 31 // views::MenuButton: |
| 39 BrowserActionsContainer* owner, | 32 virtual scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const |
| 40 Browser* browser, | 33 OVERRIDE; |
| 41 views::MenuButton* menu_button, | 34 virtual bool GetDropFormats(int* formats, |
| 42 const std::vector<BrowserActionView*>& views, | 35 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE; |
| 43 int start_index, | 36 virtual bool AreDropTypesRequired() OVERRIDE; |
| 44 bool for_drop); | 37 virtual bool CanDrop(const ui::OSExchangeData& data) OVERRIDE; |
| 38 virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE; |
| 39 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE; |
| 40 virtual void OnDragExited() OVERRIDE; |
| 41 virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE; |
| 45 | 42 |
| 46 void set_observer(Observer* observer) { observer_ = observer; } | 43 // views::MenuButtonListener: |
| 44 virtual void OnMenuButtonClicked(View* source, const gfx::Point& point) |
| 45 OVERRIDE; |
| 47 | 46 |
| 48 // Shows the overflow menu. | 47 // Shows the overflow menu. |
| 49 bool RunMenu(views::Widget* widget); | 48 void ShowOverflowMenu(bool for_drop); |
| 50 | 49 |
| 51 // Closes the overflow menu (and its context menu if open as well). | 50 // Called by the overflow menu when all the work is done. |
| 52 void CancelMenu(); | 51 void MenuDone(); |
| 53 | 52 |
| 54 // Notify the menu that the associated BrowserActionViews have been deleted. | 53 // The owning BrowserActionsContainer. |
| 55 void NotifyBrowserActionViewsDeleting(); | 54 BrowserActionsContainer* browser_actions_container_; |
| 56 | 55 |
| 57 // Overridden from views::MenuDelegate: | 56 // The overflow menu controller. |
| 58 virtual bool IsCommandEnabled(int id) const OVERRIDE; | 57 scoped_ptr<MenuController> menu_controller_; |
| 59 virtual void ExecuteCommand(int id) OVERRIDE; | |
| 60 virtual bool ShowContextMenu(views::MenuItemView* source, | |
| 61 int id, | |
| 62 const gfx::Point& p, | |
| 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 | |
| 66 // menu. | |
| 67 virtual bool GetDropFormats( | |
| 68 views::MenuItemView* menu, | |
| 69 int* formats, | |
| 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 | |
| 81 // overflow menu. | |
| 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; | |
| 86 | 58 |
| 87 private: | 59 base::WeakPtrFactory<ChevronMenuButton> weak_factory_; |
| 88 // This class manages its own lifetime. | |
| 89 virtual ~BrowserActionOverflowMenuController(); | |
| 90 | 60 |
| 91 // Returns the offset into |views_| for the given |id|. | 61 DISALLOW_COPY_AND_ASSIGN(ChevronMenuButton); |
| 92 size_t IndexForId(int id) const; | |
| 93 | |
| 94 // A pointer to the browser action container that owns the overflow menu. | |
| 95 BrowserActionsContainer* owner_; | |
| 96 | |
| 97 Browser* browser_; | |
| 98 | |
| 99 // The observer, may be null. | |
| 100 Observer* observer_; | |
| 101 | |
| 102 // A pointer to the overflow menu button that we are showing the menu for. | |
| 103 views::MenuButton* menu_button_; | |
| 104 | |
| 105 // The overflow menu for the menu button. Owned by |menu_runner_|. | |
| 106 views::MenuItemView* menu_; | |
| 107 | |
| 108 // Resposible for running the menu. | |
| 109 scoped_ptr<views::MenuRunner> menu_runner_; | |
| 110 | |
| 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_; | |
| 115 | |
| 116 // The index into the BrowserActionView vector, indicating where to start | |
| 117 // picking browser actions to draw. | |
| 118 int start_index_; | |
| 119 | |
| 120 // Whether this controller is being used for drop. | |
| 121 bool for_drop_; | |
| 122 | |
| 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_; | |
| 127 | |
| 128 friend class base::DeleteHelper<BrowserActionOverflowMenuController>; | |
| 129 | |
| 130 DISALLOW_COPY_AND_ASSIGN(BrowserActionOverflowMenuController); | |
| 131 }; | 62 }; |
| 132 | 63 |
| 133 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTR
OLLER_H_ | 64 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_BROWSER_ACTION_OVERFLOW_MENU_CONTR
OLLER_H_ |
| OLD | NEW |