[Eraser strings] Remove unused Supervised User infobar and corresponding strings
[chromium-blink-merge.git] / chrome / browser / ui / toolbar / toolbar_actions_bar.h
blob149f720e1c6d4b4b9d91c0187ed837da0f9ea7d1
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_H_
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_vector.h"
11 #include "base/memory/weak_ptr.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"
15 #include "ui/gfx/animation/tween.h"
16 #include "ui/gfx/geometry/size.h"
18 namespace extensions {
19 class Extension;
20 class ExtensionMessageBubbleController;
23 namespace user_prefs {
24 class PrefRegistrySyncable;
27 class ToolbarActionsBarDelegate;
28 class ToolbarActionViewController;
30 // A platform-independent version of the container for toolbar actions,
31 // including extension actions and component actions.
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
34 // extension toolbar model. Further, it manages dimensions for the bar,
35 // excluding animations.
36 // 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
38 // (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
40 // fixed width (the width of the menu).
41 class ToolbarActionsBar : public extensions::ExtensionToolbarModel::Observer {
42 public:
43 // A struct to contain the platform settings.
44 struct PlatformSettings {
45 explicit PlatformSettings(bool in_overflow_mode);
47 // The padding that comes before the first icon in the container.
48 int left_padding;
49 // The padding following the final icon in the container.
50 int right_padding;
51 // The spacing between each of the icons.
52 int item_spacing;
53 // The number of icons per row in the overflow menu.
54 int icons_per_overflow_menu_row;
55 // Whether or not the overflow menu is displayed as a chevron (this is being
56 // phased out).
57 bool chevron_enabled;
60 // The type of drag that occurred in a drag-and-drop operation.
61 enum DragType {
62 // The icon was dragged to the same container it started in.
63 DRAG_TO_SAME,
64 // The icon was dragged from the main container to the overflow.
65 DRAG_TO_OVERFLOW,
66 // The icon was dragged from the overflow container to the main.
67 DRAG_TO_MAIN,
70 enum HighlightType {
71 HIGHLIGHT_NONE,
72 HIGHLIGHT_INFO,
73 HIGHLIGHT_WARNING,
76 ToolbarActionsBar(ToolbarActionsBarDelegate* delegate,
77 Browser* browser,
78 ToolbarActionsBar* main_bar);
79 ~ToolbarActionsBar() override;
81 // Returns the width of a browser action icon, optionally including the
82 // following padding.
83 static int IconWidth(bool include_padding);
85 // Returns the height of a browser action icon.
86 static int IconHeight();
88 // Registers profile preferences.
89 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
91 // Returns the preferred size for the toolbar; this does *not* reflect any
92 // animations that may be running.
93 gfx::Size GetPreferredSize() const;
95 // Returns the [minimum|maximum] possible width for the toolbar.
96 int GetMinimumWidth() const;
97 int GetMaximumWidth() const;
99 // Returns the width for the given number of icons.
100 int IconCountToWidth(int icons) const;
102 // Returns the number of icons that can fit within the given width.
103 size_t WidthToIconCount(int width) const;
105 // Returns the number of icons that should be displayed.
106 size_t GetIconCount() const;
108 // Returns the frame (bounds) that the specified index should have, taking
109 // into account if this is the main or overflow bar. If this is the overflow
110 // bar and the index should not be displayed (i.e., it is shown on the main
111 // bar), returns an empty rect.
112 gfx::Rect GetFrameForIndex(size_t index) const;
114 // Returns the actions in the proper order; this may differ from the
115 // underlying order in the case of actions being popped out to show a popup.
116 std::vector<ToolbarActionViewController*> GetActions() const;
118 // Creates the toolbar actions.
119 void CreateActions();
121 // Deletes all toolbar actions.
122 void DeleteActions();
124 // Updates all the toolbar actions.
125 void Update();
127 // Sets the width for the overflow menu rows.
128 void SetOverflowRowWidth(int width);
130 // Notifies the ToolbarActionsBar that a user completed a resize gesture, and
131 // the new width is |width|.
132 void OnResizeComplete(int width);
134 // Notifies the ToolbarActionsBar that a user completed a drag and drop event,
135 // and dragged the view from |dragged_index| to |dropped_index|.
136 // |drag_type| indicates whether or not the icon was dragged between the
137 // overflow and main containers.
138 // The main container should handle all drag/drop notifications.
139 void OnDragDrop(int dragged_index,
140 int dropped_index,
141 DragType drag_type);
143 // Notifies the ToolbarActionsBar that the delegate finished animating.
144 void OnAnimationEnded();
146 // Returns true if the given |action| is visible on the main toolbar.
147 bool IsActionVisibleOnMainBar(const ToolbarActionViewController* action)
148 const;
150 // Pops out a given |action|, ensuring it is visible.
151 // |closure| will be called once any animation is complete.
152 void PopOutAction(ToolbarActionViewController* action,
153 const base::Closure& closure);
155 // Undoes the current "pop out"; i.e., moves the popped out action back into
156 // overflow.
157 void UndoPopOut();
159 // Sets the active popup owner to be |popup_owner|.
160 void SetPopupOwner(ToolbarActionViewController* popup_owner);
162 // Hides the actively showing popup, if any.
163 void HideActivePopup();
165 // Returns the main (i.e., not overflow) controller for the given action.
166 ToolbarActionViewController* GetMainControllerForAction(
167 ToolbarActionViewController* action);
169 // Returns the underlying toolbar actions, but does not order them. Primarily
170 // for use in testing.
171 const std::vector<ToolbarActionViewController*>& toolbar_actions_unordered()
172 const {
173 return toolbar_actions_.get();
175 bool enabled() const { return model_ != nullptr; }
176 bool suppress_layout() const { return suppress_layout_; }
177 bool suppress_animation() const {
178 return suppress_animation_ || disable_animations_for_testing_;
180 bool is_highlighting() const { return model_ && model_->is_highlighting(); }
181 extensions::ExtensionToolbarModel::HighlightType highlight_type() const {
182 return model_ ? model_->highlight_type()
183 : extensions::ExtensionToolbarModel::HIGHLIGHT_NONE;
185 const PlatformSettings& platform_settings() const {
186 return platform_settings_;
188 ToolbarActionViewController* popup_owner() { return popup_owner_; }
189 ToolbarActionViewController* popped_out_action() {
190 return popped_out_action_;
192 bool in_overflow_mode() const { return main_bar_ != nullptr; }
194 ToolbarActionsBarDelegate* delegate_for_test() { return delegate_; }
196 static void set_send_overflowed_action_changes_for_testing(
197 bool send_overflowed_action_changes) {
198 send_overflowed_action_changes_ = send_overflowed_action_changes;
201 // 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
203 // animates to open/closed status.
204 static bool disable_animations_for_testing_;
206 private:
207 using ToolbarActions = ScopedVector<ToolbarActionViewController>;
209 // ExtensionToolbarModel::Observer:
210 void OnToolbarExtensionAdded(const extensions::Extension* extension,
211 int index) override;
212 void OnToolbarExtensionRemoved(
213 const extensions::Extension* extension) override;
214 void OnToolbarExtensionMoved(const extensions::Extension* extension,
215 int index) 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;
221 void OnToolbarHighlightModeChanged(bool is_highlighting) override;
222 void OnToolbarModelInitialized() override;
223 Browser* GetBrowser() override;
225 // Resizes the delegate (if necessary) to the preferred size using the given
226 // |tween_type| and optionally suppressing the chevron.
227 void ResizeDelegate(gfx::Tween::Type tween_type, bool suppress_chevron);
229 // Returns the action for the given |id|, if one exists.
230 ToolbarActionViewController* GetActionForId(const std::string& id);
232 // Returns the current web contents.
233 content::WebContents* GetCurrentWebContents();
235 // Reorders the toolbar actions to reflect the model and, optionally, to
236 // "pop out" any overflowed actions that want to run (depending on the
237 // value of |pop_out_actions_to_run|.
238 void ReorderActions();
240 // Sets |overflowed_action_wants_to_run_| to the proper value.
241 void SetOverflowedActionWantsToRun();
243 // Shows an extension message bubble, if any should be shown.
244 void MaybeShowExtensionBubble(
245 scoped_ptr<extensions::ExtensionMessageBubbleController> controller);
247 // The delegate for this object (in a real build, this is the view).
248 ToolbarActionsBarDelegate* delegate_;
250 // The associated browser.
251 Browser* browser_;
253 // The observed toolbar model.
254 extensions::ExtensionToolbarModel* model_;
256 // The controller for the main toolbar actions bar. This will be null if this
257 // is the main bar.
258 ToolbarActionsBar* main_bar_;
260 // Platform-specific settings for dimensions and the overflow chevron.
261 PlatformSettings platform_settings_;
263 // The toolbar actions.
264 ToolbarActions toolbar_actions_;
266 // The action that triggered the current popup (just a reference to an action
267 // from toolbar_actions_).
268 ToolbarActionViewController* popup_owner_;
270 ScopedObserver<extensions::ExtensionToolbarModel,
271 extensions::ExtensionToolbarModel::Observer> model_observer_;
273 // True if we should suppress layout, such as when we are creating or
274 // adjusting a lot of actions at once.
275 bool suppress_layout_;
277 // 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.
279 bool suppress_animation_;
281 // If this is true, actions that want to run (e.g., an extension's page
282 // action) will pop out of overflow to draw more attention.
283 // See also TabOrderHelper in the .cc file.
284 static bool pop_out_actions_to_run_;
286 // If set to false, notifications for OnOverflowedActionWantsToRunChanged()
287 // will not be sent. Used because in unit tests there is no wrench menu to
288 // alter.
289 static bool send_overflowed_action_changes_;
291 // True if an action in the overflow menu wants to run.
292 bool overflowed_action_wants_to_run_;
294 // True if we have checked to see if there is an extension bubble that should
295 // be displayed, and, if there is, shown that bubble.
296 bool checked_extension_bubble_;
298 // The action, if any, which is currently "popped out" of the overflow in
299 // order to show a popup.
300 ToolbarActionViewController* popped_out_action_;
302 // The task to alert the |popped_out_action_| that animation has finished, and
303 // it is fully popped out.
304 base::Closure popped_out_closure_;
306 // The controller of the bubble to show once animation finishes, if any.
307 scoped_ptr<extensions::ExtensionMessageBubbleController>
308 pending_extension_bubble_controller_;
310 base::WeakPtrFactory<ToolbarActionsBar> weak_ptr_factory_;
312 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBar);
315 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_H_