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" |
11 #include "chrome/browser/ui/views/extensions/browser_action_overflow_menu_contro
ller.h" | |
12 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" | 11 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" |
13 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" | 12 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" |
| 13 #include "chrome/browser/ui/views/toolbar/chevron_menu_button.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 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 // animation ends and we don't want the chevron to flash into view while we are | 120 // animation ends and we don't want the chevron to flash into view while we are |
121 // growing the container. | 121 // growing the container. |
122 // | 122 // |
123 //////////////////////////////////////////////////////////////////////////////// | 123 //////////////////////////////////////////////////////////////////////////////// |
124 class BrowserActionsContainer | 124 class BrowserActionsContainer |
125 : public views::View, | 125 : public views::View, |
126 public views::MenuButtonListener, | 126 public views::MenuButtonListener, |
127 public views::ResizeAreaDelegate, | 127 public views::ResizeAreaDelegate, |
128 public gfx::AnimationDelegate, | 128 public gfx::AnimationDelegate, |
129 public extensions::ExtensionToolbarModel::Observer, | 129 public extensions::ExtensionToolbarModel::Observer, |
130 public BrowserActionOverflowMenuController::Observer, | |
131 public BrowserActionView::Delegate, | 130 public BrowserActionView::Delegate, |
132 public extensions::ExtensionKeybindingRegistry::Delegate { | 131 public extensions::ExtensionKeybindingRegistry::Delegate { |
133 public: | 132 public: |
134 // 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 |
135 // the last item or chevron (if visible). | 134 // the last item or chevron (if visible). |
136 static const int kItemSpacing; | 135 static const int kItemSpacing; |
137 | 136 |
138 // Constructs a BrowserActionContainer for a particular |browser| object, and | 137 // Constructs a BrowserActionContainer for a particular |browser| object, and |
139 // specifies which view is the |owner_view|. For documentation of | 138 // specifies which view is the |owner_view|. For documentation of |
140 // |main_container|, see class comments. | 139 // |main_container|, see class comments. |
141 BrowserActionsContainer(Browser* browser, | 140 BrowserActionsContainer(Browser* browser, |
142 views::View* owner_view, | 141 views::View* owner_view, |
143 BrowserActionsContainer* main_container); | 142 BrowserActionsContainer* main_container); |
144 virtual ~BrowserActionsContainer(); | 143 virtual ~BrowserActionsContainer(); |
145 | 144 |
146 void Init(); | 145 void Init(); |
147 | 146 |
148 // Get the number of browser actions being displayed. | 147 // Get the number of browser actions being displayed. |
149 size_t num_browser_actions() const { return browser_action_views_.size(); } | 148 size_t num_browser_actions() const { return browser_action_views_.size(); } |
150 | 149 |
151 // Whether we are performing resize animation on the container. | 150 // Whether we are performing resize animation on the container. |
152 bool animating() const { return animation_target_size_ > 0; } | 151 bool animating() const { return animation_target_size_ > 0; } |
153 | 152 |
154 // Returns the chevron, if any. | 153 // Returns the chevron, if any. |
155 views::View* chevron() { return chevron_; } | 154 views::View* chevron() { return chevron_.get(); } |
156 const views::View* chevron() const { return chevron_; } | 155 const views::View* chevron() const { return chevron_.get(); } |
157 | 156 |
158 // Returns the profile this container is associated with. | 157 // Returns the profile this container is associated with. |
159 Profile* profile() const { return profile_; } | 158 Profile* profile() const { return profile_; } |
160 | 159 |
161 // The class that registers for keyboard shortcuts for extension commands. | 160 // The class that registers for keyboard shortcuts for extension commands. |
162 extensions::ExtensionKeybindingRegistry* extension_keybinding_registry() { | 161 extensions::ExtensionKeybindingRegistry* extension_keybinding_registry() { |
163 return extension_keybinding_registry_.get(); | 162 return extension_keybinding_registry_.get(); |
164 } | 163 } |
165 | 164 |
166 // Get a particular browser action view. | 165 // Get a particular browser action view. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 const gfx::Point& press_pt, | 231 const gfx::Point& press_pt, |
233 const gfx::Point& p) OVERRIDE; | 232 const gfx::Point& p) OVERRIDE; |
234 | 233 |
235 // Overridden from views::ResizeAreaDelegate: | 234 // Overridden from views::ResizeAreaDelegate: |
236 virtual void OnResize(int resize_amount, bool done_resizing) OVERRIDE; | 235 virtual void OnResize(int resize_amount, bool done_resizing) OVERRIDE; |
237 | 236 |
238 // Overridden from gfx::AnimationDelegate: | 237 // Overridden from gfx::AnimationDelegate: |
239 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; | 238 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; |
240 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; | 239 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; |
241 | 240 |
242 // Overridden from BrowserActionOverflowMenuController::Observer: | |
243 virtual void NotifyMenuDeleted( | |
244 BrowserActionOverflowMenuController* controller) OVERRIDE; | |
245 | |
246 // Overridden from BrowserActionView::Delegate: | 241 // Overridden from BrowserActionView::Delegate: |
247 virtual content::WebContents* GetCurrentWebContents() OVERRIDE; | 242 virtual content::WebContents* GetCurrentWebContents() OVERRIDE; |
248 virtual bool ShownInsideMenu() const OVERRIDE; | 243 virtual bool ShownInsideMenu() const OVERRIDE; |
249 virtual void OnBrowserActionViewDragDone() OVERRIDE; | 244 virtual void OnBrowserActionViewDragDone() OVERRIDE; |
250 virtual views::MenuButton* GetOverflowReferenceView() OVERRIDE; | 245 virtual views::MenuButton* GetOverflowReferenceView() OVERRIDE; |
251 virtual void SetPopupOwner(BrowserActionView* popup_owner) OVERRIDE; | 246 virtual void SetPopupOwner(BrowserActionView* popup_owner) OVERRIDE; |
252 virtual void HideActivePopup() OVERRIDE; | 247 virtual void HideActivePopup() OVERRIDE; |
253 virtual BrowserActionView* GetMainViewForExtension( | 248 virtual BrowserActionView* GetMainViewForExtension( |
254 const extensions::Extension* extension) OVERRIDE; | 249 const extensions::Extension* extension) OVERRIDE; |
255 | 250 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 void OnBrowserActionVisibilityChanged(); | 305 void OnBrowserActionVisibilityChanged(); |
311 | 306 |
312 // Returns the preferred width of the container in order to show all icons | 307 // Returns the preferred width of the container in order to show all icons |
313 // that should be visible and, optionally, the chevron. | 308 // that should be visible and, optionally, the chevron. |
314 int GetPreferredWidth(); | 309 int GetPreferredWidth(); |
315 | 310 |
316 // Sets the chevron to be visible or not based on whether all browser actions | 311 // Sets the chevron to be visible or not based on whether all browser actions |
317 // are displayed. | 312 // are displayed. |
318 void SetChevronVisibility(); | 313 void SetChevronVisibility(); |
319 | 314 |
320 // Closes the overflow menu if open. | |
321 void CloseOverflowMenu(); | |
322 | |
323 // Cancels the timer for showing the drop down menu. | |
324 void StopShowFolderDropMenuTimer(); | |
325 | |
326 // Show the drop down folder after a slight delay. | |
327 void StartShowFolderDropMenuTimer(); | |
328 | |
329 // Show the overflow menu. | |
330 void ShowDropFolder(); | |
331 | |
332 // Given a number of |icons| and whether to |display_chevron|, returns the | 315 // Given a number of |icons| and whether to |display_chevron|, returns the |
333 // amount of pixels needed to draw the entire container. For convenience, | 316 // amount of pixels needed to draw the entire container. For convenience, |
334 // callers can set |icons| to -1 to mean "all icons". | 317 // callers can set |icons| to -1 to mean "all icons". |
335 int IconCountToWidth(int icons, bool display_chevron) const; | 318 int IconCountToWidth(int icons, bool display_chevron) const; |
336 | 319 |
337 // Given a pixel width, returns the number of icons that fit. (This | 320 // Given a pixel width, returns the number of icons that fit. (This |
338 // automatically determines whether a chevron will be needed and includes it | 321 // automatically determines whether a chevron will be needed and includes it |
339 // in the calculation.) | 322 // in the calculation.) |
340 size_t WidthToIconCount(int pixels) const; | 323 size_t WidthToIconCount(int pixels) const; |
341 | 324 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 extensions::ExtensionToolbarModel* model_; | 374 extensions::ExtensionToolbarModel* model_; |
392 | 375 |
393 // The current width of the container. | 376 // The current width of the container. |
394 int container_width_; | 377 int container_width_; |
395 | 378 |
396 // The resize area for the container. | 379 // The resize area for the container. |
397 views::ResizeArea* resize_area_; | 380 views::ResizeArea* resize_area_; |
398 | 381 |
399 // The chevron for accessing the overflow items. Can be NULL when in overflow | 382 // The chevron for accessing the overflow items. Can be NULL when in overflow |
400 // mode or if the toolbar is permanently suppressing the chevron menu. | 383 // mode or if the toolbar is permanently suppressing the chevron menu. |
401 views::MenuButton* chevron_; | 384 scoped_ptr<ChevronMenuButton> chevron_; |
402 | 385 |
403 // The painter used when we are highlighting a subset of extensions. | 386 // The painter used when we are highlighting a subset of extensions. |
404 scoped_ptr<views::Painter> highlight_painter_; | 387 scoped_ptr<views::Painter> highlight_painter_; |
405 | 388 |
406 // The menu to show for the overflow button (chevron). This class manages its | |
407 // own lifetime so that it can stay alive during drag and drop operations. | |
408 BrowserActionOverflowMenuController* overflow_menu_; | |
409 | |
410 // The animation that happens when the container snaps to place. | 389 // The animation that happens when the container snaps to place. |
411 scoped_ptr<gfx::SlideAnimation> resize_animation_; | 390 scoped_ptr<gfx::SlideAnimation> resize_animation_; |
412 | 391 |
413 // Don't show the chevron while animating. | 392 // Don't show the chevron while animating. |
414 bool suppress_chevron_; | 393 bool suppress_chevron_; |
415 | 394 |
416 // This is used while the user is resizing (and when the animations are in | 395 // This is used while the user is resizing (and when the animations are in |
417 // progress) to know how wide the delta is between the current state and what | 396 // progress) to know how wide the delta is between the current state and what |
418 // we should draw. | 397 // we should draw. |
419 int resize_amount_; | 398 int resize_amount_; |
420 | 399 |
421 // Keeps track of the absolute pixel width the container should have when we | 400 // Keeps track of the absolute pixel width the container should have when we |
422 // are done animating. | 401 // are done animating. |
423 int animation_target_size_; | 402 int animation_target_size_; |
424 | 403 |
425 // The DropPosition for the current drag-and-drop operation, or NULL if there | 404 // The DropPosition for the current drag-and-drop operation, or NULL if there |
426 // is none. | 405 // is none. |
427 scoped_ptr<DropPosition> drop_position_; | 406 scoped_ptr<DropPosition> drop_position_; |
428 | 407 |
429 // The class that registers for keyboard shortcuts for extension commands. | 408 // The class that registers for keyboard shortcuts for extension commands. |
430 scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_; | 409 scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_; |
431 | 410 |
432 ObserverList<BrowserActionsContainerObserver> observers_; | 411 ObserverList<BrowserActionsContainerObserver> observers_; |
433 | 412 |
434 // The maximum number of icons to show per row when in overflow mode (showing | 413 // The maximum number of icons to show per row when in overflow mode (showing |
435 // icons in the application menu). | 414 // icons in the application menu). |
436 static int icons_per_overflow_menu_row_; | 415 static int icons_per_overflow_menu_row_; |
437 | 416 |
438 // Handles delayed showing of the overflow menu when hovering. | |
439 base::WeakPtrFactory<BrowserActionsContainer> show_menu_task_factory_; | |
440 | |
441 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); | 417 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); |
442 }; | 418 }; |
443 | 419 |
444 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ | 420 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ |
OLD | NEW |