OLD | NEW |
| (Empty) |
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_TOOLBAR_CONTROLLER_H_ | |
6 #define CHROME_BROWSER_UI_COCOA_TOOLBAR_CONTROLLER_H_ | |
7 #pragma once | |
8 | |
9 #import <Cocoa/Cocoa.h> | |
10 | |
11 #include "base/scoped_ptr.h" | |
12 #include "base/scoped_nsobject.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 #include "chrome/browser/prefs/pref_member.h" | |
17 | |
18 @class AutocompleteTextField; | |
19 @class AutocompleteTextFieldEditor; | |
20 @class BrowserActionsContainerView; | |
21 @class BackForwardMenuController; | |
22 class Browser; | |
23 @class BrowserActionsController; | |
24 class CommandUpdater; | |
25 class LocationBar; | |
26 class LocationBarViewMac; | |
27 @class MenuButton; | |
28 namespace ToolbarControllerInternal { | |
29 class NotificationBridge; | |
30 class WrenchAcceleratorDelegate; | |
31 } // namespace ToolbarControllerInternal | |
32 class Profile; | |
33 @class ReloadButton; | |
34 class TabContents; | |
35 class ToolbarModel; | |
36 @class WrenchMenuController; | |
37 class WrenchMenuModel; | |
38 | |
39 // A controller for the toolbar in the browser window. Manages | |
40 // updating the state for location bar and back/fwd/reload/go buttons. | |
41 // Manages the bookmark bar and its position in the window relative to | |
42 // the web content view. | |
43 | |
44 @interface ToolbarController : NSViewController<CommandObserverProtocol, | |
45 URLDropTargetController> { | |
46 @protected | |
47 // The ordering is important for unit tests. If new items are added or the | |
48 // ordering is changed, make sure to update |-toolbarViews| and the | |
49 // corresponding enum in the unit tests. | |
50 IBOutlet MenuButton* backButton_; | |
51 IBOutlet MenuButton* forwardButton_; | |
52 IBOutlet ReloadButton* reloadButton_; | |
53 IBOutlet NSButton* homeButton_; | |
54 IBOutlet MenuButton* wrenchButton_; | |
55 IBOutlet AutocompleteTextField* locationBar_; | |
56 IBOutlet BrowserActionsContainerView* browserActionsContainerView_; | |
57 IBOutlet WrenchMenuController* wrenchMenuController_; | |
58 | |
59 @private | |
60 ToolbarModel* toolbarModel_; // weak, one per window | |
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 scoped_nsobject<AutocompleteTextFieldEditor> autocompleteTextFieldEditor_; | |
67 id<ViewResizer> resizeDelegate_; // weak | |
68 scoped_nsobject<BackForwardMenuController> backMenuController_; | |
69 scoped_nsobject<BackForwardMenuController> forwardMenuController_; | |
70 scoped_nsobject<BrowserActionsController> browserActionsController_; | |
71 | |
72 // Lazily-instantiated model and delegate for the menu on the | |
73 // wrench button. Once visible, it will be non-null, but will not | |
74 // reaped when the menu is hidden once it is initially shown. | |
75 scoped_ptr<ToolbarControllerInternal::WrenchAcceleratorDelegate> | |
76 acceleratorDelegate_; | |
77 scoped_ptr<WrenchMenuModel> wrenchMenuModel_; | |
78 | |
79 // Used for monitoring the optional toolbar button prefs. | |
80 scoped_ptr<ToolbarControllerInternal::NotificationBridge> notificationBridge_; | |
81 BooleanPrefMember showHomeButton_; | |
82 BooleanPrefMember showPageOptionButtons_; | |
83 BOOL hasToolbar_; // If NO, we may have only the location bar. | |
84 BOOL hasLocationBar_; // If |hasToolbar_| is YES, this must also be YES. | |
85 BOOL locationBarAtMinSize_; // If the location bar is at the minimum size. | |
86 | |
87 // We have an extra retain in the locationBar_. | |
88 // See comments in awakeFromNib for more info. | |
89 scoped_nsobject<AutocompleteTextField> locationBarRetainer_; | |
90 | |
91 // Tracking area for mouse enter/exit/moved in the toolbar. | |
92 scoped_nsobject<NSTrackingArea> trackingArea_; | |
93 | |
94 // We retain/release the hover button since interaction with the | |
95 // button may make it go away (e.g. delete menu option over a | |
96 // bookmark button). Thus this variable is not weak. The | |
97 // hoveredButton_ is required to have an NSCell that responds to | |
98 // setMouseInside:animate:. | |
99 NSButton* hoveredButton_; | |
100 } | |
101 | |
102 // Initialize the toolbar and register for command updates. The profile is | |
103 // needed for initializing the location bar. The browser is needed for | |
104 // initializing the back/forward menus. | |
105 - (id)initWithModel:(ToolbarModel*)model | |
106 commands:(CommandUpdater*)commands | |
107 profile:(Profile*)profile | |
108 browser:(Browser*)browser | |
109 resizeDelegate:(id<ViewResizer>)resizeDelegate; | |
110 | |
111 // Get the C++ bridge object representing the location bar for this tab. | |
112 - (LocationBarViewMac*)locationBarBridge; | |
113 | |
114 // Called by the Window delegate so we can provide a custom field editor if | |
115 // needed. | |
116 // Note that this may be called for objects unrelated to the toolbar. | |
117 // returns nil if we don't want to override the custom field editor for |obj|. | |
118 - (id)customFieldEditorForObject:(id)obj; | |
119 | |
120 // Make the location bar the first responder, if possible. | |
121 - (void)focusLocationBar:(BOOL)selectAll; | |
122 | |
123 // Updates the toolbar (and transitively the location bar) with the states of | |
124 // the specified |tab|. If |shouldRestore| is true, we're switching | |
125 // (back?) to this tab and should restore any previous location bar state | |
126 // (such as user editing) as well. | |
127 - (void)updateToolbarWithContents:(TabContents*)tabForRestoring | |
128 shouldRestoreState:(BOOL)shouldRestore; | |
129 | |
130 // Sets whether or not the current page in the frontmost tab is bookmarked. | |
131 - (void)setStarredState:(BOOL)isStarred; | |
132 | |
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; | |
138 | |
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; | |
143 | |
144 // Point on the star icon for the bookmark bubble to be - in the | |
145 // associated window's coordinate system. | |
146 - (NSPoint)bookmarkBubblePoint; | |
147 | |
148 // Returns the desired toolbar height for the given compression factor. | |
149 - (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight; | |
150 | |
151 // Set the opacity of the divider (the line at the bottom) *if* we have a | |
152 // |ToolbarView| (0 means don't show it); no-op otherwise. | |
153 - (void)setDividerOpacity:(CGFloat)opacity; | |
154 | |
155 // Create and add the Browser Action buttons to the toolbar view. | |
156 - (void)createBrowserActionButtons; | |
157 | |
158 // Return the BrowserActionsController for this toolbar. | |
159 - (BrowserActionsController*)browserActionsController; | |
160 | |
161 @end | |
162 | |
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)initWithModel:(ToolbarModel*)model | |
169 commands:(CommandUpdater*)commands | |
170 profile:(Profile*)profile | |
171 browser:(Browser*)browser | |
172 resizeDelegate:(id<ViewResizer>)resizeDelegate | |
173 nibFileNamed:(NSString*)nibName; | |
174 @end | |
175 | |
176 // A set of private methods used by tests, in the absence of "friends" in ObjC. | |
177 @interface ToolbarController(PrivateTestMethods) | |
178 // Returns an array of views in the order of the outlets above. | |
179 - (NSArray*)toolbarViews; | |
180 - (void)showOptionalHomeButton; | |
181 - (void)installWrenchMenu; | |
182 - (WrenchMenuController*)wrenchMenuController; | |
183 // Return a hover button for the current event. | |
184 - (NSButton*)hoverButtonForEvent:(NSEvent*)theEvent; | |
185 @end | |
186 | |
187 #endif // CHROME_BROWSER_UI_COCOA_TOOLBAR_CONTROLLER_H_ | |
OLD | NEW |