Commit ae0aa265 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Fix the fullscreen scrolling offset

The scrolling offset of the WKWebView should be handled in the
FullscreenResizer, not in Web when the flag is enabled.
This wasn't the case before because the flag was created in the middle
of the refactoring of the existing function.

Bug: 849206
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I89675ee01c43fe8eecda56f690d08ffb4eabe263
Reviewed-on: https://chromium-review.googlesource.com/1196368
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592349}
parent 20404d2b
......@@ -102,6 +102,8 @@
- (void)updateForInsets:(UIEdgeInsets)insets {
UIView* webView = self.webState->GetView();
id<CRWWebViewProxy> webViewProxy = self.webState->GetWebViewProxy();
CRWWebViewScrollViewProxy* scrollViewProxy = webViewProxy.scrollViewProxy;
CGRect newFrame = UIEdgeInsetsInsetRect(webView.superview.bounds, insets);
// Make sure the frame has changed to avoid a loop as the frame property is
......@@ -112,7 +114,22 @@
std::fabs(newFrame.size.height - webView.frame.size.height) < 0.01)
return;
// Update the content offset of the scroll view to match the padding
// that will be included in the frame.
CGFloat currentTopInset = webView.frame.origin.y;
CGPoint newContentOffset = scrollViewProxy.contentOffset;
newContentOffset.y += insets.top - currentTopInset;
scrollViewProxy.contentOffset = newContentOffset;
webView.frame = newFrame;
// Setting WKWebView frame can mistakenly reset contentOffset. Change it
// back to the initial value if necessary.
// TODO(crbug.com/645857): Remove this workaround once WebKit bug is
// fixed.
if ([scrollViewProxy contentOffset].y != newContentOffset.y) {
[scrollViewProxy setContentOffset:newContentOffset];
}
}
// Observes the frame property of the view of the |webState| using KVO.
......
......@@ -136,6 +136,9 @@ const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f};
// Updates the viewport by updating the web view frame after self.contentInset
// is changed to a new value from |oldInsets|.
- (void)resizeViewportForContentInsetChangeFromInsets:(UIEdgeInsets)oldInsets {
if (base::FeatureList::IsEnabled(web::features::kOutOfWebFullscreen))
return;
// Update the content offset of the scroll view to match the padding
// that will be included in the frame.
CGFloat topPaddingChange = self.contentInset.top - oldInsets.top;
......
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