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