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

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

Issue 597783002: Make the chevron menu button responsible for legacy overflow menu logic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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"
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // 116 //
117 // NOTE: When adding Browser Actions to a maximum width container (no overflow) 117 // NOTE: When adding Browser Actions to a maximum width container (no overflow)
118 // we make sure to suppress the chevron menu if it wasn't visible. This is 118 // we make sure to suppress the chevron menu if it wasn't visible. This is
119 // because we won't have enough space to show the new Browser Action until the 119 // because we won't have enough space to show the new Browser Action until the
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,
127 public views::ResizeAreaDelegate, 126 public views::ResizeAreaDelegate,
128 public gfx::AnimationDelegate, 127 public gfx::AnimationDelegate,
129 public extensions::ExtensionToolbarModel::Observer, 128 public extensions::ExtensionToolbarModel::Observer,
130 public BrowserActionOverflowMenuController::Observer,
131 public BrowserActionView::Delegate, 129 public BrowserActionView::Delegate,
132 public extensions::ExtensionKeybindingRegistry::Delegate { 130 public extensions::ExtensionKeybindingRegistry::Delegate {
133 public: 131 public:
134 // Horizontal spacing between most items in the container, as well as after 132 // Horizontal spacing between most items in the container, as well as after
135 // the last item or chevron (if visible). 133 // the last item or chevron (if visible).
136 static const int kItemSpacing; 134 static const int kItemSpacing;
137 135
138 // Constructs a BrowserActionContainer for a particular |browser| object, and 136 // Constructs a BrowserActionContainer for a particular |browser| object, and
139 // specifies which view is the |owner_view|. For documentation of 137 // specifies which view is the |owner_view|. For documentation of
140 // |main_container|, see class comments. 138 // |main_container|, see class comments.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 virtual void Layout() OVERRIDE; 209 virtual void Layout() OVERRIDE;
212 virtual bool GetDropFormats(int* formats, 210 virtual bool GetDropFormats(int* formats,
213 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE; 211 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE;
214 virtual bool AreDropTypesRequired() OVERRIDE; 212 virtual bool AreDropTypesRequired() OVERRIDE;
215 virtual bool CanDrop(const ui::OSExchangeData& data) OVERRIDE; 213 virtual bool CanDrop(const ui::OSExchangeData& data) OVERRIDE;
216 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE; 214 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
217 virtual void OnDragExited() OVERRIDE; 215 virtual void OnDragExited() OVERRIDE;
218 virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE; 216 virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
219 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; 217 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
220 218
221 // Overridden from views::MenuButtonListener:
222 virtual void OnMenuButtonClicked(views::View* source,
223 const gfx::Point& point) OVERRIDE;
224
225 // Overridden from views::DragController: 219 // Overridden from views::DragController:
226 virtual void WriteDragDataForView(View* sender, 220 virtual void WriteDragDataForView(View* sender,
227 const gfx::Point& press_pt, 221 const gfx::Point& press_pt,
228 ui::OSExchangeData* data) OVERRIDE; 222 ui::OSExchangeData* data) OVERRIDE;
229 virtual int GetDragOperationsForView(View* sender, 223 virtual int GetDragOperationsForView(View* sender,
230 const gfx::Point& p) OVERRIDE; 224 const gfx::Point& p) OVERRIDE;
231 virtual bool CanStartDragForView(View* sender, 225 virtual bool CanStartDragForView(View* sender,
232 const gfx::Point& press_pt, 226 const gfx::Point& press_pt,
233 const gfx::Point& p) OVERRIDE; 227 const gfx::Point& p) OVERRIDE;
234 228
235 // Overridden from views::ResizeAreaDelegate: 229 // Overridden from views::ResizeAreaDelegate:
236 virtual void OnResize(int resize_amount, bool done_resizing) OVERRIDE; 230 virtual void OnResize(int resize_amount, bool done_resizing) OVERRIDE;
237 231
238 // Overridden from gfx::AnimationDelegate: 232 // Overridden from gfx::AnimationDelegate:
239 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; 233 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
240 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; 234 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
241 235
242 // Overridden from BrowserActionOverflowMenuController::Observer:
243 virtual void NotifyMenuDeleted(
244 BrowserActionOverflowMenuController* controller) OVERRIDE;
245
246 // Overridden from BrowserActionView::Delegate: 236 // Overridden from BrowserActionView::Delegate:
247 virtual content::WebContents* GetCurrentWebContents() OVERRIDE; 237 virtual content::WebContents* GetCurrentWebContents() OVERRIDE;
248 virtual bool ShownInsideMenu() const OVERRIDE; 238 virtual bool ShownInsideMenu() const OVERRIDE;
249 virtual void OnBrowserActionViewDragDone() OVERRIDE; 239 virtual void OnBrowserActionViewDragDone() OVERRIDE;
250 virtual views::MenuButton* GetOverflowReferenceView() OVERRIDE; 240 virtual views::MenuButton* GetOverflowReferenceView() OVERRIDE;
251 virtual void SetPopupOwner(BrowserActionView* popup_owner) OVERRIDE; 241 virtual void SetPopupOwner(BrowserActionView* popup_owner) OVERRIDE;
252 virtual void HideActivePopup() OVERRIDE; 242 virtual void HideActivePopup() OVERRIDE;
253 virtual BrowserActionView* GetMainViewForExtension( 243 virtual BrowserActionView* GetMainViewForExtension(
254 const extensions::Extension* extension) OVERRIDE; 244 const extensions::Extension* extension) OVERRIDE;
255 245
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 void OnBrowserActionVisibilityChanged(); 300 void OnBrowserActionVisibilityChanged();
311 301
312 // Returns the preferred width of the container in order to show all icons 302 // Returns the preferred width of the container in order to show all icons
313 // that should be visible and, optionally, the chevron. 303 // that should be visible and, optionally, the chevron.
314 int GetPreferredWidth(); 304 int GetPreferredWidth();
315 305
316 // Sets the chevron to be visible or not based on whether all browser actions 306 // Sets the chevron to be visible or not based on whether all browser actions
317 // are displayed. 307 // are displayed.
318 void SetChevronVisibility(); 308 void SetChevronVisibility();
319 309
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 310 // Given a number of |icons| and whether to |display_chevron|, returns the
333 // amount of pixels needed to draw the entire container. For convenience, 311 // amount of pixels needed to draw the entire container. For convenience,
334 // callers can set |icons| to -1 to mean "all icons". 312 // callers can set |icons| to -1 to mean "all icons".
335 int IconCountToWidth(int icons, bool display_chevron) const; 313 int IconCountToWidth(int icons, bool display_chevron) const;
336 314
337 // Given a pixel width, returns the number of icons that fit. (This 315 // Given a pixel width, returns the number of icons that fit. (This
338 // automatically determines whether a chevron will be needed and includes it 316 // automatically determines whether a chevron will be needed and includes it
339 // in the calculation.) 317 // in the calculation.)
340 size_t WidthToIconCount(int pixels) const; 318 size_t WidthToIconCount(int pixels) const;
341 319
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 extensions::ExtensionToolbarModel* model_; 369 extensions::ExtensionToolbarModel* model_;
392 370
393 // The current width of the container. 371 // The current width of the container.
394 int container_width_; 372 int container_width_;
395 373
396 // The resize area for the container. 374 // The resize area for the container.
397 views::ResizeArea* resize_area_; 375 views::ResizeArea* resize_area_;
398 376
399 // The chevron for accessing the overflow items. Can be NULL when in overflow 377 // 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. 378 // mode or if the toolbar is permanently suppressing the chevron menu.
401 views::MenuButton* chevron_; 379 ChevronMenuButton* chevron_;
402 380
403 // The painter used when we are highlighting a subset of extensions. 381 // The painter used when we are highlighting a subset of extensions.
404 scoped_ptr<views::Painter> highlight_painter_; 382 scoped_ptr<views::Painter> highlight_painter_;
405 383
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. 384 // The animation that happens when the container snaps to place.
411 scoped_ptr<gfx::SlideAnimation> resize_animation_; 385 scoped_ptr<gfx::SlideAnimation> resize_animation_;
412 386
413 // Don't show the chevron while animating. 387 // Don't show the chevron while animating.
414 bool suppress_chevron_; 388 bool suppress_chevron_;
415 389
416 // This is used while the user is resizing (and when the animations are in 390 // 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 391 // progress) to know how wide the delta is between the current state and what
418 // we should draw. 392 // we should draw.
419 int resize_amount_; 393 int resize_amount_;
420 394
421 // Keeps track of the absolute pixel width the container should have when we 395 // Keeps track of the absolute pixel width the container should have when we
422 // are done animating. 396 // are done animating.
423 int animation_target_size_; 397 int animation_target_size_;
424 398
425 // The DropPosition for the current drag-and-drop operation, or NULL if there 399 // The DropPosition for the current drag-and-drop operation, or NULL if there
426 // is none. 400 // is none.
427 scoped_ptr<DropPosition> drop_position_; 401 scoped_ptr<DropPosition> drop_position_;
428 402
429 // The class that registers for keyboard shortcuts for extension commands. 403 // The class that registers for keyboard shortcuts for extension commands.
430 scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_; 404 scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_;
431 405
432 ObserverList<BrowserActionsContainerObserver> observers_; 406 ObserverList<BrowserActionsContainerObserver> observers_;
433 407
434 // The maximum number of icons to show per row when in overflow mode (showing 408 // The maximum number of icons to show per row when in overflow mode (showing
435 // icons in the application menu). 409 // icons in the application menu).
436 static int icons_per_overflow_menu_row_; 410 static int icons_per_overflow_menu_row_;
437 411
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); 412 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer);
442 }; 413 };
443 414
444 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ 415 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698