Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / extensions / browser_actions_controller.h
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 namespace content {
27 class WebContents;
28 }
29
30 // Sent when the visibility of the Browser Actions changes.
31 extern NSString* const kBrowserActionVisibilityChangedNotification;
32
33 // Handles state and provides an interface for controlling the Browser Actions
34 // container within the Toolbar.
35 @interface BrowserActionsController : NSObject<NSMenuDelegate> {
36  @private
37   // Reference to the current browser. Weak.
38   Browser* browser_;
39
40   // The view from Toolbar.xib we'll be rendering our browser actions in. Weak.
41   BrowserActionsContainerView* containerView_;
42
43   // The current profile. Weak.
44   Profile* profile_;
45
46   // The model that tracks the order of the toolbar icons. Weak.
47   extensions::ExtensionToolbarModel* toolbarModel_;
48
49   // The observer for the ExtensionService we're getting events from.
50   scoped_ptr<ExtensionServiceObserverBridge> observer_;
51
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
54   // extension.
55   base::scoped_nsobject<NSMutableDictionary> buttons_;
56
57   // Array of hidden buttons in the correct order in which the user specified.
58   base::scoped_nsobject<NSMutableArray> hiddenButtons_;
59
60   // The currently running chevron animation (fade in/out).
61   base::scoped_nsobject<NSViewAnimation> chevronAnimation_;
62
63   // The chevron button used when Browser Actions are hidden.
64   base::scoped_nsobject<MenuButton> chevronMenuButton_;
65
66   // The Browser Actions overflow menu.
67   base::scoped_nsobject<NSMenu> overflowMenu_;
68 }
69
70 @property(readonly, nonatomic) BrowserActionsContainerView* containerView;
71
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;
76
77 // Update the display of all buttons.
78 - (void)update;
79
80 // Returns the current number of browser action buttons within the container,
81 // whether or not they are displayed.
82 - (NSUInteger)buttonCount;
83
84 // Returns the current number of browser action buttons displayed in the
85 // container.
86 - (NSUInteger)visibleButtonCount;
87
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;
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 the action with the given
98 // |id|. If passed an id with no corresponding button, returns NSZeroPoint.
99 - (NSPoint)popupPointForId:(const std::string&)id;
100
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;
105
106 // Activates the browser action for the extension that has the given id.
107 - (void)activateBrowserAction:(const std::string&)extension_id;
108
109 // Returns the currently-active web contents.
110 - (content::WebContents*)currentWebContents;
111
112 @end  // @interface BrowserActionsController
113
114 @interface BrowserActionsController(TestingAPI)
115 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index;
116 @end
117
118 #endif  // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_