Commit 981cffb1 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Consolidate web view frame updates to |-layoutSubviews|.

This CL updates CRWWebViewContentView to utilize the normal UIView
layout flow to resize the WKWebView rather than explicitly calling
|-updateWebViewFrame|.

Bug: none
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I8e4a3c464483818c9799424c097f5ed7711d6d8e
Reviewed-on: https://chromium-review.googlesource.com/1186099Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585594}
parent 4efe61e3
...@@ -25,14 +25,6 @@ const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f}; ...@@ -25,14 +25,6 @@ const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f};
} // namespace } // namespace
@interface CRWWebViewContentView ()
// Changes web view frame to match |self.bounds| and optionally accommodates for
// |contentInset|.
- (void)updateWebViewFrame;
@end
@implementation CRWWebViewContentView @implementation CRWWebViewContentView
@synthesize contentOffset = _contentOffset; @synthesize contentOffset = _contentOffset;
@synthesize contentInset = _contentInset; @synthesize contentInset = _contentInset;
...@@ -84,25 +76,15 @@ const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f}; ...@@ -84,25 +76,15 @@ const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f};
return [_webView becomeFirstResponder]; return [_webView becomeFirstResponder];
} }
- (void)setFrame:(CGRect)frame {
if (CGRectEqualToRect(self.frame, frame))
return;
[super setFrame:frame];
[self updateWebViewFrame];
}
- (void)setBounds:(CGRect)bounds {
if (CGRectEqualToRect(self.bounds, bounds))
return;
[super setBounds:bounds];
[self updateWebViewFrame];
}
#pragma mark Layout #pragma mark Layout
- (void)layoutSubviews { - (void)layoutSubviews {
[super layoutSubviews]; [super layoutSubviews];
[self updateWebViewFrame];
CGRect frame = self.bounds;
frame = UIEdgeInsetsInsetRect(frame, _contentInset);
frame = CGRectOffset(frame, _contentOffset.x, _contentOffset.y);
self.webView.frame = frame;
} }
- (BOOL)isViewAlive { - (BOOL)isViewAlive {
...@@ -113,7 +95,7 @@ const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f}; ...@@ -113,7 +95,7 @@ const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f};
if (CGPointEqualToPoint(_contentOffset, contentOffset)) if (CGPointEqualToPoint(_contentOffset, contentOffset))
return; return;
_contentOffset = contentOffset; _contentOffset = contentOffset;
[self updateWebViewFrame]; [self setNeedsLayout];
} }
- (UIEdgeInsets)contentInset { - (UIEdgeInsets)contentInset {
...@@ -158,7 +140,8 @@ const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f}; ...@@ -158,7 +140,8 @@ const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f};
contentOffset.y += topPaddingChange; contentOffset.y += topPaddingChange;
[_scrollView setContentOffset:contentOffset]; [_scrollView setContentOffset:contentOffset];
// Update web view frame immediately to make |contentInset| animatable. // Update web view frame immediately to make |contentInset| animatable.
[self updateWebViewFrame]; [self setNeedsLayout];
[self layoutIfNeeded];
// Setting WKWebView frame can mistakenly reset contentOffset. Change it // Setting WKWebView frame can mistakenly reset contentOffset. Change it
// back to the initial value if necessary. // back to the initial value if necessary.
// TODO(crbug.com/645857): Remove this workaround once WebKit bug is // TODO(crbug.com/645857): Remove this workaround once WebKit bug is
...@@ -168,11 +151,4 @@ const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f}; ...@@ -168,11 +151,4 @@ const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f};
} }
} }
- (void)updateWebViewFrame {
CGRect frame = self.bounds;
frame = UIEdgeInsetsInsetRect(frame, _contentInset);
frame = CGRectOffset(frame, _contentOffset.x, _contentOffset.y);
self.webView.frame = frame;
}
@end @end
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