Commit 37ef13f4 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Fix fullscreenOutOfWeb for NTP

This CL fixes the fullscreen implementation living outside of web for
the NTP and other scrolling issues on web page.
It also fixes the animation of the resizing when the animator is
triggered.

Bug: 849206
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I8a13b88af6808472ef84ef6902c75c398451c961
Reviewed-on: https://chromium-review.googlesource.com/1195487Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592340}
parent 6d21afb0
......@@ -378,6 +378,7 @@ source_set("ui_internal") {
"//ios/chrome/browser/ui/ntp",
"//ios/chrome/browser/ui/ntp:ntp_controller",
"//ios/chrome/browser/ui/ntp:ntp_internal",
"//ios/chrome/browser/ui/ntp:util",
"//ios/chrome/browser/ui/ntp/recent_tabs",
"//ios/chrome/browser/ui/omnibox:omnibox_internal",
"//ios/chrome/browser/ui/overscroll_actions",
......
......@@ -170,6 +170,7 @@
#import "ios/chrome/browser/ui/main_content/main_content_ui_state.h"
#import "ios/chrome/browser/ui/main_content/web_scroll_view_main_content_ui_forwarder.h"
#import "ios/chrome/browser/ui/ntp/new_tab_page_controller.h"
#import "ios/chrome/browser/ui/ntp/ntp_util.h"
#import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_handset_coordinator.h"
#import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.h"
#import "ios/chrome/browser/ui/page_info/page_info_legacy_coordinator.h"
......@@ -4107,6 +4108,10 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
#pragma mark - ToolbarHeightProviderForFullscreen
- (CGFloat)collapsedTopToolbarHeight {
if (base::FeatureList::IsEnabled(web::features::kOutOfWebFullscreen) &&
IsVisibleUrlNewTabPage(self.currentWebState)) {
return 0;
}
// For the legacy UI, the toolbar is completely hidden when in fullscreen
// mode. After the UI refresh, kToolbarHeightFullscreen is still visible
// after scroll events.
......@@ -4121,10 +4126,18 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
}
- (CGFloat)expandedTopToolbarHeight {
if (base::FeatureList::IsEnabled(web::features::kOutOfWebFullscreen) &&
IsVisibleUrlNewTabPage(self.currentWebState)) {
return 0;
}
return self.headerHeight;
}
- (CGFloat)bottomToolbarHeight {
if (base::FeatureList::IsEnabled(web::features::kOutOfWebFullscreen) &&
IsVisibleUrlNewTabPage(self.currentWebState)) {
return 0;
}
return [self secondaryToolbarHeightWithInset];
}
......@@ -5202,6 +5215,7 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
- (void)tabModel:(TabModel*)model
didFinishLoadingTab:(Tab*)tab
success:(BOOL)success {
[_toolbarUIUpdater updateState];
[self tabLoadComplete:tab withSuccess:success];
if ([self canShowTabStrip]) {
UIUserInterfaceSizeClass sizeClass =
......
......@@ -90,6 +90,7 @@ source_set("internal") {
":ui",
"//base",
"//components/keyed_service/ios",
"//ios/chrome/browser",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/ui:ui_util",
"//ios/chrome/browser/ui/broadcaster",
......
......@@ -71,7 +71,7 @@ void FullscreenMediator::FullscreenModelProgressUpdated(
observer.FullscreenProgressUpdated(controller_, model_->progress());
}
[resizer_ updateForFullscreenProgress:model->progress()];
[resizer_ updateForCurrentState];
}
void FullscreenMediator::FullscreenModelEnabledStateChanged(
......@@ -114,7 +114,7 @@ void FullscreenMediator::FullscreenModelWasReset(FullscreenModel* model) {
observer.FullscreenProgressUpdated(controller_, model_->progress());
}
[resizer_ updateForFullscreenProgress:model_->progress()];
[resizer_ updateForCurrentState];
}
void FullscreenMediator::AnimateWithStyle(FullscreenAnimatorStyle style) {
......@@ -129,13 +129,16 @@ void FullscreenMediator::AnimateWithStyle(FullscreenAnimatorStyle style) {
style:style];
__weak FullscreenAnimator* weakAnimator = animator_;
FullscreenModel** modelPtr = &model_;
[animator_ addAnimations:^{
// Updates the WebView frame during the animation to have it animated.
[resizer_ forceToUpdateToProgress:animator_.finalProgress];
}];
[animator_ addCompletion:^(UIViewAnimatingPosition finalPosition) {
DCHECK_EQ(finalPosition, UIViewAnimatingPositionEnd);
if (!weakAnimator || !*modelPtr)
return;
model_->AnimationEndedWithProgress(
[weakAnimator progressForAnimatingPosition:finalPosition]);
[resizer_ updateForFullscreenProgress:animator_.finalProgress];
animator_ = nil;
}];
......
......@@ -27,10 +27,14 @@ class WebState;
// WebState currently displayed.
@property(nonatomic, assign) web::WebState* webState;
// Updates the WebView of the current webState to adjust it to the current
// fullscreen |progress|. |progress| should be between 0 and 1, 0 meaning that
// the application is in fullscreen, 1 that it is out of fullscreen.
- (void)updateForFullscreenProgress:(CGFloat)progress;
// Updates the WebState view, based on the current state of the webState and the
// model.
- (void)updateForCurrentState;
// Force the updates of the WebView to |progress|. |progress| should be between
// 0 and 1, 0 meaning that the application is in fullscreen, 1 that it is out of
// fullscreen.
- (void)forceToUpdateToProgress:(CGFloat)progress;
@end
......
......@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/fullscreen/fullscreen_web_view_resizer.h"
#include "ios/chrome/browser/chrome_url_constants.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_model.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/web/public/features.h"
......@@ -54,25 +55,54 @@
_webState = webState;
if (webState)
if (webState) {
[self observeWebStateViewFrame:webState];
[self updateForCurrentState];
}
}
#pragma mark - Public
- (void)updateForCurrentState {
if (!self.webState)
return;
[self updateForFullscreenProgress:self.model->progress()];
}
- (void)forceToUpdateToProgress:(CGFloat)progress {
if (!self.webState)
return;
[self.webState->GetView() removeObserver:self forKeyPath:@"frame"];
[self updateForFullscreenProgress:progress];
[self observeWebStateViewFrame:self.webState];
}
#pragma mark - Private
// Updates the WebView of the current webState to adjust it to the current
// fullscreen |progress|. |progress| should be between 0 and 1, 0 meaning that
// the application is in fullscreen, 1 that it is out of fullscreen.
- (void)updateForFullscreenProgress:(CGFloat)progress {
if (!self.webState || !self.webState->GetView().superview)
return;
UIView* webView = self.webState->GetView();
UIEdgeInsets newInsets =
UIEdgeInsetsMake(self.model->GetCollapsedToolbarHeight() +
progress * (self.model->GetExpandedToolbarHeight() -
self.model->GetCollapsedToolbarHeight()),
0, progress * self.model->GetBottomToolbarHeight(), 0);
CGRect newFrame = UIEdgeInsetsInsetRect(webView.superview.bounds, newInsets);
[self updateForInsets:newInsets];
}
// Updates the WebState view, resizing it such as |insets| is the insets between
// the WebState view and its superview.
- (void)updateForInsets:(UIEdgeInsets)insets {
UIView* webView = self.webState->GetView();
CGRect newFrame = UIEdgeInsetsInsetRect(webView.superview.bounds, insets);
// Make sure the frame has changed to avoid a loop as the frame property is
// actually monitored by this object.
......@@ -85,8 +115,6 @@
webView.frame = newFrame;
}
#pragma mark - Private
// Observes the frame property of the view of the |webState| using KVO.
- (void)observeWebStateViewFrame:(web::WebState*)webState {
if (!webState->GetView())
......@@ -94,7 +122,7 @@
[webState->GetView() addObserver:self
forKeyPath:@"frame"
options:NSKeyValueObservingOptionInitial
options:0
context:nil];
}
......@@ -106,7 +134,7 @@
if (![keyPath isEqualToString:@"frame"] || object != _webState->GetView())
return;
[self updateForFullscreenProgress:self.model->progress()];
[self updateForCurrentState];
}
@end
......@@ -59,7 +59,6 @@ class FullscreenWebViewResizerTest : public PlatformTest {
// Tests that updating the resizer works as expected.
TEST_F(FullscreenWebViewResizerTest, UpdateWebState) {
// Test.
ASSERT_EQ(1, _model.progress());
FullscreenWebViewResizer* resizer =
[[FullscreenWebViewResizer alloc] initWithModel:&_model];
......@@ -74,12 +73,28 @@ TEST_F(FullscreenWebViewResizerTest, UpdateWebState) {
// Scroll the view then update the resizer.
_model.SetYContentOffset(50);
ASSERT_EQ(0, _model.progress());
[resizer updateForFullscreenProgress:0];
[resizer updateForCurrentState];
CGRect smallInsetFrame = CGRectMake(0, kTopToolbarCollapsedHeight, kViewWidth,
kViewHeight - kTopToolbarCollapsedHeight);
EXPECT_TRUE(CGRectEqualToRect(smallInsetFrame, _webStateView.frame));
}
// Tests that it is possible to force the update the of the Resizer to a value
// differente from the model's one.
TEST_F(FullscreenWebViewResizerTest, ForceUpdateWebState) {
FullscreenWebViewResizer* resizer =
[[FullscreenWebViewResizer alloc] initWithModel:&_model];
resizer.webState = &_webState;
ASSERT_EQ(1, _model.progress());
// The frame should be updated when setting the WebState.
CGRect smallInsetFrame = CGRectMake(0, kTopToolbarCollapsedHeight, kViewWidth,
kViewHeight - kTopToolbarCollapsedHeight);
[resizer forceToUpdateToProgress:0];
EXPECT_TRUE(CGRectEqualToRect(smallInsetFrame, _webStateView.frame));
}
// Tests that nothing happen if there is no superview for the web state view.
TEST_F(FullscreenWebViewResizerTest, WebStateNoSuperview) {
// WebState view setup.
......@@ -90,22 +105,20 @@ TEST_F(FullscreenWebViewResizerTest, WebStateNoSuperview) {
web::TestWebState webState;
webState.SetView(webStateView);
// Test.
FullscreenWebViewResizer* resizer =
[[FullscreenWebViewResizer alloc] initWithModel:&_model];
resizer.webState = &webState;
EXPECT_TRUE(CGRectEqualToRect(webViewFrame, webStateView.frame));
[resizer updateForFullscreenProgress:1];
[resizer updateForCurrentState];
EXPECT_TRUE(CGRectEqualToRect(webViewFrame, webStateView.frame));
}
// Tests that nothing happen (no crash) if there is no web state.
TEST_F(FullscreenWebViewResizerTest, NoWebState) {
// Test.
FullscreenWebViewResizer* resizer =
[[FullscreenWebViewResizer alloc] initWithModel:&_model];
[resizer updateForFullscreenProgress:1];
[resizer updateForCurrentState];
}
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