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" |
12 #include "chrome/browser/ui/views/toolbar/chevron_menu_button.h" | 13 #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 // toolbar action icons (including extension icons and icons for component | 39 // browser action icons (extensions that add icons to the toolbar). It comes in |
40 // toolbar actions). It comes intwo flavors, a main container (when residing on | 40 // two flavors, a main container (when residing on the toolbar) and an overflow |
41 // the toolbar) and an overflow container (that resides in the main application | 41 // container (that resides in the main application menu, aka the Chrome menu). |
42 // menu, aka the Chrome menu). | |
43 // | 42 // |
44 // When in 'main' mode, the container supports the full functionality of a | 43 // When in 'main' mode, the container supports the full functionality of a |
45 // BrowserActionContainer, but in 'overflow' mode the container is effectively | 44 // BrowserActionContainer, but in 'overflow' mode the container is effectively |
46 // just an overflow for the 'main' toolbar (shows only the icons that the main | 45 // just an overflow for the 'main' toolbar (shows only the icons that the main |
47 // toolbar does not) and as such does not have an overflow itself. The overflow | 46 // toolbar does not) and as such does not have an overflow itself. The overflow |
48 // container also does not support resizing. Since the main container only shows | 47 // container also does not support resizing. Since the main container only shows |
49 // icons in the Chrome toolbar, it is limited to a single row of icons. The | 48 // icons in the Chrome toolbar, it is limited to a single row of icons. The |
50 // overflow container, however, is allowed to display icons in multiple rows. | 49 // overflow container, however, is allowed to display icons in multiple rows. |
51 // | 50 // |
52 // The main container is placed flush against the omnibox and hot dog menu, | 51 // 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... |
120 // because we won't have enough space to show the new Browser Action until the | 119 // 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 | 120 // animation ends and we don't want the chevron to flash into view while we are |
122 // growing the container. | 121 // growing the container. |
123 // | 122 // |
124 //////////////////////////////////////////////////////////////////////////////// | 123 //////////////////////////////////////////////////////////////////////////////// |
125 class BrowserActionsContainer | 124 class BrowserActionsContainer |
126 : public views::View, | 125 : public views::View, |
127 public views::ResizeAreaDelegate, | 126 public views::ResizeAreaDelegate, |
128 public gfx::AnimationDelegate, | 127 public gfx::AnimationDelegate, |
129 public extensions::ExtensionToolbarModel::Observer, | 128 public extensions::ExtensionToolbarModel::Observer, |
130 public ToolbarActionView::Delegate, | 129 public BrowserActionView::Delegate, |
131 public extensions::ExtensionKeybindingRegistry::Delegate { | 130 public extensions::ExtensionKeybindingRegistry::Delegate { |
132 public: | 131 public: |
133 // Horizontal spacing between most items in the container, as well as after | 132 // Horizontal spacing between most items in the container, as well as after |
134 // the last item or chevron (if visible). | 133 // the last item or chevron (if visible). |
135 static const int kItemSpacing; | 134 static const int kItemSpacing; |
136 | 135 |
137 // Constructs a BrowserActionContainer for a particular |browser| object. For | 136 // Constructs a BrowserActionContainer for a particular |browser| object. For |
138 // documentation of |main_container|, see class comments. | 137 // documentation of |main_container|, see class comments. |
139 BrowserActionsContainer(Browser* browser, | 138 BrowserActionsContainer(Browser* browser, |
140 BrowserActionsContainer* main_container); | 139 BrowserActionsContainer* main_container); |
141 virtual ~BrowserActionsContainer(); | 140 virtual ~BrowserActionsContainer(); |
142 | 141 |
143 void Init(); | 142 void Init(); |
144 | 143 |
145 // Get the number of toolbar actions being displayed. | 144 // Get the number of browser actions being displayed. |
146 size_t num_toolbar_actions() const { return toolbar_action_views_.size(); } | 145 size_t num_browser_actions() const { return browser_action_views_.size(); } |
147 | 146 |
148 // Whether we are performing resize animation on the container. | 147 // Whether we are performing resize animation on the container. |
149 bool animating() const { return animation_target_size_ > 0; } | 148 bool animating() const { return animation_target_size_ > 0; } |
150 | 149 |
151 // Returns the chevron, if any. | 150 // Returns the chevron, if any. |
152 views::View* chevron() { return chevron_; } | 151 views::View* chevron() { return chevron_; } |
153 const views::View* chevron() const { return chevron_; } | 152 const views::View* chevron() const { return chevron_; } |
154 | 153 |
155 // Returns the profile this container is associated with. | 154 // Returns the profile this container is associated with. |
156 Profile* profile() const { return profile_; } | 155 Profile* profile() const { return profile_; } |
157 | 156 |
158 // The class that registers for keyboard shortcuts for extension commands. | 157 // The class that registers for keyboard shortcuts for extension commands. |
159 extensions::ExtensionKeybindingRegistry* extension_keybinding_registry() { | 158 extensions::ExtensionKeybindingRegistry* extension_keybinding_registry() { |
160 return extension_keybinding_registry_.get(); | 159 return extension_keybinding_registry_.get(); |
161 } | 160 } |
162 | 161 |
163 // Get a particular toolbar action view. | 162 // Get a particular browser action view. |
164 ToolbarActionView* GetToolbarActionViewAt(int index) { | 163 BrowserActionView* GetBrowserActionViewAt(int index) { |
165 return toolbar_action_views_[index]; | 164 return browser_action_views_[index]; |
166 } | 165 } |
167 | 166 |
168 // Returns the ID of the action represented by the view at |index|. | 167 // Returns the ID of the action represented by the view at |index|. |
169 const std::string& GetIdAt(size_t index); | 168 const std::string& GetIdAt(size_t index); |
170 | 169 |
171 // Returns the ToolbarActionView* associated with the given |extension|, or | 170 // Returns the BrowserActionView* associated with the given |extension|, or |
172 // NULL if none exists. | 171 // NULL if none exists. |
173 ToolbarActionView* GetViewForExtension( | 172 BrowserActionView* GetViewForExtension( |
174 const extensions::Extension* extension); | 173 const extensions::Extension* extension); |
175 | 174 |
176 // Update the views to reflect the state of the toolbar actions. | 175 // Update the views to reflect the state of the browser action icons. |
177 void RefreshToolbarActionViews(); | 176 void RefreshBrowserActionViews(); |
178 | 177 |
179 // Sets up the toolbar action view vector. | 178 // Sets up the browser action view vector. |
180 void CreateToolbarActionViews(); | 179 void CreateBrowserActionViews(); |
181 | 180 |
182 // Delete all toolbar action views. | 181 // Delete all browser action views. |
183 void DeleteToolbarActionViews(); | 182 void DeleteBrowserActionViews(); |
184 | 183 |
185 // Returns how many actions are currently visible. If the intent is to find | 184 // Returns how many browser actions are currently visible. If the intent is |
186 // how many are visible once the container finishes animation, see | 185 // to find how many are visible once the container finishes animation, see |
187 // VisibleBrowserActionsAfterAnimation() below. | 186 // VisibleBrowserActionsAfterAnimation() below. |
188 size_t VisibleBrowserActions() const; | 187 size_t VisibleBrowserActions() const; |
189 | 188 |
190 // Returns how many actions will be visible once the container finishes | 189 // Returns how many browser actions will be visible once the container |
191 // animating to a new size, or (if not animating) the currently visible icons. | 190 // finishes animating to a new size, or (if not animating) the currently |
| 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 container that an extension has been moved to the overflow | 198 // Notify the browser action container that an extension has been moved to |
199 // container. | 199 // the overflow 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 ToolbarActionView::Delegate: | 237 // Overridden from BrowserActionView::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 OnToolbarActionViewDragDone() override; | 240 virtual void OnBrowserActionViewDragDone() override; |
241 virtual views::MenuButton* GetOverflowReferenceView() override; | 241 virtual views::MenuButton* GetOverflowReferenceView() override; |
242 virtual void SetPopupOwner(ToolbarActionView* popup_owner) override; | 242 virtual void SetPopupOwner(BrowserActionView* popup_owner) override; |
243 virtual void HideActivePopup() override; | 243 virtual void HideActivePopup() override; |
244 virtual ToolbarActionView* GetMainViewForAction( | 244 virtual BrowserActionView* GetMainViewForAction( |
245 ToolbarActionView* view) override; | 245 BrowserActionView* 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<ToolbarActionView*> ToolbarActionViews; | 276 typedef std::vector<BrowserActionView*> BrowserActionViews; |
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 an action's visibility may have changed. | 296 // Called when a browser 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 actions are | 303 // Sets the chevron to be visible or not based on whether all browser actions |
304 // displayed. | 304 // are 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 toolbar actions (icons/image buttons for each action). | 341 // The vector of browser actions (icons/image buttons for each action). Note |
342 ToolbarActionViews toolbar_action_views_; | 342 // that not every BrowserAction in the ToolbarModel will necessarily be in |
| 343 // this collection. Some extensions may be disabled in incognito windows. |
| 344 BrowserActionViews browser_action_views_; |
343 | 345 |
344 Profile* profile_; | 346 Profile* profile_; |
345 | 347 |
346 // The Browser object the container is associated with. | 348 // The Browser object the container is associated with. |
347 Browser* browser_; | 349 Browser* browser_; |
348 | 350 |
349 // The main container we are serving as overflow for, or NULL if this | 351 // The main container we are serving as overflow for, or NULL if this |
350 // class is the the main container. See class comments for details on | 352 // class is the the main container. See class comments for details on |
351 // the difference between main and overflow. | 353 // the difference between main and overflow. |
352 BrowserActionsContainer* main_container_; | 354 BrowserActionsContainer* main_container_; |
353 | 355 |
354 // The view that triggered the current popup (just a reference to a view | 356 // The view that triggered the current popup (just a reference to a view |
355 // from toolbar_action_views_). | 357 // from browser_action_views_). |
356 ToolbarActionView* popup_owner_; | 358 BrowserActionView* popup_owner_; |
357 | 359 |
358 // The model that tracks the order of the toolbar icons. | 360 // The model that tracks the order of the toolbar icons. |
359 extensions::ExtensionToolbarModel* model_; | 361 extensions::ExtensionToolbarModel* model_; |
360 | 362 |
361 // The current width of the container. | 363 // The current width of the container. |
362 int container_width_; | 364 int container_width_; |
363 | 365 |
364 // The resize area for the container. | 366 // The resize area for the container. |
365 views::ResizeArea* resize_area_; | 367 views::ResizeArea* resize_area_; |
366 | 368 |
(...skipping 29 matching lines...) Expand all Loading... |
396 ObserverList<BrowserActionsContainerObserver> observers_; | 398 ObserverList<BrowserActionsContainerObserver> observers_; |
397 | 399 |
398 // The maximum number of icons to show per row when in overflow mode (showing | 400 // The maximum number of icons to show per row when in overflow mode (showing |
399 // icons in the application menu). | 401 // icons in the application menu). |
400 static int icons_per_overflow_menu_row_; | 402 static int icons_per_overflow_menu_row_; |
401 | 403 |
402 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); | 404 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); |
403 }; | 405 }; |
404 | 406 |
405 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ | 407 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ |
OLD | NEW |