Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: ios/chrome/browser/ui/browser_view_controller.mm

Issue 2599313002: Create headerHeightForTab in TabHeadersDelegate. (Closed)
Patch Set: only fullscreencontroller and sideswipecontroller Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "ios/chrome/browser/ui/browser_view_controller.h" 5 #import "ios/chrome/browser/ui/browser_view_controller.h"
6 6
7 #import <AssetsLibrary/AssetsLibrary.h> 7 #import <AssetsLibrary/AssetsLibrary.h>
8 #import <MobileCoreServices/MobileCoreServices.h> 8 #import <MobileCoreServices/MobileCoreServices.h>
9 #import <PassKit/PassKit.h> 9 #import <PassKit/PassKit.h>
10 #import <Photos/Photos.h> 10 #import <Photos/Photos.h>
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 - (void)updateVoiceSearchBarVisibilityAnimated:(BOOL)animated; 727 - (void)updateVoiceSearchBarVisibilityAnimated:(BOOL)animated;
728 // The LogoAnimationControllerOwner to be used for the next logo transition 728 // The LogoAnimationControllerOwner to be used for the next logo transition
729 // animation. 729 // animation.
730 - (id<LogoAnimationControllerOwner>)currentLogoAnimationControllerOwner; 730 - (id<LogoAnimationControllerOwner>)currentLogoAnimationControllerOwner;
731 // Returns the header views, all the chrome on top of the page, including the 731 // Returns the header views, all the chrome on top of the page, including the
732 // ones that cannot be scrolled off screen by full screen. 732 // ones that cannot be scrolled off screen by full screen.
733 - (const std::vector<HeaderDefinition>)headerViews; 733 - (const std::vector<HeaderDefinition>)headerViews;
734 // Returns the footer view if one exists (e.g. the voice search bar). 734 // Returns the footer view if one exists (e.g. the voice search bar).
735 - (UIView*)footerView; 735 - (UIView*)footerView;
736 // Returns the height of the header view for the tab model's current tab. 736 // Returns the height of the header view for the tab model's current tab.
737 - (CGFloat)headerHeight; 737 - (CGFloat)headerHeightForCurrentTab;
738 // Returns the height of the header view for |tab|. 738 // Returns the height of the header view for |tab|.
739 - (CGFloat)headerHeightForTab:(Tab*)tab; 739 - (CGFloat)headerHeightForTab:(Tab*)tab;
740 // Sets the frame for the headers. 740 // Sets the frame for the headers.
741 - (void)setFramesForHeaders:(const std::vector<HeaderDefinition>)headers 741 - (void)setFramesForHeaders:(const std::vector<HeaderDefinition>)headers
742 atOffset:(CGFloat)headerOffset; 742 atOffset:(CGFloat)headerOffset;
743 // Returns the y coordinate for the footer's frame when animating the footer 743 // Returns the y coordinate for the footer's frame when animating the footer
744 // in/out of fullscreen. 744 // in/out of fullscreen.
745 - (CGFloat)footerYForHeaderOffset:(CGFloat)headerOffset; 745 - (CGFloat)footerYForHeaderOffset:(CGFloat)headerOffset;
746 // Called when the animation for setting the header view's offset is finished. 746 // Called when the animation for setting the header view's offset is finished.
747 // |completed| should indicate if the animation finished completely or was 747 // |completed| should indicate if the animation finished completely or was
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 1108
1109 - (void)setViewVisible:(BOOL)viewVisible { 1109 - (void)setViewVisible:(BOOL)viewVisible {
1110 if (_viewVisible == viewVisible) 1110 if (_viewVisible == viewVisible)
1111 return; 1111 return;
1112 _viewVisible = viewVisible; 1112 _viewVisible = viewVisible;
1113 self.visible = viewVisible; 1113 self.visible = viewVisible;
1114 [self updateDialogPresenterActiveState]; 1114 [self updateDialogPresenterActiveState];
1115 } 1115 }
1116 1116
1117 - (BOOL)isToolbarOnScreen { 1117 - (BOOL)isToolbarOnScreen {
1118 return [self headerHeight] - [self currentHeaderOffset] > 0; 1118 return [self headerHeightForCurrentTab] - [self currentHeaderOffset] > 0;
1119 } 1119 }
1120 1120
1121 - (BOOL)isInNewTabAnimation { 1121 - (BOOL)isInNewTabAnimation {
1122 return _inNewTabAnimation; 1122 return _inNewTabAnimation;
1123 } 1123 }
1124 1124
1125 - (BOOL)shouldShowVoiceSearchBar { 1125 - (BOOL)shouldShowVoiceSearchBar {
1126 // On iPads, the voice search bar should only be shown for regular horizontal 1126 // On iPads, the voice search bar should only be shown for regular horizontal
1127 // size class configurations. It should always be shown for voice search 1127 // size class configurations. It should always be shown for voice search
1128 // results Tabs on iPhones, including configurations with regular horizontal 1128 // results Tabs on iPhones, including configurations with regular horizontal
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
1823 minY += CGRectGetHeight(toolbarFrame); 1823 minY += CGRectGetHeight(toolbarFrame);
1824 1824
1825 // Account for the toolbar's drop shadow. The toolbar overlaps with the web 1825 // Account for the toolbar's drop shadow. The toolbar overlaps with the web
1826 // content slightly. 1826 // content slightly.
1827 minY -= [ToolbarController toolbarDropShadowHeight]; 1827 minY -= [ToolbarController toolbarDropShadowHeight];
1828 1828
1829 // Adjust the content area to be under the toolbar, for fullscreen or below 1829 // Adjust the content area to be under the toolbar, for fullscreen or below
1830 // the toolbar is not fullscreen. 1830 // the toolbar is not fullscreen.
1831 CGRect contentFrame = [_contentArea frame]; 1831 CGRect contentFrame = [_contentArea frame];
1832 CGFloat marginWithHeader = StatusBarHeight(); 1832 CGFloat marginWithHeader = StatusBarHeight();
1833 CGFloat overlap = [self headerHeight] != 0 ? marginWithHeader : minY; 1833 CGFloat overlap =
1834 [self headerHeightForCurrentTab] != 0 ? marginWithHeader : minY;
1834 contentFrame.size.height = CGRectGetMaxY(contentFrame) - overlap; 1835 contentFrame.size.height = CGRectGetMaxY(contentFrame) - overlap;
1835 contentFrame.origin.y = overlap; 1836 contentFrame.origin.y = overlap;
1836 [_contentArea setFrame:contentFrame]; 1837 [_contentArea setFrame:contentFrame];
1837 1838
1838 // Adjust the infobar container to be either at the bottom of the screen 1839 // Adjust the infobar container to be either at the bottom of the screen
1839 // (iPhone) or on the lower toolbar edge (iPad). 1840 // (iPhone) or on the lower toolbar edge (iPad).
1840 CGRect infoBarFrame = contentFrame; 1841 CGRect infoBarFrame = contentFrame;
1841 infoBarFrame.origin.y = CGRectGetMaxY(contentFrame); 1842 infoBarFrame.origin.y = CGRectGetMaxY(contentFrame);
1842 infoBarFrame.size.height = 0; 1843 infoBarFrame.size.height = 0;
1843 [infoBarContainerView setFrame:infoBarFrame]; 1844 [infoBarContainerView setFrame:infoBarFrame];
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
2077 - (UIImageView*)pageFullScreenOpenCloseAnimationView { 2078 - (UIImageView*)pageFullScreenOpenCloseAnimationView {
2078 CGRect viewBounds, remainder; 2079 CGRect viewBounds, remainder;
2079 CGRectDivide(self.view.bounds, &remainder, &viewBounds, StatusBarHeight(), 2080 CGRectDivide(self.view.bounds, &remainder, &viewBounds, StatusBarHeight(),
2080 CGRectMinYEdge); 2081 CGRectMinYEdge);
2081 return [[[UIImageView alloc] initWithFrame:viewBounds] autorelease]; 2082 return [[[UIImageView alloc] initWithFrame:viewBounds] autorelease];
2082 } 2083 }
2083 2084
2084 - (UIImageView*)pageOpenCloseAnimationView { 2085 - (UIImageView*)pageOpenCloseAnimationView {
2085 CGRect frame = [_contentArea bounds]; 2086 CGRect frame = [_contentArea bounds];
2086 2087
2087 frame.size.height = frame.size.height - [self headerHeight]; 2088 frame.size.height = frame.size.height - [self headerHeightForCurrentTab];
2088 frame.origin.y = [self headerHeight]; 2089 frame.origin.y = [self headerHeightForCurrentTab];
2089 2090
2090 UIImageView* pageView = 2091 UIImageView* pageView =
2091 [[[UIImageView alloc] initWithFrame:frame] autorelease]; 2092 [[[UIImageView alloc] initWithFrame:frame] autorelease];
2092 CGPoint center = CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame)); 2093 CGPoint center = CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame));
2093 pageView.center = center; 2094 pageView.center = center;
2094 2095
2095 pageView.backgroundColor = [UIColor whiteColor]; 2096 pageView.backgroundColor = [UIColor whiteColor];
2096 return pageView; 2097 return pageView;
2097 } 2098 }
2098 2099
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
2577 results.push_back(header); 2578 results.push_back(header);
2578 } 2579 }
2579 } 2580 }
2580 return results; 2581 return results;
2581 } 2582 }
2582 2583
2583 - (UIView*)footerView { 2584 - (UIView*)footerView {
2584 return _voiceSearchBar; 2585 return _voiceSearchBar;
2585 } 2586 }
2586 2587
2587 - (CGFloat)headerHeight { 2588 - (CGFloat)headerHeightForCurrentTab {
2588 return [self headerHeightForTab:[_model currentTab]]; 2589 return [self headerHeightForTab:[_model currentTab]];
2589 } 2590 }
2590 2591
2591 - (CGFloat)headerHeightForTab:(Tab*)tab { 2592 - (CGFloat)headerHeightForTab:(Tab*)tab {
2592 id nativeController = [self nativeControllerForTab:tab]; 2593 id nativeController = [self nativeControllerForTab:tab];
2593 if ([nativeController conformsToProtocol:@protocol(ToolbarOwner)] && 2594 if ([nativeController conformsToProtocol:@protocol(ToolbarOwner)] &&
2594 [nativeController respondsToSelector:@selector(toolbarHeight)] && 2595 [nativeController respondsToSelector:@selector(toolbarHeight)] &&
2595 [nativeController toolbarHeight] > 0.0 && !IsIPadIdiom()) { 2596 [nativeController toolbarHeight] > 0.0 && !IsIPadIdiom()) {
2596 // On iPhone, don't add any header height for ToolbarOwner native 2597 // On iPhone, don't add any header height for ToolbarOwner native
2597 // controllers when they're displaying their own toolbar. 2598 // controllers when they're displaying their own toolbar.
(...skipping 16 matching lines...) Expand all
2614 - (BOOL)isTabWithIDCurrent:(NSString*)sessionID { 2615 - (BOOL)isTabWithIDCurrent:(NSString*)sessionID {
2615 return self.visible && 2616 return self.visible &&
2616 [sessionID isEqualToString:[[_model currentTab] currentSessionID]]; 2617 [sessionID isEqualToString:[[_model currentTab] currentSessionID]];
2617 } 2618 }
2618 2619
2619 - (CGFloat)currentHeaderOffset { 2620 - (CGFloat)currentHeaderOffset {
2620 const std::vector<HeaderDefinition> headers = [self headerViews]; 2621 const std::vector<HeaderDefinition> headers = [self headerViews];
2621 if (!headers.size()) 2622 if (!headers.size())
2622 return 0.0; 2623 return 0.0;
2623 2624
2624 // Prerender tab does not have a toolbar, return |headerHeight| as promised by 2625 // Prerender tab does not have a toolbar, return |headerHeightForCurrentTab|
2626 // as promised by
2625 // API documentation. 2627 // API documentation.
2626 if ([[[self tabModel] currentTab] isPrerenderTab]) 2628 if ([[[self tabModel] currentTab] isPrerenderTab])
2627 return [self headerHeight]; 2629 return [self headerHeightForCurrentTab];
2628 2630
2629 UIView* topHeader = headers[0].view; 2631 UIView* topHeader = headers[0].view;
2630 return -(topHeader.frame.origin.y - [self headerOffset]); 2632 return -(topHeader.frame.origin.y - [self headerOffset]);
2631 } 2633 }
2632 2634
2633 - (CGFloat)footerYForHeaderOffset:(CGFloat)headerOffset { 2635 - (CGFloat)footerYForHeaderOffset:(CGFloat)headerOffset {
2634 UIView* footer = [self footerView]; 2636 UIView* footer = [self footerView];
2635 CGFloat headerHeight = [self headerHeight]; 2637 CGFloat headerHeight = [self headerHeightForCurrentTab];
2636 if (!footer || headerHeight == 0) 2638 if (!footer || headerHeight == 0)
2637 return 0.0; 2639 return 0.0;
2638 2640
2639 CGFloat footerHeight = CGRectGetHeight(footer.frame); 2641 CGFloat footerHeight = CGRectGetHeight(footer.frame);
2640 CGFloat offset = headerOffset * footerHeight / headerHeight; 2642 CGFloat offset = headerOffset * footerHeight / headerHeight;
2641 return std::ceil(CGRectGetHeight(self.view.bounds) - footerHeight + offset); 2643 return std::ceil(CGRectGetHeight(self.view.bounds) - footerHeight + offset);
2642 } 2644 }
2643 2645
2644 - (void)fullScreenController:(FullScreenController*)controller 2646 - (void)fullScreenController:(FullScreenController*)controller
2645 headerAnimationCompleted:(BOOL)completed 2647 headerAnimationCompleted:(BOOL)completed
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
2791 return [_toolbarController view]; 2793 return [_toolbarController view];
2792 } 2794 }
2793 2795
2794 - (UIView*)toolbarSnapshotView { 2796 - (UIView*)toolbarSnapshotView {
2795 return [[_toolbarController view] snapshotViewAfterScreenUpdates:NO]; 2797 return [[_toolbarController view] snapshotViewAfterScreenUpdates:NO];
2796 } 2798 }
2797 2799
2798 - (CGFloat)overscrollActionsControllerHeaderInset: 2800 - (CGFloat)overscrollActionsControllerHeaderInset:
2799 (OverscrollActionsController*)controller { 2801 (OverscrollActionsController*)controller {
2800 if (controller == [[[self tabModel] currentTab] overscrollActionsController]) 2802 if (controller == [[[self tabModel] currentTab] overscrollActionsController])
2801 return [self headerHeight]; 2803 return [self headerHeightForCurrentTab];
2802 else 2804 else
2803 return 0; 2805 return 0;
2804 } 2806 }
2805 2807
2806 - (CGFloat)overscrollHeaderHeight { 2808 - (CGFloat)overscrollHeaderHeight {
2807 return [self headerHeight] + StatusBarHeight(); 2809 return [self headerHeightForCurrentTab] + StatusBarHeight();
2808 } 2810 }
2809 2811
2810 #pragma mark - TabSnapshottingDelegate methods. 2812 #pragma mark - TabSnapshottingDelegate methods.
2811 2813
2812 - (CGRect)snapshotContentAreaForTab:(Tab*)tab { 2814 - (CGRect)snapshotContentAreaForTab:(Tab*)tab {
2813 CGRect pageContentArea = _contentArea.bounds; 2815 CGRect pageContentArea = _contentArea.bounds;
2814 if ([_model webUsageEnabled]) 2816 if ([_model webUsageEnabled])
2815 pageContentArea = tab.view.bounds; 2817 pageContentArea = tab.view.bounds;
2816 CGFloat headerHeight = [self headerHeightForTab:tab]; 2818 CGFloat headerHeight = [self headerHeightForTab:tab];
2817 id nativeController = [self nativeControllerForTab:tab]; 2819 id nativeController = [self nativeControllerForTab:tab];
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
3676 [[_model currentTab].webController executeUserJavaScript:script 3678 [[_model currentTab].webController executeUserJavaScript:script
3677 completionHandler:nil]; 3679 completionHandler:nil];
3678 } 3680 }
3679 3681
3680 - (web::WebState*)currentWebState { 3682 - (web::WebState*)currentWebState {
3681 return [[_model currentTab] webState]; 3683 return [[_model currentTab] webState];
3682 } 3684 }
3683 3685
3684 // This is called from within an animation block. 3686 // This is called from within an animation block.
3685 - (void)toolbarHeightChanged { 3687 - (void)toolbarHeightChanged {
3686 if ([self headerHeight] != 0) { 3688 if ([self headerHeightForCurrentTab] != 0) {
3687 // Ensure full screen height is updated. 3689 // Ensure full screen height is updated.
3688 Tab* currentTab = [_model currentTab]; 3690 Tab* currentTab = [_model currentTab];
3689 BOOL visible = self.isToolbarOnScreen; 3691 BOOL visible = self.isToolbarOnScreen;
3690 [currentTab updateFullscreenWithToolbarVisible:visible]; 3692 [currentTab updateFullscreenWithToolbarVisible:visible];
3691 } 3693 }
3692 } 3694 }
3693 3695
3694 // Load a new URL on a new page/tab. 3696 // Load a new URL on a new page/tab.
3695 - (void)webPageOrderedOpen:(const GURL&)URL 3697 - (void)webPageOrderedOpen:(const GURL&)URL
3696 referrer:(const web::Referrer&)referrer 3698 referrer:(const web::Referrer&)referrer
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
3832 } 3834 }
3833 3835
3834 - (void)willUpdateToolbarSnapshot { 3836 - (void)willUpdateToolbarSnapshot {
3835 [[_model currentTab].overscrollActionsController clear]; 3837 [[_model currentTab].overscrollActionsController clear];
3836 } 3838 }
3837 3839
3838 - (CardView*)addCardViewInFullscreen:(BOOL)fullScreen { 3840 - (CardView*)addCardViewInFullscreen:(BOOL)fullScreen {
3839 CGRect frame = [_contentArea frame]; 3841 CGRect frame = [_contentArea frame];
3840 if (!fullScreen) { 3842 if (!fullScreen) {
3841 // Changing the origin here is unnecessary, it's set in page_animation_util. 3843 // Changing the origin here is unnecessary, it's set in page_animation_util.
3842 frame.size.height -= [self headerHeight]; 3844 frame.size.height -= [self headerHeightForCurrentTab];
3843 } 3845 }
3844 3846
3845 CGFloat shortAxis = frame.size.width; 3847 CGFloat shortAxis = frame.size.width;
3846 CGFloat shortInset = kCardImageInsets.left + kCardImageInsets.right; 3848 CGFloat shortInset = kCardImageInsets.left + kCardImageInsets.right;
3847 shortAxis -= shortInset + 2 * ios_internal::page_animation_util::kCardMargin; 3849 shortAxis -= shortInset + 2 * ios_internal::page_animation_util::kCardMargin;
3848 CGFloat aspectRatio = frame.size.height / frame.size.width; 3850 CGFloat aspectRatio = frame.size.height / frame.size.width;
3849 CGFloat longAxis = std::floor(aspectRatio * shortAxis); 3851 CGFloat longAxis = std::floor(aspectRatio * shortAxis);
3850 CGFloat longInset = kCardImageInsets.top + kCardImageInsets.bottom; 3852 CGFloat longInset = kCardImageInsets.top + kCardImageInsets.bottom;
3851 CGSize cardSize = CGSizeMake(shortAxis + shortInset, longAxis + longInset); 3853 CGSize cardSize = CGSizeMake(shortAxis + shortInset, longAxis + longInset);
3852 CGRect cardFrame = {frame.origin, cardSize}; 3854 CGRect cardFrame = {frame.origin, cardSize};
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after
4729 // Panel has become visible. 4731 // Panel has become visible.
4730 _infoBarContainer->SuspendInfobars(); 4732 _infoBarContainer->SuspendInfobars();
4731 } 4733 }
4732 } 4734 }
4733 4735
4734 - (void)panelWillPromote:(ContextualSearchPanelView*)panel { 4736 - (void)panelWillPromote:(ContextualSearchPanelView*)panel {
4735 [panel removeMotionObserver:self]; 4737 [panel removeMotionObserver:self];
4736 } 4738 }
4737 4739
4738 - (CGFloat)currentHeaderHeight { 4740 - (CGFloat)currentHeaderHeight {
4739 return [self headerHeight] - [self currentHeaderOffset]; 4741 return [self headerHeightForCurrentTab] - [self currentHeaderOffset];
4740 } 4742 }
4741 4743
4742 #pragma mark - InfoBarControllerDelegate 4744 #pragma mark - InfoBarControllerDelegate
4743 4745
4744 - (void)infoBarContainerStateChanged:(bool)isAnimating { 4746 - (void)infoBarContainerStateChanged:(bool)isAnimating {
4745 InfoBarContainerView* infoBarContainerView = _infoBarContainer->view(); 4747 InfoBarContainerView* infoBarContainerView = _infoBarContainer->view();
4746 DCHECK(infoBarContainerView); 4748 DCHECK(infoBarContainerView);
4747 CGRect containerFrame = infoBarContainerView.frame; 4749 CGRect containerFrame = infoBarContainerView.frame;
4748 CGFloat height = [infoBarContainerView topmostVisibleInfoBarHeight]; 4750 CGFloat height = [infoBarContainerView topmostVisibleInfoBarHeight];
4749 containerFrame.origin.y = CGRectGetMaxY(_contentArea.frame) - height; 4751 containerFrame.origin.y = CGRectGetMaxY(_contentArea.frame) - height;
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
5096 5098
5097 - (UIView*)voiceSearchButton { 5099 - (UIView*)voiceSearchButton {
5098 return _voiceSearchButton; 5100 return _voiceSearchButton;
5099 } 5101 }
5100 5102
5101 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { 5103 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner {
5102 return [self currentLogoAnimationControllerOwner]; 5104 return [self currentLogoAnimationControllerOwner];
5103 } 5105 }
5104 5106
5105 @end 5107 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698