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 // (aka wrench) menu. The main bar can have only a single row of icons with |
mark a. foltz
2015/08/04 21:57:21
Side comment: It's confusing that it's still calle
Devlin
2015/08/04 22:12:59
The official name for the menu is now the "Chrome"
apacible
2015/08/05 01:03:41
Switched back to "fka".
| |
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 const std::vector<ToolbarActionViewController*>& toolbar_actions_unordered() | 163 const std::vector<ToolbarActionViewController*>& toolbar_actions_unordered() |
165 const { | 164 const { |
166 return toolbar_actions_.get(); | 165 return toolbar_actions_.get(); |
167 } | 166 } |
168 bool enabled() const { return model_ != nullptr; } | 167 bool enabled() const { return model_ != nullptr; } |
169 bool suppress_layout() const { return suppress_layout_; } | 168 bool suppress_layout() const { return suppress_layout_; } |
170 bool suppress_animation() const { | 169 bool suppress_animation() const { |
171 return suppress_animation_ || disable_animations_for_testing_; | 170 return suppress_animation_ || disable_animations_for_testing_; |
172 } | 171 } |
173 bool is_highlighting() const { return model_ && model_->is_highlighting(); } | 172 bool is_highlighting() const { return model_ && model_->is_highlighting(); } |
174 extensions::ExtensionToolbarModel::HighlightType highlight_type() const { | 173 ToolbarActionsModel::HighlightType highlight_type() const { |
175 return model_ ? model_->highlight_type() | 174 return model_ ? model_->highlight_type() |
176 : extensions::ExtensionToolbarModel::HIGHLIGHT_NONE; | 175 : ToolbarActionsModel::HIGHLIGHT_NONE; |
177 } | 176 } |
178 const PlatformSettings& platform_settings() const { | 177 const PlatformSettings& platform_settings() const { |
179 return platform_settings_; | 178 return platform_settings_; |
180 } | 179 } |
181 ToolbarActionViewController* popup_owner() { return popup_owner_; } | 180 ToolbarActionViewController* popup_owner() { return popup_owner_; } |
182 ToolbarActionViewController* popped_out_action() { | 181 ToolbarActionViewController* popped_out_action() { |
183 return popped_out_action_; | 182 return popped_out_action_; |
184 } | 183 } |
185 bool in_overflow_mode() const { return main_bar_ != nullptr; } | 184 bool in_overflow_mode() const { return main_bar_ != nullptr; } |
186 | 185 |
187 ToolbarActionsBarDelegate* delegate_for_test() { return delegate_; } | 186 ToolbarActionsBarDelegate* delegate_for_test() { return delegate_; } |
188 | 187 |
189 static void set_send_overflowed_action_changes_for_testing( | 188 static void set_send_overflowed_action_changes_for_testing( |
190 bool send_overflowed_action_changes) { | 189 bool send_overflowed_action_changes) { |
191 send_overflowed_action_changes_ = send_overflowed_action_changes; | 190 send_overflowed_action_changes_ = send_overflowed_action_changes; |
192 } | 191 } |
193 | 192 |
194 // During testing we can disable animations by setting this flag to true, | 193 // During testing we can disable animations by setting this flag to true, |
195 // so that the bar resizes instantly, instead of having to poll it while it | 194 // so that the bar resizes instantly, instead of having to poll it while it |
196 // animates to open/closed status. | 195 // animates to open/closed status. |
197 static bool disable_animations_for_testing_; | 196 static bool disable_animations_for_testing_; |
198 | 197 |
199 private: | 198 private: |
200 using ToolbarActions = ScopedVector<ToolbarActionViewController>; | 199 using ToolbarActions = ScopedVector<ToolbarActionViewController>; |
201 | 200 |
202 // ExtensionToolbarModel::Observer: | 201 // ToolbarActionsModel::Observer: |
203 void OnToolbarExtensionAdded(const extensions::Extension* extension, | 202 void OnToolbarActionAdded(const std::string& action_id, int index) override; |
204 int index) override; | 203 void OnToolbarActionRemoved(const std::string& action_id) override; |
205 void OnToolbarExtensionRemoved( | 204 void OnToolbarActionMoved(const std::string& action_id, int index) override; |
206 const extensions::Extension* extension) override; | 205 void OnToolbarActionUpdated(const std::string& action_id) override; |
207 void OnToolbarExtensionMoved(const extensions::Extension* extension, | 206 bool ShowToolbarActionPopup(const std::string& action_id, |
208 int index) override; | 207 bool grant_active_tab) override; |
209 void OnToolbarExtensionUpdated( | |
210 const extensions::Extension* extension) override; | |
211 bool ShowExtensionActionPopup(const extensions::Extension* extension, | |
212 bool grant_active_tab) override; | |
213 void OnToolbarVisibleCountChanged() override; | 208 void OnToolbarVisibleCountChanged() override; |
214 void OnToolbarHighlightModeChanged(bool is_highlighting) override; | 209 void OnToolbarHighlightModeChanged(bool is_highlighting) override; |
215 void OnToolbarModelInitialized() override; | 210 void OnToolbarModelInitialized() override; |
216 Browser* GetBrowser() override; | 211 Browser* GetBrowser() override; |
217 | 212 |
218 // Resizes the delegate (if necessary) to the preferred size using the given | 213 // Resizes the delegate (if necessary) to the preferred size using the given |
219 // |tween_type| and optionally suppressing the chevron. | 214 // |tween_type| and optionally suppressing the chevron. |
220 void ResizeDelegate(gfx::Tween::Type tween_type, bool suppress_chevron); | 215 void ResizeDelegate(gfx::Tween::Type tween_type, bool suppress_chevron); |
221 | 216 |
222 // Returns the action for the given |id|, if one exists. | 217 // Returns the action for the given |id|, if one exists. |
223 ToolbarActionViewController* GetActionForId(const std::string& id); | 218 ToolbarActionViewController* GetActionForId(const std::string& action_id); |
224 | 219 |
225 // Returns the current web contents. | 220 // Returns the current web contents. |
226 content::WebContents* GetCurrentWebContents(); | 221 content::WebContents* GetCurrentWebContents(); |
227 | 222 |
228 // Reorders the toolbar actions to reflect the model and, optionally, to | 223 // Reorders the toolbar actions to reflect the model and, optionally, to |
229 // "pop out" any overflowed actions that want to run (depending on the | 224 // "pop out" any overflowed actions that want to run (depending on the |
230 // value of |pop_out_actions_to_run|. | 225 // value of |pop_out_actions_to_run|. |
231 void ReorderActions(); | 226 void ReorderActions(); |
232 | 227 |
233 // Sets |overflowed_action_wants_to_run_| to the proper value. | 228 // Sets |overflowed_action_wants_to_run_| to the proper value. |
234 void SetOverflowedActionWantsToRun(); | 229 void SetOverflowedActionWantsToRun(); |
235 | 230 |
236 // Shows an extension message bubble, if any should be shown. | 231 // Shows an extension message bubble, if any should be shown. |
237 void MaybeShowExtensionBubble( | 232 void MaybeShowExtensionBubble( |
238 scoped_ptr<extensions::ExtensionMessageBubbleController> controller); | 233 scoped_ptr<extensions::ExtensionMessageBubbleController> controller); |
239 | 234 |
240 // The delegate for this object (in a real build, this is the view). | 235 // The delegate for this object (in a real build, this is the view). |
241 ToolbarActionsBarDelegate* delegate_; | 236 ToolbarActionsBarDelegate* delegate_; |
242 | 237 |
243 // The associated browser. | 238 // The associated browser. |
244 Browser* browser_; | 239 Browser* browser_; |
245 | 240 |
246 // The observed toolbar model. | 241 // The observed toolbar model. |
247 extensions::ExtensionToolbarModel* model_; | 242 ToolbarActionsModel* model_; |
248 | 243 |
249 // The controller for the main toolbar actions bar. This will be null if this | 244 // The controller for the main toolbar actions bar. This will be null if this |
250 // is the main bar. | 245 // is the main bar. |
251 ToolbarActionsBar* main_bar_; | 246 ToolbarActionsBar* main_bar_; |
252 | 247 |
253 // Platform-specific settings for dimensions and the overflow chevron. | 248 // Platform-specific settings for dimensions and the overflow chevron. |
254 PlatformSettings platform_settings_; | 249 PlatformSettings platform_settings_; |
255 | 250 |
256 // The toolbar actions. | 251 // The toolbar actions. |
257 ToolbarActions toolbar_actions_; | 252 ToolbarActions toolbar_actions_; |
258 | 253 |
254 // List of component action ids. | |
255 ActionIdList component_ids_; | |
256 | |
259 // The action that triggered the current popup (just a reference to an action | 257 // The action that triggered the current popup (just a reference to an action |
260 // from toolbar_actions_). | 258 // from toolbar_actions_). |
261 ToolbarActionViewController* popup_owner_; | 259 ToolbarActionViewController* popup_owner_; |
262 | 260 |
263 ScopedObserver<extensions::ExtensionToolbarModel, | 261 ScopedObserver<ToolbarActionsModel, |
264 extensions::ExtensionToolbarModel::Observer> model_observer_; | 262 ToolbarActionsModel::Observer> model_observer_; |
265 | 263 |
266 // True if we should suppress layout, such as when we are creating or | 264 // True if we should suppress layout, such as when we are creating or |
267 // adjusting a lot of actions at once. | 265 // adjusting a lot of actions at once. |
268 bool suppress_layout_; | 266 bool suppress_layout_; |
269 | 267 |
270 // True if we should suppress animation; we do this when first creating the | 268 // True if we should suppress animation; we do this when first creating the |
271 // toolbar, and also when switching tabs changes the state of the icons. | 269 // toolbar, and also when switching tabs changes the state of the icons. |
272 bool suppress_animation_; | 270 bool suppress_animation_; |
273 | 271 |
274 // If this is true, actions that want to run (e.g., an extension's page | 272 // If this is true, actions that want to run (e.g., an extension's page |
(...skipping 24 matching lines...) Expand all Loading... | |
299 // The controller of the bubble to show once animation finishes, if any. | 297 // The controller of the bubble to show once animation finishes, if any. |
300 scoped_ptr<extensions::ExtensionMessageBubbleController> | 298 scoped_ptr<extensions::ExtensionMessageBubbleController> |
301 pending_extension_bubble_controller_; | 299 pending_extension_bubble_controller_; |
302 | 300 |
303 base::WeakPtrFactory<ToolbarActionsBar> weak_ptr_factory_; | 301 base::WeakPtrFactory<ToolbarActionsBar> weak_ptr_factory_; |
304 | 302 |
305 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBar); | 303 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBar); |
306 }; | 304 }; |
307 | 305 |
308 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_H_ | 306 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_H_ |
OLD | NEW |