Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_actions_bar.h

Issue 766263003: [Extension Toolbar] Refactor and finish pop out logic for actions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/scoped_observer.h" 10 #include "base/scoped_observer.h"
11 #include "chrome/browser/extensions/extension_toolbar_model.h" 11 #include "chrome/browser/extensions/extension_toolbar_model.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
13 #include "ui/gfx/animation/tween.h" 12 #include "ui/gfx/animation/tween.h"
14 #include "ui/gfx/geometry/size.h" 13 #include "ui/gfx/geometry/size.h"
15 14
16 namespace extensions { 15 namespace extensions {
17 class Extension; 16 class Extension;
18 } 17 }
19 18
20 class ToolbarActionsBarDelegate; 19 class ToolbarActionsBarDelegate;
21 class ToolbarActionViewController; 20 class ToolbarActionViewController;
22 21
23 // A platform-independent version of the container for toolbar actions, 22 // A platform-independent version of the container for toolbar actions,
24 // including extension actions and component actions. 23 // including extension actions and component actions.
25 // This class manages the order of the actions, the actions' state, and owns the 24 // This class manages the order of the actions, the actions' state, and owns the
26 // action controllers, in addition to (for extensions) interfacing with the 25 // action controllers, in addition to (for extensions) interfacing with the
27 // extension toolbar model. Further, it manages dimensions for the bar, 26 // extension toolbar model. Further, it manages dimensions for the bar,
28 // excluding animations. 27 // excluding animations.
29 // This can come in two flavors, main and "overflow". The main bar is visible 28 // This can come in two flavors, main and "overflow". The main bar is visible
30 // next to the omnibox, and the overflow bar is visible inside the chrome 29 // next to the omnibox, and the overflow bar is visible inside the chrome
31 // (fka wrench) menu. The main bar can have only a single row of icons with 30 // (fka wrench) menu. The main bar can have only a single row of icons with
32 // flexible width, whereas the overflow bar has multiple rows of icons with a 31 // flexible width, whereas the overflow bar has multiple rows of icons with a
33 // fixed width (the width of the menu). 32 // fixed width (the width of the menu).
34 class ToolbarActionsBar : public extensions::ExtensionToolbarModel::Observer, 33 class ToolbarActionsBar : public extensions::ExtensionToolbarModel::Observer {
35 public TabStripModelObserver {
36 public: 34 public:
37 // A struct to contain the platform settings. 35 // A struct to contain the platform settings.
38 struct PlatformSettings { 36 struct PlatformSettings {
39 explicit PlatformSettings(bool in_overflow_mode); 37 explicit PlatformSettings(bool in_overflow_mode);
40 38
41 // The padding that comes before the first icon in the container. 39 // The padding that comes before the first icon in the container.
42 int left_padding; 40 int left_padding;
43 // The padding following the final icon in the container. 41 // The padding following the final icon in the container.
44 int right_padding; 42 int right_padding;
45 // The spacing between each of the icons. 43 // The spacing between each of the icons.
(...skipping 10 matching lines...) Expand all
56 // The icon was dragged to the same container it started in. 54 // The icon was dragged to the same container it started in.
57 DRAG_TO_SAME, 55 DRAG_TO_SAME,
58 // The icon was dragged from the main container to the overflow. 56 // The icon was dragged from the main container to the overflow.
59 DRAG_TO_OVERFLOW, 57 DRAG_TO_OVERFLOW,
60 // The icon was dragged from the overflow container to the main. 58 // The icon was dragged from the overflow container to the main.
61 DRAG_TO_MAIN, 59 DRAG_TO_MAIN,
62 }; 60 };
63 61
64 ToolbarActionsBar(ToolbarActionsBarDelegate* delegate, 62 ToolbarActionsBar(ToolbarActionsBarDelegate* delegate,
65 Browser* browser, 63 Browser* browser,
66 bool in_overflow_mode); 64 ToolbarActionsBar* main_bar);
67 ~ToolbarActionsBar() override; 65 ~ToolbarActionsBar() override;
68 66
69 // Returns the width of a browser action icon, optionally including the 67 // Returns the width of a browser action icon, optionally including the
70 // following padding. 68 // following padding.
71 static int IconWidth(bool include_padding); 69 static int IconWidth(bool include_padding);
72 70
73 // Returns the height of a browser action icon. 71 // Returns the height of a browser action icon.
74 static int IconHeight(); 72 static int IconHeight();
75 73
76 // Returns the preferred size for the toolbar; this does *not* reflect any 74 // Returns the preferred size for the toolbar; this does *not* reflect any
(...skipping 26 matching lines...) Expand all
103 void SetOverflowRowWidth(int width); 101 void SetOverflowRowWidth(int width);
104 102
105 // Notifies the ToolbarActionsBar that a user completed a resize gesture, and 103 // Notifies the ToolbarActionsBar that a user completed a resize gesture, and
106 // the new width is |width|. 104 // the new width is |width|.
107 void OnResizeComplete(int width); 105 void OnResizeComplete(int width);
108 106
109 // Notifies the ToolbarActionsBar that a user completed a drag and drop event, 107 // Notifies the ToolbarActionsBar that a user completed a drag and drop event,
110 // and dragged the view from |dragged_index| to |dropped_index|. 108 // and dragged the view from |dragged_index| to |dropped_index|.
111 // |drag_type| indicates whether or not the icon was dragged between the 109 // |drag_type| indicates whether or not the icon was dragged between the
112 // overflow and main containers. 110 // overflow and main containers.
111 // The main container should handle all drag/drop notifications.
113 void OnDragDrop(int dragged_index, 112 void OnDragDrop(int dragged_index,
114 int dropped_index, 113 int dropped_index,
115 DragType drag_type); 114 DragType drag_type);
116 115
117 const std::vector<ToolbarActionViewController*>& toolbar_actions() { 116 const std::vector<ToolbarActionViewController*>& toolbar_actions() const {
118 return toolbar_actions_.get(); 117 return toolbar_actions_.get();
119 } 118 }
120 bool enabled() const { return model_ != nullptr; } 119 bool enabled() const { return model_ != nullptr; }
121 bool suppress_layout() const { return suppress_layout_; } 120 bool suppress_layout() const { return suppress_layout_; }
122 bool suppress_animation() const { return suppress_animation_; } 121 bool suppress_animation() const { return suppress_animation_; }
123 bool is_highlighting() const { return model_ && model_->is_highlighting(); } 122 bool is_highlighting() const { return model_ && model_->is_highlighting(); }
124 const PlatformSettings& platform_settings() const { 123 const PlatformSettings& platform_settings() const {
125 return platform_settings_; 124 return platform_settings_;
126 } 125 }
127 126
128 ToolbarActionsBarDelegate* delegate_for_test() { return delegate_; } 127 ToolbarActionsBarDelegate* delegate_for_test() { return delegate_; }
129 128
129 // If this is true, actions that want to run (e.g., an extension's page
130 // action) will pop out of overflow to draw more attention.
131 // See also TabOrderHelper in the .cc file.
132 static bool pop_out_actions_to_run;
133
130 private: 134 private:
135 class TabOrderHelper;
136
131 using ToolbarActions = ScopedVector<ToolbarActionViewController>; 137 using ToolbarActions = ScopedVector<ToolbarActionViewController>;
132 138
133 // ExtensionToolbarModel::Observer: 139 // ExtensionToolbarModel::Observer:
134 void ToolbarExtensionAdded(const extensions::Extension* extension, 140 void ToolbarExtensionAdded(const extensions::Extension* extension,
135 int index) override; 141 int index) override;
136 void ToolbarExtensionRemoved(const extensions::Extension* extension) override; 142 void ToolbarExtensionRemoved(const extensions::Extension* extension) override;
137 void ToolbarExtensionMoved(const extensions::Extension* extension, 143 void ToolbarExtensionMoved(const extensions::Extension* extension,
138 int index) override; 144 int index) override;
139 void ToolbarExtensionUpdated(const extensions::Extension* extension) override; 145 void ToolbarExtensionUpdated(const extensions::Extension* extension) override;
140 bool ShowExtensionActionPopup(const extensions::Extension* extension, 146 bool ShowExtensionActionPopup(const extensions::Extension* extension,
141 bool grant_active_tab) override; 147 bool grant_active_tab) override;
142 void ToolbarVisibleCountChanged() override; 148 void ToolbarVisibleCountChanged() override;
143 void ToolbarHighlightModeChanged(bool is_highlighting) override; 149 void ToolbarHighlightModeChanged(bool is_highlighting) override;
144 void OnToolbarModelInitialized() override; 150 void OnToolbarModelInitialized() override;
145 Browser* GetBrowser() override; 151 Browser* GetBrowser() override;
146 152
147 // TabStripModelObserver:
148 void TabInsertedAt(content::WebContents* web_contents,
149 int index,
150 bool foreground) override;
151 void TabDetachedAt(content::WebContents* web_contents,
152 int index) override;
153 void TabStripModelDeleted() override;
154
155 // Resizes the delegate (if necessary) to the preferred size using the given 153 // Resizes the delegate (if necessary) to the preferred size using the given
156 // |tween_type| and optionally suppressing the chevron. 154 // |tween_type| and optionally suppressing the chevron.
157 void ResizeDelegate(gfx::Tween::Type tween_type, bool suppress_chevron); 155 void ResizeDelegate(gfx::Tween::Type tween_type, bool suppress_chevron);
158 156
159 // Returns the action for the given |id|, if one exists. 157 // Returns the action for the given |id|, if one exists.
160 ToolbarActionViewController* GetActionForId(const std::string& id); 158 ToolbarActionViewController* GetActionForId(const std::string& id);
161 159
162 // Returns the current web contents. 160 // Returns the current web contents.
163 content::WebContents* GetCurrentWebContents(); 161 content::WebContents* GetCurrentWebContents();
164 162
165 // Reorders the toolbar actions to reflect any that need to pop out. 163 // Reorders the toolbar actions to reflect the model and, optionally, to
164 // "pop out" any overflowed actions that want to run (depending on the
165 // value of |pop_out_actions_to_run|.
166 void ReorderActions(); 166 void ReorderActions();
167 167
168 // Copies the action order from the main bar (only called for the overflow).
169 void CopyActionOrder();
170
171 bool in_overflow_mode() const { return main_bar_ != nullptr; }
172
168 // The delegate for this object (in a real build, this is the view). 173 // The delegate for this object (in a real build, this is the view).
169 ToolbarActionsBarDelegate* delegate_; 174 ToolbarActionsBarDelegate* delegate_;
170 175
171 // The associated browser. 176 // The associated browser.
172 Browser* browser_; 177 Browser* browser_;
173 178
174 // The observed toolbar model. 179 // The observed toolbar model.
175 extensions::ExtensionToolbarModel* model_; 180 extensions::ExtensionToolbarModel* model_;
176 181
177 // True if this bar is for the overflow menu. 182 // The controller for the main toolbar actions bar. This will be null if this
178 bool in_overflow_mode_; 183 // is the main bar.
184 ToolbarActionsBar* main_bar_;
185
186 // The controller for the overflow toolbar actions bar; this can be null
187 // even if this is the main bar, since the overflow is not always open.
188 ToolbarActionsBar* overflow_bar_;
179 189
180 // Platform-specific settings for dimensions and the overflow chevron. 190 // Platform-specific settings for dimensions and the overflow chevron.
181 PlatformSettings platform_settings_; 191 PlatformSettings platform_settings_;
182 192
183 // The toolbar actions. 193 // The toolbar actions.
184 ToolbarActions toolbar_actions_; 194 ToolbarActions toolbar_actions_;
185 195
186 // The set of tabs for the given action (the key) is currently "popped out". 196 // The TabOrderHelper that manages popping out actions that want to act.
187 // "Popped out" actions are those that were in the overflow menu normally, but 197 // This is only non-null if |pop_out_actions_to_run| is true.
188 // want to run and are moved to the main bar so the user can see them. 198 scoped_ptr<TabOrderHelper> tab_order_helper_;
189 std::map<ToolbarActionViewController*, std::set<int>> popped_out_in_tabs_;
190
191 // The set of tab ids that have been checked for whether actions need to be
192 // popped out or not.
193 std::set<int> tabs_checked_for_pop_out_;
194 199
195 ScopedObserver<extensions::ExtensionToolbarModel, 200 ScopedObserver<extensions::ExtensionToolbarModel,
196 extensions::ExtensionToolbarModel::Observer> model_observer_; 201 extensions::ExtensionToolbarModel::Observer> model_observer_;
197 202
198 ScopedObserver<TabStripModel, TabStripModelObserver> tab_strip_observer_;
199
200 // True if we should suppress layout, such as when we are creating or 203 // True if we should suppress layout, such as when we are creating or
201 // adjusting a lot of actions at once. 204 // adjusting a lot of actions at once.
202 bool suppress_layout_; 205 bool suppress_layout_;
203 206
204 // True if we should suppress animation; we do this when first creating the 207 // True if we should suppress animation; we do this when first creating the
205 // toolbar, and also when switching tabs changes the state of the icons. 208 // toolbar, and also when switching tabs changes the state of the icons.
206 bool suppress_animation_; 209 bool suppress_animation_;
207 210
208 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBar); 211 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBar);
209 }; 212 };
210 213
211 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_H_ 214 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698