Commit f066e0e2 authored by Justin Cohen's avatar Justin Cohen Committed by Commit Bot

[ios] Make NTP really full screen.

Short term solution to long term problem of pulling the NTP out of native content.
For now, convince //ios/web to show the NTP native content as full screen (including
under the status bar) by sending a negative offset to web when calculating the frame
of the native content.

Bug: 819460
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ia4d2417aafad0afbc5dd62ffbcd35156deb3f8ad
Reviewed-on: https://chromium-review.googlesource.com/981233Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548047}
parent 5340a3f8
......@@ -1665,9 +1665,7 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
- (void)viewSafeAreaInsetsDidChange {
[super viewSafeAreaInsetsDidChange];
// Gate this behind iPhone X, since it's currently the only device that
// needs layout updates here after startup.
if (IsIPhoneX()) {
if (IsIPhoneX() || IsUIRefreshPhase1Enabled()) {
[self setUpViewLayout:NO];
}
// Update the heights of the toolbars to account for the new insets.
......@@ -5484,6 +5482,16 @@ bubblePresenterForFeature:(const base::Feature&)feature
#pragma mark - TabHeadersDelegate
- (CGFloat)tabHeaderHeightForTab:(Tab*)tab {
if (IsUIRefreshPhase1Enabled() && tab &&
tab.webState->GetVisibleURL() == kChromeUINewTabURL && !IsIPadIdiom()) {
// Also subtract the top safe area so the view will appear as full screen.
// TODO(crbug.com/826369) Remove this once NTP is out of native content.
if (@available(iOS 11, *)) {
return -self.view.safeAreaInsets.top;
} else {
return -self.topLayoutGuide.length;
}
}
return [self headerHeightForTab:tab];
}
......
......@@ -34,10 +34,11 @@ const CGFloat kSearchIconLeftMargin = 9;
@interface ContentSuggestionsHeaderView ()<ToolbarSnapshotProviding>
// Layout constraints for fake omnibox background image.
// Layout constraints for fake omnibox background image and blur.
@property(nonatomic, strong) NSLayoutConstraint* backgroundHeightConstraint;
@property(nonatomic, strong) NSLayoutConstraint* backgroundLeadingConstraint;
@property(nonatomic, strong) NSLayoutConstraint* backgroundTrailingConstraint;
@property(nonatomic, strong) NSLayoutConstraint* blurTopConstraint;
@end
......@@ -46,6 +47,7 @@ const CGFloat kSearchIconLeftMargin = 9;
@synthesize backgroundHeightConstraint = _backgroundHeightConstraint;
@synthesize backgroundLeadingConstraint = _backgroundLeadingConstraint;
@synthesize backgroundTrailingConstraint = _backgroundTrailingConstraint;
@synthesize blurTopConstraint = _blurTopConstraint;
@synthesize toolBarView = _toolBarView;
#pragma mark - Public
......@@ -91,7 +93,14 @@ const CGFloat kSearchIconLeftMargin = 9;
blur.layer.cornerRadius = kAdaptiveLocationBarCornerRadius;
[searchField insertSubview:blur atIndex:0];
blur.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(blur, searchField);
self.blurTopConstraint =
[blur.topAnchor constraintEqualToAnchor:searchField.topAnchor];
[NSLayoutConstraint activateConstraints:@[
[blur.leadingAnchor constraintEqualToAnchor:searchField.leadingAnchor],
[blur.trailingAnchor constraintEqualToAnchor:searchField.trailingAnchor],
self.blurTopConstraint,
[blur.bottomAnchor constraintEqualToAnchor:searchField.bottomAnchor]
]];
UIVisualEffect* vibrancy = [buttonFactory.toolbarConfiguration
vibrancyEffectForBlurEffect:blurEffect];
......@@ -136,10 +145,11 @@ const CGFloat kSearchIconLeftMargin = 9;
]];
}
- (CGFloat)searchFieldProgressForOffset:(CGFloat)offset {
- (CGFloat)searchFieldProgressForOffset:(CGFloat)offset
safeAreaInsets:(UIEdgeInsets)safeAreaInsets {
// The scroll offset at which point searchField's frame should stop growing.
CGFloat maxScaleOffset =
self.frame.size.height - ntp_header::kMinHeaderHeight;
CGFloat maxScaleOffset = self.frame.size.height -
ntp_header::kMinHeaderHeight - safeAreaInsets.top;
// The scroll offset at which point searchField's frame should start
// growing.
CGFloat startScaleOffset = maxScaleOffset - ntp_header::kAnimationDistance;
......@@ -168,7 +178,8 @@ const CGFloat kSearchIconLeftMargin = 9;
CGFloat searchFieldNormalWidth =
content_suggestions::searchFieldWidth(contentWidth);
CGFloat percent = [self searchFieldProgressForOffset:offset];
CGFloat percent =
[self searchFieldProgressForOffset:offset safeAreaInsets:safeAreaInsets];
if (self.cr_widthSizeClass == REGULAR && self.cr_heightSizeClass == REGULAR) {
self.alpha = 1 - percent;
widthConstraint.constant = searchFieldNormalWidth;
......@@ -179,6 +190,9 @@ const CGFloat kSearchIconLeftMargin = 9;
self.alpha = 1;
}
// Grow the blur to cover the safeArea top.
self.blurTopConstraint.constant = -safeAreaInsets.top * percent;
// Calculate the amount to grow the width and height of searchField so that
// its frame covers the entire toolbar area.
CGFloat maxXInset =
......
......@@ -162,7 +162,9 @@ const UIEdgeInsets kSearchBoxStretchInsets = {3, 3, 3, 3};
if (self.headerView.cr_widthSizeClass == REGULAR &&
self.headerView.cr_heightSizeClass == REGULAR &&
IsUIRefreshPhase1Enabled()) {
CGFloat progress = [self.headerView searchFieldProgressForOffset:offset];
CGFloat progress =
[self.headerView searchFieldProgressForOffset:offset
safeAreaInsets:safeAreaInsets];
[self.toolbarDelegate setScrollProgressForTabletOmnibox:progress];
}
......
......@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_layout_handset.h"
#import "ios/chrome/browser/ui/ntp/new_tab_page_header_constants.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -63,7 +64,13 @@ layoutAttributesForSupplementaryViewOfKind:(NSString*)kind
attributes.zIndex = 1000;
// Prevent the fake omnibox from scrolling up off of the screen.
CGFloat minY = headerHeight - ntp_header::kMinHeaderHeight;
CGFloat topSafeArea = 0;
if (@available(iOS 11, *)) {
topSafeArea = self.collectionView.safeAreaInsets.top;
} else {
topSafeArea = StatusBarHeight();
}
CGFloat minY = headerHeight - ntp_header::kMinHeaderHeight - topSafeArea;
if (contentOffset.y > minY)
origin.y = contentOffset.y - minY;
attributes.frame = {origin, attributes.frame.size};
......
......@@ -102,7 +102,8 @@
[_shadow setAlpha:0];
}
- (CGFloat)searchFieldProgressForOffset:(CGFloat)offset {
- (CGFloat)searchFieldProgressForOffset:(CGFloat)offset
safeAreaInsets:(UIEdgeInsets)safeAreaInsets {
NOTREACHED();
return 0;
}
......
......@@ -20,7 +20,8 @@ class ReadingListModel;
// Return the progress of the search field position along
// |ntp_header::kAnimationDistance| as the offset changes.
- (CGFloat)searchFieldProgressForOffset:(CGFloat)offset;
- (CGFloat)searchFieldProgressForOffset:(CGFloat)offset
safeAreaInsets:(UIEdgeInsets)safeAreaInsets;
// Changes the constraints of searchField based on its initialFrame and the
// scroll view's y |offset|. Also adjust the alpha values for |_searchBoxBorder|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment