| 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 |
| 96 - (BOOL)becomeFirstResponder { | 85 - (BOOL)becomeFirstResponder { |
| 97 return [_webView becomeFirstResponder]; | 86 return [_webView becomeFirstResponder]; |
| 98 } | 87 } |
| 99 | 88 |
| 89 - (void)setFrame:(CGRect)frame { |
| 90 if (CGRectEqualToRect(self.frame, frame)) |
| 91 return; |
| 92 [super setFrame:frame]; |
| 93 [self updateWebViewFrame]; |
| 94 } |
| 95 |
| 96 - (void)setBounds:(CGRect)bounds { |
| 97 if (CGRectEqualToRect(self.bounds, bounds)) |
| 98 return; |
| 99 [super setBounds:bounds]; |
| 100 [self updateWebViewFrame]; |
| 101 } |
| 102 |
| 100 #pragma mark Accessors | 103 #pragma mark Accessors |
| 101 | 104 |
| 102 - (UIScrollView*)scrollView { | 105 - (UIScrollView*)scrollView { |
| 103 return _scrollView.get(); | 106 return _scrollView.get(); |
| 104 } | 107 } |
| 105 | 108 |
| 106 - (UIView*)webView { | 109 - (UIView*)webView { |
| 107 return _webView.get(); | 110 return _webView.get(); |
| 108 } | 111 } |
| 109 | 112 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 146 |
| 144 - (void)updateWebViewFrame { | 147 - (void)updateWebViewFrame { |
| 145 CGRect webViewFrame = self.bounds; | 148 CGRect webViewFrame = self.bounds; |
| 146 webViewFrame.size.height -= _topContentPadding; | 149 webViewFrame.size.height -= _topContentPadding; |
| 147 webViewFrame.origin.y += _topContentPadding; | 150 webViewFrame.origin.y += _topContentPadding; |
| 148 | 151 |
| 149 self.webView.frame = webViewFrame; | 152 self.webView.frame = webViewFrame; |
| 150 } | 153 } |
| 151 | 154 |
| 152 @end | 155 @end |
| OLD | NEW |