| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 using content::WebContents; | 74 using content::WebContents; |
| 75 | 75 |
| 76 namespace { | 76 namespace { |
| 77 | 77 |
| 78 // Duration of the toolbar animation. | 78 // Duration of the toolbar animation. |
| 79 const NSTimeInterval kToolBarAnimationDuration = 0.12; | 79 const NSTimeInterval kToolBarAnimationDuration = 0.12; |
| 80 | 80 |
| 81 // The height of the location bar in Material Design. | 81 // The height of the location bar in Material Design. |
| 82 const CGFloat kMaterialDesignLocationBarHeight = 28; | 82 const CGFloat kMaterialDesignLocationBarHeight = 28; |
| 83 | 83 |
| 84 // The padding between Material Design elements (when they don't abut). | 84 // The padding between Material Design elements and the edges of the toolbar. |
| 85 const CGFloat kMaterialDesignElementPadding = 4; | 85 const CGFloat kMaterialDesignElementPadding = 4; |
| 86 | 86 |
| 87 // Toolbar buttons are 24x24 and centered in a 28x28 space, so there is a 2pt- |
| 88 // wide inset. |
| 89 const CGFloat kMaterialDesignButtonInset = 2; |
| 90 |
| 91 // The y-offset of the browser actions container from the location bar. |
| 92 const CGFloat kMaterialDesignContainerYOffset = 2; |
| 93 |
| 87 // The minimum width of the location bar in pixels. | 94 // The minimum width of the location bar in pixels. |
| 88 const CGFloat kMinimumLocationBarWidth = 100.0; | 95 const CGFloat kMinimumLocationBarWidth = 100.0; |
| 89 | 96 |
| 90 class BrowserActionsContainerDelegate : | 97 class BrowserActionsContainerDelegate : |
| 91 public BrowserActionsContainerViewSizeDelegate { | 98 public BrowserActionsContainerViewSizeDelegate { |
| 92 public: | 99 public: |
| 93 BrowserActionsContainerDelegate( | 100 BrowserActionsContainerDelegate( |
| 94 AutocompleteTextField* location_bar, | 101 AutocompleteTextField* location_bar, |
| 95 BrowserActionsContainerView* browser_actions_container_view); | 102 BrowserActionsContainerView* browser_actions_container_view); |
| 96 ~BrowserActionsContainerDelegate() override; | 103 ~BrowserActionsContainerDelegate() override; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // be called, don't initialize twice. | 289 // be called, don't initialize twice. |
| 283 if (locationBarView_) { | 290 if (locationBarView_) { |
| 284 DCHECK(base::mac::IsOSYosemiteOrLater()); | 291 DCHECK(base::mac::IsOSYosemiteOrLater()); |
| 285 return; | 292 return; |
| 286 } | 293 } |
| 287 | 294 |
| 288 // Make Material Design layout adjustments to the NIB items. | 295 // Make Material Design layout adjustments to the NIB items. |
| 289 bool isModeMaterial = ui::MaterialDesignController::IsModeMaterial(); | 296 bool isModeMaterial = ui::MaterialDesignController::IsModeMaterial(); |
| 290 if (isModeMaterial) { | 297 if (isModeMaterial) { |
| 291 ToolbarView* toolbarView = [self toolbarView]; | 298 ToolbarView* toolbarView = [self toolbarView]; |
| 299 NSRect toolbarBounds = [toolbarView bounds]; |
| 292 NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize]; | 300 NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize]; |
| 293 | 301 |
| 294 // Set the toolbar height. | 302 // Set the toolbar height. |
| 295 NSRect frame = [toolbarView frame]; | 303 NSRect frame = [toolbarView frame]; |
| 296 frame.size.height = [self baseToolbarHeight]; | 304 frame.size.height = [self baseToolbarHeight]; |
| 297 [toolbarView setFrame:frame]; | 305 [toolbarView setFrame:frame]; |
| 298 | 306 |
| 299 NSRect backButtonFrame = [backButton_ frame]; | 307 NSRect backButtonFrame = [backButton_ frame]; |
| 300 backButtonFrame.origin.x = kMaterialDesignElementPadding; | 308 backButtonFrame.origin.x = |
| 301 backButtonFrame.origin.y -= 1; | 309 kMaterialDesignElementPadding + kMaterialDesignButtonInset; |
| 310 backButtonFrame.origin.y = NSMaxY(toolbarBounds) - |
| 311 kMaterialDesignElementPadding - kMaterialDesignButtonInset - |
| 312 toolbarButtonSize.height; |
| 302 backButtonFrame.size = toolbarButtonSize; | 313 backButtonFrame.size = toolbarButtonSize; |
| 303 [backButton_ setFrame:backButtonFrame]; | 314 [backButton_ setFrame:backButtonFrame]; |
| 304 | 315 |
| 305 NSRect forwardButtonFrame = [forwardButton_ frame]; | 316 NSRect forwardButtonFrame = [forwardButton_ frame]; |
| 306 forwardButtonFrame.origin.x = NSMaxX(backButtonFrame); | 317 forwardButtonFrame.origin.x = |
| 318 NSMaxX(backButtonFrame) + 2 * kMaterialDesignButtonInset; |
| 307 forwardButtonFrame.origin.y = backButtonFrame.origin.y; | 319 forwardButtonFrame.origin.y = backButtonFrame.origin.y; |
| 308 forwardButtonFrame.size = toolbarButtonSize; | 320 forwardButtonFrame.size = toolbarButtonSize; |
| 309 [forwardButton_ setFrame:forwardButtonFrame]; | 321 [forwardButton_ setFrame:forwardButtonFrame]; |
| 310 | 322 |
| 311 NSRect reloadButtonFrame = [reloadButton_ frame]; | 323 NSRect reloadButtonFrame = [reloadButton_ frame]; |
| 312 reloadButtonFrame.origin.x = NSMaxX(forwardButtonFrame); | 324 reloadButtonFrame.origin.x = |
| 325 NSMaxX(forwardButtonFrame) + 2 * kMaterialDesignButtonInset; |
| 313 reloadButtonFrame.origin.y = forwardButtonFrame.origin.y; | 326 reloadButtonFrame.origin.y = forwardButtonFrame.origin.y; |
| 314 reloadButtonFrame.size = toolbarButtonSize; | 327 reloadButtonFrame.size = toolbarButtonSize; |
| 315 [reloadButton_ setFrame:reloadButtonFrame]; | 328 [reloadButton_ setFrame:reloadButtonFrame]; |
| 316 | 329 |
| 317 NSRect homeButtonFrame = [homeButton_ frame]; | 330 NSRect homeButtonFrame = [homeButton_ frame]; |
| 318 homeButtonFrame.origin.x = NSMaxX(reloadButtonFrame); | 331 homeButtonFrame.origin.x = |
| 332 NSMaxX(reloadButtonFrame) + 2 * kMaterialDesignButtonInset; |
| 319 homeButtonFrame.origin.y = reloadButtonFrame.origin.y; | 333 homeButtonFrame.origin.y = reloadButtonFrame.origin.y; |
| 320 homeButtonFrame.size = toolbarButtonSize; | 334 homeButtonFrame.size = toolbarButtonSize; |
| 321 [homeButton_ setFrame:homeButtonFrame]; | 335 [homeButton_ setFrame:homeButtonFrame]; |
| 322 | 336 |
| 323 // Replace the app button from the nib with an AppToolbarButton instance for | 337 // Replace the app button from the nib with an AppToolbarButton instance for |
| 324 // Material Design. | 338 // Material Design. |
| 325 AppToolbarButton* newMenuButton = | 339 AppToolbarButton* newMenuButton = |
| 326 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] | 340 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] |
| 327 autorelease]; | 341 autorelease]; |
| 328 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; | 342 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; |
| 329 [[appMenuButton_ superview] addSubview:newMenuButton]; | 343 [[appMenuButton_ superview] addSubview:newMenuButton]; |
| 330 [appMenuButton_ removeFromSuperview]; | 344 [appMenuButton_ removeFromSuperview]; |
| 331 appMenuButton_ = newMenuButton; | 345 appMenuButton_ = newMenuButton; |
| 332 | 346 |
| 333 // Adjust the menu button's position. | 347 // Adjust the menu button's position. |
| 334 NSRect toolbarBounds = [toolbarView bounds]; | |
| 335 NSRect menuButtonFrame = [appMenuButton_ frame]; | 348 NSRect menuButtonFrame = [appMenuButton_ frame]; |
| 336 menuButtonFrame.origin.x = NSMaxX(toolbarBounds) - | 349 CGFloat menuButtonFrameMaxX = |
| 337 [ToolbarController appMenuLeftPadding] - toolbarButtonSize.width; | 350 NSMaxX(toolbarBounds) - [ToolbarController appMenuLeftPadding]; |
| 351 menuButtonFrame.origin.x = |
| 352 menuButtonFrameMaxX - kMaterialDesignButtonInset - |
| 353 toolbarButtonSize.width; |
| 338 menuButtonFrame.origin.y = homeButtonFrame.origin.y; | 354 menuButtonFrame.origin.y = homeButtonFrame.origin.y; |
| 339 menuButtonFrame.size = toolbarButtonSize; | 355 menuButtonFrame.size = toolbarButtonSize; |
| 340 [appMenuButton_ setFrame:menuButtonFrame]; | 356 [appMenuButton_ setFrame:menuButtonFrame]; |
| 341 | 357 |
| 342 // Adjust the size and location on the location bar to take up the | 358 // Adjust the size and location on the location bar to take up the |
| 343 // space between the reload and menu buttons. | 359 // space between the reload and menu buttons. |
| 344 NSRect locationBarFrame = [locationBar_ frame]; | 360 NSRect locationBarFrame = [locationBar_ frame]; |
| 345 locationBarFrame.origin.x = NSMaxX(homeButtonFrame) + | 361 locationBarFrame.origin.x = NSMaxX(homeButtonFrame) + |
| 346 kMaterialDesignElementPadding; | 362 kMaterialDesignButtonInset; |
| 347 locationBarFrame.origin.y = NSMaxY(toolbarBounds) - | 363 locationBarFrame.origin.y = NSMaxY(toolbarBounds) - |
| 348 kMaterialDesignElementPadding - [ToolbarController locationBarHeight]; | 364 kMaterialDesignElementPadding - kMaterialDesignLocationBarHeight; |
| 349 locationBarFrame.size.width = | 365 locationBarFrame.size.width = |
| 350 (menuButtonFrame.origin.x - kMaterialDesignElementPadding) - | 366 menuButtonFrame.origin.x - |
| 351 locationBarFrame.origin.x; | 367 locationBarFrame.origin.x; |
| 352 locationBarFrame.size.height = toolbarButtonSize.height; | 368 locationBarFrame.size.height = kMaterialDesignLocationBarHeight; |
| 353 [locationBar_ setFrame:locationBarFrame]; | 369 [locationBar_ setFrame:locationBarFrame]; |
| 354 | 370 |
| 355 // Correctly position the extension buttons' container view. | 371 // Correctly position the extension buttons' container view. |
| 356 NSRect containerFrame = [browserActionsContainerView_ frame]; | 372 NSRect containerFrame = [browserActionsContainerView_ frame]; |
| 357 containerFrame.origin.y = locationBarFrame.origin.y; | 373 containerFrame.size.width += kMaterialDesignButtonInset; |
| 374 containerFrame.origin.y = |
| 375 locationBarFrame.origin.y + kMaterialDesignContainerYOffset; |
| 358 containerFrame.size.height = toolbarButtonSize.height; | 376 containerFrame.size.height = toolbarButtonSize.height; |
| 359 [browserActionsContainerView_ setFrame:containerFrame]; | 377 [browserActionsContainerView_ setFrame:containerFrame]; |
| 360 } else { | 378 } else { |
| 361 [[backButton_ cell] setImageID:IDR_BACK | 379 [[backButton_ cell] setImageID:IDR_BACK |
| 362 forButtonState:image_button_cell::kDefaultState]; | 380 forButtonState:image_button_cell::kDefaultState]; |
| 363 [[backButton_ cell] setImageID:IDR_BACK_H | 381 [[backButton_ cell] setImageID:IDR_BACK_H |
| 364 forButtonState:image_button_cell::kHoverState]; | 382 forButtonState:image_button_cell::kHoverState]; |
| 365 [[backButton_ cell] setImageID:IDR_BACK_P | 383 [[backButton_ cell] setImageID:IDR_BACK_P |
| 366 forButtonState:image_button_cell::kPressedState]; | 384 forButtonState:image_button_cell::kPressedState]; |
| 367 [[backButton_ cell] setImageID:IDR_BACK_D | 385 [[backButton_ cell] setImageID:IDR_BACK_D |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 if ([browserActionsContainerView_ isHidden]) { | 899 if ([browserActionsContainerView_ isHidden]) { |
| 882 CGFloat edgeXPos = [appMenuButton_ frame].origin.x; | 900 CGFloat edgeXPos = [appMenuButton_ frame].origin.x; |
| 883 leftDistance = edgeXPos - locationBarXPos - | 901 leftDistance = edgeXPos - locationBarXPos - |
| 884 [ToolbarController appMenuLeftPadding]; | 902 [ToolbarController appMenuLeftPadding]; |
| 885 } else { | 903 } else { |
| 886 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - | 904 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - |
| 887 locationBarXPos; | 905 locationBarXPos; |
| 888 // Equalize the distance between the location bar and the first extension | 906 // Equalize the distance between the location bar and the first extension |
| 889 // button, and the distance between the location bar and home/reload button. | 907 // button, and the distance between the location bar and home/reload button. |
| 890 if (ui::MaterialDesignController::IsModeMaterial()) { | 908 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 891 leftDistance -= 4; | 909 leftDistance -= kMaterialDesignButtonInset; |
| 892 } | 910 } |
| 893 } | 911 } |
| 894 if (leftDistance != 0.0) | 912 if (leftDistance != 0.0) |
| 895 [self adjustLocationSizeBy:leftDistance animate:animate]; | 913 [self adjustLocationSizeBy:leftDistance animate:animate]; |
| 896 else | 914 else |
| 897 [locationBar_ stopAnimation]; | 915 [locationBar_ stopAnimation]; |
| 898 } | 916 } |
| 899 | 917 |
| 900 - (void)maintainMinimumLocationBarWidth { | 918 - (void)maintainMinimumLocationBarWidth { |
| 901 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); | 919 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); |
| 902 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; | 920 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; |
| 903 if (locationBarAtMinSize_) { | 921 if (locationBarAtMinSize_) { |
| 904 CGFloat dX = kMinimumLocationBarWidth - locationBarWidth; | 922 CGFloat dX = kMinimumLocationBarWidth - locationBarWidth; |
| 905 [self adjustLocationSizeBy:dX animate:NO]; | 923 [self adjustLocationSizeBy:dX animate:NO]; |
| 906 } | 924 } |
| 907 } | 925 } |
| 908 | 926 |
| 909 - (void)toolbarFrameChanged { | 927 - (void)toolbarFrameChanged { |
| 910 // Do nothing if the frame changes but no Browser Action Controller is | 928 // Do nothing if the frame changes but no Browser Action Controller is |
| 911 // present. | 929 // present. |
| 912 if (!browserActionsController_.get()) | 930 if (!browserActionsController_.get()) |
| 913 return; | 931 return; |
| 914 | 932 |
| 915 if ([browserActionsContainerView_ isAnimating]) { | 933 if ([browserActionsContainerView_ isAnimating]) { |
| 916 // If the browser actions container is animating, we need to stop it first, | 934 // If the browser actions container is animating, we need to stop it first, |
| 917 // because the frame it's animating for could be incorrect with the new | 935 // because the frame it's animating for could be incorrect with the new |
| 918 // bounds (if, for instance, the bookmark bar was added). | 936 // bounds (if, for instance, the bookmark bar was added). |
| 919 // This will advance to the end of the animation, so we also need to adjust | 937 // This will advance to the end of the animation, so we also need to adjust |
| 920 // it afterwards. | 938 // it afterwards. |
| 921 CGFloat elementTopPadding = kMaterialDesignElementPadding; | 939 [browserActionsContainerView_ stopAnimation]; |
| 940 NSRect containerFrame = [browserActionsContainerView_ frame]; |
| 922 if (!ui::MaterialDesignController::IsModeMaterial()) { | 941 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 942 CGFloat elementTopPadding = |
| 943 kMaterialDesignElementPadding + kMaterialDesignButtonInset; |
| 923 // Pre-Material Design, this value is calculated from the values in | 944 // Pre-Material Design, this value is calculated from the values in |
| 924 // Toolbar.xib: the height of the toolbar (35) minus the height of the | 945 // Toolbar.xib: the height of the toolbar (35) minus the height of the |
| 925 // child elements (29) minus the y-origin of the elements (4). | 946 // child elements (29) minus the y-origin of the elements (4). |
| 926 elementTopPadding = 2; | 947 elementTopPadding = 2; |
| 948 containerFrame.origin.y = |
| 949 NSHeight([[self view] frame]) - NSHeight(containerFrame) - |
| 950 elementTopPadding; |
| 951 } else { |
| 952 containerFrame.origin.y = |
| 953 [locationBar_ frame].origin.y + kMaterialDesignContainerYOffset; |
| 927 } | 954 } |
| 928 [browserActionsContainerView_ stopAnimation]; | |
| 929 NSRect containerFrame = [browserActionsContainerView_ frame]; | |
| 930 containerFrame.origin.y = | |
| 931 NSHeight([[self view] frame]) - NSHeight(containerFrame) - | |
| 932 elementTopPadding; | |
| 933 [browserActionsContainerView_ setFrame:containerFrame]; | 955 [browserActionsContainerView_ setFrame:containerFrame]; |
| 934 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; | 956 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
| 935 } | 957 } |
| 936 | 958 |
| 937 [self maintainMinimumLocationBarWidth]; | 959 [self maintainMinimumLocationBarWidth]; |
| 938 | 960 |
| 939 if (locationBarAtMinSize_) { | 961 if (locationBarAtMinSize_) { |
| 940 // Once the grippy is pinned, leave it until it is explicity un-pinned. | 962 // Once the grippy is pinned, leave it until it is explicity un-pinned. |
| 941 [browserActionsContainerView_ setGrippyPinned:YES]; | 963 [browserActionsContainerView_ setGrippyPinned:YES]; |
| 942 NSRect containerFrame = [browserActionsContainerView_ frame]; | 964 NSRect containerFrame = [browserActionsContainerView_ frame]; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 1152 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
| 1131 // Do nothing. | 1153 // Do nothing. |
| 1132 } | 1154 } |
| 1133 | 1155 |
| 1134 // (URLDropTargetController protocol) | 1156 // (URLDropTargetController protocol) |
| 1135 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 1157 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
| 1136 return drag_util::IsUnsupportedDropData(profile_, info); | 1158 return drag_util::IsUnsupportedDropData(profile_, info); |
| 1137 } | 1159 } |
| 1138 | 1160 |
| 1139 @end | 1161 @end |
| OLD | NEW |