OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" | 5 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" |
6 | 6 |
7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 - (void)didMoveToSuperview { | 72 - (void)didMoveToSuperview { |
73 [super didMoveToSuperview]; | 73 [super didMoveToSuperview]; |
74 if (self.superview) { | 74 if (self.superview) { |
75 self.autoresizingMask = | 75 self.autoresizingMask = |
76 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 76 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
77 [self addSubview:_webView]; | 77 [self addSubview:_webView]; |
78 self.backgroundColor = [UIColor colorWithRed:kBackgroundRGBComponents[0] | 78 self.backgroundColor = [UIColor colorWithRed:kBackgroundRGBComponents[0] |
79 green:kBackgroundRGBComponents[1] | 79 green:kBackgroundRGBComponents[1] |
80 blue:kBackgroundRGBComponents[2] | 80 blue:kBackgroundRGBComponents[2] |
81 alpha:1.0]; | 81 alpha:1.0]; |
82 // The frame needs to be set immediately after the web view is added | |
83 // as a subview. The change in the frame triggers drawing operations and | |
84 // if not done after it's added as a subview, the web view exhibits | |
85 // strange behavior where clicks from certain web sites are not triggered. | |
86 // The actual value of the frame doesn't matter as long as it's not | |
87 // CGRectZero. The CRWWebViewContentView's frame will be reset to a correct | |
88 // value in a subsequent layout pass. | |
89 // TODO(crbug.com/577793): This is an undocumented and not-well-understood | |
90 // workaround for this issue. | |
91 const CGRect kDummyRect = CGRectMake(10, 20, 30, 50); | |
92 self.frame = kDummyRect; | |
93 } | 82 } |
94 } | 83 } |
95 | 84 |
| 85 - (void)setFrame:(CGRect)frame { |
| 86 if (CGRectEqualToRect(self.frame, frame)) |
| 87 return; |
| 88 [super setFrame:frame]; |
| 89 [self updateWebViewFrame]; |
| 90 } |
| 91 |
| 92 - (void)setBounds:(CGRect)bounds { |
| 93 if (CGRectEqualToRect(self.bounds, bounds)) |
| 94 return; |
| 95 [super setBounds:bounds]; |
| 96 [self updateWebViewFrame]; |
| 97 } |
| 98 |
96 #pragma mark Accessors | 99 #pragma mark Accessors |
97 | 100 |
98 - (UIScrollView*)scrollView { | 101 - (UIScrollView*)scrollView { |
99 return _scrollView.get(); | 102 return _scrollView.get(); |
100 } | 103 } |
101 | 104 |
102 - (UIView*)webView { | 105 - (UIView*)webView { |
103 return _webView.get(); | 106 return _webView.get(); |
104 } | 107 } |
105 | 108 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 142 |
140 - (void)updateWebViewFrame { | 143 - (void)updateWebViewFrame { |
141 CGRect webViewFrame = self.bounds; | 144 CGRect webViewFrame = self.bounds; |
142 webViewFrame.size.height -= _topContentPadding; | 145 webViewFrame.size.height -= _topContentPadding; |
143 webViewFrame.origin.y += _topContentPadding; | 146 webViewFrame.origin.y += _topContentPadding; |
144 | 147 |
145 self.webView.frame = webViewFrame; | 148 self.webView.frame = webViewFrame; |
146 } | 149 } |
147 | 150 |
148 @end | 151 @end |
OLD | NEW |