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
;
22 @
class BrowserActionsContainerView
;
23 class BrowserActionsContainerViewSizeDelegate
;
24 @
class BrowserActionsController
;
26 class LocationBarViewMac
;
31 @
class WrenchMenuController
;
37 namespace ToolbarControllerInternal
{
38 class NotificationBridge
;
41 // A controller for the toolbar in the browser window. Manages
42 // updating the state for location bar and back/fwd/reload/go buttons.
43 // Manages the bookmark bar and its position in the window relative to
44 // the web content view.
46 @interface ToolbarController
: NSViewController
<CommandObserverProtocol
,
47 URLDropTargetController
> {
49 // The ordering is important for unit tests. If new items are added or the
50 // ordering is changed, make sure to update |-toolbarViews| and the
51 // corresponding enum in the unit tests.
52 IBOutlet MenuButton
* backButton_
;
53 IBOutlet MenuButton
* forwardButton_
;
54 IBOutlet ReloadButton
* reloadButton_
;
55 IBOutlet ToolbarButton
* homeButton_
;
56 IBOutlet MenuButton
* wrenchButton_
;
57 IBOutlet AutocompleteTextField
* locationBar_
;
58 IBOutlet BrowserActionsContainerView
* browserActionsContainerView_
;
61 CommandUpdater
* commands_
; // weak, one per window
62 Profile
* profile_
; // weak, one per window
63 Browser
* browser_
; // weak, one per window
64 scoped_ptr
<CommandObserverBridge
> commandObserver_
;
65 scoped_ptr
<LocationBarViewMac
> locationBarView_
;
66 base::scoped_nsobject
<AutocompleteTextFieldEditor
>
67 autocompleteTextFieldEditor_
;
68 id
<ViewResizer
> resizeDelegate_
; // weak
69 base::scoped_nsobject
<BackForwardMenuController
> backMenuController_
;
70 base::scoped_nsobject
<BackForwardMenuController
> forwardMenuController_
;
71 base::scoped_nsobject
<BrowserActionsController
> browserActionsController_
;
72 scoped_ptr
<BrowserActionsContainerViewSizeDelegate
>
73 browserActionsContainerDelegate_
;
75 // Lazily-instantiated menu controller.
76 base::scoped_nsobject
<WrenchMenuController
> wrenchMenuController_
;
78 // Used for monitoring the optional toolbar button prefs.
79 scoped_ptr
<ToolbarControllerInternal::NotificationBridge
> notificationBridge_
;
80 BooleanPrefMember showHomeButton_
;
81 BOOL hasToolbar_
; // If NO, we may have only the location bar.
82 BOOL hasLocationBar_
; // If |hasToolbar_| is YES, this must also be YES.
83 BOOL locationBarAtMinSize_
; // If the location bar is at the minimum size.
85 // We have an extra retain in the locationBar_.
86 // See comments in awakeFromNib for more info.
87 base::scoped_nsobject
<AutocompleteTextField
> locationBarRetainer_
;
89 // Tracking area for mouse enter/exit/moved in the toolbar.
90 ui::ScopedCrTrackingArea trackingArea_
;
92 // We retain/release the hover button since interaction with the
93 // button may make it go away (e.g. delete menu option over a
94 // bookmark button). Thus this variable is not weak. The
95 // hoveredButton_ is required to have an NSCell that responds to
96 // setMouseInside:animate:.
97 NSButton
* hoveredButton_
;
100 // Initialize the toolbar and register for command updates. The profile is
101 // needed for initializing the location bar. The browser is needed for
102 // the toolbar model and back/forward menus.
103 - (id
)initWithCommands
:(CommandUpdater
*)commands
104 profile
:(Profile
*)profile
105 browser
:(Browser
*)browser
106 resizeDelegate
:(id
<ViewResizer
>)resizeDelegate
;
108 // Get the C++ bridge object representing the location bar for this tab.
109 - (LocationBarViewMac
*)locationBarBridge
;
111 // Called by the Window delegate so we can provide a custom field editor if
113 // Note that this may be called for objects unrelated to the toolbar.
114 // returns nil if we don't want to override the custom field editor for |obj|.
115 - (id
)customFieldEditorForObject
:(id
)obj
;
117 // Make the location bar the first responder, if possible.
118 - (void)focusLocationBar
:(BOOL
)selectAll
;
120 // Forces the toolbar (and transitively the location bar) to update its current
121 // state. If |tab| is non-NULL, we're switching (back?) to this tab and should
122 // restore any previous location bar state (such as user editing) as well.
123 - (void)updateToolbarWithContents
:(content::WebContents
*)tab
;
125 // Resets the state for |tab|.
126 - (void)resetTabState
:(content::WebContents
*)tab
;
128 // Sets whether or not the current page in the frontmost tab is bookmarked.
129 - (void)setStarredState
:(BOOL
)isStarred
;
131 // Sets whether or not the current page is translated.
132 - (void)setTranslateIconLit
:(BOOL
)on
;
134 // Sets whether or not an overflowed toolbar action wants to run.
135 // Only used if the extension toolbar redesign is on.
136 - (void)setOverflowedToolbarActionWantsToRun
:(BOOL
)overflowedActionWantsToRun
;
138 // Happens when the zoom for the active tab changes, the active tab switches, or
139 // a new tab or browser window is created. |canShowBubble| indicates if it is
140 // appropriate to show a zoom bubble for the change.
141 - (void)zoomChangedForActiveTab
:(BOOL
)canShowBubble
;
143 // Called to update the loading state. Handles updating the go/stop
144 // button state. |force| is set if the update is due to changing
145 // tabs, as opposed to the page-load finishing. See comment in
146 // reload_button_cocoa.h.
147 - (void)setIsLoading
:(BOOL
)isLoading force
:(BOOL
)force
;
149 // Allow turning off the toolbar (but we may keep the location bar without a
150 // surrounding toolbar). If |toolbar| is YES, the value of |hasLocationBar| is
151 // ignored. This changes the behavior of other methods, like |-view|.
152 - (void)setHasToolbar
:(BOOL
)toolbar hasLocationBar
:(BOOL
)locBar
;
154 // Point on the star icon for the bookmark bubble to be - in the
155 // associated window's coordinate system.
156 - (NSPoint
)bookmarkBubblePoint
;
158 // Point on the translate icon fot the Translate bubble.
159 - (NSPoint
)translateBubblePoint
;
161 // Returns the desired toolbar height for the given compression factor.
162 - (CGFloat
)desiredHeightForCompression
:(CGFloat
)compressByHeight
;
164 // Set the opacity of the divider (the line at the bottom) *if* we have a
165 // |ToolbarView| (0 means don't show it); no-op otherwise.
166 - (void)setDividerOpacity
:(CGFloat
)opacity
;
168 // Create and add the Browser Action buttons to the toolbar view.
169 - (void)createBrowserActionButtons
;
171 // Return the BrowserActionsController for this toolbar.
172 - (BrowserActionsController
*)browserActionsController
;
174 // Returns the wrench button.
175 - (NSButton
*)wrenchButton
;
177 // Returns the wrench menu controller.
178 - (WrenchMenuController
*)wrenchMenuController
;
182 // A set of private methods used by subclasses. Do not call these directly
183 // unless a subclass of ToolbarController.
184 @interface
ToolbarController(ProtectedMethods
)
185 // Designated initializer which takes a nib name in order to allow subclasses
186 // to load a different nib file.
187 - (id
)initWithCommands
:(CommandUpdater
*)commands
188 profile
:(Profile
*)profile
189 browser
:(Browser
*)browser
190 resizeDelegate
:(id
<ViewResizer
>)resizeDelegate
191 nibFileNamed
:(NSString
*)nibName
;
194 // A set of private methods used by tests, in the absence of "friends" in ObjC.
195 @interface
ToolbarController(PrivateTestMethods
)
196 // Returns an array of views in the order of the outlets above.
197 - (NSArray
*)toolbarViews
;
198 - (void)showOptionalHomeButton
;
199 - (void)installWrenchMenu
;
200 // Return a hover button for the current event.
201 - (NSButton
*)hoverButtonForEvent
:(NSEvent
*)theEvent
;
204 #endif // CHROME_BROWSER_UI_COCOA_TOOLBAR_TOOLBAR_CONTROLLER_H_