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 18 matching lines...) Expand all Loading... |
29 #include "chrome/browser/ui/browser_commands.h" | 29 #include "chrome/browser/ui/browser_commands.h" |
30 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
31 #import "chrome/browser/ui/cocoa/app_menu/app_menu_controller.h" | 31 #import "chrome/browser/ui/cocoa/app_menu/app_menu_controller.h" |
32 #import "chrome/browser/ui/cocoa/background_gradient_view.h" | 32 #import "chrome/browser/ui/cocoa/background_gradient_view.h" |
33 #include "chrome/browser/ui/cocoa/drag_util.h" | 33 #include "chrome/browser/ui/cocoa/drag_util.h" |
34 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" | 34 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" |
35 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" | 35 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" |
36 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" | 36 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" |
37 #import "chrome/browser/ui/cocoa/gradient_button_cell.h" | 37 #import "chrome/browser/ui/cocoa/gradient_button_cell.h" |
38 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 38 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
39 #import "chrome/browser/ui/cocoa/l10n_util.h" | |
40 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 39 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
41 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" | 40 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" |
42 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 41 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
43 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 42 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
44 #import "chrome/browser/ui/cocoa/menu_button.h" | 43 #import "chrome/browser/ui/cocoa/menu_button.h" |
45 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button.h" | 44 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button.h" |
46 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button_cell.h" | 45 #import "chrome/browser/ui/cocoa/toolbar/app_toolbar_button_cell.h" |
47 #import "chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.h" | 46 #import "chrome/browser/ui/cocoa/toolbar/back_forward_menu_controller.h" |
48 #import "chrome/browser/ui/cocoa/toolbar/reload_button_cocoa.h" | 47 #import "chrome/browser/ui/cocoa/toolbar/reload_button_cocoa.h" |
49 #import "chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.h" | 48 #import "chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return NSWidth([browser_actions_container_ frame]) + location_bar_flex; | 138 return NSWidth([browser_actions_container_ frame]) + location_bar_flex; |
140 } | 139 } |
141 | 140 |
142 } // namespace | 141 } // namespace |
143 | 142 |
144 @interface ToolbarController() | 143 @interface ToolbarController() |
145 @property(assign, nonatomic) Browser* browser; | 144 @property(assign, nonatomic) Browser* browser; |
146 // Height of the location bar. Used for animating the toolbar in and out when | 145 // Height of the location bar. Used for animating the toolbar in and out when |
147 // the location bar is displayed stand-alone for bookmark apps. | 146 // the location bar is displayed stand-alone for bookmark apps. |
148 + (CGFloat)locationBarHeight; | 147 + (CGFloat)locationBarHeight; |
149 // Return the amount of horizontal padding that the app menu should have on | 148 // Return the amount of left padding that the app menu should have. |
150 // each side. | 149 + (CGFloat)appMenuLeftPadding; |
151 + (CGFloat)appMenuPadding; | |
152 - (void)cleanUp; | 150 - (void)cleanUp; |
153 - (void)addAccessibilityDescriptions; | 151 - (void)addAccessibilityDescriptions; |
154 - (void)initCommandStatus:(CommandUpdater*)commands; | 152 - (void)initCommandStatus:(CommandUpdater*)commands; |
155 - (void)prefChanged:(const std::string&)prefName; | 153 - (void)prefChanged:(const std::string&)prefName; |
156 - (ToolbarView*)toolbarView; | 154 - (ToolbarView*)toolbarView; |
157 // Height of the toolbar in pixels when the bookmark bar is closed. | 155 // Height of the toolbar in pixels when the bookmark bar is closed. |
158 - (CGFloat)baseToolbarHeight; | 156 - (CGFloat)baseToolbarHeight; |
159 - (void)toolbarFrameChanged; | 157 - (void)toolbarFrameChanged; |
160 - (void)showLocationBarOnly; | 158 - (void)showLocationBarOnly; |
161 - (void)pinLocationBarBeforeBrowserActionsContainerAndAnimate:(BOOL)animate; | 159 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; |
162 - (void)maintainMinimumLocationBarWidth; | 160 - (void)maintainMinimumLocationBarWidth; |
163 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; | 161 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; |
164 - (void)browserActionsContainerDragged:(NSNotification*)notification; | 162 - (void)browserActionsContainerDragged:(NSNotification*)notification; |
165 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; | 163 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; |
166 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification; | 164 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification; |
167 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; | 165 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; |
168 - (void)updateAppMenuButtonSeverity:(AppMenuIconController::Severity)severity | 166 - (void)updateAppMenuButtonSeverity:(AppMenuIconController::Severity)severity |
169 iconType:(AppMenuIconController::IconType)iconType | 167 iconType:(AppMenuIconController::IconType)iconType |
170 animate:(BOOL)animate; | 168 animate:(BOOL)animate; |
171 @end | 169 @end |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } // namespace ToolbarControllerInternal | 229 } // namespace ToolbarControllerInternal |
232 | 230 |
233 @implementation ToolbarController | 231 @implementation ToolbarController |
234 | 232 |
235 @synthesize browser = browser_; | 233 @synthesize browser = browser_; |
236 | 234 |
237 + (CGFloat)locationBarHeight { | 235 + (CGFloat)locationBarHeight { |
238 return kLocationBarHeight; | 236 return kLocationBarHeight; |
239 } | 237 } |
240 | 238 |
241 + (CGFloat)appMenuPadding { | 239 + (CGFloat)appMenuLeftPadding { |
242 return kElementPadding; | 240 return kElementPadding; |
243 } | 241 } |
244 | 242 |
245 + (CGFloat)materialDesignButtonInset { | 243 + (CGFloat)materialDesignButtonInset { |
246 return kButtonInset; | 244 return kButtonInset; |
247 } | 245 } |
248 | 246 |
249 - (id)initWithCommands:(CommandUpdater*)commands | 247 - (id)initWithCommands:(CommandUpdater*)commands |
250 profile:(Profile*)profile | 248 profile:(Profile*)profile |
251 browser:(Browser*)browser | 249 browser:(Browser*)browser |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 290 } |
293 | 291 |
294 - (void)viewDidLoad { | 292 - (void)viewDidLoad { |
295 // When linking and running on 10.10+, both -awakeFromNib and -viewDidLoad may | 293 // When linking and running on 10.10+, both -awakeFromNib and -viewDidLoad may |
296 // be called, don't initialize twice. | 294 // be called, don't initialize twice. |
297 if (locationBarView_) { | 295 if (locationBarView_) { |
298 DCHECK(base::mac::IsAtLeastOS10_10()); | 296 DCHECK(base::mac::IsAtLeastOS10_10()); |
299 return; | 297 return; |
300 } | 298 } |
301 | 299 |
302 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); | |
303 NSAutoresizingMaskOptions leadingButtonMask = | |
304 isRTL ? NSViewMinXMargin | NSViewMinYMargin | |
305 : NSViewMaxXMargin | NSViewMinYMargin; | |
306 NSAutoresizingMaskOptions trailingButtonMask = | |
307 isRTL ? NSViewMaxXMargin | NSViewMinYMargin | |
308 : NSViewMinXMargin | NSViewMinYMargin; | |
309 | |
310 // Make Material Design layout adjustments to the NIB items. | 300 // Make Material Design layout adjustments to the NIB items. |
311 ToolbarView* toolbarView = [self toolbarView]; | 301 ToolbarView* toolbarView = [self toolbarView]; |
312 NSRect toolbarBounds = [toolbarView bounds]; | 302 NSRect toolbarBounds = [toolbarView bounds]; |
313 NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize]; | 303 NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize]; |
314 | 304 |
315 // Set the toolbar height. | 305 // Set the toolbar height. |
316 NSRect frame = [toolbarView frame]; | 306 NSRect frame = [toolbarView frame]; |
317 frame.size.height = [self baseToolbarHeight]; | 307 frame.size.height = [self baseToolbarHeight]; |
318 [toolbarView setFrame:frame]; | 308 [toolbarView setFrame:frame]; |
319 | 309 |
320 NSArray* leadingButtons = | 310 NSRect backButtonFrame = [backButton_ frame]; |
321 @[ backButton_, forwardButton_, reloadButton_, homeButton_ ]; | 311 backButtonFrame.origin.x = kElementPadding + kButtonInset; |
322 const CGFloat xStart = kElementPadding + kButtonInset; | 312 backButtonFrame.origin.y = |
323 const CGFloat xOffset = toolbarButtonSize.width + kButtonInset * 2; | |
324 const CGFloat yPosition = | |
325 NSMaxY(toolbarBounds) - kElementPadding - toolbarButtonSize.height; | 313 NSMaxY(toolbarBounds) - kElementPadding - toolbarButtonSize.height; |
326 for (NSUInteger i = 0; i < [leadingButtons count]; i++) { | 314 backButtonFrame.size = toolbarButtonSize; |
327 NSButton* button = leadingButtons[i]; | 315 [backButton_ setFrame:backButtonFrame]; |
328 NSRect buttonFrame = [button frame]; | 316 |
329 buttonFrame.size = toolbarButtonSize; | 317 NSRect forwardButtonFrame = [forwardButton_ frame]; |
330 buttonFrame.origin.y = yPosition; | 318 forwardButtonFrame.origin.x = NSMaxX(backButtonFrame) + 2 * kButtonInset; |
331 const CGFloat xPosition = xStart + i * xOffset; | 319 forwardButtonFrame.origin.y = backButtonFrame.origin.y; |
332 buttonFrame.origin.x = | 320 forwardButtonFrame.size = toolbarButtonSize; |
333 isRTL ? NSWidth(frame) - toolbarButtonSize.width - xPosition | 321 [forwardButton_ setFrame:forwardButtonFrame]; |
334 : xPosition; | 322 |
335 [button setFrame:buttonFrame]; | 323 NSRect reloadButtonFrame = [reloadButton_ frame]; |
336 [button setAutoresizingMask:leadingButtonMask]; | 324 reloadButtonFrame.origin.x = NSMaxX(forwardButtonFrame) + 2 * kButtonInset; |
337 } | 325 reloadButtonFrame.origin.y = forwardButtonFrame.origin.y; |
| 326 reloadButtonFrame.size = toolbarButtonSize; |
| 327 [reloadButton_ setFrame:reloadButtonFrame]; |
| 328 |
| 329 NSRect homeButtonFrame = [homeButton_ frame]; |
| 330 homeButtonFrame.origin.x = NSMaxX(reloadButtonFrame) + 2 * kButtonInset; |
| 331 homeButtonFrame.origin.y = reloadButtonFrame.origin.y; |
| 332 homeButtonFrame.size = toolbarButtonSize; |
| 333 [homeButton_ setFrame:homeButtonFrame]; |
338 | 334 |
339 // Replace the app button from the nib with an AppToolbarButton instance for | 335 // Replace the app button from the nib with an AppToolbarButton instance for |
340 // Material Design. | 336 // Material Design. |
341 AppToolbarButton* newMenuButton = | 337 AppToolbarButton* newMenuButton = |
342 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] | 338 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] |
343 autorelease]; | 339 autorelease]; |
344 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; | 340 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; |
345 [[appMenuButton_ superview] addSubview:newMenuButton]; | 341 [[appMenuButton_ superview] addSubview:newMenuButton]; |
346 [appMenuButton_ removeFromSuperview]; | 342 [appMenuButton_ removeFromSuperview]; |
347 appMenuButton_ = newMenuButton; | 343 appMenuButton_ = newMenuButton; |
348 | 344 |
349 // Adjust the menu button's position. | 345 // Adjust the menu button's position. |
350 NSRect menuButtonFrame = [appMenuButton_ frame]; | 346 NSRect menuButtonFrame = [appMenuButton_ frame]; |
351 if (isRTL) { | 347 CGFloat menuButtonFrameMaxX = |
352 menuButtonFrame.origin.x = [ToolbarController appMenuPadding]; | 348 NSMaxX(toolbarBounds) - [ToolbarController appMenuLeftPadding]; |
353 } else { | 349 menuButtonFrame.origin.x = |
354 CGFloat menuButtonFrameMaxX = | 350 menuButtonFrameMaxX - kButtonInset - toolbarButtonSize.width; |
355 NSMaxX(toolbarBounds) - [ToolbarController appMenuPadding]; | 351 menuButtonFrame.origin.y = homeButtonFrame.origin.y; |
356 menuButtonFrame.origin.x = | |
357 menuButtonFrameMaxX - kButtonInset - toolbarButtonSize.width; | |
358 } | |
359 menuButtonFrame.origin.y = yPosition; | |
360 menuButtonFrame.size = toolbarButtonSize; | 352 menuButtonFrame.size = toolbarButtonSize; |
361 [appMenuButton_ setFrame:menuButtonFrame]; | 353 [appMenuButton_ setFrame:menuButtonFrame]; |
362 [appMenuButton_ setAutoresizingMask:trailingButtonMask]; | |
363 | 354 |
364 // Adjust the size and location on the location bar to take up the | 355 // Adjust the size and location on the location bar to take up the |
365 // space between the reload and menu buttons. | 356 // space between the reload and menu buttons. |
366 NSRect locationBarFrame = [locationBar_ frame]; | 357 NSRect locationBarFrame = [locationBar_ frame]; |
367 locationBarFrame.origin.x = isRTL | 358 locationBarFrame.origin.x = NSMaxX(homeButtonFrame) + kButtonInset; |
368 ? NSMaxX(menuButtonFrame) + kButtonInset | 359 if (![homeButton_ isHidden]) { |
369 : NSMaxX([homeButton_ frame]) + kButtonInset; | 360 // Ensure proper spacing between the home button and the location bar. |
370 if (![homeButton_ isHidden] && !isRTL) { | |
371 // Ensure proper spacing between the home button and location bar | |
372 locationBarFrame.origin.x += kElementPadding; | 361 locationBarFrame.origin.x += kElementPadding; |
373 } | 362 } |
374 locationBarFrame.origin.y = | 363 locationBarFrame.origin.y = |
375 NSMaxY(toolbarBounds) - kLocationBarPadding - kLocationBarHeight; | 364 NSMaxY(toolbarBounds) - kLocationBarPadding - kLocationBarHeight; |
376 CGFloat rightEdge = 0; | 365 locationBarFrame.size.width = |
377 if (isRTL) { | 366 menuButtonFrame.origin.x - |
378 rightEdge = NSMinX([homeButton_ frame]) - kButtonInset; | 367 locationBarFrame.origin.x; |
379 if (![homeButton_ isHidden]) | |
380 rightEdge -= kElementPadding; | |
381 } else { | |
382 rightEdge = NSMinX(menuButtonFrame); | |
383 } | |
384 locationBarFrame.size.width = rightEdge - NSMinX(locationBarFrame); | |
385 | |
386 locationBarFrame.size.height = kLocationBarHeight; | 368 locationBarFrame.size.height = kLocationBarHeight; |
387 [locationBar_ setFrame:locationBarFrame]; | 369 [locationBar_ setFrame:locationBarFrame]; |
388 | 370 |
389 // Correctly position the extension buttons' container view. | 371 // Correctly position the extension buttons' container view. |
390 NSRect containerFrame = [browserActionsContainerView_ frame]; | 372 NSRect containerFrame = [browserActionsContainerView_ frame]; |
391 containerFrame.size.width += kButtonInset; | 373 containerFrame.size.width += kButtonInset; |
392 containerFrame.origin.y = locationBarFrame.origin.y + kContainerYOffset; | 374 containerFrame.origin.y = locationBarFrame.origin.y + kContainerYOffset; |
393 containerFrame.size.height = toolbarButtonSize.height; | 375 containerFrame.size.height = toolbarButtonSize.height; |
394 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) | |
395 containerFrame.origin.x = NSMinX(locationBarFrame); | |
396 [browserActionsContainerView_ setFrame:containerFrame]; | 376 [browserActionsContainerView_ setFrame:containerFrame]; |
397 [browserActionsContainerView_ setAutoresizingMask:trailingButtonMask]; | |
398 | 377 |
399 notificationBridge_.reset( | 378 notificationBridge_.reset( |
400 new ToolbarControllerInternal::NotificationBridge(self)); | 379 new ToolbarControllerInternal::NotificationBridge(self)); |
401 notificationBridge_->UpdateSeverity(); | 380 notificationBridge_->UpdateSeverity(); |
402 | 381 |
403 [appMenuButton_ setOpenMenuOnClick:YES]; | 382 [appMenuButton_ setOpenMenuOnClick:YES]; |
404 | 383 |
405 [backButton_ setOpenMenuOnRightClick:YES]; | 384 [backButton_ setOpenMenuOnRightClick:YES]; |
406 [forwardButton_ setOpenMenuOnRightClick:YES]; | 385 [forwardButton_ setOpenMenuOnRightClick:YES]; |
407 | 386 |
(...skipping 26 matching lines...) Expand all Loading... |
434 // and then add them to the toolbar based on those prefs. | 413 // and then add them to the toolbar based on those prefs. |
435 PrefService* prefs = profile_->GetPrefs(); | 414 PrefService* prefs = profile_->GetPrefs(); |
436 showHomeButton_.Init( | 415 showHomeButton_.Init( |
437 prefs::kShowHomeButton, prefs, | 416 prefs::kShowHomeButton, prefs, |
438 base::Bind( | 417 base::Bind( |
439 &ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged, | 418 &ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged, |
440 base::Unretained(notificationBridge_.get()))); | 419 base::Unretained(notificationBridge_.get()))); |
441 [self showOptionalHomeButton]; | 420 [self showOptionalHomeButton]; |
442 [self installAppMenu]; | 421 [self installAppMenu]; |
443 | 422 |
444 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO]; | 423 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
445 | 424 |
446 // Create the controllers for the back/forward menus. | 425 // Create the controllers for the back/forward menus. |
447 backMenuController_.reset([[BackForwardMenuController alloc] | 426 backMenuController_.reset([[BackForwardMenuController alloc] |
448 initWithBrowser:browser_ | 427 initWithBrowser:browser_ |
449 modelType:BACK_FORWARD_MENU_TYPE_BACK | 428 modelType:BACK_FORWARD_MENU_TYPE_BACK |
450 button:backButton_]); | 429 button:backButton_]); |
451 forwardMenuController_.reset([[BackForwardMenuController alloc] | 430 forwardMenuController_.reset([[BackForwardMenuController alloc] |
452 initWithBrowser:browser_ | 431 initWithBrowser:browser_ |
453 modelType:BACK_FORWARD_MENU_TYPE_FORWARD | 432 modelType:BACK_FORWARD_MENU_TYPE_FORWARD |
454 button:forwardButton_]); | 433 button:forwardButton_]); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 [self showLocationBarOnly]; | 681 [self showLocationBarOnly]; |
703 } | 682 } |
704 | 683 |
705 // (Private) Returns the backdrop to the toolbar as a ToolbarView. | 684 // (Private) Returns the backdrop to the toolbar as a ToolbarView. |
706 - (ToolbarView*)toolbarView{ | 685 - (ToolbarView*)toolbarView{ |
707 return base::mac::ObjCCastStrict<ToolbarView>([self view]); | 686 return base::mac::ObjCCastStrict<ToolbarView>([self view]); |
708 } | 687 } |
709 | 688 |
710 - (id)customFieldEditorForObject:(id)obj { | 689 - (id)customFieldEditorForObject:(id)obj { |
711 if (obj == locationBar_) { | 690 if (obj == locationBar_) { |
712 // Lazily construct Field editor, Cocoa UI code always runs on the | 691 // Lazilly construct Field editor, Cocoa UI code always runs on the |
713 // same thread, so there shoudn't be a race condition here. | 692 // same thread, so there shoudn't be a race condition here. |
714 if (autocompleteTextFieldEditor_.get() == nil) { | 693 if (autocompleteTextFieldEditor_.get() == nil) { |
715 autocompleteTextFieldEditor_.reset( | 694 autocompleteTextFieldEditor_.reset( |
716 [[AutocompleteTextFieldEditor alloc] init]); | 695 [[AutocompleteTextFieldEditor alloc] init]); |
717 } | 696 } |
718 | 697 |
719 // This needs to be called every time, otherwise notifications | 698 // This needs to be called every time, otherwise notifications |
720 // aren't sent correctly. | 699 // aren't sent correctly. |
721 DCHECK(autocompleteTextFieldEditor_.get()); | 700 DCHECK(autocompleteTextFieldEditor_.get()); |
722 [autocompleteTextFieldEditor_.get() setFieldEditor:YES]; | 701 [autocompleteTextFieldEditor_.get() setFieldEditor:YES]; |
723 return autocompleteTextFieldEditor_.get(); | 702 return autocompleteTextFieldEditor_.get(); |
724 } | 703 } |
725 return nil; | 704 return nil; |
726 } | 705 } |
727 | 706 |
728 // Returns an array of views, ordered leading to trailing. | 707 // Returns an array of views in the order of the outlets above. |
729 - (NSArray*)toolbarViews { | 708 - (NSArray*)toolbarViews { |
730 return @[ | 709 return [NSArray arrayWithObjects:backButton_, forwardButton_, reloadButton_, |
731 backButton_, forwardButton_, reloadButton_, homeButton_, locationBar_, | 710 homeButton_, appMenuButton_, locationBar_, |
732 browserActionsContainerView_, appMenuButton_ | 711 browserActionsContainerView_, nil]; |
733 ]; | 712 } |
| 713 |
| 714 // Moves |rect| to the right by |delta|, keeping the right side fixed by |
| 715 // shrinking the width to compensate. Passing a negative value for |deltaX| |
| 716 // moves to the left and increases the width. |
| 717 - (NSRect)adjustRect:(NSRect)rect byAmount:(CGFloat)deltaX { |
| 718 NSRect frame = NSOffsetRect(rect, deltaX, 0); |
| 719 frame.size.width -= deltaX; |
| 720 return frame; |
734 } | 721 } |
735 | 722 |
736 // Show or hide the home button based on the pref. | 723 // Show or hide the home button based on the pref. |
737 - (void)showOptionalHomeButton { | 724 - (void)showOptionalHomeButton { |
738 // Ignore this message if only showing the URL bar. | 725 // Ignore this message if only showing the URL bar. |
739 if (!hasToolbar_) | 726 if (!hasToolbar_) |
740 return; | 727 return; |
741 BOOL hide = showHomeButton_.GetValue() ? NO : YES; | 728 BOOL hide = showHomeButton_.GetValue() ? NO : YES; |
742 if (hide == [homeButton_ isHidden]) | 729 if (hide == [homeButton_ isHidden]) |
743 return; // Nothing to do, view state matches pref state. | 730 return; // Nothing to do, view state matches pref state. |
744 | 731 |
745 // Always shift the text field by the width of the home button minus one pixel | 732 // Always shift the text field by the width of the home button minus one pixel |
746 // since the frame edges of each button are right on top of each other. When | 733 // since the frame edges of each button are right on top of each other. When |
747 // hiding the button, reverse the direction of the movement (to the left). | 734 // hiding the button, reverse the direction of the movement (to the left). |
748 CGFloat moveX = [homeButton_ frame].size.width; | 735 CGFloat moveX = [homeButton_ frame].size.width; |
749 // Ensure proper spacing between the home button and the location bar. | 736 // Ensure proper spacing between the home button and the location bar. |
750 moveX += kElementPadding; | 737 moveX += kElementPadding; |
751 if (hide) | 738 if (hide) |
752 moveX *= -1; // Reverse the direction of the move. | 739 moveX *= -1; // Reverse the direction of the move. |
753 CGRect locationBarFrame = [locationBar_ frame]; | 740 |
754 locationBarFrame.size.width -= moveX; | 741 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] |
755 if (!cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) | 742 byAmount:moveX]]; |
756 locationBarFrame.origin.x += moveX; | |
757 [locationBar_ setFrame:locationBarFrame]; | |
758 [homeButton_ setHidden:hide]; | 743 [homeButton_ setHidden:hide]; |
759 } | 744 } |
760 | 745 |
761 // Install the app menu buttons. Calling this repeatedly is inexpensive so it | 746 // Install the app menu buttons. Calling this repeatedly is inexpensive so it |
762 // can be done every time the buttons are shown. | 747 // can be done every time the buttons are shown. |
763 - (void)installAppMenu { | 748 - (void)installAppMenu { |
764 if (appMenuController_.get()) | 749 if (appMenuController_.get()) |
765 return; | 750 return; |
766 | 751 |
767 appMenuController_.reset( | 752 appMenuController_.reset( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 selector:@selector(browserActionsContainerWillAnimate:) | 793 selector:@selector(browserActionsContainerWillAnimate:) |
809 name:kBrowserActionsContainerWillAnimate | 794 name:kBrowserActionsContainerWillAnimate |
810 object:browserActionsContainerView_]; | 795 object:browserActionsContainerView_]; |
811 [[NSNotificationCenter defaultCenter] | 796 [[NSNotificationCenter defaultCenter] |
812 addObserver:self | 797 addObserver:self |
813 selector:@selector(adjustBrowserActionsContainerForNewWindow:) | 798 selector:@selector(adjustBrowserActionsContainerForNewWindow:) |
814 name:NSWindowDidBecomeKeyNotification | 799 name:NSWindowDidBecomeKeyNotification |
815 object:[[self view] window]]; | 800 object:[[self view] window]]; |
816 } | 801 } |
817 if (![browserActionsContainerView_ isHidden]) | 802 if (![browserActionsContainerView_ isHidden]) |
818 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO]; | 803 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
819 } | 804 } |
820 | 805 |
821 - (void)updateVisibility:(BOOL)visible withAnimation:(BOOL)animate { | 806 - (void)updateVisibility:(BOOL)visible withAnimation:(BOOL)animate { |
822 CGFloat newHeight = visible ? [ToolbarController locationBarHeight] : 0; | 807 CGFloat newHeight = visible ? [ToolbarController locationBarHeight] : 0; |
823 | 808 |
824 // Perform the animation, which will cause the BrowserWindowController to | 809 // Perform the animation, which will cause the BrowserWindowController to |
825 // resize this view in the browser layout as required. | 810 // resize this view in the browser layout as required. |
826 if (animate) { | 811 if (animate) { |
827 [[self toolbarView] animateToNewHeight:newHeight | 812 [[self toolbarView] animateToNewHeight:newHeight |
828 duration:kToolBarAnimationDuration]; | 813 duration:kToolBarAnimationDuration]; |
829 } else { | 814 } else { |
830 [[self toolbarView] setHeight:newHeight]; | 815 [[self toolbarView] setHeight:newHeight]; |
831 } | 816 } |
832 } | 817 } |
833 | 818 |
834 - (void)adjustBrowserActionsContainerForNewWindow: | 819 - (void)adjustBrowserActionsContainerForNewWindow: |
835 (NSNotification*)notification { | 820 (NSNotification*)notification { |
836 [self toolbarFrameChanged]; | 821 [self toolbarFrameChanged]; |
837 [[NSNotificationCenter defaultCenter] | 822 [[NSNotificationCenter defaultCenter] |
838 removeObserver:self | 823 removeObserver:self |
839 name:NSWindowDidBecomeKeyNotification | 824 name:NSWindowDidBecomeKeyNotification |
840 object:[[self view] window]]; | 825 object:[[self view] window]]; |
841 } | 826 } |
842 | 827 |
843 - (void)browserActionsContainerDragged:(NSNotification*)notification { | 828 - (void)browserActionsContainerDragged:(NSNotification*)notification { |
844 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO]; | 829 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
845 } | 830 } |
846 | 831 |
847 - (void)browserActionsVisibilityChanged:(NSNotification*)notification { | 832 - (void)browserActionsVisibilityChanged:(NSNotification*)notification { |
848 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO]; | 833 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
849 } | 834 } |
850 | 835 |
851 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification { | 836 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification { |
852 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:YES]; | 837 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:YES]; |
853 } | 838 } |
854 | 839 |
855 - (void)pinLocationBarBeforeBrowserActionsContainerAndAnimate:(BOOL)animate { | 840 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate { |
856 CGFloat delta = 0.0; | 841 CGFloat locationBarXPos = NSMaxX([locationBar_ frame]); |
857 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { | 842 CGFloat leftDistance = 0.0; |
858 CGFloat leftEdge = NSMinX([locationBar_ frame]); | 843 |
859 if ([browserActionsContainerView_ isHidden]) { | 844 if ([browserActionsContainerView_ isHidden]) { |
860 delta = leftEdge - NSMaxX([appMenuButton_ frame]) + | 845 CGFloat edgeXPos = [appMenuButton_ frame].origin.x; |
861 [ToolbarController appMenuPadding] + kButtonInset; | 846 leftDistance = edgeXPos - locationBarXPos - |
862 } else { | 847 [ToolbarController appMenuLeftPadding] - kButtonInset; |
863 delta = leftEdge - NSMaxX([browserActionsContainerView_ frame]) + | |
864 kButtonInset; | |
865 } | |
866 } else { | 848 } else { |
867 CGFloat rightEdge = NSMaxX([locationBar_ frame]); | 849 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - |
868 if ([browserActionsContainerView_ isHidden]) { | 850 locationBarXPos; |
869 delta = NSMinX([appMenuButton_ frame]) - | 851 // Equalize the distance between the location bar and the first extension |
870 [ToolbarController appMenuPadding] - kButtonInset - rightEdge; | 852 // button, and the distance between the location bar and home/reload button. |
871 } else { | 853 leftDistance -= kButtonInset; |
872 delta = NSMinX([browserActionsContainerView_ frame]) - kButtonInset - | |
873 rightEdge; | |
874 } | |
875 } | 854 } |
876 | 855 if (leftDistance != 0.0) |
877 if (delta != 0.0) | 856 [self adjustLocationSizeBy:leftDistance animate:animate]; |
878 [self adjustLocationSizeBy:delta animate:animate]; | |
879 else | 857 else |
880 [locationBar_ stopAnimation]; | 858 [locationBar_ stopAnimation]; |
881 } | 859 } |
882 | 860 |
883 - (void)maintainMinimumLocationBarWidth { | 861 - (void)maintainMinimumLocationBarWidth { |
884 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); | 862 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); |
885 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; | 863 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; |
886 if (locationBarAtMinSize_) { | 864 if (locationBarAtMinSize_) { |
887 CGFloat dX = kMinimumLocationBarWidth - locationBarWidth; | 865 CGFloat dX = kMinimumLocationBarWidth - locationBarWidth; |
888 [self adjustLocationSizeBy:dX animate:NO]; | 866 [self adjustLocationSizeBy:dX animate:NO]; |
889 } | 867 } |
890 } | 868 } |
891 | 869 |
892 - (void)toolbarFrameChanged { | 870 - (void)toolbarFrameChanged { |
893 // Do nothing if the frame changes but no Browser Action Controller is | 871 // Do nothing if the frame changes but no Browser Action Controller is |
894 // present. | 872 // present. |
895 if (!browserActionsController_.get()) | 873 if (!browserActionsController_.get()) |
896 return; | 874 return; |
897 | 875 |
898 if ([browserActionsContainerView_ isAnimating]) { | 876 if ([browserActionsContainerView_ isAnimating]) { |
899 // If the browser actions container is animating, we need to stop it first, | 877 // If the browser actions container is animating, we need to stop it first, |
900 // because the frame it's animating for could be incorrect with the new | 878 // because the frame it's animating for could be incorrect with the new |
901 // bounds (if, for instance, the bookmark bar was added). | 879 // bounds (if, for instance, the bookmark bar was added). |
902 // This will advance to the end of the animation, so we also need to adjust | 880 // This will advance to the end of the animation, so we also need to adjust |
903 // it afterwards. | 881 // it afterwards. |
904 [browserActionsContainerView_ stopAnimation]; | 882 [browserActionsContainerView_ stopAnimation]; |
905 NSRect containerFrame = [browserActionsContainerView_ frame]; | 883 NSRect containerFrame = [browserActionsContainerView_ frame]; |
906 containerFrame.origin.y = [locationBar_ frame].origin.y + kContainerYOffset; | 884 containerFrame.origin.y = [locationBar_ frame].origin.y + kContainerYOffset; |
907 [browserActionsContainerView_ setFrame:containerFrame]; | 885 [browserActionsContainerView_ setFrame:containerFrame]; |
908 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO]; | 886 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
909 } | 887 } |
910 | 888 |
911 [self maintainMinimumLocationBarWidth]; | 889 [self maintainMinimumLocationBarWidth]; |
912 | 890 |
913 if (locationBarAtMinSize_) { | 891 if (locationBarAtMinSize_) { |
914 // Once the grippy is pinned, leave it until it is explicity un-pinned. | 892 // Once the grippy is pinned, leave it until it is explicity un-pinned. |
915 [browserActionsContainerView_ setGrippyPinned:YES]; | 893 [browserActionsContainerView_ setGrippyPinned:YES]; |
916 NSRect containerFrame = [browserActionsContainerView_ frame]; | 894 NSRect containerFrame = [browserActionsContainerView_ frame]; |
917 // Determine how much the container needs to move in case it's overlapping | 895 // Determine how much the container needs to move in case it's overlapping |
918 // with the location bar. | 896 // with the location bar. |
919 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { | 897 CGFloat dX = NSMaxX([locationBar_ frame]) - containerFrame.origin.x; |
920 CGFloat dX = NSMaxX(containerFrame) - NSMinX([locationBar_ frame]); | 898 containerFrame = NSOffsetRect(containerFrame, dX, 0); |
921 containerFrame.size.width -= dX; | 899 containerFrame.size.width -= dX; |
922 } else { | |
923 CGFloat dX = NSMaxX([locationBar_ frame]) - containerFrame.origin.x; | |
924 containerFrame = NSOffsetRect(containerFrame, dX, 0); | |
925 } | |
926 [browserActionsContainerView_ setFrame:containerFrame]; | 900 [browserActionsContainerView_ setFrame:containerFrame]; |
927 } else if (!locationBarAtMinSize_ && | 901 } else if (!locationBarAtMinSize_ && |
928 [browserActionsContainerView_ grippyPinned]) { | 902 [browserActionsContainerView_ grippyPinned]) { |
929 // Expand out the container until it hits the saved size, then unpin the | 903 // Expand out the container until it hits the saved size, then unpin the |
930 // grippy. | 904 // grippy. |
931 // Add 0.1 pixel so that it doesn't hit the minimum width codepath above. | 905 // Add 0.1 pixel so that it doesn't hit the minimum width codepath above. |
932 CGFloat dX = NSWidth([locationBar_ frame]) - | 906 CGFloat dX = NSWidth([locationBar_ frame]) - |
933 (kMinimumLocationBarWidth + 0.1); | 907 (kMinimumLocationBarWidth + 0.1); |
934 NSRect containerFrame = [browserActionsContainerView_ frame]; | 908 NSRect containerFrame = [browserActionsContainerView_ frame]; |
935 if (!cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) | 909 containerFrame = NSOffsetRect(containerFrame, -dX, 0); |
936 containerFrame = NSOffsetRect(containerFrame, -dX, 0); | |
937 containerFrame.size.width += dX; | 910 containerFrame.size.width += dX; |
938 CGFloat savedContainerWidth = | 911 CGFloat savedContainerWidth = |
939 [browserActionsController_ preferredSize].width(); | 912 [browserActionsController_ preferredSize].width(); |
940 if (NSWidth(containerFrame) >= savedContainerWidth) { | 913 if (NSWidth(containerFrame) >= savedContainerWidth) { |
941 if (!cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) { | 914 containerFrame = NSOffsetRect(containerFrame, |
942 containerFrame = NSOffsetRect( | 915 NSWidth(containerFrame) - savedContainerWidth, 0); |
943 containerFrame, NSWidth(containerFrame) - savedContainerWidth, 0); | |
944 } | |
945 containerFrame.size.width = savedContainerWidth; | 916 containerFrame.size.width = savedContainerWidth; |
946 [browserActionsContainerView_ setGrippyPinned:NO]; | 917 [browserActionsContainerView_ setGrippyPinned:NO]; |
947 } | 918 } |
948 [browserActionsContainerView_ setFrame:containerFrame]; | 919 [browserActionsContainerView_ setFrame:containerFrame]; |
949 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO]; | 920 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
950 } | 921 } |
951 } | 922 } |
952 | 923 |
953 // Hide the back, forward, reload, home, and app menu buttons of the toolbar. | 924 // Hide the back, forward, reload, home, and app menu buttons of the toolbar. |
954 // This allows the location bar to occupy the entire width. There is no way to | 925 // This allows the location bar to occupy the entire width. There is no way to |
955 // undo this operation, and once it is called, no other programmatic changes | 926 // undo this operation, and once it is called, no other programmatic changes |
956 // to the toolbar or location bar width should be made. This message is | 927 // to the toolbar or location bar width should be made. This message is |
957 // invalid if the toolbar is shown or the location bar is hidden. | 928 // invalid if the toolbar is shown or the location bar is hidden. |
958 - (void)showLocationBarOnly { | 929 - (void)showLocationBarOnly { |
959 // -showLocationBarOnly is only ever called once, shortly after | 930 // -showLocationBarOnly is only ever called once, shortly after |
960 // initialization, so the regular buttons should all be visible. | 931 // initialization, so the regular buttons should all be visible. |
961 DCHECK(!hasToolbar_ && hasLocationBar_); | 932 DCHECK(!hasToolbar_ && hasLocationBar_); |
962 DCHECK(![backButton_ isHidden]); | 933 DCHECK(![backButton_ isHidden]); |
963 | 934 |
964 // Ensure the location bar fills the toolbar. | 935 // Ensure the location bar fills the toolbar. |
965 NSRect toolbarFrame = [[self view] frame]; | 936 NSRect toolbarFrame = [[self view] frame]; |
966 toolbarFrame.size.height = [ToolbarController locationBarHeight]; | 937 toolbarFrame.size.height = [ToolbarController locationBarHeight]; |
967 [[self view] setFrame:toolbarFrame]; | 938 [[self view] setFrame:toolbarFrame]; |
968 | 939 |
969 [locationBar_ setFrame:NSMakeRect(0, 0, NSWidth([[self view] frame]), | 940 [locationBar_ setFrame:NSMakeRect(0, 0, NSWidth([[self view] frame]), |
970 [ToolbarController locationBarHeight])]; | 941 [ToolbarController locationBarHeight])]; |
971 | 942 |
972 [backButton_ setHidden:YES]; | 943 [backButton_ setHidden:YES]; |
973 [forwardButton_ setHidden:YES]; | 944 [forwardButton_ setHidden:YES]; |
974 [reloadButton_ setHidden:YES]; | 945 [reloadButton_ setHidden:YES]; |
975 [appMenuButton_ setHidden:YES]; | 946 [appMenuButton_ setHidden:YES]; |
976 [homeButton_ setHidden:YES]; | 947 [homeButton_ setHidden:YES]; |
977 [browserActionsContainerView_ setHidden:YES]; | |
978 } | 948 } |
979 | 949 |
980 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate { | 950 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate { |
981 // Ensure that the location bar is in its proper place. | 951 // Ensure that the location bar is in its proper place. |
982 NSRect locationFrame = [locationBar_ frame]; | 952 NSRect locationFrame = [locationBar_ frame]; |
983 locationFrame.size.width += dX; | 953 locationFrame.size.width += dX; |
984 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) | |
985 locationFrame.origin.x -= dX; | |
986 | 954 |
987 [locationBar_ stopAnimation]; | 955 [locationBar_ stopAnimation]; |
| 956 |
988 if (animate) | 957 if (animate) |
989 [locationBar_ animateToFrame:locationFrame]; | 958 [locationBar_ animateToFrame:locationFrame]; |
990 else | 959 else |
991 [locationBar_ setFrame:locationFrame]; | 960 [locationBar_ setFrame:locationFrame]; |
992 } | 961 } |
993 | 962 |
994 - (NSPoint)bookmarkBubblePoint { | 963 - (NSPoint)bookmarkBubblePoint { |
995 if (locationBarView_->IsStarEnabled()) | 964 if (locationBarView_->IsStarEnabled()) |
996 return locationBarView_->GetBubblePointForDecoration( | 965 return locationBarView_->GetBubblePointForDecoration( |
997 locationBarView_->star_decoration()); | 966 locationBarView_->star_decoration()); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 1082 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
1114 // Do nothing. | 1083 // Do nothing. |
1115 } | 1084 } |
1116 | 1085 |
1117 // (URLDropTargetController protocol) | 1086 // (URLDropTargetController protocol) |
1118 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 1087 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
1119 return drag_util::IsUnsupportedDropData(profile_, info); | 1088 return drag_util::IsUnsupportedDropData(profile_, info); |
1120 } | 1089 } |
1121 | 1090 |
1122 @end | 1091 @end |
OLD | NEW |