| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 ToolbarView* toolbarView = [self toolbarView]; | 297 ToolbarView* toolbarView = [self toolbarView]; |
| 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 = kElementPadding + kButtonInset; |
| 308 kMaterialDesignElementPadding + kMaterialDesignButtonInset; | 308 backButtonFrame.origin.y = |
| 309 backButtonFrame.origin.y = NSMaxY(toolbarBounds) - | 309 NSMaxY(toolbarBounds) - kElementPadding - toolbarButtonSize.height; |
| 310 kMaterialDesignElementPadding - toolbarButtonSize.height; | |
| 311 backButtonFrame.size = toolbarButtonSize; | 310 backButtonFrame.size = toolbarButtonSize; |
| 312 [backButton_ setFrame:backButtonFrame]; | 311 [backButton_ setFrame:backButtonFrame]; |
| 313 | 312 |
| 314 NSRect forwardButtonFrame = [forwardButton_ frame]; | 313 NSRect forwardButtonFrame = [forwardButton_ frame]; |
| 315 forwardButtonFrame.origin.x = | 314 forwardButtonFrame.origin.x = NSMaxX(backButtonFrame) + 2 * kButtonInset; |
| 316 NSMaxX(backButtonFrame) + 2 * kMaterialDesignButtonInset; | |
| 317 forwardButtonFrame.origin.y = backButtonFrame.origin.y; | 315 forwardButtonFrame.origin.y = backButtonFrame.origin.y; |
| 318 forwardButtonFrame.size = toolbarButtonSize; | 316 forwardButtonFrame.size = toolbarButtonSize; |
| 319 [forwardButton_ setFrame:forwardButtonFrame]; | 317 [forwardButton_ setFrame:forwardButtonFrame]; |
| 320 | 318 |
| 321 NSRect reloadButtonFrame = [reloadButton_ frame]; | 319 NSRect reloadButtonFrame = [reloadButton_ frame]; |
| 322 reloadButtonFrame.origin.x = | 320 reloadButtonFrame.origin.x = NSMaxX(forwardButtonFrame) + 2 * kButtonInset; |
| 323 NSMaxX(forwardButtonFrame) + 2 * kMaterialDesignButtonInset; | |
| 324 reloadButtonFrame.origin.y = forwardButtonFrame.origin.y; | 321 reloadButtonFrame.origin.y = forwardButtonFrame.origin.y; |
| 325 reloadButtonFrame.size = toolbarButtonSize; | 322 reloadButtonFrame.size = toolbarButtonSize; |
| 326 [reloadButton_ setFrame:reloadButtonFrame]; | 323 [reloadButton_ setFrame:reloadButtonFrame]; |
| 327 | 324 |
| 328 NSRect homeButtonFrame = [homeButton_ frame]; | 325 NSRect homeButtonFrame = [homeButton_ frame]; |
| 329 homeButtonFrame.origin.x = | 326 homeButtonFrame.origin.x = NSMaxX(reloadButtonFrame) + 2 * kButtonInset; |
| 330 NSMaxX(reloadButtonFrame) + 2 * kMaterialDesignButtonInset; | |
| 331 homeButtonFrame.origin.y = reloadButtonFrame.origin.y; | 327 homeButtonFrame.origin.y = reloadButtonFrame.origin.y; |
| 332 homeButtonFrame.size = toolbarButtonSize; | 328 homeButtonFrame.size = toolbarButtonSize; |
| 333 [homeButton_ setFrame:homeButtonFrame]; | 329 [homeButton_ setFrame:homeButtonFrame]; |
| 334 | 330 |
| 335 // Replace the app button from the nib with an AppToolbarButton instance for | 331 // Replace the app button from the nib with an AppToolbarButton instance for |
| 336 // Material Design. | 332 // Material Design. |
| 337 AppToolbarButton* newMenuButton = | 333 AppToolbarButton* newMenuButton = |
| 338 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] | 334 [[[AppToolbarButton alloc] initWithFrame:[appMenuButton_ frame]] |
| 339 autorelease]; | 335 autorelease]; |
| 340 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; | 336 [newMenuButton setAutoresizingMask:[appMenuButton_ autoresizingMask]]; |
| 341 [[appMenuButton_ superview] addSubview:newMenuButton]; | 337 [[appMenuButton_ superview] addSubview:newMenuButton]; |
| 342 [appMenuButton_ removeFromSuperview]; | 338 [appMenuButton_ removeFromSuperview]; |
| 343 appMenuButton_ = newMenuButton; | 339 appMenuButton_ = newMenuButton; |
| 344 | 340 |
| 345 // Adjust the menu button's position. | 341 // Adjust the menu button's position. |
| 346 NSRect menuButtonFrame = [appMenuButton_ frame]; | 342 NSRect menuButtonFrame = [appMenuButton_ frame]; |
| 347 CGFloat menuButtonFrameMaxX = | 343 CGFloat menuButtonFrameMaxX = |
| 348 NSMaxX(toolbarBounds) - [ToolbarController appMenuLeftPadding]; | 344 NSMaxX(toolbarBounds) - [ToolbarController appMenuLeftPadding]; |
| 349 menuButtonFrame.origin.x = | 345 menuButtonFrame.origin.x = |
| 350 menuButtonFrameMaxX - kMaterialDesignButtonInset - | 346 menuButtonFrameMaxX - kButtonInset - toolbarButtonSize.width; |
| 351 toolbarButtonSize.width; | |
| 352 menuButtonFrame.origin.y = homeButtonFrame.origin.y; | 347 menuButtonFrame.origin.y = homeButtonFrame.origin.y; |
| 353 menuButtonFrame.size = toolbarButtonSize; | 348 menuButtonFrame.size = toolbarButtonSize; |
| 354 [appMenuButton_ setFrame:menuButtonFrame]; | 349 [appMenuButton_ setFrame:menuButtonFrame]; |
| 355 | 350 |
| 356 // Adjust the size and location on the location bar to take up the | 351 // Adjust the size and location on the location bar to take up the |
| 357 // space between the reload and menu buttons. | 352 // space between the reload and menu buttons. |
| 358 NSRect locationBarFrame = [locationBar_ frame]; | 353 NSRect locationBarFrame = [locationBar_ frame]; |
| 359 locationBarFrame.origin.x = NSMaxX(homeButtonFrame) + | 354 locationBarFrame.origin.x = NSMaxX(homeButtonFrame) + kButtonInset; |
| 360 kMaterialDesignButtonInset; | |
| 361 if (![homeButton_ isHidden]) { | 355 if (![homeButton_ isHidden]) { |
| 362 // Ensure proper spacing between the home button and the location bar. | 356 // Ensure proper spacing between the home button and the location bar. |
| 363 locationBarFrame.origin.x += kMaterialDesignElementPadding; | 357 locationBarFrame.origin.x += kElementPadding; |
| 364 } | 358 } |
| 365 locationBarFrame.origin.y = NSMaxY(toolbarBounds) - | 359 locationBarFrame.origin.y = |
| 366 kMaterialDesignLocationBarPadding - kMaterialDesignLocationBarHeight; | 360 NSMaxY(toolbarBounds) - kLocationBarPadding - kLocationBarHeight; |
| 367 locationBarFrame.size.width = | 361 locationBarFrame.size.width = |
| 368 menuButtonFrame.origin.x - | 362 menuButtonFrame.origin.x - |
| 369 locationBarFrame.origin.x; | 363 locationBarFrame.origin.x; |
| 370 locationBarFrame.size.height = kMaterialDesignLocationBarHeight; | 364 locationBarFrame.size.height = kLocationBarHeight; |
| 371 [locationBar_ setFrame:locationBarFrame]; | 365 [locationBar_ setFrame:locationBarFrame]; |
| 372 | 366 |
| 373 // Correctly position the extension buttons' container view. | 367 // Correctly position the extension buttons' container view. |
| 374 NSRect containerFrame = [browserActionsContainerView_ frame]; | 368 NSRect containerFrame = [browserActionsContainerView_ frame]; |
| 375 containerFrame.size.width += kMaterialDesignButtonInset; | 369 containerFrame.size.width += kButtonInset; |
| 376 containerFrame.origin.y = | 370 containerFrame.origin.y = locationBarFrame.origin.y + kContainerYOffset; |
| 377 locationBarFrame.origin.y + kMaterialDesignContainerYOffset; | |
| 378 containerFrame.size.height = toolbarButtonSize.height; | 371 containerFrame.size.height = toolbarButtonSize.height; |
| 379 [browserActionsContainerView_ setFrame:containerFrame]; | 372 [browserActionsContainerView_ setFrame:containerFrame]; |
| 380 | 373 |
| 381 notificationBridge_.reset( | 374 notificationBridge_.reset( |
| 382 new ToolbarControllerInternal::NotificationBridge(self)); | 375 new ToolbarControllerInternal::NotificationBridge(self)); |
| 383 notificationBridge_->UpdateSeverity(); | 376 notificationBridge_->UpdateSeverity(); |
| 384 | 377 |
| 385 [appMenuButton_ setOpenMenuOnClick:YES]; | 378 [appMenuButton_ setOpenMenuOnClick:YES]; |
| 386 | 379 |
| 387 [backButton_ setOpenMenuOnRightClick:YES]; | 380 [backButton_ setOpenMenuOnRightClick:YES]; |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 return; | 723 return; |
| 731 BOOL hide = showHomeButton_.GetValue() ? NO : YES; | 724 BOOL hide = showHomeButton_.GetValue() ? NO : YES; |
| 732 if (hide == [homeButton_ isHidden]) | 725 if (hide == [homeButton_ isHidden]) |
| 733 return; // Nothing to do, view state matches pref state. | 726 return; // Nothing to do, view state matches pref state. |
| 734 | 727 |
| 735 // Always shift the text field by the width of the home button minus one pixel | 728 // 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 | 729 // 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). | 730 // hiding the button, reverse the direction of the movement (to the left). |
| 738 CGFloat moveX = [homeButton_ frame].size.width; | 731 CGFloat moveX = [homeButton_ frame].size.width; |
| 739 // Ensure proper spacing between the home button and the location bar. | 732 // Ensure proper spacing between the home button and the location bar. |
| 740 moveX += kMaterialDesignElementPadding; | 733 moveX += kElementPadding; |
| 741 if (hide) | 734 if (hide) |
| 742 moveX *= -1; // Reverse the direction of the move. | 735 moveX *= -1; // Reverse the direction of the move. |
| 743 | 736 |
| 744 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] | 737 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] |
| 745 byAmount:moveX]]; | 738 byAmount:moveX]]; |
| 746 [homeButton_ setHidden:hide]; | 739 [homeButton_ setHidden:hide]; |
| 747 } | 740 } |
| 748 | 741 |
| 749 // Install the app menu buttons. Calling this repeatedly is inexpensive so it | 742 // Install the app menu buttons. Calling this repeatedly is inexpensive so it |
| 750 // can be done every time the buttons are shown. | 743 // can be done every time the buttons are shown. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 | 839 |
| 847 if ([browserActionsContainerView_ isHidden]) { | 840 if ([browserActionsContainerView_ isHidden]) { |
| 848 CGFloat edgeXPos = [appMenuButton_ frame].origin.x; | 841 CGFloat edgeXPos = [appMenuButton_ frame].origin.x; |
| 849 leftDistance = edgeXPos - locationBarXPos - | 842 leftDistance = edgeXPos - locationBarXPos - |
| 850 [ToolbarController appMenuLeftPadding]; | 843 [ToolbarController appMenuLeftPadding]; |
| 851 } else { | 844 } else { |
| 852 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - | 845 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - |
| 853 locationBarXPos; | 846 locationBarXPos; |
| 854 // Equalize the distance between the location bar and the first extension | 847 // Equalize the distance between the location bar and the first extension |
| 855 // button, and the distance between the location bar and home/reload button. | 848 // button, and the distance between the location bar and home/reload button. |
| 856 leftDistance -= kMaterialDesignButtonInset; | 849 leftDistance -= kButtonInset; |
| 857 } | 850 } |
| 858 if (leftDistance != 0.0) | 851 if (leftDistance != 0.0) |
| 859 [self adjustLocationSizeBy:leftDistance animate:animate]; | 852 [self adjustLocationSizeBy:leftDistance animate:animate]; |
| 860 else | 853 else |
| 861 [locationBar_ stopAnimation]; | 854 [locationBar_ stopAnimation]; |
| 862 } | 855 } |
| 863 | 856 |
| 864 - (void)maintainMinimumLocationBarWidth { | 857 - (void)maintainMinimumLocationBarWidth { |
| 865 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); | 858 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); |
| 866 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; | 859 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 877 return; | 870 return; |
| 878 | 871 |
| 879 if ([browserActionsContainerView_ isAnimating]) { | 872 if ([browserActionsContainerView_ isAnimating]) { |
| 880 // If the browser actions container is animating, we need to stop it first, | 873 // 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 | 874 // because the frame it's animating for could be incorrect with the new |
| 882 // bounds (if, for instance, the bookmark bar was added). | 875 // 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 | 876 // This will advance to the end of the animation, so we also need to adjust |
| 884 // it afterwards. | 877 // it afterwards. |
| 885 [browserActionsContainerView_ stopAnimation]; | 878 [browserActionsContainerView_ stopAnimation]; |
| 886 NSRect containerFrame = [browserActionsContainerView_ frame]; | 879 NSRect containerFrame = [browserActionsContainerView_ frame]; |
| 887 containerFrame.origin.y = | 880 containerFrame.origin.y = [locationBar_ frame].origin.y + kContainerYOffset; |
| 888 [locationBar_ frame].origin.y + kMaterialDesignContainerYOffset; | |
| 889 [browserActionsContainerView_ setFrame:containerFrame]; | 881 [browserActionsContainerView_ setFrame:containerFrame]; |
| 890 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; | 882 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
| 891 } | 883 } |
| 892 | 884 |
| 893 [self maintainMinimumLocationBarWidth]; | 885 [self maintainMinimumLocationBarWidth]; |
| 894 | 886 |
| 895 if (locationBarAtMinSize_) { | 887 if (locationBarAtMinSize_) { |
| 896 // Once the grippy is pinned, leave it until it is explicity un-pinned. | 888 // Once the grippy is pinned, leave it until it is explicity un-pinned. |
| 897 [browserActionsContainerView_ setGrippyPinned:YES]; | 889 [browserActionsContainerView_ setGrippyPinned:YES]; |
| 898 NSRect containerFrame = [browserActionsContainerView_ frame]; | 890 NSRect containerFrame = [browserActionsContainerView_ frame]; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 1079 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
| 1088 // Do nothing. | 1080 // Do nothing. |
| 1089 } | 1081 } |
| 1090 | 1082 |
| 1091 // (URLDropTargetController protocol) | 1083 // (URLDropTargetController protocol) |
| 1092 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 1084 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
| 1093 return drag_util::IsUnsupportedDropData(profile_, info); | 1085 return drag_util::IsUnsupportedDropData(profile_, info); |
| 1094 } | 1086 } |
| 1095 | 1087 |
| 1096 @end | 1088 @end |
| OLD | NEW |