OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 5 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 CGFloat BrowserActionsContainerDelegate::GetMaxAllowedWidth() { | 115 CGFloat BrowserActionsContainerDelegate::GetMaxAllowedWidth() { |
116 CGFloat location_bar_flex = | 116 CGFloat location_bar_flex = |
117 NSWidth([location_bar_ frame]) - kMinimumLocationBarWidth; | 117 NSWidth([location_bar_ frame]) - kMinimumLocationBarWidth; |
118 return NSWidth([browser_actions_container_ frame]) + location_bar_flex; | 118 return NSWidth([browser_actions_container_ frame]) + location_bar_flex; |
119 } | 119 } |
120 | 120 |
121 } // namespace | 121 } // namespace |
122 | 122 |
123 @interface ToolbarController() | 123 @interface ToolbarController() |
124 @property(assign, nonatomic) Browser* browser; | 124 @property(assign, nonatomic) Browser* browser; |
| 125 - (void)cleanUp; |
125 - (void)addAccessibilityDescriptions; | 126 - (void)addAccessibilityDescriptions; |
126 - (void)initCommandStatus:(CommandUpdater*)commands; | 127 - (void)initCommandStatus:(CommandUpdater*)commands; |
127 - (void)prefChanged:(const std::string&)prefName; | 128 - (void)prefChanged:(const std::string&)prefName; |
128 - (BackgroundGradientView*)backgroundGradientView; | 129 - (BackgroundGradientView*)backgroundGradientView; |
129 - (void)toolbarFrameChanged; | 130 - (void)toolbarFrameChanged; |
130 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; | 131 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; |
131 - (void)maintainMinimumLocationBarWidth; | 132 - (void)maintainMinimumLocationBarWidth; |
132 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; | 133 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; |
133 - (void)browserActionsContainerDragged:(NSNotification*)notification; | 134 - (void)browserActionsContainerDragged:(NSNotification*)notification; |
134 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; | 135 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 200 |
200 } // namespace ToolbarControllerInternal | 201 } // namespace ToolbarControllerInternal |
201 | 202 |
202 @implementation ToolbarController | 203 @implementation ToolbarController |
203 | 204 |
204 @synthesize browser = browser_; | 205 @synthesize browser = browser_; |
205 | 206 |
206 - (id)initWithCommands:(CommandUpdater*)commands | 207 - (id)initWithCommands:(CommandUpdater*)commands |
207 profile:(Profile*)profile | 208 profile:(Profile*)profile |
208 browser:(Browser*)browser | 209 browser:(Browser*)browser |
209 resizeDelegate:(id<ViewResizer>)resizeDelegate | |
210 nibFileNamed:(NSString*)nibName { | 210 nibFileNamed:(NSString*)nibName { |
211 DCHECK(commands && profile && [nibName length]); | 211 DCHECK(commands && profile && [nibName length]); |
212 if ((self = [super initWithNibName:nibName | 212 if ((self = [super initWithNibName:nibName |
213 bundle:base::mac::FrameworkBundle()])) { | 213 bundle:base::mac::FrameworkBundle()])) { |
214 commands_ = commands; | 214 commands_ = commands; |
215 profile_ = profile; | 215 profile_ = profile; |
216 browser_ = browser; | 216 browser_ = browser; |
217 resizeDelegate_ = resizeDelegate; | |
218 hasToolbar_ = YES; | 217 hasToolbar_ = YES; |
219 hasLocationBar_ = YES; | 218 hasLocationBar_ = YES; |
220 | 219 |
221 // Register for notifications about state changes for the toolbar buttons | 220 // Register for notifications about state changes for the toolbar buttons |
222 commandObserver_.reset( | 221 commandObserver_.reset( |
223 new ToolbarControllerInternal::CommandObserverBridge(self)); | 222 new ToolbarControllerInternal::CommandObserverBridge(self)); |
224 | 223 |
225 commands->AddCommandObserver(IDC_BACK, commandObserver_.get()); | 224 commands->AddCommandObserver(IDC_BACK, commandObserver_.get()); |
226 commands->AddCommandObserver(IDC_FORWARD, commandObserver_.get()); | 225 commands->AddCommandObserver(IDC_FORWARD, commandObserver_.get()); |
227 commands->AddCommandObserver(IDC_RELOAD, commandObserver_.get()); | 226 commands->AddCommandObserver(IDC_RELOAD, commandObserver_.get()); |
228 commands->AddCommandObserver(IDC_HOME, commandObserver_.get()); | 227 commands->AddCommandObserver(IDC_HOME, commandObserver_.get()); |
229 commands->AddCommandObserver(IDC_BOOKMARK_PAGE, commandObserver_.get()); | 228 commands->AddCommandObserver(IDC_BOOKMARK_PAGE, commandObserver_.get()); |
230 // NOTE: Don't remove the command observers. ToolbarController is | 229 // NOTE: Don't remove the command observers. ToolbarController is |
231 // autoreleased at about the same time as the CommandUpdater (owned by the | 230 // autoreleased at about the same time as the CommandUpdater (owned by the |
232 // Browser), so |commands_| may not be valid any more. | 231 // Browser), so |commands_| may not be valid any more. |
233 } | 232 } |
234 return self; | 233 return self; |
235 } | 234 } |
236 | 235 |
237 - (id)initWithCommands:(CommandUpdater*)commands | 236 - (id)initWithCommands:(CommandUpdater*)commands |
238 profile:(Profile*)profile | 237 profile:(Profile*)profile |
239 browser:(Browser*)browser | 238 browser:(Browser*)browser { |
240 resizeDelegate:(id<ViewResizer>)resizeDelegate { | |
241 if ((self = [self initWithCommands:commands | 239 if ((self = [self initWithCommands:commands |
242 profile:profile | 240 profile:profile |
243 browser:browser | 241 browser:browser |
244 resizeDelegate:resizeDelegate | |
245 nibFileNamed:@"Toolbar"])) { | 242 nibFileNamed:@"Toolbar"])) { |
246 } | 243 } |
247 return self; | 244 return self; |
248 } | 245 } |
249 | 246 |
250 | |
251 - (void)dealloc { | |
252 browserActionsContainerDelegate_.reset(); | |
253 | |
254 // Unset ViewIDs of toolbar elements. | |
255 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and | |
256 // |browserActionsContainerView_| are handled by themselves. | |
257 view_id_util::UnsetID(backButton_); | |
258 view_id_util::UnsetID(forwardButton_); | |
259 view_id_util::UnsetID(homeButton_); | |
260 view_id_util::UnsetID(wrenchButton_); | |
261 | |
262 // Make sure any code in the base class which assumes [self view] is | |
263 // the "parent" view continues to work. | |
264 hasToolbar_ = YES; | |
265 hasLocationBar_ = YES; | |
266 | |
267 [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
268 | |
269 if (trackingArea_.get()) | |
270 [[self view] removeTrackingArea:trackingArea_.get()]; | |
271 [super dealloc]; | |
272 } | |
273 | |
274 // Called after the view is done loading and the outlets have been hooked up. | 247 // Called after the view is done loading and the outlets have been hooked up. |
275 // Now we can hook up bridges that rely on UI objects such as the location | 248 // Now we can hook up bridges that rely on UI objects such as the location |
276 // bar and button state. | 249 // bar and button state. |
277 - (void)awakeFromNib { | 250 - (void)awakeFromNib { |
278 [[backButton_ cell] setImageID:IDR_BACK | 251 [[backButton_ cell] setImageID:IDR_BACK |
279 forButtonState:image_button_cell::kDefaultState]; | 252 forButtonState:image_button_cell::kDefaultState]; |
280 [[backButton_ cell] setImageID:IDR_BACK_H | 253 [[backButton_ cell] setImageID:IDR_BACK_H |
281 forButtonState:image_button_cell::kHoverState]; | 254 forButtonState:image_button_cell::kHoverState]; |
282 [[backButton_ cell] setImageID:IDR_BACK_P | 255 [[backButton_ cell] setImageID:IDR_BACK_P |
283 forButtonState:image_button_cell::kPressedState]; | 256 forButtonState:image_button_cell::kPressedState]; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and | 364 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and |
392 // |browserActionsContainerView_| are handled by themselves. | 365 // |browserActionsContainerView_| are handled by themselves. |
393 view_id_util::SetID(backButton_, VIEW_ID_BACK_BUTTON); | 366 view_id_util::SetID(backButton_, VIEW_ID_BACK_BUTTON); |
394 view_id_util::SetID(forwardButton_, VIEW_ID_FORWARD_BUTTON); | 367 view_id_util::SetID(forwardButton_, VIEW_ID_FORWARD_BUTTON); |
395 view_id_util::SetID(homeButton_, VIEW_ID_HOME_BUTTON); | 368 view_id_util::SetID(homeButton_, VIEW_ID_HOME_BUTTON); |
396 view_id_util::SetID(wrenchButton_, VIEW_ID_APP_MENU); | 369 view_id_util::SetID(wrenchButton_, VIEW_ID_APP_MENU); |
397 | 370 |
398 [self addAccessibilityDescriptions]; | 371 [self addAccessibilityDescriptions]; |
399 } | 372 } |
400 | 373 |
| 374 - (void)dealloc { |
| 375 [self cleanUp]; |
| 376 [super dealloc]; |
| 377 } |
| 378 |
| 379 - (void)browserWillBeDestroyed { |
| 380 // Pass this call onto other reference counted objects. |
| 381 [backMenuController_ browserWillBeDestroyed]; |
| 382 [forwardMenuController_ browserWillBeDestroyed]; |
| 383 [browserActionsController_ browserWillBeDestroyed]; |
| 384 [wrenchMenuController_ browserWillBeDestroyed]; |
| 385 |
| 386 [self cleanUp]; |
| 387 } |
| 388 |
| 389 - (void)cleanUp { |
| 390 // Unset ViewIDs of toolbar elements. |
| 391 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and |
| 392 // |browserActionsContainerView_| are handled by themselves. |
| 393 view_id_util::UnsetID(backButton_); |
| 394 view_id_util::UnsetID(forwardButton_); |
| 395 view_id_util::UnsetID(homeButton_); |
| 396 view_id_util::UnsetID(wrenchButton_); |
| 397 |
| 398 // Make sure any code in the base class which assumes [self view] is |
| 399 // the "parent" view continues to work. |
| 400 hasToolbar_ = YES; |
| 401 hasLocationBar_ = YES; |
| 402 |
| 403 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 404 |
| 405 if (trackingArea_.get()) { |
| 406 [[self view] removeTrackingArea:trackingArea_.get()]; |
| 407 [trackingArea_.get() clearOwner]; |
| 408 trackingArea_.reset(); |
| 409 } |
| 410 |
| 411 // Destroy owned objects that hold a weak Browser*. |
| 412 locationBarView_.reset(); |
| 413 browserActionsContainerDelegate_.reset(); |
| 414 browser_ = nullptr; |
| 415 } |
| 416 |
401 - (void)addAccessibilityDescriptions { | 417 - (void)addAccessibilityDescriptions { |
402 // Set accessibility descriptions. http://openradar.appspot.com/7496255 | 418 // Set accessibility descriptions. http://openradar.appspot.com/7496255 |
403 NSString* description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_BACK); | 419 NSString* description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_BACK); |
404 [[backButton_ cell] | 420 [[backButton_ cell] |
405 accessibilitySetOverrideValue:description | 421 accessibilitySetOverrideValue:description |
406 forAttribute:NSAccessibilityDescriptionAttribute]; | 422 forAttribute:NSAccessibilityDescriptionAttribute]; |
407 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_FORWARD); | 423 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_FORWARD); |
408 [[forwardButton_ cell] | 424 [[forwardButton_ cell] |
409 accessibilitySetOverrideValue:description | 425 accessibilitySetOverrideValue:description |
410 forAttribute:NSAccessibilityDescriptionAttribute]; | 426 forAttribute:NSAccessibilityDescriptionAttribute]; |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 928 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
913 // Do nothing. | 929 // Do nothing. |
914 } | 930 } |
915 | 931 |
916 // (URLDropTargetController protocol) | 932 // (URLDropTargetController protocol) |
917 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 933 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
918 return drag_util::IsUnsupportedDropData(profile_, info); | 934 return drag_util::IsUnsupportedDropData(profile_, info); |
919 } | 935 } |
920 | 936 |
921 @end | 937 @end |
OLD | NEW |