NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / toolbar / toolbar_controller.h
blobb0238973d50aa363409863125d2194ce49c8995c
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 // Happens when the zoom for the active tab changes, the active tab switches, or
126 // a new tab or browser window is created. |canShowBubble| indicates if it is
127 // appropriate to show a zoom bubble for the change.
128 - (void)zoomChangedForActiveTab:(BOOL)canShowBubble;
130 // Called to update the loading state. Handles updating the go/stop
131 // button state. |force| is set if the update is due to changing
132 // tabs, as opposed to the page-load finishing. See comment in
133 // reload_button.h.
134 - (void)setIsLoading:(BOOL)isLoading force:(BOOL)force;
136 // Allow turning off the toolbar (but we may keep the location bar without a
137 // surrounding toolbar). If |toolbar| is YES, the value of |hasLocationBar| is
138 // ignored. This changes the behavior of other methods, like |-view|.
139 - (void)setHasToolbar:(BOOL)toolbar hasLocationBar:(BOOL)locBar;
141 // Point on the star icon for the bookmark bubble to be - in the
142 // associated window's coordinate system.
143 - (NSPoint)bookmarkBubblePoint;
145 // Returns the desired toolbar height for the given compression factor.
146 - (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight;
148 // Set the opacity of the divider (the line at the bottom) *if* we have a
149 // |ToolbarView| (0 means don't show it); no-op otherwise.
150 - (void)setDividerOpacity:(CGFloat)opacity;
152 // Create and add the Browser Action buttons to the toolbar view.
153 - (void)createBrowserActionButtons;
155 // Return the BrowserActionsController for this toolbar.
156 - (BrowserActionsController*)browserActionsController;
158 // Returns the wrench button.
159 - (NSView*)wrenchButton;
161 @end
163 // A set of private methods used by subclasses. Do not call these directly
164 // unless a subclass of ToolbarController.
165 @interface ToolbarController(ProtectedMethods)
166 // Designated initializer which takes a nib name in order to allow subclasses
167 // to load a different nib file.
168 - (id)initWithCommands:(CommandUpdater*)commands
169 profile:(Profile*)profile
170 browser:(Browser*)browser
171 resizeDelegate:(id<ViewResizer>)resizeDelegate
172 nibFileNamed:(NSString*)nibName;
173 @end
175 // A set of private methods used by tests, in the absence of "friends" in ObjC.
176 @interface ToolbarController(PrivateTestMethods)
177 // Returns an array of views in the order of the outlets above.
178 - (NSArray*)toolbarViews;
179 - (void)showOptionalHomeButton;
180 - (void)installWrenchMenu;
181 - (WrenchMenuController*)wrenchMenuController;
182 // Return a hover button for the current event.
183 - (NSButton*)hoverButtonForEvent:(NSEvent*)theEvent;
184 @end
186 #endif // CHROME_BROWSER_UI_COCOA_TOOLBAR_TOOLBAR_CONTROLLER_H_