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

Side by Side Diff: chrome/browser/ui/views/toolbar/browser_actions_container.h

Issue 653933003: Resubmit: Rename BrowserActionView to ToolbarActionView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 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_BROWSER_ACTIONS_CONTAINER_H_ 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_
7 7
8 #include "base/observer_list.h" 8 #include "base/observer_list.h"
9 #include "chrome/browser/extensions/extension_keybinding_registry.h" 9 #include "chrome/browser/extensions/extension_keybinding_registry.h"
10 #include "chrome/browser/extensions/extension_toolbar_model.h" 10 #include "chrome/browser/extensions/extension_toolbar_model.h"
11 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" 11 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h"
12 #include "chrome/browser/ui/views/toolbar/browser_action_view.h"
13 #include "chrome/browser/ui/views/toolbar/chevron_menu_button.h" 12 #include "chrome/browser/ui/views/toolbar/chevron_menu_button.h"
13 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h"
14 #include "ui/gfx/animation/animation_delegate.h" 14 #include "ui/gfx/animation/animation_delegate.h"
15 #include "ui/gfx/animation/tween.h" 15 #include "ui/gfx/animation/tween.h"
16 #include "ui/views/controls/button/menu_button_listener.h" 16 #include "ui/views/controls/button/menu_button_listener.h"
17 #include "ui/views/controls/resize_area_delegate.h" 17 #include "ui/views/controls/resize_area_delegate.h"
18 #include "ui/views/drag_controller.h" 18 #include "ui/views/drag_controller.h"
19 #include "ui/views/view.h" 19 #include "ui/views/view.h"
20 20
21 class BrowserActionsContainerObserver; 21 class BrowserActionsContainerObserver;
22 class ExtensionPopup; 22 class ExtensionPopup;
23 23
24 namespace extensions { 24 namespace extensions {
25 class ActiveTabPermissionGranter; 25 class ActiveTabPermissionGranter;
26 class Command; 26 class Command;
27 class Extension; 27 class Extension;
28 } 28 }
29 29
30 namespace gfx { 30 namespace gfx {
31 class SlideAnimation; 31 class SlideAnimation;
32 } 32 }
33 33
34 namespace views { 34 namespace views {
35 class ResizeArea; 35 class ResizeArea;
36 } 36 }
37 37
38 // The BrowserActionsContainer is a container view, responsible for drawing the 38 // The BrowserActionsContainer is a container view, responsible for drawing the
39 // browser action icons (extensions that add icons to the toolbar). It comes in 39 // toolbar action icons (including extension icons and icons for component
40 // two flavors, a main container (when residing on the toolbar) and an overflow 40 // toolbar actions). It comes intwo flavors, a main container (when residing on
41 // container (that resides in the main application menu, aka the Chrome menu). 41 // the toolbar) and an overflow container (that resides in the main application
42 // menu, aka the Chrome menu).
42 // 43 //
43 // When in 'main' mode, the container supports the full functionality of a 44 // When in 'main' mode, the container supports the full functionality of a
44 // BrowserActionContainer, but in 'overflow' mode the container is effectively 45 // BrowserActionContainer, but in 'overflow' mode the container is effectively
45 // just an overflow for the 'main' toolbar (shows only the icons that the main 46 // just an overflow for the 'main' toolbar (shows only the icons that the main
46 // toolbar does not) and as such does not have an overflow itself. The overflow 47 // toolbar does not) and as such does not have an overflow itself. The overflow
47 // container also does not support resizing. Since the main container only shows 48 // container also does not support resizing. Since the main container only shows
48 // icons in the Chrome toolbar, it is limited to a single row of icons. The 49 // icons in the Chrome toolbar, it is limited to a single row of icons. The
49 // overflow container, however, is allowed to display icons in multiple rows. 50 // overflow container, however, is allowed to display icons in multiple rows.
50 // 51 //
51 // The main container is placed flush against the omnibox and hot dog menu, 52 // The main container is placed flush against the omnibox and hot dog menu,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // because we won't have enough space to show the new Browser Action until the 120 // because we won't have enough space to show the new Browser Action until the
120 // animation ends and we don't want the chevron to flash into view while we are 121 // animation ends and we don't want the chevron to flash into view while we are
121 // growing the container. 122 // growing the container.
122 // 123 //
123 //////////////////////////////////////////////////////////////////////////////// 124 ////////////////////////////////////////////////////////////////////////////////
124 class BrowserActionsContainer 125 class BrowserActionsContainer
125 : public views::View, 126 : public views::View,
126 public views::ResizeAreaDelegate, 127 public views::ResizeAreaDelegate,
127 public gfx::AnimationDelegate, 128 public gfx::AnimationDelegate,
128 public extensions::ExtensionToolbarModel::Observer, 129 public extensions::ExtensionToolbarModel::Observer,
129 public BrowserActionView::Delegate, 130 public ToolbarActionView::Delegate,
130 public extensions::ExtensionKeybindingRegistry::Delegate { 131 public extensions::ExtensionKeybindingRegistry::Delegate {
131 public: 132 public:
132 // Horizontal spacing between most items in the container, as well as after 133 // Horizontal spacing between most items in the container, as well as after
133 // the last item or chevron (if visible). 134 // the last item or chevron (if visible).
134 static const int kItemSpacing; 135 static const int kItemSpacing;
135 136
136 // Constructs a BrowserActionContainer for a particular |browser| object. For 137 // Constructs a BrowserActionContainer for a particular |browser| object. For
137 // documentation of |main_container|, see class comments. 138 // documentation of |main_container|, see class comments.
138 BrowserActionsContainer(Browser* browser, 139 BrowserActionsContainer(Browser* browser,
139 BrowserActionsContainer* main_container); 140 BrowserActionsContainer* main_container);
140 ~BrowserActionsContainer() override; 141 ~BrowserActionsContainer() override;
141 142
142 void Init(); 143 void Init();
143 144
144 // Get the number of browser actions being displayed. 145 // Get the number of toolbar actions being displayed.
145 size_t num_browser_actions() const { return browser_action_views_.size(); } 146 size_t num_toolbar_actions() const { return toolbar_action_views_.size(); }
146 147
147 // Whether we are performing resize animation on the container. 148 // Whether we are performing resize animation on the container.
148 bool animating() const { return animation_target_size_ > 0; } 149 bool animating() const { return animation_target_size_ > 0; }
149 150
150 // Returns the chevron, if any. 151 // Returns the chevron, if any.
151 views::View* chevron() { return chevron_; } 152 views::View* chevron() { return chevron_; }
152 const views::View* chevron() const { return chevron_; } 153 const views::View* chevron() const { return chevron_; }
153 154
154 // Returns the profile this container is associated with. 155 // Returns the profile this container is associated with.
155 Profile* profile() const { return profile_; } 156 Profile* profile() const { return profile_; }
156 157
157 // The class that registers for keyboard shortcuts for extension commands. 158 // The class that registers for keyboard shortcuts for extension commands.
158 extensions::ExtensionKeybindingRegistry* extension_keybinding_registry() { 159 extensions::ExtensionKeybindingRegistry* extension_keybinding_registry() {
159 return extension_keybinding_registry_.get(); 160 return extension_keybinding_registry_.get();
160 } 161 }
161 162
162 // Get a particular browser action view. 163 // Get a particular toolbar action view.
163 BrowserActionView* GetBrowserActionViewAt(int index) { 164 ToolbarActionView* GetToolbarActionViewAt(int index) {
164 return browser_action_views_[index]; 165 return toolbar_action_views_[index];
165 } 166 }
166 167
167 // Returns the ID of the action represented by the view at |index|. 168 // Returns the ID of the action represented by the view at |index|.
168 const std::string& GetIdAt(size_t index); 169 const std::string& GetIdAt(size_t index);
169 170
170 // Returns the BrowserActionView* associated with the given |extension|, or 171 // Returns the ToolbarActionView* associated with the given |extension|, or
171 // NULL if none exists. 172 // NULL if none exists.
172 BrowserActionView* GetViewForExtension( 173 ToolbarActionView* GetViewForExtension(
173 const extensions::Extension* extension); 174 const extensions::Extension* extension);
174 175
175 // Update the views to reflect the state of the browser action icons. 176 // Update the views to reflect the state of the toolbar actions.
176 void RefreshBrowserActionViews(); 177 void RefreshToolbarActionViews();
177 178
178 // Sets up the browser action view vector. 179 // Sets up the toolbar action view vector.
179 void CreateBrowserActionViews(); 180 void CreateToolbarActionViews();
180 181
181 // Delete all browser action views. 182 // Delete all toolbar action views.
182 void DeleteBrowserActionViews(); 183 void DeleteToolbarActionViews();
183 184
184 // Returns how many browser actions are currently visible. If the intent is 185 // Returns how many actions are currently visible. If the intent is to find
185 // to find how many are visible once the container finishes animation, see 186 // how many are visible once the container finishes animation, see
186 // VisibleBrowserActionsAfterAnimation() below. 187 // VisibleBrowserActionsAfterAnimation() below.
187 size_t VisibleBrowserActions() const; 188 size_t VisibleBrowserActions() const;
188 189
189 // Returns how many browser actions will be visible once the container 190 // Returns how many actions will be visible once the container finishes
190 // finishes animating to a new size, or (if not animating) the currently 191 // animating to a new size, or (if not animating) the currently visible icons.
191 // visible icons.
192 size_t VisibleBrowserActionsAfterAnimation() const; 192 size_t VisibleBrowserActionsAfterAnimation() const;
193 193
194 // Executes |command| registered by |extension|. 194 // Executes |command| registered by |extension|.
195 void ExecuteExtensionCommand(const extensions::Extension* extension, 195 void ExecuteExtensionCommand(const extensions::Extension* extension,
196 const extensions::Command& command); 196 const extensions::Command& command);
197 197
198 // Notify the browser action container that an extension has been moved to 198 // Notify the container that an extension has been moved to the overflow
199 // the overflow container. 199 // container.
200 void NotifyActionMovedToOverflow(); 200 void NotifyActionMovedToOverflow();
201 201
202 // Add or remove an observer. 202 // Add or remove an observer.
203 void AddObserver(BrowserActionsContainerObserver* observer); 203 void AddObserver(BrowserActionsContainerObserver* observer);
204 void RemoveObserver(BrowserActionsContainerObserver* observer); 204 void RemoveObserver(BrowserActionsContainerObserver* observer);
205 205
206 // Overridden from views::View: 206 // Overridden from views::View:
207 gfx::Size GetPreferredSize() const override; 207 gfx::Size GetPreferredSize() const override;
208 int GetHeightForWidth(int width) const override; 208 int GetHeightForWidth(int width) const override;
209 gfx::Size GetMinimumSize() const override; 209 gfx::Size GetMinimumSize() const override;
(...skipping 17 matching lines...) Expand all
227 const gfx::Point& press_pt, 227 const gfx::Point& press_pt,
228 const gfx::Point& p) override; 228 const gfx::Point& p) override;
229 229
230 // Overridden from views::ResizeAreaDelegate: 230 // Overridden from views::ResizeAreaDelegate:
231 void OnResize(int resize_amount, bool done_resizing) override; 231 void OnResize(int resize_amount, bool done_resizing) override;
232 232
233 // Overridden from gfx::AnimationDelegate: 233 // Overridden from gfx::AnimationDelegate:
234 void AnimationProgressed(const gfx::Animation* animation) override; 234 void AnimationProgressed(const gfx::Animation* animation) override;
235 void AnimationEnded(const gfx::Animation* animation) override; 235 void AnimationEnded(const gfx::Animation* animation) override;
236 236
237 // Overridden from BrowserActionView::Delegate: 237 // Overridden from ToolbarActionView::Delegate:
238 content::WebContents* GetCurrentWebContents() override; 238 content::WebContents* GetCurrentWebContents() override;
239 bool ShownInsideMenu() const override; 239 bool ShownInsideMenu() const override;
240 void OnBrowserActionViewDragDone() override; 240 void OnToolbarActionViewDragDone() override;
241 views::MenuButton* GetOverflowReferenceView() override; 241 views::MenuButton* GetOverflowReferenceView() override;
242 void SetPopupOwner(BrowserActionView* popup_owner) override; 242 void SetPopupOwner(ToolbarActionView* popup_owner) override;
243 void HideActivePopup() override; 243 void HideActivePopup() override;
244 BrowserActionView* GetMainViewForAction(BrowserActionView* view) override; 244 ToolbarActionView* GetMainViewForAction(ToolbarActionView* view) override;
245 245
246 // Overridden from extension::ExtensionKeybindingRegistry::Delegate: 246 // Overridden from extension::ExtensionKeybindingRegistry::Delegate:
247 extensions::ActiveTabPermissionGranter* GetActiveTabPermissionGranter() 247 extensions::ActiveTabPermissionGranter* GetActiveTabPermissionGranter()
248 override; 248 override;
249 249
250 // Retrieve the current popup. This should only be used by unit tests. 250 // Retrieve the current popup. This should only be used by unit tests.
251 gfx::NativeView TestGetPopup(); 251 gfx::NativeView TestGetPopup();
252 252
253 // Returns the width of an icon, optionally with its padding. 253 // Returns the width of an icon, optionally with its padding.
254 static int IconWidth(bool include_padding); 254 static int IconWidth(bool include_padding);
(...skipping 10 matching lines...) Expand all
265 // Overridden from views::View: 265 // Overridden from views::View:
266 void ViewHierarchyChanged( 266 void ViewHierarchyChanged(
267 const ViewHierarchyChangedDetails& details) override; 267 const ViewHierarchyChangedDetails& details) override;
268 void OnPaint(gfx::Canvas* canvas) override; 268 void OnPaint(gfx::Canvas* canvas) override;
269 void OnThemeChanged() override; 269 void OnThemeChanged() override;
270 270
271 private: 271 private:
272 // A struct representing the position at which an action will be dropped. 272 // A struct representing the position at which an action will be dropped.
273 struct DropPosition; 273 struct DropPosition;
274 274
275 typedef std::vector<BrowserActionView*> BrowserActionViews; 275 typedef std::vector<ToolbarActionView*> ToolbarActionViews;
276 276
277 // extensions::ExtensionToolbarModel::Observer implementation. 277 // extensions::ExtensionToolbarModel::Observer implementation.
278 void ToolbarExtensionAdded(const extensions::Extension* extension, 278 void ToolbarExtensionAdded(const extensions::Extension* extension,
279 int index) override; 279 int index) override;
280 void ToolbarExtensionRemoved(const extensions::Extension* extension) override; 280 void ToolbarExtensionRemoved(const extensions::Extension* extension) override;
281 void ToolbarExtensionMoved(const extensions::Extension* extension, 281 void ToolbarExtensionMoved(const extensions::Extension* extension,
282 int index) override; 282 int index) override;
283 void ToolbarExtensionUpdated(const extensions::Extension* extension) override; 283 void ToolbarExtensionUpdated(const extensions::Extension* extension) override;
284 bool ShowExtensionActionPopup(const extensions::Extension* extension, 284 bool ShowExtensionActionPopup(const extensions::Extension* extension,
285 bool grant_active_tab) override; 285 bool grant_active_tab) override;
286 void ToolbarVisibleCountChanged() override; 286 void ToolbarVisibleCountChanged() override;
287 void ToolbarHighlightModeChanged(bool is_highlighting) override; 287 void ToolbarHighlightModeChanged(bool is_highlighting) override;
288 Browser* GetBrowser() override; 288 Browser* GetBrowser() override;
289 289
290 void LoadImages(); 290 void LoadImages();
291 291
292 // Called when a browser action's visibility may have changed. 292 // Called when an action's visibility may have changed.
293 void OnBrowserActionVisibilityChanged(); 293 void OnBrowserActionVisibilityChanged();
294 294
295 // Returns the preferred width of the container in order to show all icons 295 // Returns the preferred width of the container in order to show all icons
296 // that should be visible and, optionally, the chevron. 296 // that should be visible and, optionally, the chevron.
297 int GetPreferredWidth(); 297 int GetPreferredWidth();
298 298
299 // Sets the chevron to be visible or not based on whether all browser actions 299 // Sets the chevron to be visible or not based on whether all actions are
300 // are displayed. 300 // displayed.
301 void SetChevronVisibility(); 301 void SetChevronVisibility();
302 302
303 // Given a number of |icons|, returns the pixels needed to draw the entire 303 // Given a number of |icons|, returns the pixels needed to draw the entire
304 // container (including the chevron if the number of icons is not all the 304 // container (including the chevron if the number of icons is not all the
305 // icons and there's not a separate overflow container). For convenience, 305 // icons and there's not a separate overflow container). For convenience,
306 // callers can set |icons| to -1 to mean "all icons". 306 // callers can set |icons| to -1 to mean "all icons".
307 int IconCountToWidth(int icons) const; 307 int IconCountToWidth(int icons) const;
308 308
309 // Given a pixel width, returns the number of icons that fit. (This 309 // Given a pixel width, returns the number of icons that fit. (This
310 // automatically determines whether a chevron will be needed and includes it 310 // automatically determines whether a chevron will be needed and includes it
(...skipping 16 matching lines...) Expand all
327 // from the model's GetVisibleIconCount if this container is for the overflow. 327 // from the model's GetVisibleIconCount if this container is for the overflow.
328 size_t GetIconCount() const; 328 size_t GetIconCount() const;
329 329
330 // Whether this container is in overflow mode (as opposed to in 'main' 330 // Whether this container is in overflow mode (as opposed to in 'main'
331 // mode). See class comments for details on the difference. 331 // mode). See class comments for details on the difference.
332 bool in_overflow_mode() const { return main_container_ != NULL; } 332 bool in_overflow_mode() const { return main_container_ != NULL; }
333 333
334 // Whether or not the container has been initialized. 334 // Whether or not the container has been initialized.
335 bool initialized_; 335 bool initialized_;
336 336
337 // The vector of browser actions (icons/image buttons for each action). Note 337 // The vector of toolbar actions (icons/image buttons for each action).
338 // that not every BrowserAction in the ToolbarModel will necessarily be in 338 ToolbarActionViews toolbar_action_views_;
339 // this collection. Some extensions may be disabled in incognito windows.
340 BrowserActionViews browser_action_views_;
341 339
342 Profile* profile_; 340 Profile* profile_;
343 341
344 // The Browser object the container is associated with. 342 // The Browser object the container is associated with.
345 Browser* browser_; 343 Browser* browser_;
346 344
347 // The main container we are serving as overflow for, or NULL if this 345 // The main container we are serving as overflow for, or NULL if this
348 // class is the the main container. See class comments for details on 346 // class is the the main container. See class comments for details on
349 // the difference between main and overflow. 347 // the difference between main and overflow.
350 BrowserActionsContainer* main_container_; 348 BrowserActionsContainer* main_container_;
351 349
352 // The view that triggered the current popup (just a reference to a view 350 // The view that triggered the current popup (just a reference to a view
353 // from browser_action_views_). 351 // from toolbar_action_views_).
354 BrowserActionView* popup_owner_; 352 ToolbarActionView* popup_owner_;
355 353
356 // The model that tracks the order of the toolbar icons. 354 // The model that tracks the order of the toolbar icons.
357 extensions::ExtensionToolbarModel* model_; 355 extensions::ExtensionToolbarModel* model_;
358 356
359 // The current width of the container. 357 // The current width of the container.
360 int container_width_; 358 int container_width_;
361 359
362 // The resize area for the container. 360 // The resize area for the container.
363 views::ResizeArea* resize_area_; 361 views::ResizeArea* resize_area_;
364 362
(...skipping 29 matching lines...) Expand all
394 ObserverList<BrowserActionsContainerObserver> observers_; 392 ObserverList<BrowserActionsContainerObserver> observers_;
395 393
396 // The maximum number of icons to show per row when in overflow mode (showing 394 // The maximum number of icons to show per row when in overflow mode (showing
397 // icons in the application menu). 395 // icons in the application menu).
398 static int icons_per_overflow_menu_row_; 396 static int icons_per_overflow_menu_row_;
399 397
400 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); 398 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer);
401 }; 399 };
402 400
403 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ 401 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/browser_action_view.cc ('k') | chrome/browser/ui/views/toolbar/browser_actions_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698