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

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: Crash fix for Linux Created 6 years, 6 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).
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
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, visible only for the main container, and only when
60 // IDR_BROWSER_ACTIONS_OVERFLOW image. 71 // it has icons that don't fit in the space allocated for it. As wide as
Devlin 2014/06/26 16:29:13 nit: "don't fit in the space allocated for it and
Finnur 2014/06/27 14:23:38 The wording was becoming a bit convoluted so I att
Devlin 2014/06/27 15:19:28 Ah, much better. Thanks :)
72 // the IDR_BROWSER_ACTIONS_OVERFLOW image. When the BrowserActionsContainer
73 // is in 'overflow mode', the icons overflow to a special overflow
74 // container inside the wrench menu.
61 // s: ToolbarView::kStandardSpacing pixels of empty space (before the wrench 75 // s: ToolbarView::kStandardSpacing pixels of empty space (before the wrench
62 // menu). 76 // menu).
63 // The reason the container contains the trailing space "s", rather than having 77 // 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 78 // 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 79 // 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 80 // ultimate drop indicator. (Otherwise, we'd be trying to draw it into the
67 // padding beyond our right edge, and it wouldn't appear.) 81 // padding beyond our right edge, and it wouldn't appear.)
68 // 82 //
69 // The BrowserActionsContainer follows a few rules, in terms of user experience: 83 // The BrowserActionsContainer in 'main' mode follows a few rules, in terms of
84 // user experience:
70 // 85 //
71 // 1) The container can never grow beyond the space needed to show all icons 86 // 1) The container can never grow beyond the space needed to show all icons
72 // (hereby referred to as the max width). 87 // (hereby referred to as the max width).
73 // 2) The container can never shrink below the space needed to show just the 88 // 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 89 // 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). 90 // 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 91 // 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. 92 // 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 93 // 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 94 // actions) we grow and shrink the container as needed - but ONLY if the
80 // container was at max width to begin with. 95 // container was at max width to begin with.
81 // 5) If the container is NOT at max width (has an overflow menu), we respect 96 // 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. 97 // 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 98 // 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 99 // in the overflow. The install bubble for extensions points to the chevron
85 // menu in this case. 100 // menu in this case.
86 // 101 //
87 // Resizing the BrowserActionsContainer: 102 // Resizing the BrowserActionsContainer:
88 // 103 //
89 // The ResizeArea view sends OnResize messages to the BrowserActionsContainer 104 // The ResizeArea view sends OnResize messages to the BrowserActionsContainer
90 // class as the user drags it. This modifies the value for |resize_amount_|. 105 // 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 106 // 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 107 // calculate the size in GetPreferredSize(), though that function never exceeds
93 // the defined minimum and maximum size of the container. 108 // the defined minimum and maximum size of the container.
94 // 109 //
(...skipping 23 matching lines...) Expand all
118 : public views::View, 133 : public views::View,
119 public views::MenuButtonListener, 134 public views::MenuButtonListener,
120 public views::ResizeAreaDelegate, 135 public views::ResizeAreaDelegate,
121 public gfx::AnimationDelegate, 136 public gfx::AnimationDelegate,
122 public extensions::ExtensionToolbarModel::Observer, 137 public extensions::ExtensionToolbarModel::Observer,
123 public BrowserActionOverflowMenuController::Observer, 138 public BrowserActionOverflowMenuController::Observer,
124 public views::WidgetObserver, 139 public views::WidgetObserver,
125 public BrowserActionView::Delegate, 140 public BrowserActionView::Delegate,
126 public extensions::ExtensionKeybindingRegistry::Delegate { 141 public extensions::ExtensionKeybindingRegistry::Delegate {
127 public: 142 public:
128 BrowserActionsContainer(Browser* browser, views::View* owner_view); 143 // Constructs a BrowserActionContainer for a particular |browser| object, and
144 // specifies which view is the |owner_view|. For documentation of
145 // |main_container_|, see class comments.
146 BrowserActionsContainer(Browser* browser,
147 views::View* owner_view,
148 BrowserActionsContainer* main_container);
129 virtual ~BrowserActionsContainer(); 149 virtual ~BrowserActionsContainer();
130 150
131 void Init(); 151 void Init();
132 152
133 // Get the number of browser actions being displayed. 153 // Get the number of browser actions being displayed.
134 int num_browser_actions() const { return browser_action_views_.size(); } 154 int num_browser_actions() const { return browser_action_views_.size(); }
135 155
136 // Whether we are performing resize animation on the container. 156 // Whether we are performing resize animation on the container.
137 bool animating() const { return animation_target_size_ > 0; } 157 bool animating() const { return animation_target_size_ > 0; }
138 158
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 BrowserActionOverflowMenuController* controller) OVERRIDE; 238 BrowserActionOverflowMenuController* controller) OVERRIDE;
219 239
220 // Overridden from views::WidgetObserver: 240 // Overridden from views::WidgetObserver:
221 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 241 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
222 242
223 // Overridden from BrowserActionView::Delegate: 243 // Overridden from BrowserActionView::Delegate:
224 virtual void InspectPopup(ExtensionAction* action) OVERRIDE; 244 virtual void InspectPopup(ExtensionAction* action) OVERRIDE;
225 virtual int GetCurrentTabId() const OVERRIDE; 245 virtual int GetCurrentTabId() const OVERRIDE;
226 virtual void OnBrowserActionExecuted(BrowserActionButton* button) OVERRIDE; 246 virtual void OnBrowserActionExecuted(BrowserActionButton* button) OVERRIDE;
227 virtual void OnBrowserActionVisibilityChanged() OVERRIDE; 247 virtual void OnBrowserActionVisibilityChanged() OVERRIDE;
248 virtual bool ShownInsideMenu() const OVERRIDE;
228 249
229 // Overridden from extension::ExtensionKeybindingRegistry::Delegate: 250 // Overridden from extension::ExtensionKeybindingRegistry::Delegate:
230 virtual extensions::ActiveTabPermissionGranter* 251 virtual extensions::ActiveTabPermissionGranter*
231 GetActiveTabPermissionGranter() OVERRIDE; 252 GetActiveTabPermissionGranter() OVERRIDE;
232 253
233 // Moves a browser action with |id| to |new_index|. 254 // Moves a browser action with |id| to |new_index|.
234 void MoveBrowserAction(const std::string& extension_id, size_t new_index); 255 void MoveBrowserAction(const std::string& extension_id, size_t new_index);
235 256
236 // Shows the popup for |extension| if possible. Returns true if a new popup 257 // Shows the popup for |extension| if possible. Returns true if a new popup
237 // was shown. Showing the popup will grant tab permissions if 258 // 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); 360 bool ShouldDisplayBrowserAction(const extensions::Extension* extension);
340 361
341 // Show a popup. Returns true if a new popup was shown. Showing the popup will 362 // 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 363 // grant tab permissions if |grant_tab_permissions| is true. Only pass true
343 // for this argument for popups triggered interactively, not popups triggered 364 // for this argument for popups triggered interactively, not popups triggered
344 // by an API. 365 // by an API.
345 bool ShowPopup(BrowserActionButton* button, 366 bool ShowPopup(BrowserActionButton* button,
346 ExtensionPopup::ShowAction show_action, 367 ExtensionPopup::ShowAction show_action,
347 bool grant_tab_permissions); 368 bool grant_tab_permissions);
348 369
370 // Whether this container is overflow container (as opposed to in 'main'
371 // mode). See class comments for details on the difference.
372 bool handling_overflow() const { return main_container_ != NULL; }
373
349 // The vector of browser actions (icons/image buttons for each action). Note 374 // The vector of browser actions (icons/image buttons for each action). Note
350 // that not every BrowserAction in the ToolbarModel will necessarily be in 375 // that not every BrowserAction in the ToolbarModel will necessarily be in
351 // this collection. Some extensions may be disabled in incognito windows. 376 // this collection. Some extensions may be disabled in incognito windows.
352 BrowserActionViews browser_action_views_; 377 BrowserActionViews browser_action_views_;
353 378
354 Profile* profile_; 379 Profile* profile_;
355 380
356 // The Browser object the container is associated with. 381 // The Browser object the container is associated with.
357 Browser* browser_; 382 Browser* browser_;
358 383
359 // The view that owns us. 384 // The view that owns us.
360 views::View* owner_view_; 385 views::View* owner_view_;
361 386
387 // The main container we are serving as overflow for, or NULL if this
388 // class is the the main container. See class comments for details on
389 // the difference between main and overflow.
390 BrowserActionsContainer* main_container_;
391
362 // The current popup and the button it came from. NULL if no popup. 392 // The current popup and the button it came from. NULL if no popup.
363 ExtensionPopup* popup_; 393 ExtensionPopup* popup_;
364 394
365 // The button that triggered the current popup (just a reference to a button 395 // The button that triggered the current popup (just a reference to a button
366 // from browser_action_views_). 396 // from browser_action_views_).
367 BrowserActionButton* popup_button_; 397 BrowserActionButton* popup_button_;
368 398
369 // The model that tracks the order of the toolbar icons. 399 // The model that tracks the order of the toolbar icons.
370 extensions::ExtensionToolbarModel* model_; 400 extensions::ExtensionToolbarModel* model_;
371 401
372 // The current width of the container. 402 // The current width of the container.
373 int container_width_; 403 int container_width_;
374 404
375 // The resize area for the container. 405 // The resize area for the container.
376 views::ResizeArea* resize_area_; 406 views::ResizeArea* resize_area_;
377 407
378 // The chevron for accessing the overflow items. 408 // The chevron for accessing the overflow items. Can be NULL if the toolbar
409 // is permanently suppressing the chevron menu.
379 views::MenuButton* chevron_; 410 views::MenuButton* chevron_;
380 411
381 // The painter used when we are highlighting a subset of extensions. 412 // The painter used when we are highlighting a subset of extensions.
382 scoped_ptr<views::Painter> highlight_painter_; 413 scoped_ptr<views::Painter> highlight_painter_;
383 414
384 // The menu to show for the overflow button (chevron). This class manages its 415 // 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. 416 // own lifetime so that it can stay alive during drag and drop operations.
386 BrowserActionOverflowMenuController* overflow_menu_; 417 BrowserActionOverflowMenuController* overflow_menu_;
387 418
388 // The animation that happens when the container snaps to place. 419 // The animation that happens when the container snaps to place.
(...skipping 21 matching lines...) Expand all
410 441
411 // Handles delayed showing of the overflow menu when hovering. 442 // Handles delayed showing of the overflow menu when hovering.
412 base::WeakPtrFactory<BrowserActionsContainer> show_menu_task_factory_; 443 base::WeakPtrFactory<BrowserActionsContainer> show_menu_task_factory_;
413 444
414 ObserverList<BrowserActionsContainerObserver> observers_; 445 ObserverList<BrowserActionsContainerObserver> observers_;
415 446
416 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); 447 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer);
417 }; 448 };
418 449
419 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ 450 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698