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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 #include "ui/base/l10n/l10n_util_mac.h" | 63 #include "ui/base/l10n/l10n_util_mac.h" |
| 64 #include "ui/gfx/geometry/rect.h" | 64 #include "ui/gfx/geometry/rect.h" |
| 65 #include "ui/gfx/image/image.h" | 65 #include "ui/gfx/image/image.h" |
| 66 | 66 |
| 67 using content::OpenURLParams; | 67 using content::OpenURLParams; |
| 68 using content::Referrer; | 68 using content::Referrer; |
| 69 using content::WebContents; | 69 using content::WebContents; |
| 70 | 70 |
| 71 namespace { | 71 namespace { |
| 72 | 72 |
| 73 // Duration of the toolbar animation. | |
| 74 const NSTimeInterval kToolBarAnimationDuration = 0.12; | |
| 75 | |
| 73 // Height of the toolbar in pixels when the bookmark bar is closed. | 76 // Height of the toolbar in pixels when the bookmark bar is closed. |
| 74 const CGFloat kBaseToolbarHeightNormal = 35.0; | 77 const CGFloat kBaseToolbarHeightNormal = 35.0; |
| 75 | 78 |
| 76 // The padding above the toolbar elements. This is calculated from the values | 79 // The padding above the toolbar elements. This is calculated from the values |
| 77 // in Toolbar.xib: the height of the toolbar (35) minus the height of the child | 80 // in Toolbar.xib: the height of the toolbar (35) minus the height of the child |
| 78 // elements (29) minus the y-origin of the elements (4). | 81 // elements (29) minus the y-origin of the elements (4). |
| 79 const CGFloat kToolbarElementTopPadding = 2.0; | 82 const CGFloat kToolbarElementTopPadding = 2.0; |
| 80 | 83 |
| 81 // The minimum width of the location bar in pixels. | 84 // The minimum width of the location bar in pixels. |
| 82 const CGFloat kMinimumLocationBarWidth = 100.0; | 85 const CGFloat kMinimumLocationBarWidth = 100.0; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 | 125 |
| 123 } // namespace | 126 } // namespace |
| 124 | 127 |
| 125 @interface ToolbarController() | 128 @interface ToolbarController() |
| 126 @property(assign, nonatomic) Browser* browser; | 129 @property(assign, nonatomic) Browser* browser; |
| 127 - (void)cleanUp; | 130 - (void)cleanUp; |
| 128 - (void)addAccessibilityDescriptions; | 131 - (void)addAccessibilityDescriptions; |
| 129 - (void)initCommandStatus:(CommandUpdater*)commands; | 132 - (void)initCommandStatus:(CommandUpdater*)commands; |
| 130 - (void)prefChanged:(const std::string&)prefName; | 133 - (void)prefChanged:(const std::string&)prefName; |
| 131 - (BackgroundGradientView*)backgroundGradientView; | 134 - (BackgroundGradientView*)backgroundGradientView; |
| 135 - (AnimatableView*)animatableView; | |
| 132 - (void)toolbarFrameChanged; | 136 - (void)toolbarFrameChanged; |
| 133 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; | 137 - (void)pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:(BOOL)animate; |
| 134 - (void)maintainMinimumLocationBarWidth; | 138 - (void)maintainMinimumLocationBarWidth; |
| 135 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; | 139 - (void)adjustBrowserActionsContainerForNewWindow:(NSNotification*)notification; |
| 136 - (void)browserActionsContainerDragged:(NSNotification*)notification; | 140 - (void)browserActionsContainerDragged:(NSNotification*)notification; |
| 137 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; | 141 - (void)browserActionsVisibilityChanged:(NSNotification*)notification; |
| 138 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification; | 142 - (void)browserActionsContainerWillAnimate:(NSNotification*)notification; |
| 139 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; | 143 - (void)adjustLocationSizeBy:(CGFloat)dX animate:(BOOL)animate; |
| 140 - (void)updateWrenchButtonSeverity:(WrenchIconPainter::Severity)severity | 144 - (void)updateWrenchButtonSeverity:(WrenchIconPainter::Severity)severity |
| 141 animate:(BOOL)animate; | 145 animate:(BOOL)animate; |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 // Make location bar not editable when in a pop-up. | 594 // Make location bar not editable when in a pop-up. |
| 591 locationBarView_->SetEditable(toolbar); | 595 locationBarView_->SetEditable(toolbar); |
| 592 } | 596 } |
| 593 | 597 |
| 594 - (NSView*)view { | 598 - (NSView*)view { |
| 595 if (hasToolbar_) | 599 if (hasToolbar_) |
| 596 return [super view]; | 600 return [super view]; |
| 597 return locationBar_; | 601 return locationBar_; |
| 598 } | 602 } |
| 599 | 603 |
| 600 // (Private) Returns the backdrop to the toolbar. | 604 // (Private) Returns the backdrop to the toolbar as a BackgroundGradientView. |
| 601 - (BackgroundGradientView*)backgroundGradientView { | 605 - (BackgroundGradientView*)backgroundGradientView { |
| 602 // We really do mean |[super view]|; see our override of |-view|. | 606 // We really do mean |[super view]|; see our override of |-view|. |
| 603 DCHECK([[super view] isKindOfClass:[BackgroundGradientView class]]); | 607 DCHECK([[super view] isKindOfClass:[BackgroundGradientView class]]); |
| 604 return (BackgroundGradientView*)[super view]; | 608 return (BackgroundGradientView*)[super view]; |
| 605 } | 609 } |
| 606 | 610 |
| 611 // (Private) Returns the backdrop to the toolbar as an AnimatableView. | |
| 612 - (AnimatableView*)animatableView{ | |
| 613 // We really do mean |[super view]|; see our override of |-view|. | |
| 614 DCHECK([[super view] isKindOfClass:[AnimatableView class]]); | |
| 615 return (AnimatableView*)[super view]; | |
|
tapted
2015/10/12 23:56:43
use base::mac::ObjCCastStrict<AnimatableView>([sup
dominickn
2015/10/15 06:22:28
Done.
| |
| 616 } | |
| 617 | |
| 607 - (id)customFieldEditorForObject:(id)obj { | 618 - (id)customFieldEditorForObject:(id)obj { |
| 608 if (obj == locationBar_) { | 619 if (obj == locationBar_) { |
| 609 // Lazilly construct Field editor, Cocoa UI code always runs on the | 620 // Lazilly construct Field editor, Cocoa UI code always runs on the |
| 610 // same thread, so there shoudn't be a race condition here. | 621 // same thread, so there shoudn't be a race condition here. |
| 611 if (autocompleteTextFieldEditor_.get() == nil) { | 622 if (autocompleteTextFieldEditor_.get() == nil) { |
| 612 autocompleteTextFieldEditor_.reset( | 623 autocompleteTextFieldEditor_.reset( |
| 613 [[AutocompleteTextFieldEditor alloc] init]); | 624 [[AutocompleteTextFieldEditor alloc] init]); |
| 614 } | 625 } |
| 615 | 626 |
| 616 // This needs to be called every time, otherwise notifications | 627 // This needs to be called every time, otherwise notifications |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 [[NSNotificationCenter defaultCenter] | 730 [[NSNotificationCenter defaultCenter] |
| 720 addObserver:self | 731 addObserver:self |
| 721 selector:@selector(adjustBrowserActionsContainerForNewWindow:) | 732 selector:@selector(adjustBrowserActionsContainerForNewWindow:) |
| 722 name:NSWindowDidBecomeKeyNotification | 733 name:NSWindowDidBecomeKeyNotification |
| 723 object:[[self view] window]]; | 734 object:[[self view] window]]; |
| 724 } | 735 } |
| 725 if (![browserActionsContainerView_ isHidden]) | 736 if (![browserActionsContainerView_ isHidden]) |
| 726 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; | 737 [self pinLocationBarToLeftOfBrowserActionsContainerAndAnimate:NO]; |
| 727 } | 738 } |
| 728 | 739 |
| 740 - (void)updateVisibility:(BOOL)visible withAnimation:(BOOL)animate { | |
| 741 // This method is only called in a hosted app, when the bookmark bar is never | |
| 742 // visible. Hence, the height will always be kBaseToolbarHeightNormal. | |
| 743 [self setHasToolbar:hasToolbar_ hasLocationBar:visible]; | |
| 744 | |
| 745 AnimatableView* view = [self animatableView]; | |
| 746 CGFloat newHeight = (visible ? kBaseToolbarHeightNormal : 0); | |
|
tapted
2015/10/12 23:56:43
parens (..) not required
dominickn
2015/10/15 06:22:28
Done.
| |
| 747 if (animate) { | |
| 748 [view animateToNewHeight:newHeight | |
| 749 duration:kToolBarAnimationDuration]; | |
| 750 } else { | |
| 751 [view setHeight:newHeight]; | |
|
tapted
2015/10/12 23:56:43
Shouldn't setting the height to zero be sufficient
dominickn
2015/10/15 06:22:28
That was previously necessary because of the lack
| |
| 752 } | |
| 753 } | |
| 754 | |
| 729 - (void)adjustBrowserActionsContainerForNewWindow: | 755 - (void)adjustBrowserActionsContainerForNewWindow: |
| 730 (NSNotification*)notification { | 756 (NSNotification*)notification { |
| 731 [self toolbarFrameChanged]; | 757 [self toolbarFrameChanged]; |
| 732 [[NSNotificationCenter defaultCenter] | 758 [[NSNotificationCenter defaultCenter] |
| 733 removeObserver:self | 759 removeObserver:self |
| 734 name:NSWindowDidBecomeKeyNotification | 760 name:NSWindowDidBecomeKeyNotification |
| 735 object:[[self view] window]]; | 761 object:[[self view] window]]; |
| 736 } | 762 } |
| 737 | 763 |
| 738 - (void)browserActionsContainerDragged:(NSNotification*)notification { | 764 - (void)browserActionsContainerDragged:(NSNotification*)notification { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 950 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 976 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
| 951 // Do nothing. | 977 // Do nothing. |
| 952 } | 978 } |
| 953 | 979 |
| 954 // (URLDropTargetController protocol) | 980 // (URLDropTargetController protocol) |
| 955 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 981 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
| 956 return drag_util::IsUnsupportedDropData(profile_, info); | 982 return drag_util::IsUnsupportedDropData(profile_, info); |
| 957 } | 983 } |
| 958 | 984 |
| 959 @end | 985 @end |
| OLD | NEW |