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