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