OLD | NEW |
1 // Copyright 2014 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_TOOLBAR_TOOLBAR_ACTIONS_BAR_H_ | 5 #ifndef CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_H_ |
6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_H_ | 6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/scoped_observer.h" | 12 #include "base/scoped_observer.h" |
13 #include "chrome/browser/extensions/extension_toolbar_model.h" | |
14 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h" | 13 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h" |
| 14 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h" |
15 #include "ui/gfx/animation/tween.h" | 15 #include "ui/gfx/animation/tween.h" |
16 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
17 | 17 |
18 namespace extensions { | 18 namespace extensions { |
19 class Extension; | 19 class Extension; |
20 class ExtensionMessageBubbleController; | 20 class ExtensionMessageBubbleController; |
21 } | 21 } |
22 | 22 |
23 namespace user_prefs { | 23 namespace user_prefs { |
24 class PrefRegistrySyncable; | 24 class PrefRegistrySyncable; |
25 } | 25 } |
26 | 26 |
27 class ToolbarActionsBarDelegate; | 27 class ToolbarActionsBarDelegate; |
28 class ToolbarActionViewController; | 28 class ToolbarActionViewController; |
29 | 29 |
30 // A platform-independent version of the container for toolbar actions, | 30 // A platform-independent version of the container for toolbar actions, |
31 // including extension actions and component actions. | 31 // including extension actions and component actions. |
32 // This class manages the order of the actions, the actions' state, and owns the | 32 // This class manages the order of the actions, the actions' state, and owns the |
33 // action controllers, in addition to (for extensions) interfacing with the | 33 // action controllers, in addition to interfacing with the toolbar actions |
34 // extension toolbar model. Further, it manages dimensions for the bar, | 34 // model. Further, it manages dimensions for the bar, excluding animations. |
35 // excluding animations. | |
36 // This can come in two flavors, main and "overflow". The main bar is visible | 35 // This can come in two flavors, main and "overflow". The main bar is visible |
37 // next to the omnibox, and the overflow bar is visible inside the chrome | 36 // next to the omnibox, and the overflow bar is visible inside the chrome |
38 // (fka wrench) menu. The main bar can have only a single row of icons with | 37 // (fka wrench) menu. The main bar can have only a single row of icons with |
39 // flexible width, whereas the overflow bar has multiple rows of icons with a | 38 // flexible width, whereas the overflow bar has multiple rows of icons with a |
40 // fixed width (the width of the menu). | 39 // fixed width (the width of the menu). |
41 class ToolbarActionsBar : public extensions::ExtensionToolbarModel::Observer { | 40 class ToolbarActionsBar : public ToolbarActionsModel::Observer { |
42 public: | 41 public: |
43 // A struct to contain the platform settings. | 42 // A struct to contain the platform settings. |
44 struct PlatformSettings { | 43 struct PlatformSettings { |
45 explicit PlatformSettings(bool in_overflow_mode); | 44 explicit PlatformSettings(bool in_overflow_mode); |
46 | 45 |
47 // The padding that comes before the first icon in the container. | 46 // The padding that comes before the first icon in the container. |
48 int left_padding; | 47 int left_padding; |
49 // The padding following the final icon in the container. | 48 // The padding following the final icon in the container. |
50 int right_padding; | 49 int right_padding; |
51 // The spacing between each of the icons. | 50 // The spacing between each of the icons. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 const std::vector<ToolbarActionViewController*>& toolbar_actions_unordered() | 170 const std::vector<ToolbarActionViewController*>& toolbar_actions_unordered() |
172 const { | 171 const { |
173 return toolbar_actions_.get(); | 172 return toolbar_actions_.get(); |
174 } | 173 } |
175 bool enabled() const { return model_ != nullptr; } | 174 bool enabled() const { return model_ != nullptr; } |
176 bool suppress_layout() const { return suppress_layout_; } | 175 bool suppress_layout() const { return suppress_layout_; } |
177 bool suppress_animation() const { | 176 bool suppress_animation() const { |
178 return suppress_animation_ || disable_animations_for_testing_; | 177 return suppress_animation_ || disable_animations_for_testing_; |
179 } | 178 } |
180 bool is_highlighting() const { return model_ && model_->is_highlighting(); } | 179 bool is_highlighting() const { return model_ && model_->is_highlighting(); } |
181 extensions::ExtensionToolbarModel::HighlightType highlight_type() const { | 180 ToolbarActionsModel::HighlightType highlight_type() const { |
182 return model_ ? model_->highlight_type() | 181 return model_ ? model_->highlight_type() |
183 : extensions::ExtensionToolbarModel::HIGHLIGHT_NONE; | 182 : ToolbarActionsModel::HIGHLIGHT_NONE; |
184 } | 183 } |
185 const PlatformSettings& platform_settings() const { | 184 const PlatformSettings& platform_settings() const { |
186 return platform_settings_; | 185 return platform_settings_; |
187 } | 186 } |
188 ToolbarActionViewController* popup_owner() { return popup_owner_; } | 187 ToolbarActionViewController* popup_owner() { return popup_owner_; } |
189 ToolbarActionViewController* popped_out_action() { | 188 ToolbarActionViewController* popped_out_action() { |
190 return popped_out_action_; | 189 return popped_out_action_; |
191 } | 190 } |
192 bool in_overflow_mode() const { return main_bar_ != nullptr; } | 191 bool in_overflow_mode() const { return main_bar_ != nullptr; } |
193 | 192 |
194 ToolbarActionsBarDelegate* delegate_for_test() { return delegate_; } | 193 ToolbarActionsBarDelegate* delegate_for_test() { return delegate_; } |
195 | 194 |
196 static void set_send_overflowed_action_changes_for_testing( | 195 static void set_send_overflowed_action_changes_for_testing( |
197 bool send_overflowed_action_changes) { | 196 bool send_overflowed_action_changes) { |
198 send_overflowed_action_changes_ = send_overflowed_action_changes; | 197 send_overflowed_action_changes_ = send_overflowed_action_changes; |
199 } | 198 } |
200 | 199 |
201 // During testing we can disable animations by setting this flag to true, | 200 // During testing we can disable animations by setting this flag to true, |
202 // so that the bar resizes instantly, instead of having to poll it while it | 201 // so that the bar resizes instantly, instead of having to poll it while it |
203 // animates to open/closed status. | 202 // animates to open/closed status. |
204 static bool disable_animations_for_testing_; | 203 static bool disable_animations_for_testing_; |
205 | 204 |
206 private: | 205 private: |
207 using ToolbarActions = ScopedVector<ToolbarActionViewController>; | 206 using ToolbarActions = ScopedVector<ToolbarActionViewController>; |
208 | 207 |
209 // ExtensionToolbarModel::Observer: | 208 // ToolbarActionsModel::Observer: |
210 void OnToolbarExtensionAdded(const extensions::Extension* extension, | 209 void OnToolbarActionAdded(const std::string& action_id, int index) override; |
211 int index) override; | 210 void OnToolbarActionRemoved(const std::string& action_id) override; |
212 void OnToolbarExtensionRemoved( | 211 void OnToolbarActionMoved(const std::string& action_id, int index) override; |
213 const extensions::Extension* extension) override; | 212 void OnToolbarActionUpdated(const std::string& action_id) override; |
214 void OnToolbarExtensionMoved(const extensions::Extension* extension, | 213 bool ShowToolbarActionPopup(const std::string& action_id, |
215 int index) override; | 214 bool grant_active_tab) override; |
216 void OnToolbarExtensionUpdated( | |
217 const extensions::Extension* extension) override; | |
218 bool ShowExtensionActionPopup(const extensions::Extension* extension, | |
219 bool grant_active_tab) override; | |
220 void OnToolbarVisibleCountChanged() override; | 215 void OnToolbarVisibleCountChanged() override; |
221 void OnToolbarHighlightModeChanged(bool is_highlighting) override; | 216 void OnToolbarHighlightModeChanged(bool is_highlighting) override; |
222 void OnToolbarModelInitialized() override; | 217 void OnToolbarModelInitialized() override; |
223 Browser* GetBrowser() override; | 218 Browser* GetBrowser() override; |
224 | 219 |
225 // Resizes the delegate (if necessary) to the preferred size using the given | 220 // Resizes the delegate (if necessary) to the preferred size using the given |
226 // |tween_type| and optionally suppressing the chevron. | 221 // |tween_type| and optionally suppressing the chevron. |
227 void ResizeDelegate(gfx::Tween::Type tween_type, bool suppress_chevron); | 222 void ResizeDelegate(gfx::Tween::Type tween_type, bool suppress_chevron); |
228 | 223 |
229 // Returns the action for the given |id|, if one exists. | 224 // Returns the action for the given |id|, if one exists. |
230 ToolbarActionViewController* GetActionForId(const std::string& id); | 225 ToolbarActionViewController* GetActionForId(const std::string& action_id); |
231 | 226 |
232 // Returns the current web contents. | 227 // Returns the current web contents. |
233 content::WebContents* GetCurrentWebContents(); | 228 content::WebContents* GetCurrentWebContents(); |
234 | 229 |
235 // Reorders the toolbar actions to reflect the model and, optionally, to | 230 // Reorders the toolbar actions to reflect the model and, optionally, to |
236 // "pop out" any overflowed actions that want to run (depending on the | 231 // "pop out" any overflowed actions that want to run (depending on the |
237 // value of |pop_out_actions_to_run|. | 232 // value of |pop_out_actions_to_run|. |
238 void ReorderActions(); | 233 void ReorderActions(); |
239 | 234 |
240 // Sets |overflowed_action_wants_to_run_| to the proper value. | 235 // Sets |overflowed_action_wants_to_run_| to the proper value. |
241 void SetOverflowedActionWantsToRun(); | 236 void SetOverflowedActionWantsToRun(); |
242 | 237 |
243 // Shows an extension message bubble, if any should be shown. | 238 // Shows an extension message bubble, if any should be shown. |
244 void MaybeShowExtensionBubble( | 239 void MaybeShowExtensionBubble( |
245 scoped_ptr<extensions::ExtensionMessageBubbleController> controller); | 240 scoped_ptr<extensions::ExtensionMessageBubbleController> controller); |
246 | 241 |
247 // The delegate for this object (in a real build, this is the view). | 242 // The delegate for this object (in a real build, this is the view). |
248 ToolbarActionsBarDelegate* delegate_; | 243 ToolbarActionsBarDelegate* delegate_; |
249 | 244 |
250 // The associated browser. | 245 // The associated browser. |
251 Browser* browser_; | 246 Browser* browser_; |
252 | 247 |
253 // The observed toolbar model. | 248 // The observed toolbar model. |
254 extensions::ExtensionToolbarModel* model_; | 249 ToolbarActionsModel* model_; |
255 | 250 |
256 // The controller for the main toolbar actions bar. This will be null if this | 251 // The controller for the main toolbar actions bar. This will be null if this |
257 // is the main bar. | 252 // is the main bar. |
258 ToolbarActionsBar* main_bar_; | 253 ToolbarActionsBar* main_bar_; |
259 | 254 |
260 // Platform-specific settings for dimensions and the overflow chevron. | 255 // Platform-specific settings for dimensions and the overflow chevron. |
261 PlatformSettings platform_settings_; | 256 PlatformSettings platform_settings_; |
262 | 257 |
263 // The toolbar actions. | 258 // The toolbar actions. |
264 ToolbarActions toolbar_actions_; | 259 ToolbarActions toolbar_actions_; |
265 | 260 |
266 // The action that triggered the current popup (just a reference to an action | 261 // The action that triggered the current popup (just a reference to an action |
267 // from toolbar_actions_). | 262 // from toolbar_actions_). |
268 ToolbarActionViewController* popup_owner_; | 263 ToolbarActionViewController* popup_owner_; |
269 | 264 |
270 ScopedObserver<extensions::ExtensionToolbarModel, | 265 ScopedObserver<ToolbarActionsModel, ToolbarActionsModel::Observer> |
271 extensions::ExtensionToolbarModel::Observer> model_observer_; | 266 model_observer_; |
272 | 267 |
273 // True if we should suppress layout, such as when we are creating or | 268 // True if we should suppress layout, such as when we are creating or |
274 // adjusting a lot of actions at once. | 269 // adjusting a lot of actions at once. |
275 bool suppress_layout_; | 270 bool suppress_layout_; |
276 | 271 |
277 // True if we should suppress animation; we do this when first creating the | 272 // True if we should suppress animation; we do this when first creating the |
278 // toolbar, and also when switching tabs changes the state of the icons. | 273 // toolbar, and also when switching tabs changes the state of the icons. |
279 bool suppress_animation_; | 274 bool suppress_animation_; |
280 | 275 |
281 // If this is true, actions that want to run (e.g., an extension's page | 276 // If this is true, actions that want to run (e.g., an extension's page |
(...skipping 24 matching lines...) Expand all Loading... |
306 // The controller of the bubble to show once animation finishes, if any. | 301 // The controller of the bubble to show once animation finishes, if any. |
307 scoped_ptr<extensions::ExtensionMessageBubbleController> | 302 scoped_ptr<extensions::ExtensionMessageBubbleController> |
308 pending_extension_bubble_controller_; | 303 pending_extension_bubble_controller_; |
309 | 304 |
310 base::WeakPtrFactory<ToolbarActionsBar> weak_ptr_factory_; | 305 base::WeakPtrFactory<ToolbarActionsBar> weak_ptr_factory_; |
311 | 306 |
312 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBar); | 307 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBar); |
313 }; | 308 }; |
314 | 309 |
315 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_H_ | 310 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_H_ |
OLD | NEW |