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

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

Issue 324393002: Extension Toolbar redesign, part 1 (overflow) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Linux width issue Created 6 years, 5 months 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 | Annotate | Revision Log
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"
(...skipping 24 matching lines...) Expand all
35 } 35 }
36 36
37 namespace gfx { 37 namespace gfx {
38 class SlideAnimation; 38 class SlideAnimation;
39 } 39 }
40 40
41 namespace views { 41 namespace views {
42 class ResizeArea; 42 class ResizeArea;
43 } 43 }
44 44
45 //////////////////////////////////////////////////////////////////////////////// 45 // The BrowserActionsContainer is a container view, responsible for drawing the
46 // browser action icons (extensions that add icons to the toolbar). It comes in
47 // two flavors, a main container (when residing on the toolbar) and an overflow
48 // container (that resides in the main application menu, known as the
49 // hot dog/hamburger menu).
Peter Kasting 2014/06/30 23:36:34 Nit: Again, do not use "hot dog" or "hamburger" to
Finnur 2014/07/02 16:59:56 Done.
46 // 50 //
47 // The BrowserActionsContainer is a container view, responsible for drawing the 51 // When in 'main' mode, the container supports the full functionality of a
48 // browser action icons (extensions that add icons to the toolbar). 52 // BrowserActionContainer but in 'overflow' mode the container is effectively
Peter Kasting 2014/06/30 23:36:33 Nit: BrowserActionContainer but -> BrowserActionCo
Finnur 2014/07/02 16:59:56 Done.
53 // just an overflow for the 'main' toolbar (shows only the icons that the main
54 // toolbar does not) and as such does not have an overflow itself. The overflow
55 // container also does not support resizing. Since the main container only shows
56 // icons in the Chrome toolbar, it is limited to a single row of icons. The
57 // overflow container, however, is allowed to display icons in multiple rows.
49 // 58 //
50 // The container is placed flush against the omnibox and wrench menu, and its 59 // The main container is placed flush against the omnibox and hot dog menu,
51 // layout looks like: 60 // whereas the overflow container is placed within the hot dog menu. The
61 // layout is similar to this:
52 // rI_I_IcCs 62 // rI_I_IcCs
53 // Where the letters are as follows: 63 // Where the letters are as follows:
54 // r: An invisible resize area. This is ToolbarView::kStandardSpacing pixels 64 // r: An invisible resize area. This is ToolbarView::kStandardSpacing pixels
55 // wide and directly adjacent to the omnibox. 65 // wide and directly adjacent to the omnibox. Only shown for the main
66 // container.
56 // I: An icon. This is as wide as the IDR_BROWSER_ACTION image. 67 // I: An icon. This is as wide as the IDR_BROWSER_ACTION image.
57 // _: kItemSpacing pixels of empty space. 68 // _: kItemSpacing pixels of empty space.
58 // c: kChevronSpacing pixels of empty space. Only present if C is present. 69 // c: kChevronSpacing pixels of empty space. Only present if C is present.
59 // C: An optional chevron, visible for overflow. As wide as the 70 // C: An optional chevron, as wide as the IDR_BROWSER_ACTIONS_OVERFLOW image,
60 // IDR_BROWSER_ACTIONS_OVERFLOW image. 71 // and visible only when all of the following statements are true:
72 // - This is the main container.
Peter Kasting 2014/06/30 23:36:34 Nit: This point is already clear from the fact tha
Finnur 2014/07/02 16:59:57 Done.
73 // - The container is set to a width smaller than needed to show all icons.
74 // - There is no other container in 'overflow' mode to handle the
75 // non-visible icons for this container.
76 // NOTE: When the BrowserActionsContainer is in 'overflow mode', the icons
77 // for the 'main' container overflow to a special overflow container
78 // inside the wrench menu.
Peter Kasting 2014/06/30 23:36:33 Nit: This NOTE seems like a rehash of comments abo
Finnur 2014/07/02 16:59:57 Done.
61 // s: ToolbarView::kStandardSpacing pixels of empty space (before the wrench 79 // s: ToolbarView::kStandardSpacing pixels of empty space (before the wrench
62 // menu). 80 // menu).
63 // The reason the container contains the trailing space "s", rather than having 81 // The reason the container contains the trailing space "s", rather than having
64 // it be handled by the parent view, is so that when the chevron is invisible 82 // it be handled by the parent view, is so that when the chevron is invisible
65 // and the user starts dragging an icon around, we have the space to draw the 83 // and the user starts dragging an icon around, we have the space to draw the
66 // ultimate drop indicator. (Otherwise, we'd be trying to draw it into the 84 // ultimate drop indicator. (Otherwise, we'd be trying to draw it into the
67 // padding beyond our right edge, and it wouldn't appear.) 85 // padding beyond our right edge, and it wouldn't appear.)
68 // 86 //
69 // The BrowserActionsContainer follows a few rules, in terms of user experience: 87 // The BrowserActionsContainer in 'main' mode follows a few rules, in terms of
88 // user experience:
70 // 89 //
71 // 1) The container can never grow beyond the space needed to show all icons 90 // 1) The container can never grow beyond the space needed to show all icons
72 // (hereby referred to as the max width). 91 // (hereby referred to as the max width).
73 // 2) The container can never shrink below the space needed to show just the 92 // 2) The container can never shrink below the space needed to show just the
74 // initial padding and the chevron (ignoring the case where there are no icons 93 // initial padding and the chevron (ignoring the case where there are no icons
75 // to show, in which case the container won't be visible anyway). 94 // to show, in which case the container won't be visible anyway).
76 // 3) The container snaps into place (to the pixel count that fits the visible 95 // 3) The container snaps into place (to the pixel count that fits the visible
77 // icons) to make sure there is no wasted space at the edges of the container. 96 // icons) to make sure there is no wasted space at the edges of the container.
78 // 4) If the user adds or removes icons (read: installs/uninstalls browser 97 // 4) If the user adds or removes icons (read: installs/uninstalls browser
79 // actions) we grow and shrink the container as needed - but ONLY if the 98 // actions) we grow and shrink the container as needed - but ONLY if the
80 // container was at max width to begin with. 99 // container was at max width to begin with.
81 // 5) If the container is NOT at max width (has an overflow menu), we respect 100 // 5) If the container is NOT at max width (has an overflow menu), we respect
82 // that size when adding and removing icons and DON'T grow/shrink the container. 101 // that size when adding and removing icons and DON'T grow/shrink the container.
83 // This means that new icons (which always appear at the far right) will show up 102 // This means that new icons (which always appear at the far right) will show up
84 // in the overflow menu. The install bubble for extensions points to the chevron 103 // in the overflow. The install bubble for extensions points to the chevron
85 // menu in this case. 104 // menu in this case.
86 // 105 //
87 // Resizing the BrowserActionsContainer: 106 // Resizing the BrowserActionsContainer:
88 // 107 //
89 // The ResizeArea view sends OnResize messages to the BrowserActionsContainer 108 // The ResizeArea view sends OnResize messages to the BrowserActionsContainer
90 // class as the user drags it. This modifies the value for |resize_amount_|. 109 // class as the user drags it. This modifies the value for |resize_amount_|.
91 // That indicates to the container that a resize is in progress and is used to 110 // That indicates to the container that a resize is in progress and is used to
92 // calculate the size in GetPreferredSize(), though that function never exceeds 111 // calculate the size in GetPreferredSize(), though that function never exceeds
93 // the defined minimum and maximum size of the container. 112 // the defined minimum and maximum size of the container.
94 // 113 //
(...skipping 23 matching lines...) Expand all
118 : public views::View, 137 : public views::View,
119 public views::MenuButtonListener, 138 public views::MenuButtonListener,
120 public views::ResizeAreaDelegate, 139 public views::ResizeAreaDelegate,
121 public gfx::AnimationDelegate, 140 public gfx::AnimationDelegate,
122 public extensions::ExtensionToolbarModel::Observer, 141 public extensions::ExtensionToolbarModel::Observer,
123 public BrowserActionOverflowMenuController::Observer, 142 public BrowserActionOverflowMenuController::Observer,
124 public views::WidgetObserver, 143 public views::WidgetObserver,
125 public BrowserActionView::Delegate, 144 public BrowserActionView::Delegate,
126 public extensions::ExtensionKeybindingRegistry::Delegate { 145 public extensions::ExtensionKeybindingRegistry::Delegate {
127 public: 146 public:
128 BrowserActionsContainer(Browser* browser, views::View* owner_view); 147 // Constructs a BrowserActionContainer for a particular |browser| object, and
148 // specifies which view is the |owner_view|. For documentation of
149 // |main_container_|, see class comments.
Peter Kasting 2014/06/30 23:36:34 Nit: No trailing underscore
Finnur 2014/07/02 16:59:57 Done.
150 BrowserActionsContainer(Browser* browser,
151 views::View* owner_view,
152 BrowserActionsContainer* main_container);
129 virtual ~BrowserActionsContainer(); 153 virtual ~BrowserActionsContainer();
130 154
131 void Init(); 155 void Init();
132 156
133 // Get the number of browser actions being displayed. 157 // Get the number of browser actions being displayed.
134 int num_browser_actions() const { return browser_action_views_.size(); } 158 int num_browser_actions() const { return browser_action_views_.size(); }
135 159
136 // Whether we are performing resize animation on the container. 160 // Whether we are performing resize animation on the container.
137 bool animating() const { return animation_target_size_ > 0; } 161 bool animating() const { return animation_target_size_ > 0; }
138 162
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 BrowserActionOverflowMenuController* controller) OVERRIDE; 242 BrowserActionOverflowMenuController* controller) OVERRIDE;
219 243
220 // Overridden from views::WidgetObserver: 244 // Overridden from views::WidgetObserver:
221 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 245 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
222 246
223 // Overridden from BrowserActionView::Delegate: 247 // Overridden from BrowserActionView::Delegate:
224 virtual void InspectPopup(ExtensionAction* action) OVERRIDE; 248 virtual void InspectPopup(ExtensionAction* action) OVERRIDE;
225 virtual int GetCurrentTabId() const OVERRIDE; 249 virtual int GetCurrentTabId() const OVERRIDE;
226 virtual void OnBrowserActionExecuted(BrowserActionButton* button) OVERRIDE; 250 virtual void OnBrowserActionExecuted(BrowserActionButton* button) OVERRIDE;
227 virtual void OnBrowserActionVisibilityChanged() OVERRIDE; 251 virtual void OnBrowserActionVisibilityChanged() OVERRIDE;
252 virtual bool ShownInsideMenu() const OVERRIDE;
228 253
229 // Overridden from extension::ExtensionKeybindingRegistry::Delegate: 254 // Overridden from extension::ExtensionKeybindingRegistry::Delegate:
230 virtual extensions::ActiveTabPermissionGranter* 255 virtual extensions::ActiveTabPermissionGranter*
231 GetActiveTabPermissionGranter() OVERRIDE; 256 GetActiveTabPermissionGranter() OVERRIDE;
232 257
233 // Moves a browser action with |id| to |new_index|. 258 // Moves a browser action with |id| to |new_index|.
234 void MoveBrowserAction(const std::string& extension_id, size_t new_index); 259 void MoveBrowserAction(const std::string& extension_id, size_t new_index);
235 260
236 // Shows the popup for |extension| if possible. Returns true if a new popup 261 // Shows the popup for |extension| if possible. Returns true if a new popup
237 // was shown. Showing the popup will grant tab permissions if 262 // was shown. Showing the popup will grant tab permissions if
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 bool ShouldDisplayBrowserAction(const extensions::Extension* extension); 364 bool ShouldDisplayBrowserAction(const extensions::Extension* extension);
340 365
341 // Show a popup. Returns true if a new popup was shown. Showing the popup will 366 // Show a popup. Returns true if a new popup was shown. Showing the popup will
342 // grant tab permissions if |grant_tab_permissions| is true. Only pass true 367 // grant tab permissions if |grant_tab_permissions| is true. Only pass true
343 // for this argument for popups triggered interactively, not popups triggered 368 // for this argument for popups triggered interactively, not popups triggered
344 // by an API. 369 // by an API.
345 bool ShowPopup(BrowserActionButton* button, 370 bool ShowPopup(BrowserActionButton* button,
346 ExtensionPopup::ShowAction show_action, 371 ExtensionPopup::ShowAction show_action,
347 bool grant_tab_permissions); 372 bool grant_tab_permissions);
348 373
374 // Whether this container is overflow container (as opposed to in 'main'
Peter Kasting 2014/06/30 23:36:34 Nit: overflow container -> in overflow mode (or sa
Peter Kasting 2014/07/02 20:54:00 You should still do this.
Finnur 2014/07/03 13:59:31 Indeed.
375 // mode). See class comments for details on the difference.
376 bool handling_overflow() const { return main_container_ != NULL; }
Peter Kasting 2014/06/30 23:36:34 Nit: handling_overflow() is a rather confusing nam
Finnur 2014/07/02 16:59:56 Changed it to in_overflow_mode. I think that is th
377
349 // The vector of browser actions (icons/image buttons for each action). Note 378 // The vector of browser actions (icons/image buttons for each action). Note
350 // that not every BrowserAction in the ToolbarModel will necessarily be in 379 // that not every BrowserAction in the ToolbarModel will necessarily be in
351 // this collection. Some extensions may be disabled in incognito windows. 380 // this collection. Some extensions may be disabled in incognito windows.
352 BrowserActionViews browser_action_views_; 381 BrowserActionViews browser_action_views_;
353 382
354 Profile* profile_; 383 Profile* profile_;
355 384
356 // The Browser object the container is associated with. 385 // The Browser object the container is associated with.
357 Browser* browser_; 386 Browser* browser_;
358 387
359 // The view that owns us. 388 // The view that owns us.
360 views::View* owner_view_; 389 views::View* owner_view_;
361 390
391 // The main container we are serving as overflow for, or NULL if this
392 // class is the the main container. See class comments for details on
393 // the difference between main and overflow.
394 BrowserActionsContainer* main_container_;
395
362 // The current popup and the button it came from. NULL if no popup. 396 // The current popup and the button it came from. NULL if no popup.
363 ExtensionPopup* popup_; 397 ExtensionPopup* popup_;
364 398
365 // The button that triggered the current popup (just a reference to a button 399 // The button that triggered the current popup (just a reference to a button
366 // from browser_action_views_). 400 // from browser_action_views_).
367 BrowserActionButton* popup_button_; 401 BrowserActionButton* popup_button_;
368 402
369 // The model that tracks the order of the toolbar icons. 403 // The model that tracks the order of the toolbar icons.
370 extensions::ExtensionToolbarModel* model_; 404 extensions::ExtensionToolbarModel* model_;
371 405
372 // The current width of the container. 406 // The current width of the container.
373 int container_width_; 407 int container_width_;
374 408
375 // The resize area for the container. 409 // The resize area for the container.
376 views::ResizeArea* resize_area_; 410 views::ResizeArea* resize_area_;
377 411
378 // The chevron for accessing the overflow items. 412 // The chevron for accessing the overflow items. Can be NULL if the toolbar
413 // is permanently suppressing the chevron menu.
Peter Kasting 2014/06/30 23:36:34 Nit: "NULL when in overflow mode or when the toolb
Finnur 2014/07/02 16:59:56 Done.
379 views::MenuButton* chevron_; 414 views::MenuButton* chevron_;
380 415
381 // The painter used when we are highlighting a subset of extensions. 416 // The painter used when we are highlighting a subset of extensions.
382 scoped_ptr<views::Painter> highlight_painter_; 417 scoped_ptr<views::Painter> highlight_painter_;
383 418
384 // The menu to show for the overflow button (chevron). This class manages its 419 // The menu to show for the overflow button (chevron). This class manages its
385 // own lifetime so that it can stay alive during drag and drop operations. 420 // own lifetime so that it can stay alive during drag and drop operations.
386 BrowserActionOverflowMenuController* overflow_menu_; 421 BrowserActionOverflowMenuController* overflow_menu_;
387 422
388 // The animation that happens when the container snaps to place. 423 // The animation that happens when the container snaps to place.
(...skipping 21 matching lines...) Expand all
410 445
411 // Handles delayed showing of the overflow menu when hovering. 446 // Handles delayed showing of the overflow menu when hovering.
412 base::WeakPtrFactory<BrowserActionsContainer> show_menu_task_factory_; 447 base::WeakPtrFactory<BrowserActionsContainer> show_menu_task_factory_;
413 448
414 ObserverList<BrowserActionsContainerObserver> observers_; 449 ObserverList<BrowserActionsContainerObserver> observers_;
415 450
416 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); 451 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer);
417 }; 452 };
418 453
419 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ 454 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698