| 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/extension_keybinding_registry_views
.h" | 11 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" |
| 12 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" | |
| 13 #include "chrome/browser/ui/views/toolbar/chevron_menu_button.h" | 12 #include "chrome/browser/ui/views/toolbar/chevron_menu_button.h" |
| 13 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.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 |
| 24 namespace extensions { | 24 namespace extensions { |
| 25 class ActiveTabPermissionGranter; | 25 class ActiveTabPermissionGranter; |
| 26 class Command; | 26 class Command; |
| 27 class Extension; | 27 class Extension; |
| 28 } | 28 } |
| 29 | 29 |
| 30 namespace gfx { | 30 namespace gfx { |
| 31 class SlideAnimation; | 31 class SlideAnimation; |
| 32 } | 32 } |
| 33 | 33 |
| 34 namespace views { | 34 namespace views { |
| 35 class ResizeArea; | 35 class ResizeArea; |
| 36 } | 36 } |
| 37 | 37 |
| 38 // The BrowserActionsContainer is a container view, responsible for drawing the | 38 // The BrowserActionsContainer is a container view, responsible for drawing the |
| 39 // browser action icons (extensions that add icons to the toolbar). It comes in | 39 // toolbar action icons (including extension icons and icons for component |
| 40 // two flavors, a main container (when residing on the toolbar) and an overflow | 40 // toolbar actions). It comes intwo flavors, a main container (when residing on |
| 41 // container (that resides in the main application menu, aka the Chrome menu). | 41 // the toolbar) and an overflow container (that resides in the main application |
| 42 // menu, aka the Chrome menu). |
| 42 // | 43 // |
| 43 // When in 'main' mode, the container supports the full functionality of a | 44 // When in 'main' mode, the container supports the full functionality of a |
| 44 // BrowserActionContainer, but in 'overflow' mode the container is effectively | 45 // BrowserActionContainer, but in 'overflow' mode the container is effectively |
| 45 // just an overflow for the 'main' toolbar (shows only the icons that the main | 46 // just an overflow for the 'main' toolbar (shows only the icons that the main |
| 46 // toolbar does not) and as such does not have an overflow itself. The overflow | 47 // toolbar does not) and as such does not have an overflow itself. The overflow |
| 47 // container also does not support resizing. Since the main container only shows | 48 // container also does not support resizing. Since the main container only shows |
| 48 // icons in the Chrome toolbar, it is limited to a single row of icons. The | 49 // icons in the Chrome toolbar, it is limited to a single row of icons. The |
| 49 // overflow container, however, is allowed to display icons in multiple rows. | 50 // overflow container, however, is allowed to display icons in multiple rows. |
| 50 // | 51 // |
| 51 // The main container is placed flush against the omnibox and hot dog menu, | 52 // The main container is placed flush against the omnibox and hot dog menu, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // because we won't have enough space to show the new Browser Action until the | 120 // 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 | 121 // animation ends and we don't want the chevron to flash into view while we are |
| 121 // growing the container. | 122 // growing the container. |
| 122 // | 123 // |
| 123 //////////////////////////////////////////////////////////////////////////////// | 124 //////////////////////////////////////////////////////////////////////////////// |
| 124 class BrowserActionsContainer | 125 class BrowserActionsContainer |
| 125 : public views::View, | 126 : public views::View, |
| 126 public views::ResizeAreaDelegate, | 127 public views::ResizeAreaDelegate, |
| 127 public gfx::AnimationDelegate, | 128 public gfx::AnimationDelegate, |
| 128 public extensions::ExtensionToolbarModel::Observer, | 129 public extensions::ExtensionToolbarModel::Observer, |
| 129 public BrowserActionView::Delegate, | 130 public ToolbarActionView::Delegate, |
| 130 public extensions::ExtensionKeybindingRegistry::Delegate { | 131 public extensions::ExtensionKeybindingRegistry::Delegate { |
| 131 public: | 132 public: |
| 132 // 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 |
| 133 // the last item or chevron (if visible). | 134 // the last item or chevron (if visible). |
| 134 static const int kItemSpacing; | 135 static const int kItemSpacing; |
| 135 | 136 |
| 136 // Constructs a BrowserActionContainer for a particular |browser| object. For | 137 // Constructs a BrowserActionContainer for a particular |browser| object. For |
| 137 // documentation of |main_container|, see class comments. | 138 // documentation of |main_container|, see class comments. |
| 138 BrowserActionsContainer(Browser* browser, | 139 BrowserActionsContainer(Browser* browser, |
| 139 BrowserActionsContainer* main_container); | 140 BrowserActionsContainer* main_container); |
| 140 virtual ~BrowserActionsContainer(); | 141 virtual ~BrowserActionsContainer(); |
| 141 | 142 |
| 142 void Init(); | 143 void Init(); |
| 143 | 144 |
| 144 // Get the number of browser actions being displayed. | 145 // Get the number of toolbar actions being displayed. |
| 145 size_t num_browser_actions() const { return browser_action_views_.size(); } | 146 size_t num_toolbar_actions() const { return toolbar_action_views_.size(); } |
| 146 | 147 |
| 147 // Whether we are performing resize animation on the container. | 148 // Whether we are performing resize animation on the container. |
| 148 bool animating() const { return animation_target_size_ > 0; } | 149 bool animating() const { return animation_target_size_ > 0; } |
| 149 | 150 |
| 150 // Returns the chevron, if any. | 151 // Returns the chevron, if any. |
| 151 views::View* chevron() { return chevron_; } | 152 views::View* chevron() { return chevron_; } |
| 152 const views::View* chevron() const { return chevron_; } | 153 const views::View* chevron() const { return chevron_; } |
| 153 | 154 |
| 154 // Returns the profile this container is associated with. | 155 // Returns the profile this container is associated with. |
| 155 Profile* profile() const { return profile_; } | 156 Profile* profile() const { return profile_; } |
| 156 | 157 |
| 157 // The class that registers for keyboard shortcuts for extension commands. | 158 // The class that registers for keyboard shortcuts for extension commands. |
| 158 extensions::ExtensionKeybindingRegistry* extension_keybinding_registry() { | 159 extensions::ExtensionKeybindingRegistry* extension_keybinding_registry() { |
| 159 return extension_keybinding_registry_.get(); | 160 return extension_keybinding_registry_.get(); |
| 160 } | 161 } |
| 161 | 162 |
| 162 // Get a particular browser action view. | 163 // Get a particular toolbar action view. |
| 163 BrowserActionView* GetBrowserActionViewAt(int index) { | 164 ToolbarActionView* GetToolbarActionViewAt(int index) { |
| 164 return browser_action_views_[index]; | 165 return toolbar_action_views_[index]; |
| 165 } | 166 } |
| 166 | 167 |
| 167 // Returns the ID of the action represented by the view at |index|. | 168 // Returns the ID of the action represented by the view at |index|. |
| 168 const std::string& GetIdAt(size_t index); | 169 const std::string& GetIdAt(size_t index); |
| 169 | 170 |
| 170 // Returns the BrowserActionView* associated with the given |extension|, or | 171 // Returns the ToolbarActionView* associated with the given |extension|, or |
| 171 // NULL if none exists. | 172 // NULL if none exists. |
| 172 BrowserActionView* GetViewForExtension( | 173 ToolbarActionView* GetViewForExtension( |
| 173 const extensions::Extension* extension); | 174 const extensions::Extension* extension); |
| 174 | 175 |
| 175 // Update the views to reflect the state of the browser action icons. | 176 // Update the views to reflect the state of the toolbar actions. |
| 176 void RefreshBrowserActionViews(); | 177 void RefreshToolbarActionViews(); |
| 177 | 178 |
| 178 // Sets up the browser action view vector. | 179 // Sets up the toolbar action view vector. |
| 179 void CreateBrowserActionViews(); | 180 void CreateToolbarActionViews(); |
| 180 | 181 |
| 181 // Delete all browser action views. | 182 // Delete all toolbar action views. |
| 182 void DeleteBrowserActionViews(); | 183 void DeleteToolbarActionViews(); |
| 183 | 184 |
| 184 // Returns how many browser actions are currently visible. If the intent is | 185 // Returns how many actions are currently visible. If the intent is to find |
| 185 // to find how many are visible once the container finishes animation, see | 186 // how many are visible once the container finishes animation, see |
| 186 // VisibleBrowserActionsAfterAnimation() below. | 187 // VisibleBrowserActionsAfterAnimation() below. |
| 187 size_t VisibleBrowserActions() const; | 188 size_t VisibleBrowserActions() const; |
| 188 | 189 |
| 189 // Returns how many browser actions will be visible once the container | 190 // Returns how many actions will be visible once the container finishes |
| 190 // finishes animating to a new size, or (if not animating) the currently | 191 // animating to a new size, or (if not animating) the currently visible icons. |
| 191 // visible icons. | |
| 192 size_t VisibleBrowserActionsAfterAnimation() const; | 192 size_t VisibleBrowserActionsAfterAnimation() const; |
| 193 | 193 |
| 194 // Executes |command| registered by |extension|. | 194 // Executes |command| registered by |extension|. |
| 195 void ExecuteExtensionCommand(const extensions::Extension* extension, | 195 void ExecuteExtensionCommand(const extensions::Extension* extension, |
| 196 const extensions::Command& command); | 196 const extensions::Command& command); |
| 197 | 197 |
| 198 // Notify the browser action container that an extension has been moved to | 198 // Notify the container that an extension has been moved to the overflow |
| 199 // the overflow container. | 199 // container. |
| 200 void NotifyActionMovedToOverflow(); | 200 void NotifyActionMovedToOverflow(); |
| 201 | 201 |
| 202 // Add or remove an observer. | 202 // Add or remove an observer. |
| 203 void AddObserver(BrowserActionsContainerObserver* observer); | 203 void AddObserver(BrowserActionsContainerObserver* observer); |
| 204 void RemoveObserver(BrowserActionsContainerObserver* observer); | 204 void RemoveObserver(BrowserActionsContainerObserver* observer); |
| 205 | 205 |
| 206 // Overridden from views::View: | 206 // Overridden from views::View: |
| 207 virtual gfx::Size GetPreferredSize() const override; | 207 virtual gfx::Size GetPreferredSize() const override; |
| 208 virtual int GetHeightForWidth(int width) const override; | 208 virtual int GetHeightForWidth(int width) const override; |
| 209 virtual gfx::Size GetMinimumSize() const override; | 209 virtual gfx::Size GetMinimumSize() const override; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 227 const gfx::Point& press_pt, | 227 const gfx::Point& press_pt, |
| 228 const gfx::Point& p) override; | 228 const gfx::Point& p) override; |
| 229 | 229 |
| 230 // Overridden from views::ResizeAreaDelegate: | 230 // Overridden from views::ResizeAreaDelegate: |
| 231 virtual void OnResize(int resize_amount, bool done_resizing) override; | 231 virtual void OnResize(int resize_amount, bool done_resizing) override; |
| 232 | 232 |
| 233 // Overridden from gfx::AnimationDelegate: | 233 // Overridden from gfx::AnimationDelegate: |
| 234 virtual void AnimationProgressed(const gfx::Animation* animation) override; | 234 virtual void AnimationProgressed(const gfx::Animation* animation) override; |
| 235 virtual void AnimationEnded(const gfx::Animation* animation) override; | 235 virtual void AnimationEnded(const gfx::Animation* animation) override; |
| 236 | 236 |
| 237 // Overridden from BrowserActionView::Delegate: | 237 // Overridden from ToolbarActionView::Delegate: |
| 238 virtual content::WebContents* GetCurrentWebContents() override; | 238 virtual content::WebContents* GetCurrentWebContents() override; |
| 239 virtual bool ShownInsideMenu() const override; | 239 virtual bool ShownInsideMenu() const override; |
| 240 virtual void OnBrowserActionViewDragDone() override; | 240 virtual void OnToolbarActionViewDragDone() override; |
| 241 virtual views::MenuButton* GetOverflowReferenceView() override; | 241 virtual views::MenuButton* GetOverflowReferenceView() override; |
| 242 virtual void SetPopupOwner(BrowserActionView* popup_owner) override; | 242 virtual void SetPopupOwner(ToolbarActionView* popup_owner) override; |
| 243 virtual void HideActivePopup() override; | 243 virtual void HideActivePopup() override; |
| 244 virtual BrowserActionView* GetMainViewForAction( | 244 virtual ToolbarActionView* GetMainViewForAction( |
| 245 BrowserActionView* view) override; | 245 ToolbarActionView* view) override; |
| 246 | 246 |
| 247 // Overridden from extension::ExtensionKeybindingRegistry::Delegate: | 247 // Overridden from extension::ExtensionKeybindingRegistry::Delegate: |
| 248 virtual extensions::ActiveTabPermissionGranter* | 248 virtual extensions::ActiveTabPermissionGranter* |
| 249 GetActiveTabPermissionGranter() override; | 249 GetActiveTabPermissionGranter() override; |
| 250 | 250 |
| 251 // Retrieve the current popup. This should only be used by unit tests. | 251 // Retrieve the current popup. This should only be used by unit tests. |
| 252 gfx::NativeView TestGetPopup(); | 252 gfx::NativeView TestGetPopup(); |
| 253 | 253 |
| 254 // Returns the width of an icon, optionally with its padding. | 254 // Returns the width of an icon, optionally with its padding. |
| 255 static int IconWidth(bool include_padding); | 255 static int IconWidth(bool include_padding); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 266 // Overridden from views::View: | 266 // Overridden from views::View: |
| 267 virtual void ViewHierarchyChanged( | 267 virtual void ViewHierarchyChanged( |
| 268 const ViewHierarchyChangedDetails& details) override; | 268 const ViewHierarchyChangedDetails& details) override; |
| 269 virtual void OnPaint(gfx::Canvas* canvas) override; | 269 virtual void OnPaint(gfx::Canvas* canvas) override; |
| 270 virtual void OnThemeChanged() override; | 270 virtual void OnThemeChanged() override; |
| 271 | 271 |
| 272 private: | 272 private: |
| 273 // A struct representing the position at which an action will be dropped. | 273 // A struct representing the position at which an action will be dropped. |
| 274 struct DropPosition; | 274 struct DropPosition; |
| 275 | 275 |
| 276 typedef std::vector<BrowserActionView*> BrowserActionViews; | 276 typedef std::vector<ToolbarActionView*> ToolbarActionViews; |
| 277 | 277 |
| 278 // extensions::ExtensionToolbarModel::Observer implementation. | 278 // extensions::ExtensionToolbarModel::Observer implementation. |
| 279 virtual void ToolbarExtensionAdded(const extensions::Extension* extension, | 279 virtual void ToolbarExtensionAdded(const extensions::Extension* extension, |
| 280 int index) override; | 280 int index) override; |
| 281 virtual void ToolbarExtensionRemoved( | 281 virtual void ToolbarExtensionRemoved( |
| 282 const extensions::Extension* extension) override; | 282 const extensions::Extension* extension) override; |
| 283 virtual void ToolbarExtensionMoved(const extensions::Extension* extension, | 283 virtual void ToolbarExtensionMoved(const extensions::Extension* extension, |
| 284 int index) override; | 284 int index) override; |
| 285 virtual void ToolbarExtensionUpdated( | 285 virtual void ToolbarExtensionUpdated( |
| 286 const extensions::Extension* extension) override; | 286 const extensions::Extension* extension) override; |
| 287 virtual bool ShowExtensionActionPopup( | 287 virtual bool ShowExtensionActionPopup( |
| 288 const extensions::Extension* extension, | 288 const extensions::Extension* extension, |
| 289 bool grant_active_tab) override; | 289 bool grant_active_tab) override; |
| 290 virtual void ToolbarVisibleCountChanged() override; | 290 virtual void ToolbarVisibleCountChanged() override; |
| 291 virtual void ToolbarHighlightModeChanged(bool is_highlighting) override; | 291 virtual void ToolbarHighlightModeChanged(bool is_highlighting) override; |
| 292 virtual Browser* GetBrowser() override; | 292 virtual Browser* GetBrowser() override; |
| 293 | 293 |
| 294 void LoadImages(); | 294 void LoadImages(); |
| 295 | 295 |
| 296 // Called when a browser action's visibility may have changed. | 296 // Called when an action's visibility may have changed. |
| 297 void OnBrowserActionVisibilityChanged(); | 297 void OnBrowserActionVisibilityChanged(); |
| 298 | 298 |
| 299 // Returns the preferred width of the container in order to show all icons | 299 // Returns the preferred width of the container in order to show all icons |
| 300 // that should be visible and, optionally, the chevron. | 300 // that should be visible and, optionally, the chevron. |
| 301 int GetPreferredWidth(); | 301 int GetPreferredWidth(); |
| 302 | 302 |
| 303 // Sets the chevron to be visible or not based on whether all browser actions | 303 // Sets the chevron to be visible or not based on whether all actions are |
| 304 // are displayed. | 304 // displayed. |
| 305 void SetChevronVisibility(); | 305 void SetChevronVisibility(); |
| 306 | 306 |
| 307 // Given a number of |icons|, returns the pixels needed to draw the entire | 307 // Given a number of |icons|, returns the pixels needed to draw the entire |
| 308 // container (including the chevron if the number of icons is not all the | 308 // container (including the chevron if the number of icons is not all the |
| 309 // icons and there's not a separate overflow container). For convenience, | 309 // icons and there's not a separate overflow container). For convenience, |
| 310 // callers can set |icons| to -1 to mean "all icons". | 310 // callers can set |icons| to -1 to mean "all icons". |
| 311 int IconCountToWidth(int icons) const; | 311 int IconCountToWidth(int icons) const; |
| 312 | 312 |
| 313 // Given a pixel width, returns the number of icons that fit. (This | 313 // Given a pixel width, returns the number of icons that fit. (This |
| 314 // automatically determines whether a chevron will be needed and includes it | 314 // automatically determines whether a chevron will be needed and includes it |
| (...skipping 16 matching lines...) Expand all Loading... |
| 331 // from the model's GetVisibleIconCount if this container is for the overflow. | 331 // from the model's GetVisibleIconCount if this container is for the overflow. |
| 332 size_t GetIconCount() const; | 332 size_t GetIconCount() const; |
| 333 | 333 |
| 334 // Whether this container is in overflow mode (as opposed to in 'main' | 334 // Whether this container is in overflow mode (as opposed to in 'main' |
| 335 // mode). See class comments for details on the difference. | 335 // mode). See class comments for details on the difference. |
| 336 bool in_overflow_mode() const { return main_container_ != NULL; } | 336 bool in_overflow_mode() const { return main_container_ != NULL; } |
| 337 | 337 |
| 338 // Whether or not the container has been initialized. | 338 // Whether or not the container has been initialized. |
| 339 bool initialized_; | 339 bool initialized_; |
| 340 | 340 |
| 341 // The vector of browser actions (icons/image buttons for each action). Note | 341 // The vector of toolbar actions (icons/image buttons for each action). |
| 342 // that not every BrowserAction in the ToolbarModel will necessarily be in | 342 ToolbarActionViews toolbar_action_views_; |
| 343 // this collection. Some extensions may be disabled in incognito windows. | |
| 344 BrowserActionViews browser_action_views_; | |
| 345 | 343 |
| 346 Profile* profile_; | 344 Profile* profile_; |
| 347 | 345 |
| 348 // The Browser object the container is associated with. | 346 // The Browser object the container is associated with. |
| 349 Browser* browser_; | 347 Browser* browser_; |
| 350 | 348 |
| 351 // The main container we are serving as overflow for, or NULL if this | 349 // The main container we are serving as overflow for, or NULL if this |
| 352 // class is the the main container. See class comments for details on | 350 // class is the the main container. See class comments for details on |
| 353 // the difference between main and overflow. | 351 // the difference between main and overflow. |
| 354 BrowserActionsContainer* main_container_; | 352 BrowserActionsContainer* main_container_; |
| 355 | 353 |
| 356 // The view that triggered the current popup (just a reference to a view | 354 // The view that triggered the current popup (just a reference to a view |
| 357 // from browser_action_views_). | 355 // from toolbar_action_views_). |
| 358 BrowserActionView* popup_owner_; | 356 ToolbarActionView* popup_owner_; |
| 359 | 357 |
| 360 // The model that tracks the order of the toolbar icons. | 358 // The model that tracks the order of the toolbar icons. |
| 361 extensions::ExtensionToolbarModel* model_; | 359 extensions::ExtensionToolbarModel* model_; |
| 362 | 360 |
| 363 // The current width of the container. | 361 // The current width of the container. |
| 364 int container_width_; | 362 int container_width_; |
| 365 | 363 |
| 366 // The resize area for the container. | 364 // The resize area for the container. |
| 367 views::ResizeArea* resize_area_; | 365 views::ResizeArea* resize_area_; |
| 368 | 366 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 398 ObserverList<BrowserActionsContainerObserver> observers_; | 396 ObserverList<BrowserActionsContainerObserver> observers_; |
| 399 | 397 |
| 400 // The maximum number of icons to show per row when in overflow mode (showing | 398 // The maximum number of icons to show per row when in overflow mode (showing |
| 401 // icons in the application menu). | 399 // icons in the application menu). |
| 402 static int icons_per_overflow_menu_row_; | 400 static int icons_per_overflow_menu_row_; |
| 403 | 401 |
| 404 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); | 402 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); |
| 405 }; | 403 }; |
| 406 | 404 |
| 407 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ | 405 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ |
| OLD | NEW |