| 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 #import "base/mac/scoped_nsobject.h" | 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." |
| 13 #endif |
| 11 | 14 |
| 12 namespace { | 15 namespace { |
| 13 | 16 |
| 14 // Background color RGB values for the content view which is displayed when the | 17 // Background color RGB values for the content view which is displayed when the |
| 15 // |_webView| is offset from the screen due to user interaction. Displaying this | 18 // |_webView| is offset from the screen due to user interaction. Displaying this |
| 16 // background color is handled by UIWebView but not WKWebView, so it needs to be | 19 // background color is handled by UIWebView but not WKWebView, so it needs to be |
| 17 // set in CRWWebViewContentView to support both. The color value matches that | 20 // set in CRWWebViewContentView to support both. The color value matches that |
| 18 // used by UIWebView. | 21 // used by UIWebView. |
| 19 const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f}; | 22 const CGFloat kBackgroundRGBComponents[] = {0.75f, 0.74f, 0.76f}; |
| 20 | 23 |
| 21 } // namespace | 24 } // namespace |
| 22 | 25 |
| 23 @interface CRWWebViewContentView () { | 26 @interface CRWWebViewContentView () { |
| 24 // The web view being shown. | 27 // The web view being shown. |
| 25 base::scoped_nsobject<UIView> _webView; | 28 UIView* _webView; |
| 26 // The web view's scroll view. | 29 // The web view's scroll view. |
| 27 base::scoped_nsobject<UIScrollView> _scrollView; | 30 UIScrollView* _scrollView; |
| 28 // Backs up property of the same name if |_webView| is a WKWebView. | 31 // Backs up property of the same name if |_webView| is a WKWebView. |
| 29 CGFloat _topContentPadding; | 32 CGFloat _topContentPadding; |
| 30 } | 33 } |
| 31 | 34 |
| 32 // Changes web view frame to match |self.bounds| and optionally accomodates for | 35 // Changes web view frame to match |self.bounds| and optionally accomodates for |
| 33 // |_topContentPadding| (iff |_webView| is a WKWebView). | 36 // |_topContentPadding| (iff |_webView| is a WKWebView). |
| 34 - (void)updateWebViewFrame; | 37 - (void)updateWebViewFrame; |
| 35 | 38 |
| 36 @end | 39 @end |
| 37 | 40 |
| 38 @implementation CRWWebViewContentView | 41 @implementation CRWWebViewContentView |
| 39 | 42 |
| 40 @synthesize shouldUseInsetForTopPadding = _shouldUseInsetForTopPadding; | 43 @synthesize shouldUseInsetForTopPadding = _shouldUseInsetForTopPadding; |
| 41 | 44 |
| 42 - (instancetype)initWithWebView:(UIView*)webView | 45 - (instancetype)initWithWebView:(UIView*)webView |
| 43 scrollView:(UIScrollView*)scrollView { | 46 scrollView:(UIScrollView*)scrollView { |
| 44 self = [super initWithFrame:CGRectZero]; | 47 self = [super initWithFrame:CGRectZero]; |
| 45 if (self) { | 48 if (self) { |
| 46 DCHECK(webView); | 49 DCHECK(webView); |
| 47 DCHECK(scrollView); | 50 DCHECK(scrollView); |
| 48 DCHECK([scrollView isDescendantOfView:webView]); | 51 DCHECK([scrollView isDescendantOfView:webView]); |
| 49 _webView.reset([webView retain]); | 52 _webView = webView; |
| 50 _scrollView.reset([scrollView retain]); | 53 _scrollView = scrollView; |
| 51 } | 54 } |
| 52 return self; | 55 return self; |
| 53 } | 56 } |
| 54 | 57 |
| 55 - (instancetype)initForTesting { | 58 - (instancetype)initForTesting { |
| 56 return [super initWithFrame:CGRectZero]; | 59 return [super initWithFrame:CGRectZero]; |
| 57 } | 60 } |
| 58 | 61 |
| 59 - (instancetype)initWithCoder:(NSCoder*)decoder { | 62 - (instancetype)initWithCoder:(NSCoder*)decoder { |
| 60 NOTREACHED(); | 63 NOTREACHED(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 - (void)setBounds:(CGRect)bounds { | 96 - (void)setBounds:(CGRect)bounds { |
| 94 if (CGRectEqualToRect(self.bounds, bounds)) | 97 if (CGRectEqualToRect(self.bounds, bounds)) |
| 95 return; | 98 return; |
| 96 [super setBounds:bounds]; | 99 [super setBounds:bounds]; |
| 97 [self updateWebViewFrame]; | 100 [self updateWebViewFrame]; |
| 98 } | 101 } |
| 99 | 102 |
| 100 #pragma mark Accessors | 103 #pragma mark Accessors |
| 101 | 104 |
| 102 - (UIScrollView*)scrollView { | 105 - (UIScrollView*)scrollView { |
| 103 return _scrollView.get(); | 106 return _scrollView; |
| 104 } | 107 } |
| 105 | 108 |
| 106 - (UIView*)webView { | 109 - (UIView*)webView { |
| 107 return _webView.get(); | 110 return _webView; |
| 108 } | 111 } |
| 109 | 112 |
| 110 #pragma mark Layout | 113 #pragma mark Layout |
| 111 | 114 |
| 112 - (void)layoutSubviews { | 115 - (void)layoutSubviews { |
| 113 [super layoutSubviews]; | 116 [super layoutSubviews]; |
| 114 [self updateWebViewFrame]; | 117 [self updateWebViewFrame]; |
| 115 } | 118 } |
| 116 | 119 |
| 117 - (BOOL)isViewAlive { | 120 - (BOOL)isViewAlive { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 168 |
| 166 - (void)updateWebViewFrame { | 169 - (void)updateWebViewFrame { |
| 167 CGRect webViewFrame = self.bounds; | 170 CGRect webViewFrame = self.bounds; |
| 168 webViewFrame.size.height -= _topContentPadding; | 171 webViewFrame.size.height -= _topContentPadding; |
| 169 webViewFrame.origin.y += _topContentPadding; | 172 webViewFrame.origin.y += _topContentPadding; |
| 170 | 173 |
| 171 self.webView.frame = webViewFrame; | 174 self.webView.frame = webViewFrame; |
| 172 } | 175 } |
| 173 | 176 |
| 174 @end | 177 @end |
| OLD | NEW |