Skip to content

Commit

Permalink
Adding CRWWebViewContentView as a subview when it is set
Browse files Browse the repository at this point in the history
Adding subviews in layoutSubviews is problematic
(see http://stackoverflow.com/questions/34301366/call-addsubview-within-layoutsubviews/34301753)

This CL moves it out of |layoutSubviews| and
into when the CRWWebViewContentView is actually
set on the ContainerView.

The existing logic will take care of removing
the old ContentView from the superview
when there is a need to replace the
ContentView.

As a (intended) side effect this CL fixes a bug in UIWebView
 where adding it as part of layoutSubViews would lead to issues
in scrolling of certain pages.

BUG=568097
TEST=
Illustrated in the bug.

Review URL: https://codereview.chromium.org/1531593002

Cr-Commit-Position: refs/heads/master@{#365691}
  • Loading branch information
shreyasv authored and Commit bot committed Dec 17, 2015
1 parent 46115a9 commit f5406c8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ios/web/web_state/ui/crw_web_controller_container_view.mm
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ - (void)setWebViewContentView:(CRWWebViewContentView*)webViewContentView {
if (![_webViewContentView isEqual:webViewContentView]) {
[_webViewContentView removeFromSuperview];
_webViewContentView.reset([webViewContentView retain]);
if (_webViewContentView) {
DCHECK(![_webViewContentView superview]);
[self addSubview:_webViewContentView];
}
}
}

Expand Down Expand Up @@ -215,12 +219,10 @@ - (CGRect)visibleFrame {
- (void)layoutSubviews {
[super layoutSubviews];

// webViewcontentView layout.
if (self.webViewContentView) {
if (!self.webViewContentView.superview)
[self addSubview:self.webViewContentView];
self.webViewContentView.frame = self.bounds;
}
self.webViewContentView.frame = self.bounds;

// TODO(crbug.com/570114): Move adding of the following subviews to another
// place.

// nativeController layout.
if (self.nativeController) {
Expand Down

0 comments on commit f5406c8

Please sign in to comment.