Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / browser_actions_controller.h
blobfea685ad672ce627e418ae861e06fc1168f3f7ca
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 #import "chrome/browser/ui/cocoa/has_weak_browser_pointer.h"
13 #include "ui/gfx/geometry/size.h"
15 class Browser;
16 @class BrowserActionButton;
17 @class BrowserActionsContainerView;
18 @class MenuButton;
19 class ToolbarActionsBar;
20 @class ToolbarActionsBarBubbleMac;
21 class ToolbarActionsBarDelegate;
23 namespace content {
24 class WebContents;
27 // Sent when the visibility of the Browser Actions changes.
28 extern NSString* const kBrowserActionVisibilityChangedNotification;
30 // Handles state and provides an interface for controlling the Browser Actions
31 // container within the Toolbar.
32 @interface BrowserActionsController
33 : NSObject<NSMenuDelegate, HasWeakBrowserPointer> {
34 @private
35 // Reference to the current browser. Weak.
36 Browser* browser_;
38 // The view from Toolbar.xib we'll be rendering our browser actions in. Weak.
39 BrowserActionsContainerView* containerView_;
41 // Array of toolbar action buttons in the correct order for them to be
42 // displayed (includes both hidden and visible buttons).
43 base::scoped_nsobject<NSMutableArray> buttons_;
45 // The delegate for the ToolbarActionsBar.
46 scoped_ptr<ToolbarActionsBarDelegate> toolbarActionsBarBridge_;
48 // The controlling ToolbarActionsBar.
49 scoped_ptr<ToolbarActionsBar> toolbarActionsBar_;
51 // True if we should supppress the chevron (we do this during drag
52 // animations).
53 BOOL suppressChevron_;
55 // True if this is the overflow container for toolbar actions.
56 BOOL isOverflow_;
58 // The currently running chevron animation (fade in/out).
59 base::scoped_nsobject<NSViewAnimation> chevronAnimation_;
61 // The chevron button used when Browser Actions are hidden.
62 base::scoped_nsobject<MenuButton> chevronMenuButton_;
64 // The Browser Actions overflow menu.
65 base::scoped_nsobject<NSMenu> overflowMenu_;
67 // The bubble that is actively showing, if any.
68 ToolbarActionsBarBubbleMac* activeBubble_;
70 // The index of the currently-focused view in the overflow menu, or -1 if
71 // no view is focused.
72 NSInteger focusedViewIndex_;
75 @property(readonly, nonatomic) BrowserActionsContainerView* containerView;
76 @property(readonly, nonatomic) Browser* browser;
77 @property(readonly, nonatomic) BOOL isOverflow;
78 @property(readonly, nonatomic) ToolbarActionsBarBubbleMac* activeBubble;
80 // Initializes the controller given the current browser and container view that
81 // will hold the browser action buttons. If |mainController| is nil, the created
82 // BrowserActionsController will be the main controller; otherwise (if this is
83 // for the overflow menu), |mainController| should be controller of the main bar
84 // for the |browser|.
85 - (id)initWithBrowser:(Browser*)browser
86 containerView:(BrowserActionsContainerView*)container
87 mainController:(BrowserActionsController*)mainController;
89 // Update the display of all buttons.
90 - (void)update;
92 // Returns the current number of browser action buttons within the container,
93 // whether or not they are displayed.
94 - (NSUInteger)buttonCount;
96 // Returns the current number of browser action buttons displayed in the
97 // container.
98 - (NSUInteger)visibleButtonCount;
100 // Returns the preferred size for the container.
101 - (gfx::Size)preferredSize;
103 // Returns where the popup arrow should point to for the action with the given
104 // |id|. If passed an id with no corresponding button, returns NSZeroPoint.
105 - (NSPoint)popupPointForId:(const std::string&)id;
107 // Returns whether the chevron button is currently hidden or in the process of
108 // being hidden (fading out). Will return NO if it is not hidden or is in the
109 // process of fading in.
110 - (BOOL)chevronIsHidden;
112 // Returns the currently-active web contents.
113 - (content::WebContents*)currentWebContents;
115 // Returns the BrowserActionButton in the main browser actions container (as
116 // opposed to the overflow) for the action of the given id.
117 - (BrowserActionButton*)mainButtonForId:(const std::string&)id;
119 // Returns the associated ToolbarActionsBar.
120 - (ToolbarActionsBar*)toolbarActionsBar;
122 // Sets whether or not the overflow container is focused in the wrench menu.
123 - (void)setFocusedInOverflow:(BOOL)focused;
125 // Returns the size for the provided |maxWidth| of the overflow menu.
126 - (gfx::Size)sizeForOverflowWidth:(int)maxWidth;
128 @end // @interface BrowserActionsController
130 @interface BrowserActionsController(TestingAPI)
131 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index;
132 @end
134 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_