| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate_views.h" | 9 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate_views.h" |
| 10 #include "ui/views/animation/ink_drop_host.h" | |
| 11 #include "ui/views/context_menu_controller.h" | 10 #include "ui/views/context_menu_controller.h" |
| 12 #include "ui/views/controls/button/menu_button.h" | 11 #include "ui/views/controls/button/menu_button.h" |
| 13 #include "ui/views/controls/button/menu_button_listener.h" | 12 #include "ui/views/controls/button/menu_button_listener.h" |
| 14 #include "ui/views/drag_controller.h" | 13 #include "ui/views/drag_controller.h" |
| 15 #include "ui/views/view.h" | 14 #include "ui/views/view.h" |
| 16 | 15 |
| 17 class ExtensionAction; | 16 class ExtensionAction; |
| 18 class Profile; | 17 class Profile; |
| 19 | 18 |
| 20 namespace extensions { | 19 namespace extensions { |
| 21 class Extension; | 20 class Extension; |
| 22 } | 21 } |
| 23 | 22 |
| 24 namespace gfx { | 23 namespace gfx { |
| 25 class Image; | 24 class Image; |
| 26 } | 25 } |
| 27 | 26 |
| 28 namespace views { | 27 namespace views { |
| 29 class MenuItemView; | 28 class MenuItemView; |
| 30 class MenuRunner; | 29 class MenuRunner; |
| 31 } | 30 } |
| 32 | 31 |
| 33 //////////////////////////////////////////////////////////////////////////////// | 32 //////////////////////////////////////////////////////////////////////////////// |
| 34 // ToolbarActionView | 33 // ToolbarActionView |
| 35 // A wrapper around a ToolbarActionViewController to display a toolbar action | 34 // A wrapper around a ToolbarActionViewController to display a toolbar action |
| 36 // action in the BrowserActionsContainer. | 35 // action in the BrowserActionsContainer. |
| 37 class ToolbarActionView : public views::MenuButton, | 36 class ToolbarActionView : public views::MenuButton, |
| 38 public ToolbarActionViewDelegateViews, | 37 public ToolbarActionViewDelegateViews, |
| 39 public views::MenuButtonListener, | 38 public views::MenuButtonListener, |
| 40 public views::ContextMenuController, | 39 public views::ContextMenuController { |
| 41 public views::InkDropHost { | |
| 42 public: | 40 public: |
| 43 // Need DragController here because ToolbarActionView could be | 41 // Need DragController here because ToolbarActionView could be |
| 44 // dragged/dropped. | 42 // dragged/dropped. |
| 45 class Delegate : public views::DragController { | 43 class Delegate : public views::DragController { |
| 46 public: | 44 public: |
| 47 // Returns the current web contents. | 45 // Returns the current web contents. |
| 48 virtual content::WebContents* GetCurrentWebContents() = 0; | 46 virtual content::WebContents* GetCurrentWebContents() = 0; |
| 49 | 47 |
| 50 // Whether the container for this button is shown inside a menu. | 48 // Whether the container for this button is shown inside a menu. |
| 51 virtual bool ShownInsideMenu() const = 0; | 49 virtual bool ShownInsideMenu() const = 0; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 79 bool ShouldEnterPushedState(const ui::Event& event) override; | 77 bool ShouldEnterPushedState(const ui::Event& event) override; |
| 80 | 78 |
| 81 // ToolbarActionViewDelegateViews: | 79 // ToolbarActionViewDelegateViews: |
| 82 content::WebContents* GetCurrentWebContents() const override; | 80 content::WebContents* GetCurrentWebContents() const override; |
| 83 void UpdateState() override; | 81 void UpdateState() override; |
| 84 | 82 |
| 85 // views::MenuButtonListener: | 83 // views::MenuButtonListener: |
| 86 void OnMenuButtonClicked(views::View* sender, | 84 void OnMenuButtonClicked(views::View* sender, |
| 87 const gfx::Point& point) override; | 85 const gfx::Point& point) override; |
| 88 | 86 |
| 89 // views::InkDropHost: | |
| 90 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; | |
| 91 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; | |
| 92 | |
| 93 ToolbarActionViewController* view_controller() { | 87 ToolbarActionViewController* view_controller() { |
| 94 return view_controller_; | 88 return view_controller_; |
| 95 } | 89 } |
| 96 | 90 |
| 97 // Returns button icon so it can be accessed during tests. | 91 // Returns button icon so it can be accessed during tests. |
| 98 gfx::ImageSkia GetIconForTest(); | 92 gfx::ImageSkia GetIconForTest(); |
| 99 | 93 |
| 100 bool wants_to_run_for_testing() const { return wants_to_run_; } | 94 bool wants_to_run_for_testing() const { return wants_to_run_; } |
| 101 | 95 |
| 102 // Set a callback to be called directly before the context menu is shown. | 96 // Set a callback to be called directly before the context menu is shown. |
| 103 // The toolbar action opening the menu will be passed in. | 97 // The toolbar action opening the menu will be passed in. |
| 104 static void set_context_menu_callback_for_testing( | 98 static void set_context_menu_callback_for_testing( |
| 105 ContextMenuCallback* callback); | 99 ContextMenuCallback* callback); |
| 106 | 100 |
| 107 views::MenuItemView* menu_for_testing() { return menu_; } | 101 views::MenuItemView* menu_for_testing() { return menu_; } |
| 108 | 102 |
| 109 private: | 103 private: |
| 110 // views::MenuButton: | 104 // views::MenuButton: |
| 111 gfx::Size GetPreferredSize() const override; | 105 gfx::Size GetPreferredSize() const override; |
| 112 bool OnMousePressed(const ui::MouseEvent& event) override; | 106 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 113 void OnGestureEvent(ui::GestureEvent* event) override; | 107 void OnGestureEvent(ui::GestureEvent* event) override; |
| 114 void OnDragDone() override; | 108 void OnDragDone() override; |
| 115 void ViewHierarchyChanged( | 109 void ViewHierarchyChanged( |
| 116 const ViewHierarchyChangedDetails& details) override; | 110 const ViewHierarchyChangedDetails& details) override; |
| 111 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 112 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 117 | 113 |
| 118 // ToolbarActionViewDelegateViews: | 114 // ToolbarActionViewDelegateViews: |
| 119 views::View* GetAsView() override; | 115 views::View* GetAsView() override; |
| 120 views::FocusManager* GetFocusManagerForAccelerator() override; | 116 views::FocusManager* GetFocusManagerForAccelerator() override; |
| 121 views::View* GetReferenceViewForPopup() override; | 117 views::View* GetReferenceViewForPopup() override; |
| 122 bool IsMenuRunning() const override; | 118 bool IsMenuRunning() const override; |
| 123 void OnPopupShown(bool by_user) override; | 119 void OnPopupShown(bool by_user) override; |
| 124 void OnPopupClosed() override; | 120 void OnPopupClosed() override; |
| 125 | 121 |
| 126 // views::ContextMenuController: | 122 // views::ContextMenuController: |
| 127 void ShowContextMenuForView(views::View* source, | 123 void ShowContextMenuForView(views::View* source, |
| 128 const gfx::Point& point, | 124 const gfx::Point& point, |
| 129 ui::MenuSourceType source_type) override; | 125 ui::MenuSourceType source_type) override; |
| 130 | 126 |
| 131 // views::InkDropHost: | |
| 132 gfx::Point CalculateInkDropCenter() const override; | |
| 133 | |
| 134 // Shows the context menu (if one exists) for the toolbar action. | 127 // Shows the context menu (if one exists) for the toolbar action. |
| 135 void DoShowContextMenu(ui::MenuSourceType source_type); | 128 void DoShowContextMenu(ui::MenuSourceType source_type); |
| 136 | 129 |
| 137 // Closes the currently-active menu, if needed. This is the case when there | 130 // Closes the currently-active menu, if needed. This is the case when there |
| 138 // is an active menu that wouldn't close automatically when a new one is | 131 // is an active menu that wouldn't close automatically when a new one is |
| 139 // opened. | 132 // opened. |
| 140 // Returns true if a menu was closed, false otherwise. | 133 // Returns true if a menu was closed, false otherwise. |
| 141 bool CloseActiveMenuIfNeeded(); | 134 bool CloseActiveMenuIfNeeded(); |
| 142 | 135 |
| 143 // A lock to keep the MenuButton pressed when a menu or popup is visible. | 136 // A lock to keep the MenuButton pressed when a menu or popup is visible. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 174 base::TimeTicks popup_closed_time_; | 167 base::TimeTicks popup_closed_time_; |
| 175 | 168 |
| 176 scoped_ptr<views::InkDropDelegate> ink_drop_delegate_; | 169 scoped_ptr<views::InkDropDelegate> ink_drop_delegate_; |
| 177 | 170 |
| 178 base::WeakPtrFactory<ToolbarActionView> weak_factory_; | 171 base::WeakPtrFactory<ToolbarActionView> weak_factory_; |
| 179 | 172 |
| 180 DISALLOW_COPY_AND_ASSIGN(ToolbarActionView); | 173 DISALLOW_COPY_AND_ASSIGN(ToolbarActionView); |
| 181 }; | 174 }; |
| 182 | 175 |
| 183 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ | 176 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ |
| OLD | NEW |