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 "content/public/browser/notification_observer.h" | 10 #include "content/public/browser/notification_observer.h" |
11 #include "content/public/browser/notification_registrar.h" | 11 #include "content/public/browser/notification_registrar.h" |
| 12 #include "ui/views/animation/ink_drop_host.h" |
12 #include "ui/views/context_menu_controller.h" | 13 #include "ui/views/context_menu_controller.h" |
13 #include "ui/views/controls/button/menu_button.h" | 14 #include "ui/views/controls/button/menu_button.h" |
14 #include "ui/views/controls/button/menu_button_listener.h" | 15 #include "ui/views/controls/button/menu_button_listener.h" |
15 #include "ui/views/drag_controller.h" | 16 #include "ui/views/drag_controller.h" |
16 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
17 | 18 |
18 class ExtensionAction; | 19 class ExtensionAction; |
19 class Profile; | 20 class Profile; |
20 | 21 |
21 namespace extensions { | 22 namespace extensions { |
22 class Extension; | 23 class Extension; |
23 } | 24 } |
24 | 25 |
25 namespace gfx { | 26 namespace gfx { |
26 class Image; | 27 class Image; |
27 } | 28 } |
28 | 29 |
29 namespace views { | 30 namespace views { |
| 31 class InkDropAnimationController; |
30 class MenuItemView; | 32 class MenuItemView; |
31 class MenuRunner; | 33 class MenuRunner; |
32 } | 34 } |
33 | 35 |
34 //////////////////////////////////////////////////////////////////////////////// | 36 //////////////////////////////////////////////////////////////////////////////// |
35 // ToolbarActionView | 37 // ToolbarActionView |
36 // A wrapper around a ToolbarActionViewController to display a toolbar action | 38 // A wrapper around a ToolbarActionViewController to display a toolbar action |
37 // action in the BrowserActionsContainer. | 39 // action in the BrowserActionsContainer. |
38 class ToolbarActionView : public views::MenuButton, | 40 class ToolbarActionView : public views::MenuButton, |
39 public ToolbarActionViewDelegateViews, | 41 public ToolbarActionViewDelegateViews, |
40 public views::MenuButtonListener, | 42 public views::MenuButtonListener, |
41 public views::ContextMenuController, | 43 public views::ContextMenuController, |
42 public content::NotificationObserver { | 44 public content::NotificationObserver, |
| 45 public views::InkDropHost { |
43 public: | 46 public: |
44 // Need DragController here because ToolbarActionView could be | 47 // Need DragController here because ToolbarActionView could be |
45 // dragged/dropped. | 48 // dragged/dropped. |
46 class Delegate : public views::DragController { | 49 class Delegate : public views::DragController { |
47 public: | 50 public: |
48 // Returns the current web contents. | 51 // Returns the current web contents. |
49 virtual content::WebContents* GetCurrentWebContents() = 0; | 52 virtual content::WebContents* GetCurrentWebContents() = 0; |
50 | 53 |
51 // Whether the container for this button is shown inside a menu. | 54 // Whether the container for this button is shown inside a menu. |
52 virtual bool ShownInsideMenu() const = 0; | 55 virtual bool ShownInsideMenu() const = 0; |
(...skipping 16 matching lines...) Expand all Loading... |
69 Profile* profile, | 72 Profile* profile, |
70 Delegate* delegate); | 73 Delegate* delegate); |
71 ~ToolbarActionView() override; | 74 ~ToolbarActionView() override; |
72 | 75 |
73 // views::MenuButton: | 76 // views::MenuButton: |
74 void GetAccessibleState(ui::AXViewState* state) override; | 77 void GetAccessibleState(ui::AXViewState* state) override; |
75 | 78 |
76 // views::MenuButtonListener: | 79 // views::MenuButtonListener: |
77 void OnMenuButtonClicked(views::View* sender, | 80 void OnMenuButtonClicked(views::View* sender, |
78 const gfx::Point& point) override; | 81 const gfx::Point& point) override; |
| 82 void OnMenuButtonClickCanceled(views::View* sender) override; |
79 | 83 |
80 // content::NotificationObserver: | 84 // content::NotificationObserver: |
81 void Observe(int type, | 85 void Observe(int type, |
82 const content::NotificationSource& source, | 86 const content::NotificationSource& source, |
83 const content::NotificationDetails& details) override; | 87 const content::NotificationDetails& details) override; |
84 | 88 |
85 // views::MenuButton: | 89 // views::MenuButton: |
86 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; | 90 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; |
87 void OnMouseEntered(const ui::MouseEvent& event) override; | 91 void OnMouseEntered(const ui::MouseEvent& event) override; |
88 bool ShouldEnterPushedState(const ui::Event& event) override; | 92 bool ShouldEnterPushedState(const ui::Event& event) override; |
(...skipping 12 matching lines...) Expand all Loading... |
101 bool wants_to_run_for_testing() const { return wants_to_run_; } | 105 bool wants_to_run_for_testing() const { return wants_to_run_; } |
102 | 106 |
103 using ContextMenuCallback = base::Callback<void(ToolbarActionView*)>; | 107 using ContextMenuCallback = base::Callback<void(ToolbarActionView*)>; |
104 // Set a callback to be called directly before the context menu is shown. | 108 // Set a callback to be called directly before the context menu is shown. |
105 // The toolbar action opening the menu will be passed in. | 109 // The toolbar action opening the menu will be passed in. |
106 static void set_context_menu_callback_for_testing( | 110 static void set_context_menu_callback_for_testing( |
107 ContextMenuCallback* callback); | 111 ContextMenuCallback* callback); |
108 | 112 |
109 views::MenuItemView* menu_for_testing() { return menu_; } | 113 views::MenuItemView* menu_for_testing() { return menu_; } |
110 | 114 |
| 115 // views::InkDropHost: |
| 116 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 117 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 118 |
| 119 protected: |
| 120 // Returns the Point where the ink drop should be centered. |
| 121 virtual gfx::Point CalculateInkDropCenter() const; |
| 122 |
| 123 views::InkDropAnimationController* ink_drop_animation_controller() { |
| 124 return ink_drop_animation_controller_.get(); |
| 125 } |
| 126 |
111 private: | 127 private: |
112 // views::MenuButton: | 128 // views::MenuButton: |
113 gfx::Size GetPreferredSize() const override; | 129 gfx::Size GetPreferredSize() const override; |
| 130 void Layout() override; |
| 131 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 132 void OnGestureEvent(ui::GestureEvent* event) override; |
114 void OnDragDone() override; | 133 void OnDragDone() override; |
115 void ViewHierarchyChanged( | 134 void ViewHierarchyChanged( |
116 const ViewHierarchyChangedDetails& details) override; | 135 const ViewHierarchyChangedDetails& details) override; |
117 | 136 |
118 // ToolbarActionViewDelegateViews: | 137 // ToolbarActionViewDelegateViews: |
119 views::View* GetAsView() override; | 138 views::View* GetAsView() override; |
120 views::FocusManager* GetFocusManagerForAccelerator() override; | 139 views::FocusManager* GetFocusManagerForAccelerator() override; |
121 views::View* GetReferenceViewForPopup() override; | 140 views::View* GetReferenceViewForPopup() override; |
122 bool IsMenuRunning() const override; | 141 bool IsMenuRunning() const override; |
123 void OnPopupShown(bool by_user) override; | 142 void OnPopupShown(bool by_user) override; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 184 |
166 // If non-null, this is the next toolbar action context menu that wants to run | 185 // If non-null, this is the next toolbar action context menu that wants to run |
167 // once the current owner (this one) is done. | 186 // once the current owner (this one) is done. |
168 base::Closure followup_context_menu_task_; | 187 base::Closure followup_context_menu_task_; |
169 | 188 |
170 // The time the popup was last closed. | 189 // The time the popup was last closed. |
171 base::TimeTicks popup_closed_time_; | 190 base::TimeTicks popup_closed_time_; |
172 | 191 |
173 content::NotificationRegistrar registrar_; | 192 content::NotificationRegistrar registrar_; |
174 | 193 |
| 194 // Animation controller for the ink drop ripple effect. |
| 195 scoped_ptr<views::InkDropAnimationController> ink_drop_animation_controller_; |
| 196 |
175 base::WeakPtrFactory<ToolbarActionView> weak_factory_; | 197 base::WeakPtrFactory<ToolbarActionView> weak_factory_; |
176 | 198 |
177 DISALLOW_COPY_AND_ASSIGN(ToolbarActionView); | 199 DISALLOW_COPY_AND_ASSIGN(ToolbarActionView); |
178 }; | 200 }; |
179 | 201 |
180 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ | 202 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ |
OLD | NEW |