[Extension Toolbar] Refactor and finish pop out logic for actions
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / browser_actions_controller.h
blob32cf1c8547e6beb48c291cb44502781a33618a2a
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_
8 #import <Cocoa/Cocoa.h>
10 #import "base/mac/scoped_nsobject.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "ui/gfx/geometry/size.h"
14 class Browser;
15 @class BrowserActionButton;
16 @class BrowserActionsContainerView;
17 @class MenuButton;
18 class ToolbarActionsBar;
19 class ToolbarActionsBarDelegate;
21 namespace content {
22 class WebContents;
25 // Sent when the visibility of the Browser Actions changes.
26 extern NSString* const kBrowserActionVisibilityChangedNotification;
28 // Handles state and provides an interface for controlling the Browser Actions
29 // container within the Toolbar.
30 @interface BrowserActionsController : NSObject<NSMenuDelegate> {
31 @private
32 // Reference to the current browser. Weak.
33 Browser* browser_;
35 // The view from Toolbar.xib we'll be rendering our browser actions in. Weak.
36 BrowserActionsContainerView* containerView_;
38 // Array of toolbar action buttons in the correct order for them to be
39 // displayed (includes both hidden and visible buttons).
40 base::scoped_nsobject<NSMutableArray> buttons_;
42 // The delegate for the ToolbarActionsBar.
43 scoped_ptr<ToolbarActionsBarDelegate> toolbarActionsBarBridge_;
45 // The controlling ToolbarActionsBar.
46 scoped_ptr<ToolbarActionsBar> toolbarActionsBar_;
48 // True if we should supppress the chevron (we do this during drag
49 // animations).
50 BOOL suppressChevron_;
52 // True if this is the overflow container for toolbar actions.
53 BOOL isOverflow_;
55 // The currently running chevron animation (fade in/out).
56 base::scoped_nsobject<NSViewAnimation> chevronAnimation_;
58 // The chevron button used when Browser Actions are hidden.
59 base::scoped_nsobject<MenuButton> chevronMenuButton_;
61 // The Browser Actions overflow menu.
62 base::scoped_nsobject<NSMenu> overflowMenu_;
65 @property(readonly, nonatomic) BrowserActionsContainerView* containerView;
66 @property(readonly, nonatomic) Browser* browser;
68 // Initializes the controller given the current browser and container view that
69 // will hold the browser action buttons. If |mainController| is nil, the created
70 // BrowserActionsController will be the main controller; otherwise (if this is
71 // for the overflow menu), |mainController| should be controller of the main bar
72 // for the |browser|.
73 - (id)initWithBrowser:(Browser*)browser
74 containerView:(BrowserActionsContainerView*)container
75 mainController:(BrowserActionsController*)mainController;
77 // Update the display of all buttons.
78 - (void)update;
80 // Returns the current number of browser action buttons within the container,
81 // whether or not they are displayed.
82 - (NSUInteger)buttonCount;
84 // Returns the current number of browser action buttons displayed in the
85 // container.
86 - (NSUInteger)visibleButtonCount;
88 // Returns the preferred size for the container.
89 - (gfx::Size)preferredSize;
91 // Returns where the popup arrow should point to for the action with the given
92 // |id|. If passed an id with no corresponding button, returns NSZeroPoint.
93 - (NSPoint)popupPointForId:(const std::string&)id;
95 // Returns whether the chevron button is currently hidden or in the process of
96 // being hidden (fading out). Will return NO if it is not hidden or is in the
97 // process of fading in.
98 - (BOOL)chevronIsHidden;
100 // Returns the currently-active web contents.
101 - (content::WebContents*)currentWebContents;
103 @end // @interface BrowserActionsController
105 @interface BrowserActionsController(TestingAPI)
106 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index;
107 - (ToolbarActionsBar*)toolbarActionsBar;
108 + (BrowserActionsController*)fromToolbarActionsBarDelegate:
109 (ToolbarActionsBarDelegate*)delegate;
110 @end
112 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_