| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // Toolbar buttons are 24x24 and centered in a 28x28 space, so there is a 2pt- | 96 // Toolbar buttons are 24x24 and centered in a 28x28 space, so there is a 2pt- |
| 97 // wide inset. | 97 // wide inset. |
| 98 const CGFloat kButtonInset = 2; | 98 const CGFloat kButtonInset = 2; |
| 99 | 99 |
| 100 // The y-offset of the browser actions container from the location bar. | 100 // The y-offset of the browser actions container from the location bar. |
| 101 const CGFloat kContainerYOffset = 2; | 101 const CGFloat kContainerYOffset = 2; |
| 102 | 102 |
| 103 // The minimum width of the location bar in pixels. | 103 // The minimum width of the location bar in pixels. |
| 104 const CGFloat kMinimumLocationBarWidth = 100.0; | 104 const CGFloat kMinimumLocationBarWidth = 100.0; |
| 105 | 105 |
| 106 class BrowserActionsContainerDelegate : | |
| 107 public BrowserActionsContainerViewSizeDelegate { | |
| 108 public: | |
| 109 BrowserActionsContainerDelegate( | |
| 110 AutocompleteTextField* location_bar, | |
| 111 BrowserActionsContainerView* browser_actions_container_view); | |
| 112 ~BrowserActionsContainerDelegate() override; | |
| 113 | |
| 114 private: | |
| 115 // BrowserActionsContainerSizeDelegate: | |
| 116 CGFloat GetMaxAllowedWidth() override; | |
| 117 | |
| 118 AutocompleteTextField* location_bar_; | |
| 119 BrowserActionsContainerView* browser_actions_container_; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainerDelegate); | |
| 122 }; | |
| 123 | |
| 124 BrowserActionsContainerDelegate::BrowserActionsContainerDelegate( | |
| 125 AutocompleteTextField* location_bar, | |
| 126 BrowserActionsContainerView* browser_actions_container_view) | |
| 127 : location_bar_(location_bar), | |
| 128 browser_actions_container_(browser_actions_container_view) { | |
| 129 [browser_actions_container_ setDelegate:this]; | |
| 130 } | |
| 131 | |
| 132 BrowserActionsContainerDelegate::~BrowserActionsContainerDelegate() { | |
| 133 [browser_actions_container_ setDelegate:nil]; | |
| 134 } | |
| 135 | |
| 136 CGFloat BrowserActionsContainerDelegate::GetMaxAllowedWidth() { | |
| 137 CGFloat location_bar_flex = | |
| 138 NSWidth([location_bar_ frame]) - kMinimumLocationBarWidth; | |
| 139 return NSWidth([browser_actions_container_ frame]) + location_bar_flex; | |
| 140 } | |
| 141 | |
| 142 } // namespace | 106 } // namespace |
| 143 | 107 |
| 144 @interface ToolbarController() | 108 @interface ToolbarController() |
| 145 @property(assign, nonatomic) Browser* browser; | 109 @property(assign, nonatomic) Browser* browser; |
| 146 // Height of the location bar. Used for animating the toolbar in and out when | 110 // 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. | 111 // the location bar is displayed stand-alone for bookmark apps. |
| 148 + (CGFloat)locationBarHeight; | 112 + (CGFloat)locationBarHeight; |
| 149 // Return the amount of horizontal padding that the app menu should have on | 113 // Return the amount of horizontal padding that the app menu should have on |
| 150 // each side. | 114 // each side. |
| 151 + (CGFloat)appMenuPadding; | 115 + (CGFloat)appMenuPadding; |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 485 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 522 | 486 |
| 523 if (trackingArea_.get()) { | 487 if (trackingArea_.get()) { |
| 524 [[self view] removeTrackingArea:trackingArea_.get()]; | 488 [[self view] removeTrackingArea:trackingArea_.get()]; |
| 525 [trackingArea_.get() clearOwner]; | 489 [trackingArea_.get() clearOwner]; |
| 526 trackingArea_.reset(); | 490 trackingArea_.reset(); |
| 527 } | 491 } |
| 528 | 492 |
| 529 // Destroy owned objects that hold a weak Browser*. | 493 // Destroy owned objects that hold a weak Browser*. |
| 530 locationBarView_.reset(); | 494 locationBarView_.reset(); |
| 531 browserActionsContainerDelegate_.reset(); | |
| 532 browser_ = nullptr; | 495 browser_ = nullptr; |
| 533 } | 496 } |
| 534 | 497 |
| 535 - (void)addAccessibilityDescriptions { | 498 - (void)addAccessibilityDescriptions { |
| 536 // Set accessibility descriptions. http://openradar.appspot.com/7496255 | 499 // Set accessibility descriptions. http://openradar.appspot.com/7496255 |
| 537 NSString* description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_BACK); | 500 NSString* description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_BACK); |
| 538 [[backButton_ cell] | 501 [[backButton_ cell] |
| 539 accessibilitySetOverrideValue:description | 502 accessibilitySetOverrideValue:description |
| 540 forAttribute:NSAccessibilityDescriptionAttribute]; | 503 forAttribute:NSAccessibilityDescriptionAttribute]; |
| 541 NSString* helpTag = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_TOOLTIP_BACK); | 504 NSString* helpTag = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_TOOLTIP_BACK); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 } | 742 } |
| 780 | 743 |
| 781 - (void)prefChanged:(const std::string&)prefName { | 744 - (void)prefChanged:(const std::string&)prefName { |
| 782 if (prefName == prefs::kShowHomeButton) { | 745 if (prefName == prefs::kShowHomeButton) { |
| 783 [self showOptionalHomeButton]; | 746 [self showOptionalHomeButton]; |
| 784 } | 747 } |
| 785 } | 748 } |
| 786 | 749 |
| 787 - (void)createBrowserActionButtons { | 750 - (void)createBrowserActionButtons { |
| 788 if (!browserActionsController_.get()) { | 751 if (!browserActionsController_.get()) { |
| 789 browserActionsContainerDelegate_.reset( | |
| 790 new BrowserActionsContainerDelegate(locationBar_, | |
| 791 browserActionsContainerView_)); | |
| 792 browserActionsController_.reset([[BrowserActionsController alloc] | 752 browserActionsController_.reset([[BrowserActionsController alloc] |
| 793 initWithBrowser:browser_ | 753 initWithBrowser:browser_ |
| 794 containerView:browserActionsContainerView_ | 754 containerView:browserActionsContainerView_ |
| 795 mainController:nil]); | 755 mainController:nil]); |
| 796 [[NSNotificationCenter defaultCenter] | 756 [[NSNotificationCenter defaultCenter] |
| 797 addObserver:self | 757 addObserver:self |
| 798 selector:@selector(browserActionsContainerDragged:) | 758 selector:@selector(browserActionsContainerDragged:) |
| 799 name:kBrowserActionGrippyDraggingNotification | 759 name:kBrowserActionGrippyDraggingNotification |
| 800 object:browserActionsContainerView_]; | 760 object:browserActionsContainerView_]; |
| 801 [[NSNotificationCenter defaultCenter] | 761 [[NSNotificationCenter defaultCenter] |
| 802 addObserver:self | 762 addObserver:self |
| 803 selector:@selector(browserActionsVisibilityChanged:) | 763 selector:@selector(browserActionsVisibilityChanged:) |
| 804 name:kBrowserActionVisibilityChangedNotification | 764 name:kBrowserActionVisibilityChangedNotification |
| 805 object:browserActionsController_]; | 765 object:browserActionsController_]; |
| 806 [[NSNotificationCenter defaultCenter] | 766 [[NSNotificationCenter defaultCenter] |
| 807 addObserver:self | 767 addObserver:self |
| 808 selector:@selector(browserActionsContainerWillAnimate:) | 768 selector:@selector(browserActionsContainerWillAnimate:) |
| 809 name:kBrowserActionsContainerWillAnimate | 769 name:kBrowserActionsContainerWillAnimate |
| 810 object:browserActionsContainerView_]; | 770 object:browserActionsContainerView_]; |
| 811 [[NSNotificationCenter defaultCenter] | 771 [[NSNotificationCenter defaultCenter] |
| 812 addObserver:self | 772 addObserver:self |
| 813 selector:@selector(adjustBrowserActionsContainerForNewWindow:) | 773 selector:@selector(adjustBrowserActionsContainerForNewWindow:) |
| 814 name:NSWindowDidBecomeKeyNotification | 774 name:NSWindowDidBecomeKeyNotification |
| 815 object:[[self view] window]]; | 775 object:[[self view] window]]; |
| 816 } | 776 } |
| 817 if (![browserActionsContainerView_ isHidden]) | 777 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO]; |
| 818 [self pinLocationBarBeforeBrowserActionsContainerAndAnimate:NO]; | |
| 819 } | 778 } |
| 820 | 779 |
| 821 - (void)updateVisibility:(BOOL)visible withAnimation:(BOOL)animate { | 780 - (void)updateVisibility:(BOOL)visible withAnimation:(BOOL)animate { |
| 822 CGFloat newHeight = visible ? [ToolbarController locationBarHeight] : 0; | 781 CGFloat newHeight = visible ? [ToolbarController locationBarHeight] : 0; |
| 823 | 782 |
| 824 // Perform the animation, which will cause the BrowserWindowController to | 783 // Perform the animation, which will cause the BrowserWindowController to |
| 825 // resize this view in the browser layout as required. | 784 // resize this view in the browser layout as required. |
| 826 if (animate) { | 785 if (animate) { |
| 827 [[self toolbarView] animateToNewHeight:newHeight | 786 [[self toolbarView] animateToNewHeight:newHeight |
| 828 duration:kToolBarAnimationDuration]; | 787 duration:kToolBarAnimationDuration]; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 CGFloat rightEdge = NSMaxX([locationBar_ frame]); | 827 CGFloat rightEdge = NSMaxX([locationBar_ frame]); |
| 869 if ([browserActionsContainerView_ isHidden]) { | 828 if ([browserActionsContainerView_ isHidden]) { |
| 870 delta = NSMinX([appMenuButton_ frame]) - | 829 delta = NSMinX([appMenuButton_ frame]) - |
| 871 [ToolbarController appMenuPadding] - kButtonInset - rightEdge; | 830 [ToolbarController appMenuPadding] - kButtonInset - rightEdge; |
| 872 } else { | 831 } else { |
| 873 delta = NSMinX([browserActionsContainerView_ animationEndFrame]) - | 832 delta = NSMinX([browserActionsContainerView_ animationEndFrame]) - |
| 874 kButtonInset - rightEdge; | 833 kButtonInset - rightEdge; |
| 875 } | 834 } |
| 876 } | 835 } |
| 877 | 836 |
| 878 if (delta != 0.0) | 837 [self adjustLocationSizeBy:delta animate:animate]; |
| 879 [self adjustLocationSizeBy:delta animate:animate]; | |
| 880 else | |
| 881 [locationBar_ stopAnimation]; | |
| 882 } | 838 } |
| 883 | 839 |
| 884 - (void)maintainMinimumLocationBarWidth { | 840 - (void)maintainMinimumLocationBarWidth { |
| 885 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); | 841 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); |
| 886 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; | 842 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; |
| 887 if (locationBarAtMinSize_) { | 843 if (locationBarAtMinSize_) { |
| 888 CGFloat dX = kMinimumLocationBarWidth - locationBarWidth; | 844 CGFloat dX = kMinimumLocationBarWidth - locationBarWidth; |
| 889 [self adjustLocationSizeBy:dX animate:NO]; | 845 [self adjustLocationSizeBy:dX animate:NO]; |
| 890 } | 846 } |
| 891 } | 847 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 | 928 |
| 973 [backButton_ setHidden:YES]; | 929 [backButton_ setHidden:YES]; |
| 974 [forwardButton_ setHidden:YES]; | 930 [forwardButton_ setHidden:YES]; |
| 975 [reloadButton_ setHidden:YES]; | 931 [reloadButton_ setHidden:YES]; |
| 976 [appMenuButton_ setHidden:YES]; | 932 [appMenuButton_ setHidden:YES]; |
| 977 [homeButton_ setHidden:YES]; | 933 [homeButton_ setHidden:YES]; |
| 978 [browserActionsContainerView_ setHidden:YES]; | 934 [browserActionsContainerView_ setHidden:YES]; |
| 979 } | 935 } |
| 980 | 936 |
| 981 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate { | 937 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate { |
| 938 NSRect locationFrame = [locationBar_ frame]; |
| 939 |
| 940 CGFloat location_bar_flex = NSWidth(locationFrame) - kMinimumLocationBarWidth; |
| 941 [browserActionsController_ |
| 942 setMaxWidth:NSWidth(browserActionsContainerView_.frame) + |
| 943 location_bar_flex]; |
| 944 |
| 945 [locationBar_ stopAnimation]; |
| 946 |
| 947 if (dX == 0) |
| 948 return; |
| 949 |
| 982 // Ensure that the location bar is in its proper place. | 950 // Ensure that the location bar is in its proper place. |
| 983 NSRect locationFrame = [locationBar_ frame]; | |
| 984 locationFrame.size.width += dX; | 951 locationFrame.size.width += dX; |
| 985 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) | 952 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) |
| 986 locationFrame.origin.x -= dX; | 953 locationFrame.origin.x -= dX; |
| 987 | 954 |
| 988 [locationBar_ stopAnimation]; | |
| 989 if (animate) | 955 if (animate) |
| 990 [locationBar_ animateToFrame:locationFrame]; | 956 [locationBar_ animateToFrame:locationFrame]; |
| 991 else | 957 else |
| 992 [locationBar_ setFrame:locationFrame]; | 958 [locationBar_ setFrame:locationFrame]; |
| 993 } | 959 } |
| 994 | 960 |
| 995 - (NSPoint)bookmarkBubblePoint { | 961 - (NSPoint)bookmarkBubblePoint { |
| 996 if (locationBarView_->IsStarEnabled()) | 962 if (locationBarView_->IsStarEnabled()) |
| 997 return locationBarView_->GetBubblePointForDecoration( | 963 return locationBarView_->GetBubblePointForDecoration( |
| 998 locationBarView_->star_decoration()); | 964 locationBarView_->star_decoration()); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 1090 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
| 1125 // Do nothing. | 1091 // Do nothing. |
| 1126 } | 1092 } |
| 1127 | 1093 |
| 1128 // (URLDropTargetController protocol) | 1094 // (URLDropTargetController protocol) |
| 1129 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 1095 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
| 1130 return drag_util::IsUnsupportedDropData(profile_, info); | 1096 return drag_util::IsUnsupportedDropData(profile_, info); |
| 1131 } | 1097 } |
| 1132 | 1098 |
| 1133 @end | 1099 @end |
| OLD | NEW |