[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / toolbar / toolbar_controller.h
blob851e97b1beb4da2f0b1f0de9d14985f197bc2d46
1 // Copyright (c) 2012 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_TOOLBAR_TOOLBAR_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_COCOA_TOOLBAR_TOOLBAR_CONTROLLER_H_
8 #import <Cocoa/Cocoa.h>
10 #include "base/mac/scoped_nsobject.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/prefs/pref_member.h"
13 #import "chrome/browser/ui/cocoa/command_observer_bridge.h"
14 #import "chrome/browser/ui/cocoa/url_drop_target.h"
15 #import "chrome/browser/ui/cocoa/view_resizer.h"
16 #import "ui/base/cocoa/tracking_area.h"
18 @class AutocompleteTextField;
19 @class AutocompleteTextFieldEditor;
20 @class BackForwardMenuController;
21 class Browser;
22 @class BrowserActionsContainerView;
23 @class BrowserActionsController;
24 class CommandUpdater;
25 class LocationBarViewMac;
26 @class MenuButton;
27 class Profile;
28 @class ReloadButton;
29 @class ToolbarButton;
30 @class WrenchMenuController;
32 namespace content {
33 class WebContents;
36 namespace ToolbarControllerInternal {
37 class NotificationBridge;
40 // A controller for the toolbar in the browser window. Manages
41 // updating the state for location bar and back/fwd/reload/go buttons.
42 // Manages the bookmark bar and its position in the window relative to
43 // the web content view.
45 @interface ToolbarController : NSViewController<CommandObserverProtocol,
46 URLDropTargetController> {
47 @protected
48 // The ordering is important for unit tests. If new items are added or the
49 // ordering is changed, make sure to update |-toolbarViews| and the
50 // corresponding enum in the unit tests.
51 IBOutlet MenuButton* backButton_;
52 IBOutlet MenuButton* forwardButton_;
53 IBOutlet ReloadButton* reloadButton_;
54 IBOutlet ToolbarButton* homeButton_;
55 IBOutlet MenuButton* wrenchButton_;
56 IBOutlet AutocompleteTextField* locationBar_;
57 IBOutlet BrowserActionsContainerView* browserActionsContainerView_;
59 @private
60 CommandUpdater* commands_; // weak, one per window
61 Profile* profile_; // weak, one per window
62 Browser* browser_; // weak, one per window
63 scoped_ptr<CommandObserverBridge> commandObserver_;
64 scoped_ptr<LocationBarViewMac> locationBarView_;
65 base::scoped_nsobject<AutocompleteTextFieldEditor>
66 autocompleteTextFieldEditor_;
67 id<ViewResizer> resizeDelegate_; // weak
68 base::scoped_nsobject<BackForwardMenuController> backMenuController_;
69 base::scoped_nsobject<BackForwardMenuController> forwardMenuController_;
70 base::scoped_nsobject<BrowserActionsController> browserActionsController_;
72 // Lazily-instantiated menu controller.
73 base::scoped_nsobject<WrenchMenuController> wrenchMenuController_;
75 // Used for monitoring the optional toolbar button prefs.
76 scoped_ptr<ToolbarControllerInternal::NotificationBridge> notificationBridge_;
77 BooleanPrefMember showHomeButton_;
78 BOOL hasToolbar_; // If NO, we may have only the location bar.
79 BOOL hasLocationBar_; // If |hasToolbar_| is YES, this must also be YES.
80 BOOL locationBarAtMinSize_; // If the location bar is at the minimum size.
82 // We have an extra retain in the locationBar_.
83 // See comments in awakeFromNib for more info.
84 base::scoped_nsobject<AutocompleteTextField> locationBarRetainer_;
86 // Tracking area for mouse enter/exit/moved in the toolbar.
87 ui::ScopedCrTrackingArea trackingArea_;
89 // We retain/release the hover button since interaction with the
90 // button may make it go away (e.g. delete menu option over a
91 // bookmark button). Thus this variable is not weak. The
92 // hoveredButton_ is required to have an NSCell that responds to
93 // setMouseInside:animate:.
94 NSButton* hoveredButton_;
97 // Initialize the toolbar and register for command updates. The profile is
98 // needed for initializing the location bar. The browser is needed for
99 // the toolbar model and back/forward menus.
100 - (id)initWithCommands:(CommandUpdater*)commands
101 profile:(Profile*)profile
102 browser:(Browser*)browser
103 resizeDelegate:(id<ViewResizer>)resizeDelegate;
105 // Get the C++ bridge object representing the location bar for this tab.
106 - (LocationBarViewMac*)locationBarBridge;
108 // Called by the Window delegate so we can provide a custom field editor if
109 // needed.
110 // Note that this may be called for objects unrelated to the toolbar.
111 // returns nil if we don't want to override the custom field editor for |obj|.
112 - (id)customFieldEditorForObject:(id)obj;
114 // Make the location bar the first responder, if possible.
115 - (void)focusLocationBar:(BOOL)selectAll;
117 // Forces the toolbar (and transitively the location bar) to update its current
118 // state. If |tab| is non-NULL, we're switching (back?) to this tab and should
119 // restore any previous location bar state (such as user editing) as well.
120 - (void)updateToolbarWithContents:(content::WebContents*)tab;
122 // Sets whether or not the current page in the frontmost tab is bookmarked.
123 - (void)setStarredState:(BOOL)isStarred;
125 // Sets whether or not the current page is translated.
126 - (void)setTranslateIconLit:(BOOL)on;
128 // Happens when the zoom for the active tab changes, the active tab switches, or
129 // a new tab or browser window is created. |canShowBubble| indicates if it is
130 // appropriate to show a zoom bubble for the change.
131 - (void)zoomChangedForActiveTab:(BOOL)canShowBubble;
133 // Called to update the loading state. Handles updating the go/stop
134 // button state. |force| is set if the update is due to changing
135 // tabs, as opposed to the page-load finishing. See comment in
136 // reload_button.h.
137 - (void)setIsLoading:(BOOL)isLoading force:(BOOL)force;
139 // Allow turning off the toolbar (but we may keep the location bar without a
140 // surrounding toolbar). If |toolbar| is YES, the value of |hasLocationBar| is
141 // ignored. This changes the behavior of other methods, like |-view|.
142 - (void)setHasToolbar:(BOOL)toolbar hasLocationBar:(BOOL)locBar;
144 // Point on the star icon for the bookmark bubble to be - in the
145 // associated window's coordinate system.
146 - (NSPoint)bookmarkBubblePoint;
148 // Point on the translate icon fot the Translate bubble.
149 - (NSPoint)translateBubblePoint;
151 // Returns the desired toolbar height for the given compression factor.
152 - (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight;
154 // Set the opacity of the divider (the line at the bottom) *if* we have a
155 // |ToolbarView| (0 means don't show it); no-op otherwise.
156 - (void)setDividerOpacity:(CGFloat)opacity;
158 // Create and add the Browser Action buttons to the toolbar view.
159 - (void)createBrowserActionButtons;
161 // Return the BrowserActionsController for this toolbar.
162 - (BrowserActionsController*)browserActionsController;
164 // Returns the wrench button.
165 - (NSView*)wrenchButton;
167 // Activates the page action for the extension that has the given id.
168 - (void)activatePageAction:(const std::string&)extension_id;
170 // Activates the browser action for the extension that has the given id.
171 - (void)activateBrowserAction:(const std::string&)extension_id;
173 @end
175 // A set of private methods used by subclasses. Do not call these directly
176 // unless a subclass of ToolbarController.
177 @interface ToolbarController(ProtectedMethods)
178 // Designated initializer which takes a nib name in order to allow subclasses
179 // to load a different nib file.
180 - (id)initWithCommands:(CommandUpdater*)commands
181 profile:(Profile*)profile
182 browser:(Browser*)browser
183 resizeDelegate:(id<ViewResizer>)resizeDelegate
184 nibFileNamed:(NSString*)nibName;
185 @end
187 // A set of private methods used by tests, in the absence of "friends" in ObjC.
188 @interface ToolbarController(PrivateTestMethods)
189 // Returns an array of views in the order of the outlets above.
190 - (NSArray*)toolbarViews;
191 - (void)showOptionalHomeButton;
192 - (void)installWrenchMenu;
193 - (WrenchMenuController*)wrenchMenuController;
194 // Return a hover button for the current event.
195 - (NSButton*)hoverButtonForEvent:(NSEvent*)theEvent;
196 @end
198 #endif // CHROME_BROWSER_UI_COCOA_TOOLBAR_TOOLBAR_CONTROLLER_H_