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

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