| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "chrome/browser/extensions/extension_keybinding_registry.h" | |
| 13 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 12 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 14 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" | 13 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" |
| 15 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" | |
| 16 #include "chrome/browser/ui/views/toolbar/chevron_menu_button.h" | 14 #include "chrome/browser/ui/views/toolbar/chevron_menu_button.h" |
| 17 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" | 15 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" |
| 18 #include "ui/gfx/animation/animation_delegate.h" | 16 #include "ui/gfx/animation/animation_delegate.h" |
| 19 #include "ui/gfx/animation/slide_animation.h" | 17 #include "ui/gfx/animation/slide_animation.h" |
| 20 #include "ui/gfx/animation/tween.h" | 18 #include "ui/gfx/animation/tween.h" |
| 21 #include "ui/views/controls/resize_area_delegate.h" | 19 #include "ui/views/controls/resize_area_delegate.h" |
| 22 #include "ui/views/drag_controller.h" | 20 #include "ui/views/drag_controller.h" |
| 23 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
| 24 #include "ui/views/widget/widget_observer.h" | 22 #include "ui/views/widget/widget_observer.h" |
| 25 | 23 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // size (animation_target_size_), using |resize_amount| to keep track of the | 115 // size (animation_target_size_), using |resize_amount| to keep track of the |
| 118 // animation progress. | 116 // animation progress. |
| 119 // | 117 // |
| 120 // NOTE: When adding Browser Actions to a maximum width container (no overflow) | 118 // NOTE: When adding Browser Actions to a maximum width container (no overflow) |
| 121 // we make sure to suppress the chevron menu if it wasn't visible. This is | 119 // we make sure to suppress the chevron menu if it wasn't visible. This is |
| 122 // 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 |
| 123 // 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 |
| 124 // growing the container. | 122 // growing the container. |
| 125 // | 123 // |
| 126 //////////////////////////////////////////////////////////////////////////////// | 124 //////////////////////////////////////////////////////////////////////////////// |
| 127 class BrowserActionsContainer | 125 class BrowserActionsContainer : public views::View, |
| 128 : public views::View, | 126 public ToolbarActionsBarDelegate, |
| 129 public ToolbarActionsBarDelegate, | 127 public views::ResizeAreaDelegate, |
| 130 public views::ResizeAreaDelegate, | 128 public gfx::AnimationDelegate, |
| 131 public gfx::AnimationDelegate, | 129 public ToolbarActionView::Delegate, |
| 132 public ToolbarActionView::Delegate, | 130 public views::WidgetObserver { |
| 133 public views::WidgetObserver, | |
| 134 public extensions::ExtensionKeybindingRegistry::Delegate { | |
| 135 public: | 131 public: |
| 136 // Constructs a BrowserActionContainer for a particular |browser| object. For | 132 // Constructs a BrowserActionContainer for a particular |browser| object. For |
| 137 // documentation of |main_container|, see class comments. | 133 // documentation of |main_container|, see class comments. |
| 138 BrowserActionsContainer(Browser* browser, | 134 BrowserActionsContainer(Browser* browser, |
| 139 BrowserActionsContainer* main_container); | 135 BrowserActionsContainer* main_container); |
| 140 ~BrowserActionsContainer() override; | 136 ~BrowserActionsContainer() override; |
| 141 | 137 |
| 142 void Init(); | 138 void Init(); |
| 143 | 139 |
| 144 // Get the number of toolbar actions being displayed. | 140 // Get the number of toolbar actions being displayed. |
| 145 size_t num_toolbar_actions() const { return toolbar_action_views_.size(); } | 141 size_t num_toolbar_actions() const { return toolbar_action_views_.size(); } |
| 146 | 142 |
| 147 // Returns the chevron, if any. | 143 // Returns the chevron, if any. |
| 148 views::View* chevron() { return chevron_; } | 144 views::View* chevron() { return chevron_; } |
| 149 const views::View* chevron() const { return chevron_; } | 145 const views::View* chevron() const { return chevron_; } |
| 150 | 146 |
| 151 // Returns the browser this container is associated with. | 147 // Returns the browser this container is associated with. |
| 152 Browser* browser() const { return browser_; } | 148 Browser* browser() const { return browser_; } |
| 153 | 149 |
| 154 ToolbarActionsBar* toolbar_actions_bar() { | 150 ToolbarActionsBar* toolbar_actions_bar() { |
| 155 return toolbar_actions_bar_.get(); | 151 return toolbar_actions_bar_.get(); |
| 156 } | 152 } |
| 157 | 153 |
| 158 // The class that registers for keyboard shortcuts for extension commands. | |
| 159 extensions::ExtensionKeybindingRegistry* extension_keybinding_registry() { | |
| 160 return extension_keybinding_registry_.get(); | |
| 161 } | |
| 162 | |
| 163 // Get a particular toolbar action view. | 154 // Get a particular toolbar action view. |
| 164 ToolbarActionView* GetToolbarActionViewAt(int index) { | 155 ToolbarActionView* GetToolbarActionViewAt(int index) { |
| 165 return toolbar_action_views_[index]; | 156 return toolbar_action_views_[index]; |
| 166 } | 157 } |
| 167 | 158 |
| 168 // Whether we are performing resize animation on the container. | 159 // Whether we are performing resize animation on the container. |
| 169 bool animating() const { | 160 bool animating() const { |
| 170 return resize_animation_ && resize_animation_->is_animating(); | 161 return resize_animation_ && resize_animation_->is_animating(); |
| 171 } | 162 } |
| 172 | 163 |
| 173 // Returns the ID of the action represented by the view at |index|. | 164 // Returns the ID of the action represented by the view at |index|. |
| 174 std::string GetIdAt(size_t index) const; | 165 std::string GetIdAt(size_t index) const; |
| 175 | 166 |
| 176 // Returns the ToolbarActionView* associated with the given |extension|, or | 167 // Returns the ToolbarActionView* associated with the given |extension|, or |
| 177 // NULL if none exists. | 168 // NULL if none exists. |
| 178 ToolbarActionView* GetViewForId(const std::string& id); | 169 ToolbarActionView* GetViewForId(const std::string& id); |
| 179 | 170 |
| 180 // Update the views to reflect the state of the toolbar actions. | 171 // Update the views to reflect the state of the toolbar actions. |
| 181 void RefreshToolbarActionViews(); | 172 void RefreshToolbarActionViews(); |
| 182 | 173 |
| 183 // Returns how many actions are currently visible. If the intent is to find | 174 // Returns how many actions are currently visible. If the intent is to find |
| 184 // how many are visible once the container finishes animation, see | 175 // how many are visible once the container finishes animation, see |
| 185 // VisibleBrowserActionsAfterAnimation() below. | 176 // VisibleBrowserActionsAfterAnimation() below. |
| 186 size_t VisibleBrowserActions() const; | 177 size_t VisibleBrowserActions() const; |
| 187 | 178 |
| 188 // Returns how many actions will be visible once the container finishes | 179 // Returns how many actions will be visible once the container finishes |
| 189 // animating to a new size, or (if not animating) the currently visible icons. | 180 // animating to a new size, or (if not animating) the currently visible icons. |
| 190 size_t VisibleBrowserActionsAfterAnimation() const; | 181 size_t VisibleBrowserActionsAfterAnimation() const; |
| 191 | 182 |
| 192 // Executes |command| registered by |extension|. | |
| 193 void ExecuteExtensionCommand(const extensions::Extension* extension, | |
| 194 const extensions::Command& command); | |
| 195 | |
| 196 // Returns the preferred width given the limit of |max_width|. (Unlike most | 183 // Returns the preferred width given the limit of |max_width|. (Unlike most |
| 197 // views, since we don't want to show part of an icon or a large space after | 184 // views, since we don't want to show part of an icon or a large space after |
| 198 // the omnibox, this is probably *not* |max_width|). | 185 // the omnibox, this is probably *not* |max_width|). |
| 199 int GetWidthForMaxWidth(int max_width) const; | 186 int GetWidthForMaxWidth(int max_width) const; |
| 200 | 187 |
| 201 // Overridden from views::View: | 188 // Overridden from views::View: |
| 202 gfx::Size GetPreferredSize() const override; | 189 gfx::Size GetPreferredSize() const override; |
| 203 int GetHeightForWidth(int width) const override; | 190 int GetHeightForWidth(int width) const override; |
| 204 gfx::Size GetMinimumSize() const override; | 191 gfx::Size GetMinimumSize() const override; |
| 205 void Layout() override; | 192 void Layout() override; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 void StopAnimating() override; | 240 void StopAnimating() override; |
| 254 int GetChevronWidth() const override; | 241 int GetChevronWidth() const override; |
| 255 void ShowExtensionMessageBubble( | 242 void ShowExtensionMessageBubble( |
| 256 scoped_ptr<extensions::ExtensionMessageBubbleController> controller, | 243 scoped_ptr<extensions::ExtensionMessageBubbleController> controller, |
| 257 ToolbarActionViewController* anchor_action) override; | 244 ToolbarActionViewController* anchor_action) override; |
| 258 | 245 |
| 259 // views::WidgetObserver: | 246 // views::WidgetObserver: |
| 260 void OnWidgetClosing(views::Widget* widget) override; | 247 void OnWidgetClosing(views::Widget* widget) override; |
| 261 void OnWidgetDestroying(views::Widget* widget) override; | 248 void OnWidgetDestroying(views::Widget* widget) override; |
| 262 | 249 |
| 263 // Overridden from extension::ExtensionKeybindingRegistry::Delegate: | |
| 264 extensions::ActiveTabPermissionGranter* GetActiveTabPermissionGranter() | |
| 265 override; | |
| 266 | |
| 267 views::BubbleDelegateView* active_bubble() { return active_bubble_; } | 250 views::BubbleDelegateView* active_bubble() { return active_bubble_; } |
| 268 | 251 |
| 269 ChevronMenuButton* chevron_for_testing() { return chevron_; } | 252 ChevronMenuButton* chevron_for_testing() { return chevron_; } |
| 270 | 253 |
| 271 protected: | 254 protected: |
| 272 // Overridden from views::View: | 255 // Overridden from views::View: |
| 273 void ViewHierarchyChanged( | 256 void ViewHierarchyChanged( |
| 274 const ViewHierarchyChangedDetails& details) override; | 257 const ViewHierarchyChangedDetails& details) override; |
| 275 void OnPaint(gfx::Canvas* canvas) override; | 258 void OnPaint(gfx::Canvas* canvas) override; |
| 276 void OnThemeChanged() override; | 259 void OnThemeChanged() override; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 int resize_amount_; | 324 int resize_amount_; |
| 342 | 325 |
| 343 // Keeps track of the absolute pixel width the container should have when we | 326 // Keeps track of the absolute pixel width the container should have when we |
| 344 // are done animating. | 327 // are done animating. |
| 345 int animation_target_size_; | 328 int animation_target_size_; |
| 346 | 329 |
| 347 // The DropPosition for the current drag-and-drop operation, or NULL if there | 330 // The DropPosition for the current drag-and-drop operation, or NULL if there |
| 348 // is none. | 331 // is none. |
| 349 scoped_ptr<DropPosition> drop_position_; | 332 scoped_ptr<DropPosition> drop_position_; |
| 350 | 333 |
| 351 // The class that registers for keyboard shortcuts for extension commands. | |
| 352 scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_; | |
| 353 | |
| 354 // The extension bubble that is actively showing, if any. | 334 // The extension bubble that is actively showing, if any. |
| 355 views::BubbleDelegateView* active_bubble_; | 335 views::BubbleDelegateView* active_bubble_; |
| 356 | 336 |
| 357 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); | 337 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); |
| 358 }; | 338 }; |
| 359 | 339 |
| 360 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ | 340 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ |
| OLD | NEW |