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. 4 5 #ifndef CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_ 7 8 #import <Cocoa/Cocoa.h> 9 10 #import "base/mac/scoped_nsobject.h" 11 #include "base/memory/scoped_ptr.h" 12 13 class Browser; 14 @class BrowserActionButton; 15 @class BrowserActionsContainerView; 16 @class ExtensionPopupController; 17 class ExtensionServiceObserverBridge; 18 @class MenuButton; 19 class Profile; 20 21 namespace extensions { 22 class Extension; 23 class ExtensionToolbarModel; 24 } 25 26 // Sent when the visibility of the Browser Actions changes. 27 extern NSString* const kBrowserActionVisibilityChangedNotification; 28 29 // Handles state and provides an interface for controlling the Browser Actions 30 // container within the Toolbar. 31 @interface BrowserActionsController : NSObject<NSMenuDelegate> { 32 @private 33 // Reference to the current browser. Weak. 34 Browser* browser_; 35 36 // The view from Toolbar.xib we'll be rendering our browser actions in. Weak. 37 BrowserActionsContainerView* containerView_; 38 39 // The current profile. Weak. 40 Profile* profile_; 41 42 // The model that tracks the order of the toolbar icons. Weak. 43 extensions::ExtensionToolbarModel* toolbarModel_; 44 45 // The observer for the ExtensionService we're getting events from. 46 scoped_ptr<ExtensionServiceObserverBridge> observer_; 47 48 // A dictionary of Extension ID -> BrowserActionButton pairs representing the 49 // buttons present in the container view. The ID is a string unique to each 50 // extension. 51 base::scoped_nsobject<NSMutableDictionary> buttons_; 52 53 // Array of hidden buttons in the correct order in which the user specified. 54 base::scoped_nsobject<NSMutableArray> hiddenButtons_; 55 56 // The currently running chevron animation (fade in/out). 57 base::scoped_nsobject<NSViewAnimation> chevronAnimation_; 58 59 // The chevron button used when Browser Actions are hidden. 60 base::scoped_nsobject<MenuButton> chevronMenuButton_; 61 62 // The Browser Actions overflow menu. 63 base::scoped_nsobject<NSMenu> overflowMenu_; 64 } 65 66 @property(readonly, nonatomic) BrowserActionsContainerView* containerView; 67 68 // Initializes the controller given the current browser and container view that 69 // will hold the browser action buttons. 70 - (id)initWithBrowser:(Browser*)browser 71 containerView:(BrowserActionsContainerView*)container; 72 73 // Update the display of all buttons. 74 - (void)update; 75 76 // Returns the current number of browser action buttons within the container, 77 // whether or not they are displayed. 78 - (NSUInteger)buttonCount; 79 80 // Returns the current number of browser action buttons displayed in the 81 // container. 82 - (NSUInteger)visibleButtonCount; 83 84 // Resizes the container given the number of visible buttons, taking into 85 // account the size of the grippy. Also updates the persistent width preference. 86 - (void)resizeContainerAndAnimate:(BOOL)animate; 87 88 // Returns the NSView for the action button associated with an extension. 89 - (NSView*)browserActionViewForExtension:( 90 const extensions::Extension*)extension; 91 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; 96 97 // Returns where the popup arrow should point to for a given Browser Action. If 98 // it is passed an extension that is not a Browser Action, then it will return 99 // NSZeroPoint. 100 - (NSPoint)popupPointForBrowserAction:(const extensions::Extension*)extension; 101 102 // Returns whether the chevron button is currently hidden or in the process of 103 // being hidden (fading out). Will return NO if it is not hidden or is in the 104 // process of fading in. 105 - (BOOL)chevronIsHidden; 106 107 // Activates the browser action for the extension that has the given id. 108 - (void)activateBrowserAction:(const std::string&)extension_id; 109 110 @end // @interface BrowserActionsController 111 112 @interface BrowserActionsController(TestingAPI) 113 - (NSButton*)buttonWithIndex:(NSUInteger)index; 114 @end 115 116 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_ 117