| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/toolbar_controller.h" | 5 #import "chrome/browser/cocoa/toolbar_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/l10n_util_mac.h" | 9 #include "app/l10n_util_mac.h" |
| 10 #include "base/mac_util.h" | 10 #include "base/mac_util.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "grit/chromium_strings.h" | 44 #include "grit/chromium_strings.h" |
| 45 #include "grit/generated_resources.h" | 45 #include "grit/generated_resources.h" |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 // Names of images in the bundle for buttons. | 49 // Names of images in the bundle for buttons. |
| 50 NSString* const kBackButtonImageName = @"back_Template.pdf"; | 50 NSString* const kBackButtonImageName = @"back_Template.pdf"; |
| 51 NSString* const kForwardButtonImageName = @"forward_Template.pdf"; | 51 NSString* const kForwardButtonImageName = @"forward_Template.pdf"; |
| 52 NSString* const kReloadButtonImageName = @"reload_Template.pdf"; | 52 NSString* const kReloadButtonImageName = @"reload_Template.pdf"; |
| 53 NSString* const kHomeButtonImageName = @"home_Template.pdf"; | 53 NSString* const kHomeButtonImageName = @"home_Template.pdf"; |
| 54 NSString* const kStarButtonImageName = @"star_Template.pdf"; | |
| 55 NSString* const kStarButtonFillingImageName = @"starred.pdf"; | |
| 56 NSString* const kGoButtonGoImageName = @"go_Template.pdf"; | 54 NSString* const kGoButtonGoImageName = @"go_Template.pdf"; |
| 57 NSString* const kGoButtonStopImageName = @"stop_Template.pdf"; | 55 NSString* const kGoButtonStopImageName = @"stop_Template.pdf"; |
| 58 NSString* const kPageButtonImageName = @"menu_page_Template.pdf"; | 56 NSString* const kPageButtonImageName = @"menu_page_Template.pdf"; |
| 59 NSString* const kWrenchButtonImageName = @"menu_chrome_Template.pdf"; | 57 NSString* const kWrenchButtonImageName = @"menu_chrome_Template.pdf"; |
| 60 | 58 |
| 61 // Height of the toolbar in pixels when the bookmark bar is closed. | 59 // Height of the toolbar in pixels when the bookmark bar is closed. |
| 62 const CGFloat kBaseToolbarHeight = 36.0; | 60 const CGFloat kBaseToolbarHeight = 36.0; |
| 63 | 61 |
| 64 // The distance from the 'Go' button to the Browser Actions container in pixels. | 62 // The distance from the 'Go' button to the Browser Actions container in pixels. |
| 65 const CGFloat kBrowserActionsContainerLeftPadding = 5.0; | 63 const CGFloat kBrowserActionsContainerLeftPadding = 5.0; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // bar and button state. | 216 // bar and button state. |
| 219 - (void)awakeFromNib { | 217 - (void)awakeFromNib { |
| 220 // A bug in AppKit (<rdar://7298597>, <http://openradar.me/7298597>) causes | 218 // A bug in AppKit (<rdar://7298597>, <http://openradar.me/7298597>) causes |
| 221 // images loaded directly from nibs in a framework to not get their "template" | 219 // images loaded directly from nibs in a framework to not get their "template" |
| 222 // flags set properly. Thus, despite the images being set on the buttons in | 220 // flags set properly. Thus, despite the images being set on the buttons in |
| 223 // the xib, we must set them in code. | 221 // the xib, we must set them in code. |
| 224 [backButton_ setImage:nsimage_cache::ImageNamed(kBackButtonImageName)]; | 222 [backButton_ setImage:nsimage_cache::ImageNamed(kBackButtonImageName)]; |
| 225 [forwardButton_ setImage:nsimage_cache::ImageNamed(kForwardButtonImageName)]; | 223 [forwardButton_ setImage:nsimage_cache::ImageNamed(kForwardButtonImageName)]; |
| 226 [reloadButton_ setImage:nsimage_cache::ImageNamed(kReloadButtonImageName)]; | 224 [reloadButton_ setImage:nsimage_cache::ImageNamed(kReloadButtonImageName)]; |
| 227 [homeButton_ setImage:nsimage_cache::ImageNamed(kHomeButtonImageName)]; | 225 [homeButton_ setImage:nsimage_cache::ImageNamed(kHomeButtonImageName)]; |
| 228 [starButton_ setImage:nsimage_cache::ImageNamed(kStarButtonImageName)]; | |
| 229 [goButton_ setImage:nsimage_cache::ImageNamed(kGoButtonGoImageName)]; | 226 [goButton_ setImage:nsimage_cache::ImageNamed(kGoButtonGoImageName)]; |
| 230 [pageButton_ setImage:nsimage_cache::ImageNamed(kPageButtonImageName)]; | 227 [pageButton_ setImage:nsimage_cache::ImageNamed(kPageButtonImageName)]; |
| 231 [wrenchButton_ setImage:nsimage_cache::ImageNamed(kWrenchButtonImageName)]; | 228 [wrenchButton_ setImage:nsimage_cache::ImageNamed(kWrenchButtonImageName)]; |
| 232 | 229 |
| 233 [pageButton_ setShowsBorderOnlyWhileMouseInside:YES]; | 230 [pageButton_ setShowsBorderOnlyWhileMouseInside:YES]; |
| 234 [wrenchButton_ setShowsBorderOnlyWhileMouseInside:YES]; | 231 [wrenchButton_ setShowsBorderOnlyWhileMouseInside:YES]; |
| 235 | 232 |
| 236 [self initCommandStatus:commands_]; | 233 [self initCommandStatus:commands_]; |
| 237 bubblePositioner_.reset(new BubblePositionerMac(self)); | 234 bubblePositioner_.reset(new BubblePositionerMac(self)); |
| 238 locationBarView_.reset(new LocationBarViewMac(locationBar_, | 235 locationBarView_.reset(new LocationBarViewMac(locationBar_, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 accessibilitySetOverrideValue:description | 302 accessibilitySetOverrideValue:description |
| 306 forAttribute:NSAccessibilityDescriptionAttribute]; | 303 forAttribute:NSAccessibilityDescriptionAttribute]; |
| 307 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_RELOAD); | 304 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_RELOAD); |
| 308 [[reloadButton_ cell] | 305 [[reloadButton_ cell] |
| 309 accessibilitySetOverrideValue:description | 306 accessibilitySetOverrideValue:description |
| 310 forAttribute:NSAccessibilityDescriptionAttribute]; | 307 forAttribute:NSAccessibilityDescriptionAttribute]; |
| 311 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_HOME); | 308 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_HOME); |
| 312 [[homeButton_ cell] | 309 [[homeButton_ cell] |
| 313 accessibilitySetOverrideValue:description | 310 accessibilitySetOverrideValue:description |
| 314 forAttribute:NSAccessibilityDescriptionAttribute]; | 311 forAttribute:NSAccessibilityDescriptionAttribute]; |
| 315 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_STAR); | |
| 316 [[starButton_ cell] | |
| 317 accessibilitySetOverrideValue:description | |
| 318 forAttribute:NSAccessibilityDescriptionAttribute]; | |
| 319 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_LOCATION); | 312 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_LOCATION); |
| 320 [[locationBar_ cell] | 313 [[locationBar_ cell] |
| 321 accessibilitySetOverrideValue:description | 314 accessibilitySetOverrideValue:description |
| 322 forAttribute:NSAccessibilityDescriptionAttribute]; | 315 forAttribute:NSAccessibilityDescriptionAttribute]; |
| 323 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_GO); | 316 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_GO); |
| 324 [[goButton_ cell] | 317 [[goButton_ cell] |
| 325 accessibilitySetOverrideValue:description | 318 accessibilitySetOverrideValue:description |
| 326 forAttribute:NSAccessibilityDescriptionAttribute]; | 319 forAttribute:NSAccessibilityDescriptionAttribute]; |
| 327 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_PAGE); | 320 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_PAGE); |
| 328 [[pageButton_ cell] | 321 [[pageButton_ cell] |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 break; | 380 break; |
| 388 case IDC_FORWARD: | 381 case IDC_FORWARD: |
| 389 button = forwardButton_; | 382 button = forwardButton_; |
| 390 break; | 383 break; |
| 391 case IDC_RELOAD: | 384 case IDC_RELOAD: |
| 392 button = reloadButton_; | 385 button = reloadButton_; |
| 393 break; | 386 break; |
| 394 case IDC_HOME: | 387 case IDC_HOME: |
| 395 button = homeButton_; | 388 button = homeButton_; |
| 396 break; | 389 break; |
| 397 case IDC_BOOKMARK_PAGE: | |
| 398 button = starButton_; | |
| 399 break; | |
| 400 } | 390 } |
| 401 [button setEnabled:enabled]; | 391 [button setEnabled:enabled]; |
| 402 } | 392 } |
| 403 | 393 |
| 404 // Init the enabled state of the buttons on the toolbar to match the state in | 394 // Init the enabled state of the buttons on the toolbar to match the state in |
| 405 // the controller. | 395 // the controller. |
| 406 - (void)initCommandStatus:(CommandUpdater*)commands { | 396 - (void)initCommandStatus:(CommandUpdater*)commands { |
| 407 [backButton_ setEnabled:commands->IsCommandEnabled(IDC_BACK) ? YES : NO]; | 397 [backButton_ setEnabled:commands->IsCommandEnabled(IDC_BACK) ? YES : NO]; |
| 408 [forwardButton_ | 398 [forwardButton_ |
| 409 setEnabled:commands->IsCommandEnabled(IDC_FORWARD) ? YES : NO]; | 399 setEnabled:commands->IsCommandEnabled(IDC_FORWARD) ? YES : NO]; |
| 410 [reloadButton_ setEnabled:commands->IsCommandEnabled(IDC_RELOAD) ? YES : NO]; | 400 [reloadButton_ setEnabled:commands->IsCommandEnabled(IDC_RELOAD) ? YES : NO]; |
| 411 [homeButton_ setEnabled:commands->IsCommandEnabled(IDC_HOME) ? YES : NO]; | 401 [homeButton_ setEnabled:commands->IsCommandEnabled(IDC_HOME) ? YES : NO]; |
| 412 [starButton_ | |
| 413 setEnabled:commands->IsCommandEnabled(IDC_BOOKMARK_PAGE) ? YES : NO]; | |
| 414 } | 402 } |
| 415 | 403 |
| 416 - (void)updateToolbarWithContents:(TabContents*)tab | 404 - (void)updateToolbarWithContents:(TabContents*)tab |
| 417 shouldRestoreState:(BOOL)shouldRestore { | 405 shouldRestoreState:(BOOL)shouldRestore { |
| 418 locationBarView_->Update(tab, shouldRestore ? true : false); | 406 locationBarView_->Update(tab, shouldRestore ? true : false); |
| 419 | 407 |
| 420 [locationBar_ updateCursorAndToolTipRects]; | 408 [locationBar_ updateCursorAndToolTipRects]; |
| 421 | 409 |
| 422 if (browserActionsController_.get()) { | 410 if (browserActionsController_.get()) { |
| 423 [browserActionsController_ update]; | 411 [browserActionsController_ update]; |
| 424 } | 412 } |
| 425 } | 413 } |
| 426 | 414 |
| 427 - (void)setStarredState:(BOOL)isStarred { | 415 - (void)setStarredState:(BOOL)isStarred { |
| 428 NSImage* starImage = nil; | 416 locationBarView_->SetStarred(isStarred ? true : false); |
| 429 NSString* toolTip; | |
| 430 if (isStarred) { | |
| 431 starImage = nsimage_cache::ImageNamed(kStarButtonFillingImageName); | |
| 432 // Cache the string since we'll need it a lot | |
| 433 static NSString* starredToolTip = | |
| 434 [l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STARRED) retain]; | |
| 435 toolTip = starredToolTip; | |
| 436 } else { | |
| 437 // Cache the string since we'll need it a lot | |
| 438 static NSString* starToolTip = | |
| 439 [l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STAR) retain]; | |
| 440 toolTip = starToolTip; | |
| 441 } | |
| 442 | |
| 443 [(GradientButtonCell*)[starButton_ cell] setUnderlayImage:starImage]; | |
| 444 [starButton_ setToolTip:toolTip]; | |
| 445 } | 417 } |
| 446 | 418 |
| 447 - (void)setIsLoading:(BOOL)isLoading { | 419 - (void)setIsLoading:(BOOL)isLoading { |
| 448 NSString* imageName = kGoButtonGoImageName; | 420 NSString* imageName = kGoButtonGoImageName; |
| 449 NSInteger tag = IDC_GO; | 421 NSInteger tag = IDC_GO; |
| 450 if (isLoading) { | 422 if (isLoading) { |
| 451 imageName = kGoButtonStopImageName; | 423 imageName = kGoButtonStopImageName; |
| 452 tag = IDC_STOP; | 424 tag = IDC_STOP; |
| 453 } | 425 } |
| 454 NSImage* stopStartImage = nsimage_cache::ImageNamed(imageName); | 426 NSImage* stopStartImage = nsimage_cache::ImageNamed(imageName); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 DCHECK(autocompleteTextFieldEditor_.get()); | 473 DCHECK(autocompleteTextFieldEditor_.get()); |
| 502 [autocompleteTextFieldEditor_.get() setFieldEditor:YES]; | 474 [autocompleteTextFieldEditor_.get() setFieldEditor:YES]; |
| 503 return autocompleteTextFieldEditor_.get(); | 475 return autocompleteTextFieldEditor_.get(); |
| 504 } | 476 } |
| 505 return nil; | 477 return nil; |
| 506 } | 478 } |
| 507 | 479 |
| 508 // Returns an array of views in the order of the outlets above. | 480 // Returns an array of views in the order of the outlets above. |
| 509 - (NSArray*)toolbarViews { | 481 - (NSArray*)toolbarViews { |
| 510 return [NSArray arrayWithObjects:backButton_, forwardButton_, reloadButton_, | 482 return [NSArray arrayWithObjects:backButton_, forwardButton_, reloadButton_, |
| 511 homeButton_, starButton_, goButton_, pageButton_, wrenchButton_, | 483 homeButton_, goButton_, pageButton_, wrenchButton_, |
| 512 locationBar_, browserActionsContainerView_, nil]; | 484 locationBar_, browserActionsContainerView_, nil]; |
| 513 } | 485 } |
| 514 | 486 |
| 515 // Moves |rect| to the right by |delta|, keeping the right side fixed by | 487 // Moves |rect| to the right by |delta|, keeping the right side fixed by |
| 516 // shrinking the width to compensate. Passing a negative value for |deltaX| | 488 // shrinking the width to compensate. Passing a negative value for |deltaX| |
| 517 // moves to the left and increases the width. | 489 // moves to the left and increases the width. |
| 518 - (NSRect)adjustRect:(NSRect)rect byAmount:(CGFloat)deltaX { | 490 - (NSRect)adjustRect:(NSRect)rect byAmount:(CGFloat)deltaX { |
| 519 NSRect frame = NSOffsetRect(rect, deltaX, 0); | 491 NSRect frame = NSOffsetRect(rect, deltaX, 0); |
| 520 frame.size.width -= deltaX; | 492 frame.size.width -= deltaX; |
| 521 return frame; | 493 return frame; |
| 522 } | 494 } |
| 523 | 495 |
| 524 // Computes the padding between the buttons that should have a separation from | 496 // Computes the padding between the buttons that should have a |
| 525 // the positions in the nib. Since the forward and reload buttons are always | 497 // separation from the positions in the nib. |homeButton_| is right |
| 526 // visible, we use those buttons as the canonical spacing. | 498 // of |forwardButton_| unless it has been hidden, in which case |
| 499 // |reloadButton_| is in that spot. |
| 527 - (CGFloat)interButtonSpacing { | 500 - (CGFloat)interButtonSpacing { |
| 528 NSRect forwardFrame = [forwardButton_ frame]; | 501 const NSRect forwardFrame = [forwardButton_ frame]; |
| 529 NSRect reloadFrame = [reloadButton_ frame]; | 502 NSButton* nextButton = [homeButton_ isHidden] ? reloadButton_ : homeButton_; |
| 530 DCHECK(NSMinX(reloadFrame) > NSMaxX(forwardFrame)); | 503 const NSRect nextButtonFrame = [nextButton frame]; |
| 531 return NSMinX(reloadFrame) - NSMaxX(forwardFrame); | 504 DCHECK_GT(NSMinX(nextButtonFrame), NSMaxX(forwardFrame)); |
| 505 return NSMinX(nextButtonFrame) - NSMaxX(forwardFrame); |
| 532 } | 506 } |
| 533 | 507 |
| 534 // Show or hide the home button based on the pref. | 508 // Show or hide the home button based on the pref. |
| 535 - (void)showOptionalHomeButton { | 509 - (void)showOptionalHomeButton { |
| 536 // Ignore this message if only showing the URL bar. | 510 // Ignore this message if only showing the URL bar. |
| 537 if (!hasToolbar_) | 511 if (!hasToolbar_) |
| 538 return; | 512 return; |
| 539 BOOL hide = showHomeButton_.GetValue() ? NO : YES; | 513 BOOL hide = showHomeButton_.GetValue() ? NO : YES; |
| 540 if (hide == [homeButton_ isHidden]) | 514 if (hide == [homeButton_ isHidden]) |
| 541 return; // Nothing to do, view state matches pref state. | 515 return; // Nothing to do, view state matches pref state. |
| 542 | 516 |
| 543 // Always shift the star and text field by the width of the home button plus | 517 // Always shift the star and text field by the width of the home button plus |
| 544 // the appropriate gap width. If we're hiding the button, we have to | 518 // the appropriate gap width. If we're hiding the button, we have to |
| 545 // reverse the direction of the movement (to the left). | 519 // reverse the direction of the movement (to the left). |
| 546 CGFloat moveX = [self interButtonSpacing] + [homeButton_ frame].size.width; | 520 CGFloat moveX = [self interButtonSpacing] + [homeButton_ frame].size.width; |
| 547 if (hide) | 521 if (hide) |
| 548 moveX *= -1; // Reverse the direction of the move. | 522 moveX *= -1; // Reverse the direction of the move. |
| 549 | 523 |
| 550 [starButton_ setFrame:NSOffsetRect([starButton_ frame], moveX, 0)]; | 524 [reloadButton_ setFrame:NSOffsetRect([reloadButton_ frame], moveX, 0)]; |
| 551 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] | 525 [locationBar_ setFrame:[self adjustRect:[locationBar_ frame] |
| 552 byAmount:moveX]]; | 526 byAmount:moveX]]; |
| 553 [homeButton_ setHidden:hide]; | 527 [homeButton_ setHidden:hide]; |
| 554 } | 528 } |
| 555 | 529 |
| 556 // Lazily install the menus on the page and wrench buttons. Calling this | 530 // Lazily install the menus on the page and wrench buttons. Calling this |
| 557 // repeatedly is inexpensive so it can be done every time the buttons are shown. | 531 // repeatedly is inexpensive so it can be done every time the buttons are shown. |
| 558 - (void)installPageWrenchMenus { | 532 - (void)installPageWrenchMenus { |
| 559 if (pageMenuModel_.get()) | 533 if (pageMenuModel_.get()) |
| 560 return; | 534 return; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 return; | 737 return; |
| 764 } | 738 } |
| 765 | 739 |
| 766 [NSAnimationContext beginGrouping]; | 740 [NSAnimationContext beginGrouping]; |
| 767 [[NSAnimationContext currentContext] setDuration:kAnimationDuration]; | 741 [[NSAnimationContext currentContext] setDuration:kAnimationDuration]; |
| 768 [[goButton_ animator] setFrame:goFrame]; | 742 [[goButton_ animator] setFrame:goFrame]; |
| 769 [[locationBar_ animator] setFrame:locationFrame]; | 743 [[locationBar_ animator] setFrame:locationFrame]; |
| 770 [NSAnimationContext endGrouping]; | 744 [NSAnimationContext endGrouping]; |
| 771 } | 745 } |
| 772 | 746 |
| 773 - (NSRect)starButtonInWindowCoordinates { | 747 - (NSRect)starIconInWindowCoordinates { |
| 774 return [starButton_ convertRect:[starButton_ bounds] toView:nil]; | 748 return [locationBar_ convertRect:[locationBar_ starIconFrame] toView:nil]; |
| 775 } | 749 } |
| 776 | 750 |
| 777 - (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight { | 751 - (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight { |
| 778 // With no toolbar, just ignore the compression. | 752 // With no toolbar, just ignore the compression. |
| 779 return hasToolbar_ ? kBaseToolbarHeight - compressByHeight : | 753 return hasToolbar_ ? kBaseToolbarHeight - compressByHeight : |
| 780 NSHeight([locationBar_ frame]); | 754 NSHeight([locationBar_ frame]); |
| 781 } | 755 } |
| 782 | 756 |
| 783 - (void)setDividerOpacity:(CGFloat)opacity { | 757 - (void)setDividerOpacity:(CGFloat)opacity { |
| 784 BackgroundGradientView* view = [self backgroundGradientView]; | 758 BackgroundGradientView* view = [self backgroundGradientView]; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { | 859 - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { |
| 886 // Do nothing. | 860 // Do nothing. |
| 887 } | 861 } |
| 888 | 862 |
| 889 // (URLDropTargetController protocol) | 863 // (URLDropTargetController protocol) |
| 890 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 864 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
| 891 // Do nothing. | 865 // Do nothing. |
| 892 } | 866 } |
| 893 | 867 |
| 894 @end | 868 @end |
| OLD | NEW |