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