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"
14 @class BrowserActionButton;
15 @class BrowserActionsContainerView;
16 @class ExtensionPopupController;
17 class ExtensionServiceObserverBridge;
21 namespace extensions {
23 class ExtensionToolbarModel;
30 // Sent when the visibility of the Browser Actions changes.
31 extern NSString* const kBrowserActionVisibilityChangedNotification;
33 // Handles state and provides an interface for controlling the Browser Actions
34 // container within the Toolbar.
35 @interface BrowserActionsController : NSObject<NSMenuDelegate> {
37 // Reference to the current browser. Weak.
40 // The view from Toolbar.xib we'll be rendering our browser actions in. Weak.
41 BrowserActionsContainerView* containerView_;
43 // The current profile. Weak.
46 // The model that tracks the order of the toolbar icons. Weak.
47 extensions::ExtensionToolbarModel* toolbarModel_;
49 // The observer for the ExtensionService we're getting events from.
50 scoped_ptr<ExtensionServiceObserverBridge> observer_;
52 // A dictionary of Extension ID -> BrowserActionButton pairs representing the
53 // buttons present in the container view. The ID is a string unique to each
55 base::scoped_nsobject<NSMutableDictionary> buttons_;
57 // Array of hidden buttons in the correct order in which the user specified.
58 base::scoped_nsobject<NSMutableArray> hiddenButtons_;
60 // The currently running chevron animation (fade in/out).
61 base::scoped_nsobject<NSViewAnimation> chevronAnimation_;
63 // The chevron button used when Browser Actions are hidden.
64 base::scoped_nsobject<MenuButton> chevronMenuButton_;
66 // The Browser Actions overflow menu.
67 base::scoped_nsobject<NSMenu> overflowMenu_;
70 @property(readonly, nonatomic) BrowserActionsContainerView* containerView;
72 // Initializes the controller given the current browser and container view that
73 // will hold the browser action buttons.
74 - (id)initWithBrowser:(Browser*)browser
75 containerView:(BrowserActionsContainerView*)container;
77 // Update the display of all buttons.
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
86 - (NSUInteger)visibleButtonCount;
88 // Resizes the container given the number of visible buttons, taking into
89 // account the size of the grippy. Also updates the persistent width preference.
90 - (void)resizeContainerAndAnimate:(BOOL)animate;
92 // Returns the saved width determined by the number of shown Browser Actions
93 // preference property. If no preference is found, then the width for the
94 // container is returned as if all buttons are shown.
95 - (CGFloat)savedWidth;
97 // Returns where the popup arrow should point to for the action with the given
98 // |id|. If passed an id with no corresponding button, returns NSZeroPoint.
99 - (NSPoint)popupPointForId:(const std::string&)id;
101 // Returns whether the chevron button is currently hidden or in the process of
102 // being hidden (fading out). Will return NO if it is not hidden or is in the
103 // process of fading in.
104 - (BOOL)chevronIsHidden;
106 // Activates the browser action for the extension that has the given id.
107 - (void)activateBrowserAction:(const std::string&)extension_id;
109 // Returns the currently-active web contents.
110 - (content::WebContents*)currentWebContents;
112 @end // @interface BrowserActionsController
114 @interface BrowserActionsController(TestingAPI)
115 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index;
118 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_