Chromium Code Reviews| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 | 72 |
| 73 using content::OpenURLParams; | 73 using content::OpenURLParams; |
| 74 using content::Referrer; | 74 using content::Referrer; |
| 75 using content::WebContents; | 75 using content::WebContents; |
| 76 | 76 |
| 77 namespace { | 77 namespace { |
| 78 | 78 |
| 79 // Duration of the toolbar animation. | 79 // Duration of the toolbar animation. |
| 80 const NSTimeInterval kToolBarAnimationDuration = 0.12; | 80 const NSTimeInterval kToolBarAnimationDuration = 0.12; |
| 81 | 81 |
| 82 // The height of the location bar in Material Design. | 82 // The height of the location bar. |
| 83 const CGFloat kMaterialDesignLocationBarHeight = 28; | 83 const CGFloat kLocationBarHeight = 28; |
| 84 | 84 |
| 85 // The padding between the top of the toolbar and the top of the | 85 // The padding between the top of the toolbar and the top of the |
| 86 // location bar. | 86 // location bar. |
| 87 const CGFloat kMaterialDesignLocationBarPadding = 2; | 87 const CGFloat kLocationBarPadding = 2; |
| 88 | 88 |
| 89 // The padding between Material Design elements and the edges of the toolbar. | 89 // The padding between elements and the edges of the toolbar. |
| 90 const CGFloat kMaterialDesignElementPadding = 4; | 90 const CGFloat kElementPadding = 4; |
| 91 | 91 |
| 92 // Toolbar buttons are 24x24 and centered in a 28x28 space, so there is a 2pt- | 92 // Toolbar buttons are 24x24 and centered in a 28x28 space, so there is a 2pt- |
| 93 // wide inset. | 93 // wide inset. |
| 94 const CGFloat kMaterialDesignButtonInset = 2; | 94 const CGFloat kButtonInset = 2; |
| 95 | 95 |
| 96 // The y-offset of the browser actions container from the location bar. | 96 // The y-offset of the browser actions container from the location bar. |
| 97 const CGFloat kMaterialDesignContainerYOffset = 2; | 97 const CGFloat kContainerYOffset = 2; |
| 98 | 98 |
| 99 // The minimum width of the location bar in pixels. | 99 // The minimum width of the location bar in pixels. |
| 100 const CGFloat kMinimumLocationBarWidth = 100.0; | 100 const CGFloat kMinimumLocationBarWidth = 100.0; |
| 101 | 101 |
| 102 class BrowserActionsContainerDelegate : | 102 class BrowserActionsContainerDelegate : |
| 103 public BrowserActionsContainerViewSizeDelegate { | 103 public BrowserActionsContainerViewSizeDelegate { |
| 104 public: | 104 public: |
| 105 BrowserActionsContainerDelegate( | 105 BrowserActionsContainerDelegate( |
| 106 AutocompleteTextField* location_bar, | 106 AutocompleteTextField* location_bar, |
| 107 BrowserActionsContainerView* browser_actions_container_view); | 107 BrowserActionsContainerView* browser_actions_container_view); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 DISALLOW_COPY_AND_ASSIGN(NotificationBridge); | 223 DISALLOW_COPY_AND_ASSIGN(NotificationBridge); |
| 224 }; | 224 }; |
| 225 | 225 |
| 226 } // namespace ToolbarControllerInternal | 226 } // namespace ToolbarControllerInternal |
| 227 | 227 |
| 228 @implementation ToolbarController | 228 @implementation ToolbarController |
| 229 | 229 |
| 230 @synthesize browser = browser_; | 230 @synthesize browser = browser_; |
| 231 | 231 |
| 232 + (CGFloat)locationBarHeight { | 232 + (CGFloat)locationBarHeight { |
| 233 return kMaterialDesignLocationBarHeight; | 233 return kLocationBarHeight; |
| 234 } | 234 } |
| 235 | 235 |
| 236 + (CGFloat)appMenuLeftPadding { | 236 + (CGFloat)appMenuLeftPadding { |
| 237 return kMaterialDesignElementPadding; | 237 return kElementPadding; |
| 238 } | 238 } |
| 239 | 239 |
| 240 + (CGFloat)materialDesignButtonInset { | 240 + (CGFloat)materialDesignButtonInset { |
| 241 return kMaterialDesignButtonInset; | 241 return kButtonInset; |
| 242 } | 242 } |
| 243 | 243 |
| 244 - (id)initWithCommands:(CommandUpdater*)commands | 244 - (id)initWithCommands:(CommandUpdater*)commands |
| 245 profile:(Profile*)profile | 245 profile:(Profile*)profile |
| 246 browser:(Browser*)browser | 246 browser:(Browser*)browser |
| 247 resizeDelegate:(id<ViewResizer>)resizeDelegate { | 247 resizeDelegate:(id<ViewResizer>)resizeDelegate { |
| 248 DCHECK(commands && profile); | 248 DCHECK(commands && profile); |
| 249 if ((self = [super initWithNibName:@"Toolbar" | 249 if ((self = [super initWithNibName:@"Toolbar" |
| 250 bundle:base::mac::FrameworkBundle()])) { | 250 bundle:base::mac::FrameworkBundle()])) { |
| 251 commands_ = commands; | 251 commands_ = commands; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 NSRect toolbarBounds = [toolbarView bounds]; | 298 NSRect toolbarBounds = [toolbarView bounds]; |
| 299 NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize]; | 299 NSSize toolbarButtonSize = [ToolbarButton toolbarButtonSize]; |
| 300 | 300 |
| 301 // Set the toolbar height. | 301 // Set the toolbar height. |
| 302 NSRect frame = [toolbarView frame]; | 302 NSRect frame = [toolbarView frame]; |
| 303 frame.size.height = [self baseToolbarHeight]; | 303 frame.size.height = [self baseToolbarHeight]; |
| 304 [toolbarView setFrame:frame]; | 304 [toolbarView setFrame:frame]; |
| 305 | 305 |
| 306 NSRect backButtonFrame = [backButton_ frame]; | 306 NSRect backButtonFrame = [backButton_ frame]; |
| 307 backButtonFrame.origin.x = | 307 backButtonFrame.origin.x = |
| 308 kMaterialDesignElementPadding + kMaterialDesignButtonInset; | 308 kElementPadding + kButtonInset; |
|
Avi (use Gerrit)
2016/09/28 16:01:58
Some of these can be rewrapped. Try a clang format
Elly Fong-Jones
2016/09/28 19:02:27
Done.
| |
| 309 backButtonFrame.origin.y = NSMaxY(toolbarBounds) - | 309 backButtonFrame.origin.y = NSMaxY(toolbarBounds) - |
| 310 kMaterialDesignElementPadding - toolbarButtonSize.height; | 310 kElementPadding - toolbarButtonSize.height; |
| 311 backButtonFrame.size = toolbarButtonSize; | 311 backButtonFrame.size = toolbarButtonSize; |
| 312 [backButton_ setFrame:backButtonFrame]; | 312 [backButton_ setFrame:backButtonFrame]; |
| 313 | 313 |
| 314 NSRect forwardButtonFrame = [forwardButton_ frame]; | 314 NSRect forwardButtonFrame = [forwardButton_ frame]; |
| 315 forwardButtonFrame.origin.x = | 315 forwardButtonFrame.origin.x = |
| 316 NSMaxX(backButtonFrame) + 2 * kMaterialDesignButtonInset; | 316 NSMaxX(backButtonFrame) + 2 * kButtonInset; |
| 317 forwardButtonFrame.origin.y = backButtonFrame.origin.y; | 317 forwardButtonFrame.origin.y = backButtonFrame.origin.y; |
| 318 forwardButtonFrame.size = toolbarButtonSize; | 318 forwardButtonFrame.size = toolbarButtonSize; |
| 319 [forwardButton_ setFrame:forwardButtonFrame]; | 319 [forwardButton_ setFrame:forwardButtonFrame]; |
| 320 | 320 |
| 321 NSRect reloadButtonFrame = [reloadButton_ frame]; | 321 NSRect reloadButtonFrame = [reloadButton_ frame]; |
| 322 reloadButtonFrame.origin.x = | 322 reloadButtonFrame.origin.x = |
| 323 NSMaxX(forwardButtonFrame) + 2 * kMaterialDesignButtonInset; | 323 NSMaxX(forwardButtonFrame) + 2 * kButtonInset; |
| 324 reloadButtonFrame.origin.y = forwardButtonFrame.origin.y; | 324 reloadButtonFrame.origin.y = forwardButtonFrame.origin.y; |
| 325 reloadButtonFrame.size = toolbarButtonSize; | 325 reloadButtonFrame.size = toolbarButtonSize; |
| 326 [reloadButton_ setFrame:reloadButtonFrame]; | 326 [reloadButton_ setFrame:reloadButtonFrame]; |
| 327 | 327 |
| 328 NSRect homeButtonFrame = [homeButton_ frame]; | 328 NSRect homeButtonFrame = [homeButton_ frame]; |
| 329 homeButtonFrame.origin.x = | 329 homeButtonFrame.origin.x = |
| 330 NSMaxX(reloadButtonFrame) + 2 * kMaterialDesignButtonInset; | 330 NSMaxX(reloadButtonFrame) + 2 * kButtonInset; |
| 331 homeButtonFrame.origin.y = reloadButtonFrame.origin.y; | 331 homeButtonFrame.origin.y = reloadButtonFrame.origin.y; |
| 332 homeButtonFrame.size = toolbarButtonSize; | 332 homeButtonFrame.size = toolbarButtonSize; |
| 333 [homeButton_ setFrame:homeButtonFrame]; | 333 [homeButton_ setFrame:homeButtonFrame]; |
| 334 | 334 |
| 335 // 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 |
| 336 // Material Design. | 336 // Material Design. |
| 337 AppToolbarButton* newMenuButton = | 337 AppToolbarButton* newMenuButton = |
| 338 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] | 338 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] |
| 339 autorelease]; | 339 autorelease]; |
| 340 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; | 340 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; |
| 341 [[appMenuButton_ superview] addSubview:newMenuButton]; | 341 [[appMenuButton_ superview] addSubview:newMenuButton]; |
| 342 [appMenuButton_ removeFromSuperview]; | 342 [appMenuButton_ removeFromSuperview]; |
| 343 appMenuButton_ = newMenuButton; | 343 appMenuButton_ = newMenuButton; |
| 344 | 344 |
| 345 // Adjust the menu button's position. | 345 // Adjust the menu button's position. |
| 346 NSRect menuButtonFrame = [appMenuButton_ frame]; | 346 NSRect menuButtonFrame = [appMenuButton_ frame]; |
| 347 CGFloat menuButtonFrameMaxX = | 347 CGFloat menuButtonFrameMaxX = |
| 348 NSMaxX(toolbarBounds) - [ToolbarController appMenuLeftPadding]; | 348 NSMaxX(toolbarBounds) - [ToolbarController appMenuLeftPadding]; |
| 349 menuButtonFrame.origin.x = | 349 menuButtonFrame.origin.x = |
| 350 menuButtonFrameMaxX - kMaterialDesignButtonInset - | 350 menuButtonFrameMaxX - kButtonInset - |
| 351 toolbarButtonSize.width; | 351 toolbarButtonSize.width; |
| 352 menuButtonFrame.origin.y = homeButtonFrame.origin.y; | 352 menuButtonFrame.origin.y = homeButtonFrame.origin.y; |
| 353 menuButtonFrame.size = toolbarButtonSize; | 353 menuButtonFrame.size = toolbarButtonSize; |
| 354 [appMenuButton_ setFrame:menuButtonFrame]; | 354 [appMenuButton_ setFrame:menuButtonFrame]; |
| 355 | 355 |
| 356 // Adjust the size and location on the location bar to take up the | 356 // Adjust the size and location on the location bar to take up the |
| 357 // space between the reload and menu buttons. | 357 // space between the reload and menu buttons. |
| 358 NSRect locationBarFrame = [locationBar_ frame]; | 358 NSRect locationBarFrame = [locationBar_ frame]; |
| 359 locationBarFrame.origin.x = NSMaxX(homeButtonFrame) + | 359 locationBarFrame.origin.x = NSMaxX(homeButtonFrame) + |
| 360 kMaterialDesignButtonInset; | 360 kButtonInset; |
| 361 if (![homeButton_ isHidden]) { | 361 if (![homeButton_ isHidden]) { |
| 362 // Ensure proper spacing between the home button and the location bar. | 362 // Ensure proper spacing between the home button and the location bar. |
| 363 locationBarFrame.origin.x += kMaterialDesignElementPadding; | 363 locationBarFrame.origin.x += kElementPadding; |
| 364 } | 364 } |
| 365 locationBarFrame.origin.y = NSMaxY(toolbarBounds) - | 365 locationBarFrame.origin.y = NSMaxY(toolbarBounds) - |
| 366 kMaterialDesignLocationBarPadding - kMaterialDesignLocationBarHeight; | 366 kLocationBarPadding - kLocationBarHeight; |
| 367 locationBarFrame.size.width = | 367 locationBarFrame.size.width = |
| 368 menuButtonFrame.origin.x - | 368 menuButtonFrame.origin.x - |
| 369 locationBarFrame.origin.x; | 369 locationBarFrame.origin.x; |
| 370 locationBarFrame.size.height = kMaterialDesignLocationBarHeight; | 370 locationBarFrame.size.height = kLocationBarHeight; |
| 371 [locationBar_ setFrame:locationBarFrame]; | 371 [locationBar_ setFrame:locationBarFrame]; |
| 372 | 372 |
| 373 // Correctly position the extension buttons' container view. | 373 // Correctly position the extension buttons' container view. |
| 374 NSRect containerFrame = [browserActionsContainerView_ frame]; | 374 NSRect containerFrame = [browserActionsContainerView_ frame]; |
| 375 containerFrame.size.width += kMaterialDesignButtonInset; | 375 containerFrame.size.width += kButtonInset; |
| 376 containerFrame.origin.y = | 376 containerFrame.origin.y = |
| 377 locationBarFrame.origin.y + kMaterialDesignContainerYOffset; | 377 locationBarFrame.origin.y + kContainerYOffset; |
| 378 containerFrame.size.height = toolbarButtonSize.height; | 378 containerFrame.size.height = toolbarButtonSize.height; |
| 379 [browserActionsContainerView_ setFrame:containerFrame]; | 379 [browserActionsContainerView_ setFrame:containerFrame]; |
| 380 | 380 |
| 381 notificationBridge_.reset( | 381 notificationBridge_.reset( |
| 382 new ToolbarControllerInternal::NotificationBridge(self)); | 382 new ToolbarControllerInternal::NotificationBridge(self)); |
| 383 notificationBridge_->UpdateSeverity(); | 383 notificationBridge_->UpdateSeverity(); |
| 384 | 384 |
| 385 [appMenuButton_ setOpenMenuOnClick:YES]; | 385 [appMenuButton_ setOpenMenuOnClick:YES]; |
| 386 | 386 |
| 387 [backButton_ setOpenMenuOnRightClick:YES]; | 387 [backButton_ setOpenMenuOnRightClick:YES]; |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 return; | 730 return; |
| 731 BOOL hide = showHomeButton_.GetValue() ? NO : YES; | 731 BOOL hide = showHomeButton_.GetValue() ? NO : YES; |
| 732 if (hide == [homeButton_ isHidden]) | 732 if (hide == [homeButton_ isHidden]) |
| 733 return; // Nothing to do, view state matches pref state. | 733 return; // Nothing to do, view state matches pref state. |
| 734 | 734 |
| 735 // Always shift the text field by the width of the home button minus one pixel | 735 // Always shift the text field by the width of the home button minus one pixel |
| 736 // since the frame edges of each button are right on top of each other. When | 736 // since the frame edges of each button are right on top of each other. When |
| 737 // hiding the button, reverse the direction of the movement (to the left). | 737 // hiding the button, reverse the direction of the movement (to the left). |
| 738 CGFloat moveX = [homeButton_ frame].size.width; | 738 CGFloat moveX = [homeButton_ frame].size.width; |
| 739 // Ensure proper spacing between the home button and the location bar. | 739 // Ensure proper spacing between the home button and the location bar. |
| 740 moveX += kMaterialDesignElementPadding; | 740 moveX += kElementPadding; |
| 741 if (hide) | 741 if (hide) |
| 742 moveX *= -1; // Reverse the direction of the move. | 742 moveX *= -1; // Reverse the direction of the move. |
| 743 | 743 |
| 744 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] | 744 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] |
| 745 byAmount:moveX]]; | 745 byAmount:moveX]]; |
| 746 [homeButton_ setHidden:hide]; | 746 [homeButton_ setHidden:hide]; |
| 747 } | 747 } |
| 748 | 748 |
| 749 // Install the app menu buttons. Calling this repeatedly is inexpensive so it | 749 // Install the app menu buttons. Calling this repeatedly is inexpensive so it |
| 750 // can be done every time the buttons are shown. | 750 // can be done every time the buttons are shown. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 846 | 846 |
| 847 if ([browserActionsContainerView_ isHidden]) { | 847 if ([browserActionsContainerView_ isHidden]) { |
| 848 CGFloat edgeXPos = [appMenuButton_ frame].origin.x; | 848 CGFloat edgeXPos = [appMenuButton_ frame].origin.x; |
| 849 leftDistance = edgeXPos - locationBarXPos - | 849 leftDistance = edgeXPos - locationBarXPos - |
| 850 [ToolbarController appMenuLeftPadding]; | 850 [ToolbarController appMenuLeftPadding]; |
| 851 } else { | 851 } else { |
| 852 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - | 852 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - |
| 853 locationBarXPos; | 853 locationBarXPos; |
| 854 // Equalize the distance between the location bar and the first extension | 854 // Equalize the distance between the location bar and the first extension |
| 855 // button, and the distance between the location bar and home/reload button. | 855 // button, and the distance between the location bar and home/reload button. |
| 856 leftDistance -= kMaterialDesignButtonInset; | 856 leftDistance -= kButtonInset; |
| 857 } | 857 } |
| 858 if (leftDistance != 0.0) | 858 if (leftDistance != 0.0) |
| 859 [self adjustLocationSizeBy:leftDistance animate:animate]; | 859 [self adjustLocationSizeBy:leftDistance animate:animate]; |
| 860 else | 860 else |
| 861 [locationBar_ stopAnimation]; | 861 [locationBar_ stopAnimation]; |
| 862 } | 862 } |
| 863 | 863 |
| 864 - (void)maintainMinimumLocationBarWidth { | 864 - (void)maintainMinimumLocationBarWidth { |
| 865 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); | 865 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); |
| 866 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; | 866 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 878 | 878 |
| 879 if ([browserActionsContainerView_ isAnimating]) { | 879 if ([browserActionsContainerView_ isAnimating]) { |
| 880 // If the browser actions container is animating, we need to stop it first, | 880 // If the browser actions container is animating, we need to stop it first, |
| 881 // because the frame it's animating for could be incorrect with the new | 881 // because the frame it's animating for could be incorrect with the new |
| 882 // bounds (if, for instance, the bookmark bar was added). | 882 // bounds (if, for instance, the bookmark bar was added). |
| 883 // This will advance to the end of the animation, so we also need to adjust | 883 // This will advance to the end of the animation, so we also need to adjust |
| 884 // it afterwards. | 884 // it afterwards. |
| 885 [browserActionsContainerView_ stopAnimation]; | 885 [browserActionsContainerView_ stopAnimation]; |
| 886 NSRect containerFrame = [browserActionsContainerView_ frame]; | 886 NSRect containerFrame = [browserActionsContainerView_ frame]; |
| 887 containerFrame.origin.y = | 887 containerFrame.origin.y = |
| 888 [locationBar_ frame].origin.y + kMaterialDesignContainerYOffset; | 888 [locationBar_ frame].origin.y + kContainerYOffset; |
| 889 [browserActionsContainerView_ setFrame:containerFrame]; | 889 [browserActionsContainerView_ setFrame:containerFrame]; |
| 890 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; | 890 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
| 891 } | 891 } |
| 892 | 892 |
| 893 [self maintainMinimumLocationBarWidth]; | 893 [self maintainMinimumLocationBarWidth]; |
| 894 | 894 |
| 895 if (locationBarAtMinSize_) { | 895 if (locationBarAtMinSize_) { |
| 896 // Once the grippy is pinned, leave it until it is explicity un-pinned. | 896 // Once the grippy is pinned, leave it until it is explicity un-pinned. |
| 897 [browserActionsContainerView_ setGrippyPinned:YES]; | 897 [browserActionsContainerView_ setGrippyPinned:YES]; |
| 898 NSRect containerFrame = [browserActionsContainerView_ frame]; | 898 NSRect containerFrame = [browserActionsContainerView_ frame]; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1087 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 1087 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
| 1088 // Do nothing. | 1088 // Do nothing. |
| 1089 } | 1089 } |
| 1090 | 1090 |
| 1091 // (URLDropTargetController protocol) | 1091 // (URLDropTargetController protocol) |
| 1092 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 1092 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
| 1093 return drag_util::IsUnsupportedDropData(profile_, info); | 1093 return drag_util::IsUnsupportedDropData(profile_, info); |
| 1094 } | 1094 } |
| 1095 | 1095 |
| 1096 @end | 1096 @end |
| OLD | NEW |