Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: chrome/browser/ui/views/toolbar/browser_actions_container.h

Issue 419023002: Move ShowPopup logic from BrowserActionsContainer to BrowserActionView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/chrome_views_export.h"
12 #include "chrome/browser/ui/views/extensions/browser_action_overflow_menu_contro ller.h" 11 #include "chrome/browser/ui/views/extensions/browser_action_overflow_menu_contro ller.h"
13 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h"
14 #include "chrome/browser/ui/views/extensions/extension_popup.h"
15 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" 12 #include "chrome/browser/ui/views/toolbar/browser_action_view.h"
16 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h"
17 #include "content/public/browser/notification_observer.h" 13 #include "content/public/browser/notification_observer.h"
18 #include "ui/gfx/animation/animation_delegate.h" 14 #include "ui/gfx/animation/animation_delegate.h"
19 #include "ui/gfx/animation/tween.h" 15 #include "ui/gfx/animation/tween.h"
20 #include "ui/views/controls/button/menu_button.h"
21 #include "ui/views/controls/button/menu_button_listener.h" 16 #include "ui/views/controls/button/menu_button_listener.h"
22 #include "ui/views/controls/resize_area_delegate.h" 17 #include "ui/views/controls/resize_area_delegate.h"
23 #include "ui/views/drag_controller.h" 18 #include "ui/views/drag_controller.h"
24 #include "ui/views/view.h" 19 #include "ui/views/view.h"
25 #include "ui/views/widget/widget_observer.h"
26 20
27 class BrowserActionButton; 21 class BrowserActionsContainerObserver;
28 class ExtensionKeybindingRegistryViews; 22 class ExtensionKeybindingRegistryViews;
29 class ExtensionPopup; 23 class ExtensionPopup;
30 24
31 namespace extensions { 25 namespace extensions {
32 class ActiveTabPermissionGranter; 26 class ActiveTabPermissionGranter;
33 class Command; 27 class Command;
34 class Extension; 28 class Extension;
35 } 29 }
36 30
37 namespace gfx { 31 namespace gfx {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // growing the container. 122 // growing the container.
129 // 123 //
130 //////////////////////////////////////////////////////////////////////////////// 124 ////////////////////////////////////////////////////////////////////////////////
131 class BrowserActionsContainer 125 class BrowserActionsContainer
132 : public views::View, 126 : public views::View,
133 public views::MenuButtonListener, 127 public views::MenuButtonListener,
134 public views::ResizeAreaDelegate, 128 public views::ResizeAreaDelegate,
135 public gfx::AnimationDelegate, 129 public gfx::AnimationDelegate,
136 public extensions::ExtensionToolbarModel::Observer, 130 public extensions::ExtensionToolbarModel::Observer,
137 public BrowserActionOverflowMenuController::Observer, 131 public BrowserActionOverflowMenuController::Observer,
138 public views::WidgetObserver,
139 public BrowserActionView::Delegate, 132 public BrowserActionView::Delegate,
140 public extensions::ExtensionKeybindingRegistry::Delegate { 133 public extensions::ExtensionKeybindingRegistry::Delegate {
141 public: 134 public:
142 // Constructs a BrowserActionContainer for a particular |browser| object, and 135 // Constructs a BrowserActionContainer for a particular |browser| object, and
143 // specifies which view is the |owner_view|. For documentation of 136 // specifies which view is the |owner_view|. For documentation of
144 // |main_container|, see class comments. 137 // |main_container|, see class comments.
145 BrowserActionsContainer(Browser* browser, 138 BrowserActionsContainer(Browser* browser,
146 views::View* owner_view, 139 views::View* owner_view,
147 BrowserActionsContainer* main_container); 140 BrowserActionsContainer* main_container);
148 virtual ~BrowserActionsContainer(); 141 virtual ~BrowserActionsContainer();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 virtual void OnResize(int resize_amount, bool done_resizing) OVERRIDE; 222 virtual void OnResize(int resize_amount, bool done_resizing) OVERRIDE;
230 223
231 // Overridden from gfx::AnimationDelegate: 224 // Overridden from gfx::AnimationDelegate:
232 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; 225 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
233 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; 226 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
234 227
235 // Overridden from BrowserActionOverflowMenuController::Observer: 228 // Overridden from BrowserActionOverflowMenuController::Observer:
236 virtual void NotifyMenuDeleted( 229 virtual void NotifyMenuDeleted(
237 BrowserActionOverflowMenuController* controller) OVERRIDE; 230 BrowserActionOverflowMenuController* controller) OVERRIDE;
238 231
239 // Overridden from views::WidgetObserver:
240 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
241
242 // Overridden from BrowserActionView::Delegate: 232 // Overridden from BrowserActionView::Delegate:
243 virtual void InspectPopup(ExtensionAction* action) OVERRIDE;
244 virtual int GetCurrentTabId() const OVERRIDE; 233 virtual int GetCurrentTabId() const OVERRIDE;
245 virtual void OnBrowserActionExecuted(BrowserActionButton* button) OVERRIDE;
246 virtual void OnBrowserActionVisibilityChanged() OVERRIDE; 234 virtual void OnBrowserActionVisibilityChanged() OVERRIDE;
247 virtual bool ShownInsideMenu() const OVERRIDE; 235 virtual bool ShownInsideMenu() const OVERRIDE;
248 virtual void OnBrowserActionViewDragDone() OVERRIDE; 236 virtual void OnBrowserActionViewDragDone() OVERRIDE;
237 virtual views::View* GetOverflowReferenceView() OVERRIDE;
238 virtual void SetPopupOwner(BrowserActionButton* popup_owner) OVERRIDE;
239 virtual void HideActivePopup() OVERRIDE;
240 virtual extensions::ExtensionToolbarModel* GetModel() OVERRIDE;
249 241
250 // Overridden from extension::ExtensionKeybindingRegistry::Delegate: 242 // Overridden from extension::ExtensionKeybindingRegistry::Delegate:
251 virtual extensions::ActiveTabPermissionGranter* 243 virtual extensions::ActiveTabPermissionGranter*
252 GetActiveTabPermissionGranter() OVERRIDE; 244 GetActiveTabPermissionGranter() OVERRIDE;
253 245
254 // Moves a browser action with |id| to |new_index|. 246 // Moves a browser action with |id| to |new_index|.
255 void MoveBrowserAction(const std::string& extension_id, size_t new_index); 247 void MoveBrowserAction(const std::string& extension_id, size_t new_index);
256 248
257 // Shows the popup for |extension| if possible. Returns true if a new popup 249 // Shows the popup for |extension| if possible. Returns true if a new popup
258 // was shown. Showing the popup will grant tab permissions if 250 // was shown. Showing the popup will grant tab permissions if
Yoyo Zhou 2014/07/30 01:46:33 Should this say active tab permissions?
Devlin 2014/07/30 16:14:26 For clarity, probably. Done.
259 // |grant_tab_permissions| is true. Only pass true for this argument for 251 // |grant_tab_permissions| is true. Only pass true for this argument for
260 // popups triggered interactively, not popups triggered by an API. 252 // popups triggered interactively, not popups triggered by an API.
261 bool ShowPopup(const extensions::Extension* extension, 253 // If |can_override| is true, this popup can override other popups (hiding
262 bool grant_tab_permissions); 254 // them) and does not have to be in the active window.
263 255 bool ShowPopupForExtension(const extensions::Extension* extension,
264 // Hide the current popup. 256 bool grant_tab_permissions,
265 void HidePopup(); 257 bool can_override);
266
267 // Simulate a click on a browser action button. This should only be
268 // used by unit tests.
269 void TestExecuteBrowserAction(int index);
270 258
271 // Retrieve the current popup. This should only be used by unit tests. 259 // Retrieve the current popup. This should only be used by unit tests.
272 ExtensionPopup* TestGetPopup() { return popup_; } 260 ExtensionPopup* TestGetPopup();
273 261
274 // Set how many icons the container should show. This should only be used by 262 // Set how many icons the container should show. This should only be used by
275 // unit tests. 263 // unit tests.
276 void TestSetIconVisibilityCount(size_t icons); 264 void TestSetIconVisibilityCount(size_t icons);
277 265
278 // During testing we can disable animations by setting this flag to true, 266 // During testing we can disable animations by setting this flag to true,
279 // so that the bar resizes instantly, instead of having to poll it while it 267 // so that the bar resizes instantly, instead of having to poll it while it
280 // animates to open/closed status. 268 // animates to open/closed status.
281 static bool disable_animations_during_testing_; 269 static bool disable_animations_during_testing_;
282 270
(...skipping 16 matching lines...) Expand all
299 // Returns the height of an icon. 287 // Returns the height of an icon.
300 static int IconHeight(); 288 static int IconHeight();
301 289
302 // extensions::ExtensionToolbarModel::Observer implementation. 290 // extensions::ExtensionToolbarModel::Observer implementation.
303 virtual void BrowserActionAdded(const extensions::Extension* extension, 291 virtual void BrowserActionAdded(const extensions::Extension* extension,
304 int index) OVERRIDE; 292 int index) OVERRIDE;
305 virtual void BrowserActionRemoved( 293 virtual void BrowserActionRemoved(
306 const extensions::Extension* extension) OVERRIDE; 294 const extensions::Extension* extension) OVERRIDE;
307 virtual void BrowserActionMoved(const extensions::Extension* extension, 295 virtual void BrowserActionMoved(const extensions::Extension* extension,
308 int index) OVERRIDE; 296 int index) OVERRIDE;
309 virtual bool BrowserActionShowPopup(
310 const extensions::Extension* extension) OVERRIDE;
311 virtual void VisibleCountChanged() OVERRIDE; 297 virtual void VisibleCountChanged() OVERRIDE;
312 virtual void HighlightModeChanged(bool is_highlighting) OVERRIDE; 298 virtual void HighlightModeChanged(bool is_highlighting) OVERRIDE;
313 299
314 void LoadImages(); 300 void LoadImages();
315 301
316 // Sets the initial container width. 302 // Sets the initial container width.
317 void SetContainerWidth(); 303 void SetContainerWidth();
318 304
319 // Closes the overflow menu if open. 305 // Closes the overflow menu if open.
320 void CloseOverflowMenu(); 306 void CloseOverflowMenu();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 // the target size). This also saves the target number of visible icons in 338 // the target size). This also saves the target number of visible icons in
353 // the pref if we're not incognito. 339 // the pref if we're not incognito.
354 void SaveDesiredSizeAndAnimate(gfx::Tween::Type type, 340 void SaveDesiredSizeAndAnimate(gfx::Tween::Type type,
355 size_t num_visible_icons); 341 size_t num_visible_icons);
356 342
357 // Returns true if this extension should be shown in this toolbar. This can 343 // Returns true if this extension should be shown in this toolbar. This can
358 // return false if we are in an incognito window and the extension is disabled 344 // return false if we are in an incognito window and the extension is disabled
359 // for incognito. 345 // for incognito.
360 bool ShouldDisplayBrowserAction(const extensions::Extension* extension); 346 bool ShouldDisplayBrowserAction(const extensions::Extension* extension);
361 347
362 // Show a popup. Returns true if a new popup was shown. Showing the popup will
363 // grant tab permissions if |grant_tab_permissions| is true. Only pass true
364 // for this argument for popups triggered interactively, not popups triggered
365 // by an API.
366 bool ShowPopup(BrowserActionButton* button,
367 ExtensionPopup::ShowAction show_action,
368 bool grant_tab_permissions);
369
370 // Whether this container is in overflow mode (as opposed to in 'main' 348 // Whether this container is in overflow mode (as opposed to in 'main'
371 // mode). See class comments for details on the difference. 349 // mode). See class comments for details on the difference.
372 bool in_overflow_mode() const { return main_container_ != NULL; } 350 bool in_overflow_mode() const { return main_container_ != NULL; }
373 351
374 // The vector of browser actions (icons/image buttons for each action). Note 352 // The vector of browser actions (icons/image buttons for each action). Note
375 // that not every BrowserAction in the ToolbarModel will necessarily be in 353 // that not every BrowserAction in the ToolbarModel will necessarily be in
376 // this collection. Some extensions may be disabled in incognito windows. 354 // this collection. Some extensions may be disabled in incognito windows.
377 BrowserActionViews browser_action_views_; 355 BrowserActionViews browser_action_views_;
378 356
379 Profile* profile_; 357 Profile* profile_;
380 358
381 // The Browser object the container is associated with. 359 // The Browser object the container is associated with.
382 Browser* browser_; 360 Browser* browser_;
383 361
384 // The view that owns us. 362 // The view that owns us.
385 views::View* owner_view_; 363 views::View* owner_view_;
386 364
387 // The main container we are serving as overflow for, or NULL if this 365 // The main container we are serving as overflow for, or NULL if this
388 // class is the the main container. See class comments for details on 366 // class is the the main container. See class comments for details on
389 // the difference between main and overflow. 367 // the difference between main and overflow.
390 BrowserActionsContainer* main_container_; 368 BrowserActionsContainer* main_container_;
391 369
392 // The current popup and the button it came from. NULL if no popup.
393 ExtensionPopup* popup_;
394
395 // The button that triggered the current popup (just a reference to a button 370 // The button that triggered the current popup (just a reference to a button
396 // from browser_action_views_). 371 // from browser_action_views_).
397 BrowserActionButton* popup_button_; 372 BrowserActionButton* popup_owner_;
398 373
399 // The model that tracks the order of the toolbar icons. 374 // The model that tracks the order of the toolbar icons.
400 extensions::ExtensionToolbarModel* model_; 375 extensions::ExtensionToolbarModel* model_;
401 376
402 // The current width of the container. 377 // The current width of the container.
403 int container_width_; 378 int container_width_;
404 379
405 // The resize area for the container. 380 // The resize area for the container.
406 views::ResizeArea* resize_area_; 381 views::ResizeArea* resize_area_;
407 382
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 416
442 // Handles delayed showing of the overflow menu when hovering. 417 // Handles delayed showing of the overflow menu when hovering.
443 base::WeakPtrFactory<BrowserActionsContainer> show_menu_task_factory_; 418 base::WeakPtrFactory<BrowserActionsContainer> show_menu_task_factory_;
444 419
445 ObserverList<BrowserActionsContainerObserver> observers_; 420 ObserverList<BrowserActionsContainerObserver> observers_;
446 421
447 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer); 422 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainer);
448 }; 423 };
449 424
450 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_ 425 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTIONS_CONTAINER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698