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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 | 199 |
200 } // namespace ToolbarControllerInternal | 200 } // namespace ToolbarControllerInternal |
201 | 201 |
202 @implementation ToolbarController | 202 @implementation ToolbarController |
203 | 203 |
204 @synthesize browser = browser_; | 204 @synthesize browser = browser_; |
205 | 205 |
206 - (id)initWithCommands:(CommandUpdater*)commands | 206 - (id)initWithCommands:(CommandUpdater*)commands |
207 profile:(Profile*)profile | 207 profile:(Profile*)profile |
208 browser:(Browser*)browser | 208 browser:(Browser*)browser |
209 resizeDelegate:(id<ViewResizer>)resizeDelegate | 209 resizeDelegate:(id<ViewResizer>)resizeDelegate |
tapted
2015/07/07 04:25:59
Can this be removed?
jackhou1
2015/07/07 08:33:06
Done.
| |
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()); |
(...skipping 12 matching lines...) Expand all Loading... | |
240 resizeDelegate:(id<ViewResizer>)resizeDelegate { | 239 resizeDelegate:(id<ViewResizer>)resizeDelegate { |
241 if ((self = [self initWithCommands:commands | 240 if ((self = [self initWithCommands:commands |
242 profile:profile | 241 profile:profile |
243 browser:browser | 242 browser:browser |
244 resizeDelegate:resizeDelegate | 243 resizeDelegate:resizeDelegate |
245 nibFileNamed:@"Toolbar"])) { | 244 nibFileNamed:@"Toolbar"])) { |
246 } | 245 } |
247 return self; | 246 return self; |
248 } | 247 } |
249 | 248 |
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. | 249 // 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 | 250 // Now we can hook up bridges that rely on UI objects such as the location |
276 // bar and button state. | 251 // bar and button state. |
277 - (void)awakeFromNib { | 252 - (void)awakeFromNib { |
278 [[backButton_ cell] setImageID:IDR_BACK | 253 [[backButton_ cell] setImageID:IDR_BACK |
279 forButtonState:image_button_cell::kDefaultState]; | 254 forButtonState:image_button_cell::kDefaultState]; |
280 [[backButton_ cell] setImageID:IDR_BACK_H | 255 [[backButton_ cell] setImageID:IDR_BACK_H |
281 forButtonState:image_button_cell::kHoverState]; | 256 forButtonState:image_button_cell::kHoverState]; |
282 [[backButton_ cell] setImageID:IDR_BACK_P | 257 [[backButton_ cell] setImageID:IDR_BACK_P |
283 forButtonState:image_button_cell::kPressedState]; | 258 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 | 366 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and |
392 // |browserActionsContainerView_| are handled by themselves. | 367 // |browserActionsContainerView_| are handled by themselves. |
393 view_id_util::SetID(backButton_, VIEW_ID_BACK_BUTTON); | 368 view_id_util::SetID(backButton_, VIEW_ID_BACK_BUTTON); |
394 view_id_util::SetID(forwardButton_, VIEW_ID_FORWARD_BUTTON); | 369 view_id_util::SetID(forwardButton_, VIEW_ID_FORWARD_BUTTON); |
395 view_id_util::SetID(homeButton_, VIEW_ID_HOME_BUTTON); | 370 view_id_util::SetID(homeButton_, VIEW_ID_HOME_BUTTON); |
396 view_id_util::SetID(wrenchButton_, VIEW_ID_APP_MENU); | 371 view_id_util::SetID(wrenchButton_, VIEW_ID_APP_MENU); |
397 | 372 |
398 [self addAccessibilityDescriptions]; | 373 [self addAccessibilityDescriptions]; |
399 } | 374 } |
400 | 375 |
376 - (void)browserWillBeDestroyed { | |
377 // This method indicates imminent destruction. Destroy owned objects that hold | |
378 // a weak Browser*, or pass this call onto reference counted objects. | |
379 locationBarView_.reset(); | |
380 [backMenuController_ browserWillBeDestroyed]; | |
381 [forwardMenuController_ browserWillBeDestroyed]; | |
382 [browserActionsController_ browserWillBeDestroyed]; | |
383 [wrenchMenuController_ browserWillBeDestroyed]; | |
384 browserActionsContainerDelegate_.reset(); | |
385 | |
386 // Unset ViewIDs of toolbar elements. | |
387 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and | |
388 // |browserActionsContainerView_| are handled by themselves. | |
389 view_id_util::UnsetID(backButton_); | |
390 view_id_util::UnsetID(forwardButton_); | |
391 view_id_util::UnsetID(homeButton_); | |
392 view_id_util::UnsetID(wrenchButton_); | |
393 | |
394 // Make sure any code in the base class which assumes [self view] is | |
395 // the "parent" view continues to work. | |
396 hasToolbar_ = YES; | |
397 hasLocationBar_ = YES; | |
398 | |
399 [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
400 | |
401 if (trackingArea_.get()) | |
402 [[self view] removeTrackingArea:trackingArea_.get()]; | |
403 | |
404 browser_ = nullptr; | |
405 } | |
406 | |
401 - (void)addAccessibilityDescriptions { | 407 - (void)addAccessibilityDescriptions { |
402 // Set accessibility descriptions. http://openradar.appspot.com/7496255 | 408 // Set accessibility descriptions. http://openradar.appspot.com/7496255 |
403 NSString* description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_BACK); | 409 NSString* description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_BACK); |
404 [[backButton_ cell] | 410 [[backButton_ cell] |
405 accessibilitySetOverrideValue:description | 411 accessibilitySetOverrideValue:description |
406 forAttribute:NSAccessibilityDescriptionAttribute]; | 412 forAttribute:NSAccessibilityDescriptionAttribute]; |
407 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_FORWARD); | 413 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_FORWARD); |
408 [[forwardButton_ cell] | 414 [[forwardButton_ cell] |
409 accessibilitySetOverrideValue:description | 415 accessibilitySetOverrideValue:description |
410 forAttribute:NSAccessibilityDescriptionAttribute]; | 416 forAttribute:NSAccessibilityDescriptionAttribute]; |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 918 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
913 // Do nothing. | 919 // Do nothing. |
914 } | 920 } |
915 | 921 |
916 // (URLDropTargetController protocol) | 922 // (URLDropTargetController protocol) |
917 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 923 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
918 return drag_util::IsUnsupportedDropData(profile_, info); | 924 return drag_util::IsUnsupportedDropData(profile_, info); |
919 } | 925 } |
920 | 926 |
921 @end | 927 @end |
OLD | NEW |