| 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/chrome_views_export.h" | |
| 12 #include "chrome/browser/ui/views/extensions/browser_action_overflow_menu_contro
ller.h" | 11 #include "chrome/browser/ui/views/extensions/browser_action_overflow_menu_contro
ller.h" |
| 13 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" | |
| 14 #include "chrome/browser/ui/views/extensions/extension_popup.h" | |
| 15 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" | 12 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" |
| 16 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h" | |
| 17 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
| 18 #include "ui/gfx/animation/animation_delegate.h" | 14 #include "ui/gfx/animation/animation_delegate.h" |
| 19 #include "ui/gfx/animation/tween.h" | 15 #include "ui/gfx/animation/tween.h" |
| 20 #include "ui/views/controls/button/menu_button.h" | |
| 21 #include "ui/views/controls/button/menu_button_listener.h" | 16 #include "ui/views/controls/button/menu_button_listener.h" |
| 22 #include "ui/views/controls/resize_area_delegate.h" | 17 #include "ui/views/controls/resize_area_delegate.h" |
| 23 #include "ui/views/drag_controller.h" | 18 #include "ui/views/drag_controller.h" |
| 24 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
| 25 #include "ui/views/widget/widget_observer.h" | |
| 26 | 20 |
| 27 class BrowserActionButton; | 21 class BrowserActionsContainerObserver; |
| 28 class ExtensionKeybindingRegistryViews; | 22 class ExtensionKeybindingRegistryViews; |
| 29 class ExtensionPopup; | 23 class ExtensionPopup; |
| 30 | 24 |
| 31 namespace extensions { | 25 namespace extensions { |
| 32 class ActiveTabPermissionGranter; | 26 class ActiveTabPermissionGranter; |
| 33 class Command; | 27 class Command; |
| 34 class Extension; | 28 class Extension; |
| 35 } | 29 } |
| 36 | 30 |
| 37 namespace gfx { | 31 namespace gfx { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // growing the container. | 122 // growing the container. |
| 129 // | 123 // |
| 130 //////////////////////////////////////////////////////////////////////////////// | 124 //////////////////////////////////////////////////////////////////////////////// |
| 131 class BrowserActionsContainer | 125 class BrowserActionsContainer |
| 132 : public views::View, | 126 : public views::View, |
| 133 public views::MenuButtonListener, | 127 public views::MenuButtonListener, |
| 134 public views::ResizeAreaDelegate, | 128 public views::ResizeAreaDelegate, |
| 135 public gfx::AnimationDelegate, | 129 public gfx::AnimationDelegate, |
| 136 public extensions::ExtensionToolbarModel::Observer, | 130 public extensions::ExtensionToolbarModel::Observer, |
| 137 public BrowserActionOverflowMenuController::Observer, | 131 public BrowserActionOverflowMenuController::Observer, |
| 138 public views::WidgetObserver, | |
| 139 public BrowserActionView::Delegate, | 132 public BrowserActionView::Delegate, |
| 140 public extensions::ExtensionKeybindingRegistry::Delegate { | 133 public extensions::ExtensionKeybindingRegistry::Delegate { |
| 141 public: | 134 public: |
| 142 // Constructs a BrowserActionContainer for a particular |browser| object, and | 135 // Constructs a BrowserActionContainer for a particular |browser| object, and |
| 143 // specifies which view is the |owner_view|. For documentation of | 136 // specifies which view is the |owner_view|. For documentation of |
| 144 // |main_container|, see class comments. | 137 // |main_container|, see class comments. |
| 145 BrowserActionsContainer(Browser* browser, | 138 BrowserActionsContainer(Browser* browser, |
| 146 views::View* owner_view, | 139 views::View* owner_view, |
| 147 BrowserActionsContainer* main_container); | 140 BrowserActionsContainer* main_container); |
| 148 virtual ~BrowserActionsContainer(); | 141 virtual ~BrowserActionsContainer(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 virtual void OnResize(int resize_amount, bool done_resizing) OVERRIDE; | 222 virtual void OnResize(int resize_amount, bool done_resizing) OVERRIDE; |
| 230 | 223 |
| 231 // Overridden from gfx::AnimationDelegate: | 224 // Overridden from gfx::AnimationDelegate: |
| 232 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; | 225 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; |
| 233 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; | 226 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; |
| 234 | 227 |
| 235 // Overridden from BrowserActionOverflowMenuController::Observer: | 228 // Overridden from BrowserActionOverflowMenuController::Observer: |
| 236 virtual void NotifyMenuDeleted( | 229 virtual void NotifyMenuDeleted( |
| 237 BrowserActionOverflowMenuController* controller) OVERRIDE; | 230 BrowserActionOverflowMenuController* controller) OVERRIDE; |
| 238 | 231 |
| 239 // Overridden from views::WidgetObserver: | |
| 240 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; | |
| 241 | |
| 242 // Overridden from BrowserActionView::Delegate: | 232 // Overridden from BrowserActionView::Delegate: |
| 243 virtual void InspectPopup(ExtensionAction* action) OVERRIDE; | |
| 244 virtual int GetCurrentTabId() const OVERRIDE; | 233 virtual int GetCurrentTabId() const OVERRIDE; |
| 245 virtual void OnBrowserActionExecuted(BrowserActionButton* button) OVERRIDE; | |
| 246 virtual void OnBrowserActionVisibilityChanged() OVERRIDE; | 234 virtual void OnBrowserActionVisibilityChanged() OVERRIDE; |
| 247 virtual bool ShownInsideMenu() const OVERRIDE; | 235 virtual bool ShownInsideMenu() const OVERRIDE; |
| 248 virtual void OnBrowserActionViewDragDone() OVERRIDE; | 236 virtual void OnBrowserActionViewDragDone() OVERRIDE; |
| 237 virtual views::View* GetOverflowReferenceView() OVERRIDE; |
| 238 virtual void SetPopupOwner(BrowserActionButton* popup_owner) OVERRIDE; |
| 239 virtual void HideActivePopup() OVERRIDE; |
| 240 virtual extensions::ExtensionToolbarModel* GetModel() OVERRIDE; |
| 249 | 241 |
| 250 // Overridden from extension::ExtensionKeybindingRegistry::Delegate: | 242 // Overridden from extension::ExtensionKeybindingRegistry::Delegate: |
| 251 virtual extensions::ActiveTabPermissionGranter* | 243 virtual extensions::ActiveTabPermissionGranter* |
| 252 GetActiveTabPermissionGranter() OVERRIDE; | 244 GetActiveTabPermissionGranter() OVERRIDE; |
| 253 | 245 |
| 254 // Moves a browser action with |id| to |new_index|. | 246 // Moves a browser action with |id| to |new_index|. |
| 255 void MoveBrowserAction(const std::string& extension_id, size_t new_index); | 247 void MoveBrowserAction(const std::string& extension_id, size_t new_index); |
| 256 | 248 |
| 257 // Shows the popup for |extension| if possible. Returns true if a new popup | 249 // Shows the popup for |extension| if possible. Returns true if a new popup |
| 258 // was shown. Showing the popup will grant tab permissions if | 250 // was shown. Showing the popup will grant active tab permissions if |
| 259 // |grant_tab_permissions| is true. Only pass true for this argument for | 251 // |grant_tab_permissions| is true. Only pass true for this argument for |
| 260 // popups triggered interactively, not popups triggered by an API. | 252 // popups triggered interactively, not popups triggered by an API. |
| 261 bool ShowPopup(const extensions::Extension* extension, | 253 // If |can_override| is true, this popup can override other popups (hiding |
| 262 bool grant_tab_permissions); | 254 // them) and does not have to be in the active window. |
| 263 | 255 bool ShowPopupForExtension(const extensions::Extension* extension, |
| 264 // Hide the current popup. | 256 bool grant_tab_permissions, |
| 265 void HidePopup(); | 257 bool can_override); |
| 266 | |
| 267 // Simulate a click on a browser action button. This should only be | |
| 268 // used by unit tests. | |
| 269 void TestExecuteBrowserAction(int index); | |
| 270 | 258 |
| 271 // Retrieve the current popup. This should only be used by unit tests. | 259 // Retrieve the current popup. This should only be used by unit tests. |
| 272 ExtensionPopup* TestGetPopup() { return popup_; } | 260 ExtensionPopup* TestGetPopup(); |
| 273 | 261 |
| 274 // Set how many icons the container should show. This should only be used by | 262 // Set how many icons the container should show. This should only be used by |
| 275 // unit tests. | 263 // unit tests. |
| 276 void TestSetIconVisibilityCount(size_t icons); | 264 void TestSetIconVisibilityCount(size_t icons); |
| 277 | 265 |
| 278 // During testing we can disable animations by setting this flag to true, | 266 // During testing we can disable animations by setting this flag to true, |
| 279 // so that the bar resizes instantly, instead of having to poll it while it | 267 // so that the bar resizes instantly, instead of having to poll it while it |
| 280 // animates to open/closed status. | 268 // animates to open/closed status. |
| 281 static bool disable_animations_during_testing_; | 269 static bool disable_animations_during_testing_; |
| 282 | 270 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 // the target size). This also saves the target number of visible icons in | 339 // the target size). This also saves the target number of visible icons in |
| 352 // the pref if we're not incognito. | 340 // the pref if we're not incognito. |
| 353 void SaveDesiredSizeAndAnimate(gfx::Tween::Type type, | 341 void SaveDesiredSizeAndAnimate(gfx::Tween::Type type, |
| 354 size_t num_visible_icons); | 342 size_t num_visible_icons); |
| 355 | 343 |
| 356 // Returns true if this extension should be shown in this toolbar. This can | 344 // Returns true if this extension should be shown in this toolbar. This can |
| 357 // return false if we are in an incognito window and the extension is disabled | 345 // return false if we are in an incognito window and the extension is disabled |
| 358 // for incognito. | 346 // for incognito. |
| 359 bool ShouldDisplayBrowserAction(const extensions::Extension* extension); | 347 bool ShouldDisplayBrowserAction(const extensions::Extension* extension); |
| 360 | 348 |
| 361 // Show a popup. Returns true if a new popup was shown. Showing the popup will | |
| 362 // grant tab permissions if |grant_tab_permissions| is true. Only pass true | |
| 363 // for this argument for popups triggered interactively, not popups triggered | |
| 364 // by an API. | |
| 365 bool ShowPopup(BrowserActionButton* button, | |
| 366 ExtensionPopup::ShowAction show_action, | |
| 367 bool grant_tab_permissions); | |
| 368 | |
| 369 // Return the index of the first visible icon. | 349 // Return the index of the first visible icon. |
| 370 size_t GetFirstVisibleIconIndex() const; | 350 size_t GetFirstVisibleIconIndex() const; |
| 371 | 351 |
| 372 // Whether this container is in overflow mode (as opposed to in 'main' | 352 // Whether this container is in overflow mode (as opposed to in 'main' |
| 373 // mode). See class comments for details on the difference. | 353 // mode). See class comments for details on the difference. |
| 374 bool in_overflow_mode() const { return main_container_ != NULL; } | 354 bool in_overflow_mode() const { return main_container_ != NULL; } |
| 375 | 355 |
| 376 // The vector of browser actions (icons/image buttons for each action). Note | 356 // The vector of browser actions (icons/image buttons for each action). Note |
| 377 // that not every BrowserAction in the ToolbarModel will necessarily be in | 357 // that not every BrowserAction in the ToolbarModel will necessarily be in |
| 378 // this collection. Some extensions may be disabled in incognito windows. | 358 // this collection. Some extensions may be disabled in incognito windows. |
| 379 BrowserActionViews browser_action_views_; | 359 BrowserActionViews browser_action_views_; |
| 380 | 360 |
| 381 Profile* profile_; | 361 Profile* profile_; |
| 382 | 362 |
| 383 // The Browser object the container is associated with. | 363 // The Browser object the container is associated with. |
| 384 Browser* browser_; | 364 Browser* browser_; |
| 385 | 365 |
| 386 // The view that owns us. | 366 // The view that owns us. |
| 387 views::View* owner_view_; | 367 views::View* owner_view_; |
| 388 | 368 |
| 389 // The main container we are serving as overflow for, or NULL if this | 369 // The main container we are serving as overflow for, or NULL if this |
| 390 // class is the the main container. See class comments for details on | 370 // class is the the main container. See class comments for details on |
| 391 // the difference between main and overflow. | 371 // the difference between main and overflow. |
| 392 BrowserActionsContainer* main_container_; | 372 BrowserActionsContainer* main_container_; |
| 393 | 373 |
| 394 // The current popup and the button it came from. NULL if no popup. | |
| 395 ExtensionPopup* popup_; | |
| 396 | |
| 397 // The button that triggered the current popup (just a reference to a button | 374 // The button that triggered the current popup (just a reference to a button |
| 398 // from browser_action_views_). | 375 // from browser_action_views_). |
| 399 BrowserActionButton* popup_button_; | 376 BrowserActionButton* popup_owner_; |
| 400 | 377 |
| 401 // The model that tracks the order of the toolbar icons. | 378 // The model that tracks the order of the toolbar icons. |
| 402 extensions::ExtensionToolbarModel* model_; | 379 extensions::ExtensionToolbarModel* model_; |
| 403 | 380 |
| 404 // The current width of the container. | 381 // The current width of the container. |
| 405 int container_width_; | 382 int container_width_; |
| 406 | 383 |
| 407 // The resize area for the container. | 384 // The resize area for the container. |
| 408 views::ResizeArea* resize_area_; | 385 views::ResizeArea* resize_area_; |
| 409 | 386 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 421 |
| 445 // Handles delayed showing of the overflow menu when hovering. | 422 // Handles delayed showing of the overflow menu when hovering. |
| 446 base::WeakPtrFactory<BrowserActionsContainer> show_menu_task_factory_; | 423 base::WeakPtrFactory<BrowserActionsContainer> show_menu_task_factory_; |
| 447 | 424 |
| 448 ObserverList<BrowserActionsContainerObserver> observers_; | 425 ObserverList<BrowserActionsContainerObserver> observers_; |
| 449 | 426 |
| 450 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); | 427 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); |
| 451 }; | 428 }; |
| 452 | 429 |
| 453 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ | 430 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ |
| OLD | NEW |