| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_ | 6 #define CHROME_BROWSER_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_ |
| 7 | 7 |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 | 9 |
| 10 #import "base/scoped_nsobject.h" | 10 #import "base/scoped_nsobject.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 | 12 |
| 13 class Browser; | 13 class Browser; |
| 14 @class BrowserActionButton; | 14 @class BrowserActionButton; |
| 15 @class BrowserActionsContainerView; | 15 @class BrowserActionsContainerView; |
| 16 class Extension; | 16 class Extension; |
| 17 @class ExtensionPopupController; | 17 @class ExtensionPopupController; |
| 18 class ExtensionToolbarModel; | 18 class ExtensionToolbarModel; |
| 19 class ExtensionsServiceObserverBridge; | 19 class ExtensionsServiceObserverBridge; |
| 20 class PrefService; |
| 20 class Profile; | 21 class Profile; |
| 21 | 22 |
| 23 // The padding between browser action buttons. |
| 22 extern const CGFloat kBrowserActionButtonPadding; | 24 extern const CGFloat kBrowserActionButtonPadding; |
| 23 | 25 |
| 24 extern NSString* const kBrowserActionsChangedNotification; | 26 // Sent when the visibility of the Browser Actions changes. |
| 27 extern const NSString* kBrowserActionVisibilityChangedNotification; |
| 25 | 28 |
| 29 // Handles state and provides an interface for controlling the Browser Actions |
| 30 // container within the Toolbar. |
| 26 @interface BrowserActionsController : NSObject { | 31 @interface BrowserActionsController : NSObject { |
| 27 @private | 32 @private |
| 28 // Reference to the current browser. Weak. | 33 // Reference to the current browser. Weak. |
| 29 Browser* browser_; | 34 Browser* browser_; |
| 30 | 35 |
| 31 // The view from Toolbar.xib we'll be rendering our browser actions in. Weak. | 36 // The view from Toolbar.xib we'll be rendering our browser actions in. Weak. |
| 32 BrowserActionsContainerView* containerView_; | 37 BrowserActionsContainerView* containerView_; |
| 33 | 38 |
| 34 // The current profile. Weak. | 39 // The current profile. Weak. |
| 35 Profile* profile_; | 40 Profile* profile_; |
| 36 | 41 |
| 37 // The model that tracks the order of the toolbar icons. Weak. | 42 // The model that tracks the order of the toolbar icons. Weak. |
| 38 ExtensionToolbarModel* toolbarModel_; | 43 ExtensionToolbarModel* toolbarModel_; |
| 39 | 44 |
| 40 // The observer for the ExtensionsService we're getting events from. | 45 // The observer for the ExtensionsService we're getting events from. |
| 41 scoped_ptr<ExtensionsServiceObserverBridge> observer_; | 46 scoped_ptr<ExtensionsServiceObserverBridge> observer_; |
| 42 | 47 |
| 43 // A dictionary of Extension ID -> BrowserActionButton pairs representing the | 48 // A dictionary of Extension ID -> BrowserActionButton pairs representing the |
| 44 // buttons present in the container view. The ID is a string unique to each | 49 // buttons present in the container view. The ID is a string unique to each |
| 45 // extension. | 50 // extension. |
| 46 scoped_nsobject<NSMutableDictionary> buttons_; | 51 scoped_nsobject<NSMutableDictionary> buttons_; |
| 47 | |
| 48 // The order of the BrowserActionButton objects within the dictionary. | |
| 49 scoped_nsobject<NSMutableArray> buttonOrder_; | |
| 50 } | 52 } |
| 51 | 53 |
| 52 @property(readonly, nonatomic) BrowserActionsContainerView* containerView; | 54 @property(readonly, nonatomic) BrowserActionsContainerView* containerView; |
| 53 | 55 |
| 54 // Initializes the controller given the current browser and container view that | 56 // Initializes the controller given the current browser and container view that |
| 55 // will hold the browser action buttons. | 57 // will hold the browser action buttons. |
| 56 - (id)initWithBrowser:(Browser*)browser | 58 - (id)initWithBrowser:(Browser*)browser |
| 57 containerView:(BrowserActionsContainerView*)container; | 59 containerView:(BrowserActionsContainerView*)container; |
| 58 | 60 |
| 59 // Creates and appends any existing browser action buttons present within the | |
| 60 // extensions service to the toolbar. | |
| 61 - (void)createButtons; | |
| 62 | |
| 63 // Returns the ideal (not current) width to fit all visible extensions and other | |
| 64 // UI elements in the container nicely. | |
| 65 - (CGFloat)idealContainerWidth; | |
| 66 | |
| 67 // Update the display of all buttons. | 61 // Update the display of all buttons. |
| 68 - (void)update; | 62 - (void)update; |
| 69 | 63 |
| 70 // Returns the current number of browser action buttons within the container, | 64 // Returns the current number of browser action buttons within the container, |
| 71 // whether or not they are displayed. | 65 // whether or not they are displayed. |
| 72 - (NSUInteger)buttonCount; | 66 - (NSUInteger)buttonCount; |
| 73 | 67 |
| 74 // Returns the current number of browser action buttons displayed in the | 68 // Returns the current number of browser action buttons displayed in the |
| 75 // container. | 69 // container. |
| 76 - (NSUInteger)visibleButtonCount; | 70 - (NSUInteger)visibleButtonCount; |
| 77 | 71 |
| 72 // Resizes the container to fit all the visible buttons and other elements |
| 73 // (grippy and overflow button). |
| 74 - (void)resizeContainerWithAnimation:(BOOL)animate; |
| 75 |
| 78 // Executes the action designated by the extension. | 76 // Executes the action designated by the extension. |
| 79 - (void)browserActionClicked:(BrowserActionButton*)sender; | 77 - (void)browserActionClicked:(BrowserActionButton*)sender; |
| 80 | 78 |
| 81 // Returns the NSView for the action button associated with an extension. | 79 // Returns the NSView for the action button associated with an extension. |
| 82 - (NSView*)browserActionViewForExtension:(Extension*)extension; | 80 - (NSView*)browserActionViewForExtension:(Extension*)extension; |
| 83 | 81 |
| 82 // Returns the saved width preference as specified by the user. If none is |
| 83 // specified, then zero is returned, indicating that the width has never been |
| 84 // set. |
| 85 - (CGFloat)savedWidth; |
| 86 |
| 87 // Registers the user preferences used by this class. |
| 88 + (void)registerUserPrefs:(PrefService*)prefs; |
| 89 |
| 84 @end // @interface BrowserActionsController | 90 @end // @interface BrowserActionsController |
| 85 | 91 |
| 86 @interface BrowserActionsController(TestingAPI) | 92 @interface BrowserActionsController(TestingAPI) |
| 87 - (NSButton*)buttonWithIndex:(int)index; | 93 - (NSButton*)buttonWithIndex:(NSUInteger)index; |
| 88 @end | 94 @end |
| 89 | 95 |
| 90 #endif // CHROME_BROWSER_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_ | 96 #endif // CHROME_BROWSER_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_ |
| OLD | NEW |