| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ | 5 #ifndef CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ |
| 6 #define CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ | 6 #define CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "app/slide_animation.h" | 12 #include "app/slide_animation.h" |
| 13 #include "base/task.h" | 13 #include "base/task.h" |
| 14 #include "chrome/browser/extensions/extension_action_context_menu_model.h" | 14 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 15 #include "chrome/browser/extensions/extension_toolbar_model.h" | 15 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 16 #include "chrome/browser/extensions/image_loading_tracker.h" | 16 #include "chrome/browser/extensions/image_loading_tracker.h" |
| 17 #include "chrome/browser/views/browser_bubble.h" | 17 #include "chrome/browser/views/browser_bubble.h" |
| 18 #include "chrome/browser/views/extensions/browser_action_overflow_menu_controlle
r.h" | 18 #include "chrome/browser/views/extensions/browser_action_overflow_menu_controlle
r.h" |
| 19 #include "chrome/browser/views/extensions/extension_action_context_menu.h" | |
| 20 #include "chrome/browser/views/extensions/extension_popup.h" | 19 #include "chrome/browser/views/extensions/extension_popup.h" |
| 21 #include "chrome/common/notification_observer.h" | 20 #include "chrome/common/notification_observer.h" |
| 22 #include "chrome/common/notification_registrar.h" | 21 #include "chrome/common/notification_registrar.h" |
| 23 #include "views/controls/button/menu_button.h" | 22 #include "views/controls/button/menu_button.h" |
| 24 #include "views/controls/menu/view_menu_delegate.h" | 23 #include "views/controls/menu/view_menu_delegate.h" |
| 25 #include "views/controls/resize_gripper.h" | 24 #include "views/controls/resize_gripper.h" |
| 26 #include "views/view.h" | 25 #include "views/view.h" |
| 27 | 26 |
| 28 class Browser; | 27 class Browser; |
| 29 class BrowserActionsContainer; | 28 class BrowserActionsContainer; |
| 30 class BrowserActionOverflowMenuController; | 29 class BrowserActionOverflowMenuController; |
| 31 class BrowserActionsContainer; | 30 class BrowserActionsContainer; |
| 32 class Extension; | 31 class Extension; |
| 33 class ExtensionAction; | 32 class ExtensionAction; |
| 34 class ExtensionPopup; | 33 class ExtensionPopup; |
| 35 class PrefService; | 34 class PrefService; |
| 36 class Profile; | 35 class Profile; |
| 37 | 36 |
| 37 namespace views { |
| 38 class Menu2; |
| 39 } |
| 40 |
| 38 //////////////////////////////////////////////////////////////////////////////// | 41 //////////////////////////////////////////////////////////////////////////////// |
| 39 // BrowserActionButton | 42 // BrowserActionButton |
| 40 | 43 |
| 41 // The BrowserActionButton is a specialization of the MenuButton class. | 44 // The BrowserActionButton is a specialization of the MenuButton class. |
| 42 // It acts on a ExtensionAction, in this case a BrowserAction and handles | 45 // It acts on a ExtensionAction, in this case a BrowserAction and handles |
| 43 // loading the image for the button asynchronously on the file thread. | 46 // loading the image for the button asynchronously on the file thread. |
| 44 class BrowserActionButton : public views::MenuButton, | 47 class BrowserActionButton : public views::MenuButton, |
| 45 public views::ButtonListener, | 48 public views::ButtonListener, |
| 46 public ImageLoadingTracker::Observer, | 49 public ImageLoadingTracker::Observer, |
| 47 public NotificationObserver { | 50 public NotificationObserver { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 // Whether we are currently showing/just finished showing a context menu. | 112 // Whether we are currently showing/just finished showing a context menu. |
| 110 bool showing_context_menu_; | 113 bool showing_context_menu_; |
| 111 | 114 |
| 112 // The default icon for our browser action. This might be non-empty if the | 115 // The default icon for our browser action. This might be non-empty if the |
| 113 // browser action had a value for default_icon in the manifest. | 116 // browser action had a value for default_icon in the manifest. |
| 114 SkBitmap default_icon_; | 117 SkBitmap default_icon_; |
| 115 | 118 |
| 116 // The browser action shelf. | 119 // The browser action shelf. |
| 117 BrowserActionsContainer* panel_; | 120 BrowserActionsContainer* panel_; |
| 118 | 121 |
| 122 scoped_ptr<ExtensionContextMenuModel> context_menu_contents_; |
| 123 scoped_ptr<views::Menu2> context_menu_menu_; |
| 124 |
| 119 NotificationRegistrar registrar_; | 125 NotificationRegistrar registrar_; |
| 120 | 126 |
| 121 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); | 127 DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); |
| 122 }; | 128 }; |
| 123 | 129 |
| 124 | 130 |
| 125 //////////////////////////////////////////////////////////////////////////////// | 131 //////////////////////////////////////////////////////////////////////////////// |
| 126 // BrowserActionView | 132 // BrowserActionView |
| 127 // A single section in the browser action container. This contains the actual | 133 // A single section in the browser action container. This contains the actual |
| 128 // BrowserActionButton, as well as the logic to paint the badge. | 134 // BrowserActionButton, as well as the logic to paint the badge. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 // | 232 // |
| 227 //////////////////////////////////////////////////////////////////////////////// | 233 //////////////////////////////////////////////////////////////////////////////// |
| 228 class BrowserActionsContainer | 234 class BrowserActionsContainer |
| 229 : public views::View, | 235 : public views::View, |
| 230 public views::ViewMenuDelegate, | 236 public views::ViewMenuDelegate, |
| 231 public views::DragController, | 237 public views::DragController, |
| 232 public views::ResizeGripper::ResizeGripperDelegate, | 238 public views::ResizeGripper::ResizeGripperDelegate, |
| 233 public AnimationDelegate, | 239 public AnimationDelegate, |
| 234 public ExtensionToolbarModel::Observer, | 240 public ExtensionToolbarModel::Observer, |
| 235 public BrowserActionOverflowMenuController::Observer, | 241 public BrowserActionOverflowMenuController::Observer, |
| 236 public ExtensionActionContextMenuModel::MenuDelegate, | 242 public ExtensionContextMenuModel::PopupDelegate, |
| 237 public ExtensionPopup::Observer { | 243 public ExtensionPopup::Observer { |
| 238 | 244 |
| 239 friend class ShowFolderMenuTask; | 245 friend class ShowFolderMenuTask; |
| 240 public: | 246 public: |
| 241 BrowserActionsContainer(Browser* browser, views::View* owner_view); | 247 BrowserActionsContainer(Browser* browser, views::View* owner_view); |
| 242 virtual ~BrowserActionsContainer(); | 248 virtual ~BrowserActionsContainer(); |
| 243 | 249 |
| 244 static void RegisterUserPrefs(PrefService* prefs); | 250 static void RegisterUserPrefs(PrefService* prefs); |
| 245 | 251 |
| 246 // Get the number of browser actions being displayed. | 252 // Get the number of browser actions being displayed. |
| 247 int num_browser_actions() const { return browser_action_views_.size(); } | 253 int num_browser_actions() const { return browser_action_views_.size(); } |
| 248 | 254 |
| 249 // Whether we are performing resize animation on the container. | 255 // Whether we are performing resize animation on the container. |
| 250 bool animating() const { return animation_target_size_ > 0; } | 256 bool animating() const { return animation_target_size_ > 0; } |
| 251 | 257 |
| 252 // Returns the chevron, if any. | 258 // Returns the chevron, if any. |
| 253 const views::View* chevron() const { return chevron_; } | 259 const views::View* chevron() const { return chevron_; } |
| 254 | 260 |
| 255 // Returns the profile this container is associated with. | 261 // Returns the profile this container is associated with. |
| 256 Profile* profile() const { return profile_; } | 262 Profile* profile() const { return profile_; } |
| 257 | 263 |
| 258 // Returns the context menu for Browser Actions. Constructs the menu object if | 264 // Returns the browser this container is associated with. |
| 259 // not constructed yet. This menu is used for all browser actions (regardless | 265 Browser* browser() const { return browser_; } |
| 260 // of whether they are in the overflow menu or not). | |
| 261 ExtensionActionContextMenu* GetContextMenu(); | |
| 262 | 266 |
| 263 // Returns the current tab's ID, or -1 if there is no current tab. | 267 // Returns the current tab's ID, or -1 if there is no current tab. |
| 264 int GetCurrentTabId() const; | 268 int GetCurrentTabId() const; |
| 265 | 269 |
| 266 // Get a particular browser action view. | 270 // Get a particular browser action view. |
| 267 BrowserActionView* GetBrowserActionViewAt(int index) { | 271 BrowserActionView* GetBrowserActionViewAt(int index) { |
| 268 return browser_action_views_[index]; | 272 return browser_action_views_[index]; |
| 269 } | 273 } |
| 270 | 274 |
| 271 // Retrieve the BrowserActionView for |extension|. | 275 // Retrieve the BrowserActionView for |extension|. |
| 272 BrowserActionView* GetBrowserActionView(Extension* extension); | 276 BrowserActionView* GetBrowserActionView(ExtensionAction* action); |
| 273 | 277 |
| 274 // Update the views to reflect the state of the browser action icons. | 278 // Update the views to reflect the state of the browser action icons. |
| 275 void RefreshBrowserActionViews(); | 279 void RefreshBrowserActionViews(); |
| 276 | 280 |
| 277 // Sets up the browser action view vector. | 281 // Sets up the browser action view vector. |
| 278 void CreateBrowserActionViews(); | 282 void CreateBrowserActionViews(); |
| 279 | 283 |
| 280 // Delete all browser action views. | 284 // Delete all browser action views. |
| 281 void DeleteBrowserActionViews(); | 285 void DeleteBrowserActionViews(); |
| 282 | 286 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 virtual void OnResize(int resize_amount, bool done_resizing); | 326 virtual void OnResize(int resize_amount, bool done_resizing); |
| 323 | 327 |
| 324 // Overridden from AnimationDelegate: | 328 // Overridden from AnimationDelegate: |
| 325 virtual void AnimationProgressed(const Animation* animation); | 329 virtual void AnimationProgressed(const Animation* animation); |
| 326 virtual void AnimationEnded(const Animation* animation); | 330 virtual void AnimationEnded(const Animation* animation); |
| 327 | 331 |
| 328 // Overridden from BrowserActionOverflowMenuController::Observer: | 332 // Overridden from BrowserActionOverflowMenuController::Observer: |
| 329 virtual void NotifyMenuDeleted( | 333 virtual void NotifyMenuDeleted( |
| 330 BrowserActionOverflowMenuController* controller); | 334 BrowserActionOverflowMenuController* controller); |
| 331 | 335 |
| 332 // Overridden from ExtensionActionContextMenuModel::MenuDelegate | 336 // Overridden from ExtensionContextMenuModel::PopupDelegate |
| 333 virtual void ShowPopupForDevToolsWindow(Extension* extension, | 337 virtual void InspectPopup(ExtensionAction* action); |
| 334 ExtensionAction* extension_action); | |
| 335 | 338 |
| 336 // Overriden from ExtensionPopup::Delegate | 339 // Overriden from ExtensionPopup::Delegate |
| 337 virtual void ExtensionPopupClosed(ExtensionPopup* popup); | 340 virtual void ExtensionPopupClosed(ExtensionPopup* popup); |
| 338 | 341 |
| 339 // Moves a browser action with |id| to |new_index|. | 342 // Moves a browser action with |id| to |new_index|. |
| 340 void MoveBrowserAction(const std::string& extension_id, size_t new_index); | 343 void MoveBrowserAction(const std::string& extension_id, size_t new_index); |
| 341 | 344 |
| 342 // Hide the current popup. | 345 // Hide the current popup. |
| 343 void HidePopup(); | 346 void HidePopup(); |
| 344 | 347 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 359 static bool disable_animations_during_testing_; | 362 static bool disable_animations_during_testing_; |
| 360 | 363 |
| 361 private: | 364 private: |
| 362 typedef std::vector<BrowserActionView*> BrowserActionViews; | 365 typedef std::vector<BrowserActionView*> BrowserActionViews; |
| 363 | 366 |
| 364 // ExtensionToolbarModel::Observer implementation. | 367 // ExtensionToolbarModel::Observer implementation. |
| 365 virtual void BrowserActionAdded(Extension* extension, int index); | 368 virtual void BrowserActionAdded(Extension* extension, int index); |
| 366 virtual void BrowserActionRemoved(Extension* extension); | 369 virtual void BrowserActionRemoved(Extension* extension); |
| 367 virtual void BrowserActionMoved(Extension* extension, int index); | 370 virtual void BrowserActionMoved(Extension* extension, int index); |
| 368 | 371 |
| 369 // Closes the overflow and context menu if open. | 372 // Closes the overflow menu if open. |
| 370 void CloseMenus(); | 373 void CloseOverflowMenu(); |
| 371 | 374 |
| 372 // Cancels the timer for showing the drop down menu. | 375 // Cancels the timer for showing the drop down menu. |
| 373 void StopShowFolderDropMenuTimer(); | 376 void StopShowFolderDropMenuTimer(); |
| 374 | 377 |
| 375 // Show the drop down folder after a slight delay. | 378 // Show the drop down folder after a slight delay. |
| 376 void StartShowFolderDropMenuTimer(); | 379 void StartShowFolderDropMenuTimer(); |
| 377 | 380 |
| 378 // Show the overflow menu. | 381 // Show the overflow menu. |
| 379 void ShowDropFolder(); | 382 void ShowDropFolder(); |
| 380 | 383 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 // The resize gripper for the container. | 445 // The resize gripper for the container. |
| 443 views::ResizeGripper* resize_gripper_; | 446 views::ResizeGripper* resize_gripper_; |
| 444 | 447 |
| 445 // The chevron for accessing the overflow items. | 448 // The chevron for accessing the overflow items. |
| 446 views::MenuButton* chevron_; | 449 views::MenuButton* chevron_; |
| 447 | 450 |
| 448 // The menu to show for the overflow button (chevron). This class manages its | 451 // The menu to show for the overflow button (chevron). This class manages its |
| 449 // own lifetime so that it can stay alive during drag and drop operations. | 452 // own lifetime so that it can stay alive during drag and drop operations. |
| 450 BrowserActionOverflowMenuController* overflow_menu_; | 453 BrowserActionOverflowMenuController* overflow_menu_; |
| 451 | 454 |
| 452 // The context menu that the overflow menu shows. Is NULL until the menu is | |
| 453 // shown for the first time. | |
| 454 scoped_ptr<ExtensionActionContextMenu> context_menu_; | |
| 455 | |
| 456 // The animation that happens when the container snaps to place. | 455 // The animation that happens when the container snaps to place. |
| 457 scoped_ptr<SlideAnimation> resize_animation_; | 456 scoped_ptr<SlideAnimation> resize_animation_; |
| 458 | 457 |
| 459 // Don't show the chevron while animating. | 458 // Don't show the chevron while animating. |
| 460 bool suppress_chevron_; | 459 bool suppress_chevron_; |
| 461 | 460 |
| 462 // This is used while the user is resizing (and when the animations are in | 461 // This is used while the user is resizing (and when the animations are in |
| 463 // progress) to know how wide the delta is between the current state and what | 462 // progress) to know how wide the delta is between the current state and what |
| 464 // we should draw. | 463 // we should draw. |
| 465 int resize_amount_; | 464 int resize_amount_; |
| 466 | 465 |
| 467 // Keeps track of the absolute pixel width the container should have when we | 466 // Keeps track of the absolute pixel width the container should have when we |
| 468 // are done animating. | 467 // are done animating. |
| 469 int animation_target_size_; | 468 int animation_target_size_; |
| 470 | 469 |
| 471 // The x position for where to draw the drop indicator. -1 if no indicator. | 470 // The x position for where to draw the drop indicator. -1 if no indicator. |
| 472 int drop_indicator_position_; | 471 int drop_indicator_position_; |
| 473 | 472 |
| 474 ScopedRunnableMethodFactory<BrowserActionsContainer> task_factory_; | 473 ScopedRunnableMethodFactory<BrowserActionsContainer> task_factory_; |
| 475 | 474 |
| 476 // Handles delayed showing of the overflow menu when hovering. | 475 // Handles delayed showing of the overflow menu when hovering. |
| 477 ScopedRunnableMethodFactory<BrowserActionsContainer> show_menu_task_factory_; | 476 ScopedRunnableMethodFactory<BrowserActionsContainer> show_menu_task_factory_; |
| 478 | 477 |
| 479 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); | 478 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); |
| 480 }; | 479 }; |
| 481 | 480 |
| 482 #endif // CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ | 481 #endif // CHROME_BROWSER_VIEWS_BROWSER_ACTIONS_CONTAINER_H_ |
| OLD | NEW |