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 // in Toolbar.xib: the height of the toolbar (35) minus the height of the child | 74 // in Toolbar.xib: the height of the toolbar (35) minus the height of the child |
75 // elements (29) minus the y-origin of the elements (4). | 75 // elements (29) minus the y-origin of the elements (4). |
76 const CGFloat kToolbarElementTopPadding = 2.0; | 76 const CGFloat kToolbarElementTopPadding = 2.0; |
77 | 77 |
78 // The minimum width of the location bar in pixels. | 78 // The minimum width of the location bar in pixels. |
79 const CGFloat kMinimumLocationBarWidth = 100.0; | 79 const CGFloat kMinimumLocationBarWidth = 100.0; |
80 | 80 |
81 // The amount of left padding that the wrench menu should have. | 81 // The amount of left padding that the wrench menu should have. |
82 const CGFloat kWrenchMenuLeftPadding = 3.0; | 82 const CGFloat kWrenchMenuLeftPadding = 3.0; |
83 | 83 |
| 84 class BrowserActionsContainerDelegate : |
| 85 public BrowserActionsContainerViewSizeDelegate { |
| 86 public: |
| 87 BrowserActionsContainerDelegate( |
| 88 AutocompleteTextField* location_bar, |
| 89 BrowserActionsContainerView* browser_actions_container_view); |
| 90 ~BrowserActionsContainerDelegate() override; |
| 91 |
| 92 private: |
| 93 // BrowserActionsContainerSizeDelegate: |
| 94 CGFloat GetMaxAllowedWidth() override; |
| 95 |
| 96 AutocompleteTextField* location_bar_; |
| 97 BrowserActionsContainerView* browser_actions_container_; |
| 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainerDelegate); |
| 100 }; |
| 101 |
| 102 BrowserActionsContainerDelegate::BrowserActionsContainerDelegate( |
| 103 AutocompleteTextField* location_bar, |
| 104 BrowserActionsContainerView* browser_actions_container_view) |
| 105 : location_bar_(location_bar), |
| 106 browser_actions_container_(browser_actions_container_view) { |
| 107 [browser_actions_container_ setDelegate:this]; |
| 108 } |
| 109 |
| 110 BrowserActionsContainerDelegate::~BrowserActionsContainerDelegate() { |
| 111 [browser_actions_container_ setDelegate:nil]; |
| 112 } |
| 113 |
| 114 CGFloat BrowserActionsContainerDelegate::GetMaxAllowedWidth() { |
| 115 CGFloat location_bar_flex = |
| 116 NSWidth([location_bar_ frame]) - kMinimumLocationBarWidth; |
| 117 return NSWidth([browser_actions_container_ frame]) + location_bar_flex; |
| 118 } |
| 119 |
84 } // namespace | 120 } // namespace |
85 | 121 |
86 @interface ToolbarController() | 122 @interface ToolbarController() |
87 @property(assign, nonatomic) Browser* browser; | 123 @property(assign, nonatomic) Browser* browser; |
88 - (void)addAccessibilityDescriptions; | 124 - (void)addAccessibilityDescriptions; |
89 - (void)initCommandStatus:(CommandUpdater*)commands; | 125 - (void)initCommandStatus:(CommandUpdater*)commands; |
90 - (void)prefChanged:(const std::string&)prefName; | 126 - (void)prefChanged:(const std::string&)prefName; |
91 - (BackgroundGradientView*)backgroundGradientView; | 127 - (BackgroundGradientView*)backgroundGradientView; |
92 - (void)toolbarFrameChanged; | 128 - (void)toolbarFrameChanged; |
93 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; | 129 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; |
94 - (void)maintainMinimumLocationBarWidth; | 130 - (void)maintainMinimumLocationBarWidth; |
95 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; | 131 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; |
96 - (void)browserActionsContainerWillDrag:(NSNotification*)notification; | |
97 - (void)browserActionsContainerDragged:(NSNotification*)notification; | 132 - (void)browserActionsContainerDragged:(NSNotification*)notification; |
98 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; | 133 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; |
99 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification; | 134 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification; |
100 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; | 135 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; |
101 - (void)updateWrenchButtonSeverity:(WrenchIconPainter::Severity)severity | 136 - (void)updateWrenchButtonSeverity:(WrenchIconPainter::Severity)severity |
102 animate:(BOOL)animate; | 137 animate:(BOOL)animate; |
103 @end | 138 @end |
104 | 139 |
105 namespace ToolbarControllerInternal { | 140 namespace ToolbarControllerInternal { |
106 | 141 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 profile:profile | 212 profile:profile |
178 browser:browser | 213 browser:browser |
179 resizeDelegate:resizeDelegate | 214 resizeDelegate:resizeDelegate |
180 nibFileNamed:@"Toolbar"])) { | 215 nibFileNamed:@"Toolbar"])) { |
181 } | 216 } |
182 return self; | 217 return self; |
183 } | 218 } |
184 | 219 |
185 | 220 |
186 - (void)dealloc { | 221 - (void)dealloc { |
| 222 browserActionsContainerDelegate_.reset(); |
| 223 |
187 // Unset ViewIDs of toolbar elements. | 224 // Unset ViewIDs of toolbar elements. |
188 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and | 225 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and |
189 // |browserActionsContainerView_| are handled by themselves. | 226 // |browserActionsContainerView_| are handled by themselves. |
190 view_id_util::UnsetID(backButton_); | 227 view_id_util::UnsetID(backButton_); |
191 view_id_util::UnsetID(forwardButton_); | 228 view_id_util::UnsetID(forwardButton_); |
192 view_id_util::UnsetID(homeButton_); | 229 view_id_util::UnsetID(homeButton_); |
193 view_id_util::UnsetID(wrenchButton_); | 230 view_id_util::UnsetID(wrenchButton_); |
194 | 231 |
195 // Make sure any code in the base class which assumes [self view] is | 232 // Make sure any code in the base class which assumes [self view] is |
196 // the "parent" view continues to work. | 233 // the "parent" view continues to work. |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 } | 619 } |
583 | 620 |
584 - (void)prefChanged:(const std::string&)prefName { | 621 - (void)prefChanged:(const std::string&)prefName { |
585 if (prefName == prefs::kShowHomeButton) { | 622 if (prefName == prefs::kShowHomeButton) { |
586 [self showOptionalHomeButton]; | 623 [self showOptionalHomeButton]; |
587 } | 624 } |
588 } | 625 } |
589 | 626 |
590 - (void)createBrowserActionButtons { | 627 - (void)createBrowserActionButtons { |
591 if (!browserActionsController_.get()) { | 628 if (!browserActionsController_.get()) { |
| 629 browserActionsContainerDelegate_.reset( |
| 630 new BrowserActionsContainerDelegate(locationBar_, |
| 631 browserActionsContainerView_)); |
592 browserActionsController_.reset([[BrowserActionsController alloc] | 632 browserActionsController_.reset([[BrowserActionsController alloc] |
593 initWithBrowser:browser_ | 633 initWithBrowser:browser_ |
594 containerView:browserActionsContainerView_ | 634 containerView:browserActionsContainerView_ |
595 mainController:nil]); | 635 mainController:nil]); |
596 [[NSNotificationCenter defaultCenter] | 636 [[NSNotificationCenter defaultCenter] |
597 addObserver:self | 637 addObserver:self |
598 selector:@selector(browserActionsContainerWillDrag:) | |
599 name:kBrowserActionGrippyWillDragNotification | |
600 object:browserActionsContainerView_]; | |
601 [[NSNotificationCenter defaultCenter] | |
602 addObserver:self | |
603 selector:@selector(browserActionsContainerDragged:) | 638 selector:@selector(browserActionsContainerDragged:) |
604 name:kBrowserActionGrippyDraggingNotification | 639 name:kBrowserActionGrippyDraggingNotification |
605 object:browserActionsContainerView_]; | 640 object:browserActionsContainerView_]; |
606 [[NSNotificationCenter defaultCenter] | 641 [[NSNotificationCenter defaultCenter] |
607 addObserver:self | 642 addObserver:self |
608 selector:@selector(browserActionsVisibilityChanged:) | 643 selector:@selector(browserActionsVisibilityChanged:) |
609 name:kBrowserActionVisibilityChangedNotification | 644 name:kBrowserActionVisibilityChangedNotification |
610 object:browserActionsController_]; | 645 object:browserActionsController_]; |
611 [[NSNotificationCenter defaultCenter] | 646 [[NSNotificationCenter defaultCenter] |
612 addObserver:self | 647 addObserver:self |
(...skipping 17 matching lines...) Expand all Loading... |
630 [self toolbarFrameChanged]; | 665 [self toolbarFrameChanged]; |
631 [[NSNotificationCenter defaultCenter] | 666 [[NSNotificationCenter defaultCenter] |
632 removeObserver:self | 667 removeObserver:self |
633 name:NSWindowDidBecomeKeyNotification | 668 name:NSWindowDidBecomeKeyNotification |
634 object:[[self view] window]]; | 669 object:[[self view] window]]; |
635 } | 670 } |
636 | 671 |
637 - (void)browserActionsContainerDragged:(NSNotification*)notification { | 672 - (void)browserActionsContainerDragged:(NSNotification*)notification { |
638 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); | 673 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); |
639 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; | 674 locationBarAtMinSize_ = locationBarWidth <= kMinimumLocationBarWidth; |
640 [browserActionsContainerView_ setCanDragLeft:!locationBarAtMinSize_]; | |
641 [browserActionsContainerView_ setGrippyPinned:locationBarAtMinSize_]; | |
642 [self adjustLocationSizeBy: | 675 [self adjustLocationSizeBy: |
643 [browserActionsContainerView_ resizeDeltaX] animate:NO]; | 676 [browserActionsContainerView_ resizeDeltaX] animate:NO]; |
644 } | 677 } |
645 | 678 |
646 - (void)browserActionsContainerWillDrag:(NSNotification*)notification { | |
647 CGFloat deltaX = [[notification.userInfo objectForKey:kTranslationWithDelta] | |
648 floatValue]; | |
649 CGFloat locationBarWidth = NSWidth([locationBar_ frame]); | |
650 BOOL locationBarWillBeAtMinSize = | |
651 (locationBarWidth + deltaX) <= kMinimumLocationBarWidth; | |
652 | |
653 // Prevent the |browserActionsContainerView_| from dragging if the width of | |
654 // location bar will reach the minimum. | |
655 [browserActionsContainerView_ setCanDragLeft:!locationBarWillBeAtMinSize]; | |
656 } | |
657 | |
658 - (void)browserActionsVisibilityChanged:(NSNotification*)notification { | 679 - (void)browserActionsVisibilityChanged:(NSNotification*)notification { |
659 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; | 680 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
660 } | 681 } |
661 | 682 |
662 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification { | 683 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification { |
663 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:YES]; | 684 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:YES]; |
664 } | 685 } |
665 | 686 |
666 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate { | 687 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate { |
667 CGFloat locationBarXPos = NSMaxX([locationBar_ frame]); | 688 CGFloat locationBarXPos = NSMaxX([locationBar_ frame]); |
668 CGFloat leftDistance; | 689 CGFloat leftDistance = 0.0; |
669 | 690 |
670 if ([browserActionsContainerView_ isHidden]) { | 691 if ([browserActionsContainerView_ isHidden]) { |
671 CGFloat edgeXPos = [wrenchButton_ frame].origin.x; | 692 CGFloat edgeXPos = [wrenchButton_ frame].origin.x; |
672 leftDistance = edgeXPos - locationBarXPos - kWrenchMenuLeftPadding; | 693 leftDistance = edgeXPos - locationBarXPos - kWrenchMenuLeftPadding; |
673 } else { | 694 } else { |
674 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - | 695 leftDistance = NSMinX([browserActionsContainerView_ animationEndFrame]) - |
675 locationBarXPos; | 696 locationBarXPos; |
676 } | 697 } |
677 if (leftDistance != 0.0) | 698 if (leftDistance != 0.0) |
678 [self adjustLocationSizeBy:leftDistance animate:animate]; | 699 [self adjustLocationSizeBy:leftDistance animate:animate]; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 887 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
867 // Do nothing. | 888 // Do nothing. |
868 } | 889 } |
869 | 890 |
870 // (URLDropTargetController protocol) | 891 // (URLDropTargetController protocol) |
871 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 892 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
872 return drag_util::IsUnsupportedDropData(profile_, info); | 893 return drag_util::IsUnsupportedDropData(profile_, info); |
873 } | 894 } |
874 | 895 |
875 @end | 896 @end |
OLD | NEW |