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 { |
(...skipping 10 matching lines...) Expand all Loading... | |
32 } | 33 } |
33 | 34 |
34 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
35 // ToolbarActionView | 36 // ToolbarActionView |
36 // A wrapper around a ToolbarActionViewController to display a toolbar action | 37 // A wrapper around a ToolbarActionViewController to display a toolbar action |
37 // action in the BrowserActionsContainer. | 38 // action in the BrowserActionsContainer. |
38 class ToolbarActionView : public views::MenuButton, | 39 class ToolbarActionView : public views::MenuButton, |
39 public ToolbarActionViewDelegateViews, | 40 public ToolbarActionViewDelegateViews, |
40 public views::MenuButtonListener, | 41 public views::MenuButtonListener, |
41 public views::ContextMenuController, | 42 public views::ContextMenuController, |
42 public content::NotificationObserver { | 43 public content::NotificationObserver, |
44 public views::InkDropHost { | |
43 public: | 45 public: |
44 // Need DragController here because ToolbarActionView could be | 46 // Need DragController here because ToolbarActionView could be |
45 // dragged/dropped. | 47 // dragged/dropped. |
46 class Delegate : public views::DragController { | 48 class Delegate : public views::DragController { |
47 public: | 49 public: |
48 // Returns the current web contents. | 50 // Returns the current web contents. |
49 virtual content::WebContents* GetCurrentWebContents() = 0; | 51 virtual content::WebContents* GetCurrentWebContents() = 0; |
50 | 52 |
51 // Whether the container for this button is shown inside a menu. | 53 // Whether the container for this button is shown inside a menu. |
52 virtual bool ShownInsideMenu() const = 0; | 54 virtual bool ShownInsideMenu() const = 0; |
53 | 55 |
54 // Notifies that a drag completed. | 56 // Notifies that a drag completed. |
55 virtual void OnToolbarActionViewDragDone() = 0; | 57 virtual void OnToolbarActionViewDragDone() = 0; |
56 | 58 |
57 // Returns the view of the toolbar actions overflow menu to use as a | 59 // Returns the view of the toolbar actions overflow menu to use as a |
58 // reference point for a popup when this view isn't visible. | 60 // reference point for a popup when this view isn't visible. |
59 virtual views::MenuButton* GetOverflowReferenceView() = 0; | 61 virtual views::MenuButton* GetOverflowReferenceView() = 0; |
60 | 62 |
61 // Notifies the delegate that the mouse entered the view. | 63 // Notifies the delegate that the mouse entered the view. |
62 virtual void OnMouseEnteredToolbarActionView() = 0; | 64 virtual void OnMouseEnteredToolbarActionView() = 0; |
63 | 65 |
64 protected: | 66 protected: |
65 ~Delegate() override {} | 67 ~Delegate() override {} |
66 }; | 68 }; |
67 | 69 |
70 // Callback type used for testing. | |
71 using ContextMenuCallback = base::Callback<void(ToolbarActionView*)>; | |
72 | |
68 ToolbarActionView(ToolbarActionViewController* view_controller, | 73 ToolbarActionView(ToolbarActionViewController* view_controller, |
69 Profile* profile, | 74 Profile* profile, |
70 Delegate* delegate); | 75 Delegate* delegate); |
71 ~ToolbarActionView() override; | 76 ~ToolbarActionView() override; |
72 | 77 |
73 // views::MenuButton: | 78 // views::MenuButton: |
74 void GetAccessibleState(ui::AXViewState* state) override; | 79 void GetAccessibleState(ui::AXViewState* state) override; |
80 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; | |
81 void OnMouseEntered(const ui::MouseEvent& event) override; | |
82 bool ShouldEnterPushedState(const ui::Event& event) override; | |
75 | 83 |
76 // views::MenuButtonListener: | 84 // views::MenuButtonListener: |
77 void OnMenuButtonClicked(views::View* sender, | 85 void OnMenuButtonClicked(views::View* sender, |
78 const gfx::Point& point) override; | 86 const gfx::Point& point) override; |
79 | 87 |
80 // content::NotificationObserver: | 88 // content::NotificationObserver: |
81 void Observe(int type, | 89 void Observe(int type, |
82 const content::NotificationSource& source, | 90 const content::NotificationSource& source, |
83 const content::NotificationDetails& details) override; | 91 const content::NotificationDetails& details) override; |
84 | 92 |
85 // views::MenuButton: | 93 // ToolbarActionViewDelegateViews: |
Peter Kasting
2015/11/24 22:27:16
Nit: This should be between the MenuButton and Men
varkha
2015/11/25 18:53:23
Done.
| |
86 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; | 94 content::WebContents* GetCurrentWebContents() const override; |
87 void OnMouseEntered(const ui::MouseEvent& event) override; | 95 void UpdateState() override; |
88 bool ShouldEnterPushedState(const ui::Event& event) override; | |
89 | 96 |
90 // ToolbarActionViewDelegate: (public because called by others). | 97 // views::InkDropHost: |
91 void UpdateState() override; | 98 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
92 content::WebContents* GetCurrentWebContents() const override; | 99 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; |
93 | 100 |
94 ToolbarActionViewController* view_controller() { | 101 ToolbarActionViewController* view_controller() { |
95 return view_controller_; | 102 return view_controller_; |
96 } | 103 } |
97 | 104 |
98 // Returns button icon so it can be accessed during tests. | 105 // Returns button icon so it can be accessed during tests. |
99 gfx::ImageSkia GetIconForTest(); | 106 gfx::ImageSkia GetIconForTest(); |
100 | 107 |
101 bool wants_to_run_for_testing() const { return wants_to_run_; } | 108 bool wants_to_run_for_testing() const { return wants_to_run_; } |
102 | 109 |
103 using ContextMenuCallback = base::Callback<void(ToolbarActionView*)>; | |
104 // Set a callback to be called directly before the context menu is shown. | 110 // Set a callback to be called directly before the context menu is shown. |
105 // The toolbar action opening the menu will be passed in. | 111 // The toolbar action opening the menu will be passed in. |
106 static void set_context_menu_callback_for_testing( | 112 static void set_context_menu_callback_for_testing( |
107 ContextMenuCallback* callback); | 113 ContextMenuCallback* callback); |
108 | 114 |
109 views::MenuItemView* menu_for_testing() { return menu_; } | 115 views::MenuItemView* menu_for_testing() { return menu_; } |
110 | 116 |
111 private: | 117 private: |
112 // views::MenuButton: | 118 // views::MenuButton: |
113 gfx::Size GetPreferredSize() const override; | 119 gfx::Size GetPreferredSize() const override; |
120 bool OnMousePressed(const ui::MouseEvent& event) override; | |
121 void OnGestureEvent(ui::GestureEvent* event) override; | |
114 void OnDragDone() override; | 122 void OnDragDone() override; |
115 void ViewHierarchyChanged( | 123 void ViewHierarchyChanged( |
116 const ViewHierarchyChangedDetails& details) override; | 124 const ViewHierarchyChangedDetails& details) override; |
125 views::InkDropDelegate* GetInkDropDelegate() const override; | |
117 | 126 |
118 // ToolbarActionViewDelegateViews: | 127 // ToolbarActionViewDelegateViews: |
119 views::View* GetAsView() override; | 128 views::View* GetAsView() override; |
120 views::FocusManager* GetFocusManagerForAccelerator() override; | 129 views::FocusManager* GetFocusManagerForAccelerator() override; |
121 views::View* GetReferenceViewForPopup() override; | 130 views::View* GetReferenceViewForPopup() override; |
122 bool IsMenuRunning() const override; | 131 bool IsMenuRunning() const override; |
123 void OnPopupShown(bool by_user) override; | 132 void OnPopupShown(bool by_user) override; |
124 void OnPopupClosed() override; | 133 void OnPopupClosed() override; |
125 | 134 |
126 // views::ContextMenuController: | 135 // views::ContextMenuController: |
127 void ShowContextMenuForView(views::View* source, | 136 void ShowContextMenuForView(views::View* source, |
128 const gfx::Point& point, | 137 const gfx::Point& point, |
129 ui::MenuSourceType source_type) override; | 138 ui::MenuSourceType source_type) override; |
130 | 139 |
140 // views::InkDropHost: | |
141 gfx::Point CalculateInkDropCenter() const override; | |
142 | |
131 // Shows the context menu (if one exists) for the toolbar action. | 143 // Shows the context menu (if one exists) for the toolbar action. |
132 void DoShowContextMenu(ui::MenuSourceType source_type); | 144 void DoShowContextMenu(ui::MenuSourceType source_type); |
133 | 145 |
134 // Closes the currently-active menu, if needed. This is the case when there | 146 // Closes the currently-active menu, if needed. This is the case when there |
135 // is an active menu that wouldn't close automatically when a new one is | 147 // is an active menu that wouldn't close automatically when a new one is |
136 // opened. | 148 // opened. |
137 // Returns true if a menu was closed, false otherwise. | 149 // Returns true if a menu was closed, false otherwise. |
138 bool CloseActiveMenuIfNeeded(); | 150 bool CloseActiveMenuIfNeeded(); |
139 | 151 |
140 // A lock to keep the MenuButton pressed when a menu or popup is visible. | 152 // A lock to keep the MenuButton pressed when a menu or popup is visible. |
(...skipping 24 matching lines...) Expand all Loading... | |
165 | 177 |
166 // If non-null, this is the next toolbar action context menu that wants to run | 178 // If non-null, this is the next toolbar action context menu that wants to run |
167 // once the current owner (this one) is done. | 179 // once the current owner (this one) is done. |
168 base::Closure followup_context_menu_task_; | 180 base::Closure followup_context_menu_task_; |
169 | 181 |
170 // The time the popup was last closed. | 182 // The time the popup was last closed. |
171 base::TimeTicks popup_closed_time_; | 183 base::TimeTicks popup_closed_time_; |
172 | 184 |
173 content::NotificationRegistrar registrar_; | 185 content::NotificationRegistrar registrar_; |
174 | 186 |
187 // Animation delegate for the ink drop ripple effect. | |
188 scoped_ptr<views::InkDropDelegate> ink_drop_delegate_; | |
189 | |
175 base::WeakPtrFactory<ToolbarActionView> weak_factory_; | 190 base::WeakPtrFactory<ToolbarActionView> weak_factory_; |
176 | 191 |
177 DISALLOW_COPY_AND_ASSIGN(ToolbarActionView); | 192 DISALLOW_COPY_AND_ASSIGN(ToolbarActionView); |
178 }; | 193 }; |
179 | 194 |
180 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ | 195 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_ACTION_VIEW_H_ |
OLD | NEW |