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/web_state/ui/crw_web_controller_container_view.h" | 5 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" |
6 | 6 |
7 #import "base/ios/weak_nsobject.h" | |
8 #include "base/logging.h" | 7 #include "base/logging.h" |
9 #import "base/mac/scoped_nsobject.h" | |
10 #import "ios/web/public/web_state/ui/crw_content_view.h" | 8 #import "ios/web/public/web_state/ui/crw_content_view.h" |
11 #import "ios/web/public/web_state/ui/crw_native_content.h" | 9 #import "ios/web/public/web_state/ui/crw_native_content.h" |
12 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" | 10 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" |
13 #import "ios/web/web_state/ui/crw_web_view_proxy_impl.h" | 11 #import "ios/web/web_state/ui/crw_web_view_proxy_impl.h" |
14 | 12 |
13 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
14 #error "This file requires ARC support." | |
15 #endif | |
16 | |
15 #pragma mark - CRWToolbarContainerView | 17 #pragma mark - CRWToolbarContainerView |
16 | 18 |
17 // Class that manages the display of toolbars. | 19 // Class that manages the display of toolbars. |
18 @interface CRWToolbarContainerView : UIView { | 20 @interface CRWToolbarContainerView : UIView { |
19 // Backing object for |self.toolbars|. | 21 // Backing object for |self.toolbars|. |
20 base::scoped_nsobject<NSMutableArray> _toolbars; | 22 NSMutableArray* _toolbars; |
21 } | 23 } |
22 | 24 |
23 // The toolbars currently managed by this view. | 25 // The toolbars currently managed by this view. |
24 @property(nonatomic, retain, readonly) NSMutableArray* toolbars; | 26 @property(nonatomic, strong, readonly) NSMutableArray* toolbars; |
25 | 27 |
26 // Adds |toolbar| as a subview and bottom aligns to any previously added | 28 // Adds |toolbar| as a subview and bottom aligns to any previously added |
27 // toolbars. | 29 // toolbars. |
28 - (void)addToolbar:(UIView*)toolbar; | 30 - (void)addToolbar:(UIView*)toolbar; |
29 | 31 |
30 // Removes |toolbar| from the container view. | 32 // Removes |toolbar| from the container view. |
31 - (void)removeToolbar:(UIView*)toolbar; | 33 - (void)removeToolbar:(UIView*)toolbar; |
32 | 34 |
33 @end | 35 @end |
34 | 36 |
35 @implementation CRWToolbarContainerView | 37 @implementation CRWToolbarContainerView |
36 | 38 |
37 #pragma mark Accessors | 39 #pragma mark Accessors |
38 | 40 |
39 - (NSMutableArray*)toolbars { | 41 - (NSMutableArray*)toolbars { |
40 if (!_toolbars) | 42 if (!_toolbars) |
41 _toolbars.reset([[NSMutableArray alloc] init]); | 43 _toolbars = [[NSMutableArray alloc] init]; |
42 return _toolbars.get(); | 44 return _toolbars; |
43 } | 45 } |
44 | 46 |
45 #pragma mark Layout | 47 #pragma mark Layout |
46 | 48 |
47 - (void)layoutSubviews { | 49 - (void)layoutSubviews { |
48 [super layoutSubviews]; | 50 [super layoutSubviews]; |
49 | 51 |
50 // Bottom-align the toolbars. | 52 // Bottom-align the toolbars. |
51 CGPoint toolbarOrigin = | 53 CGPoint toolbarOrigin = |
52 CGPointMake(self.bounds.origin.x, CGRectGetMaxY(self.bounds)); | 54 CGPointMake(self.bounds.origin.x, CGRectGetMaxY(self.bounds)); |
(...skipping 29 matching lines...) Expand all Loading... | |
82 DCHECK([self.toolbars containsObject:toolbar]); | 84 DCHECK([self.toolbars containsObject:toolbar]); |
83 [self.toolbars removeObject:toolbar]; | 85 [self.toolbars removeObject:toolbar]; |
84 [toolbar removeFromSuperview]; | 86 [toolbar removeFromSuperview]; |
85 } | 87 } |
86 | 88 |
87 @end | 89 @end |
88 | 90 |
89 #pragma mark - CRWWebControllerContainerView | 91 #pragma mark - CRWWebControllerContainerView |
90 | 92 |
91 @interface CRWWebControllerContainerView () { | 93 @interface CRWWebControllerContainerView () { |
92 // The delegate passed on initialization. | |
93 base::WeakNSProtocol<id<CRWWebControllerContainerViewDelegate>> _delegate; | |
94 // Backing objects for corresponding properties. | |
95 base::scoped_nsobject<CRWWebViewContentView> _webViewContentView; | |
96 base::scoped_nsprotocol<id<CRWNativeContent>> _nativeController; | |
97 base::scoped_nsobject<CRWContentView> _transientContentView; | |
98 base::scoped_nsobject<CRWToolbarContainerView> _toolbarContainerView; | |
99 } | 94 } |
100 | 95 |
101 // Redefine properties as readwrite. | 96 // Redefine properties as readwrite. |
102 @property(nonatomic, retain, readwrite) | 97 @property(nonatomic, strong, readwrite) |
103 CRWWebViewContentView* webViewContentView; | 98 CRWWebViewContentView* webViewContentView; |
104 @property(nonatomic, retain, readwrite) id<CRWNativeContent> nativeController; | 99 @property(nonatomic, strong, readwrite) id<CRWNativeContent> nativeController; |
105 @property(nonatomic, retain, readwrite) CRWContentView* transientContentView; | 100 @property(nonatomic, strong, readwrite) CRWContentView* transientContentView; |
106 | 101 |
107 // Container view that displays any added toolbars. It is always the top-most | 102 // Container view that displays any added toolbars. It is always the top-most |
108 // subview, and is bottom aligned with the CRWWebControllerContainerView. | 103 // subview, and is bottom aligned with the CRWWebControllerContainerView. |
109 @property(nonatomic, retain, readonly) | 104 @property(nonatomic, strong, readonly) |
110 CRWToolbarContainerView* toolbarContainerView; | 105 CRWToolbarContainerView* toolbarContainerView; |
111 | 106 |
112 // Convenience getter for the proxy object. | 107 // Convenience getter for the proxy object. |
113 @property(nonatomic, readonly) CRWWebViewProxyImpl* contentViewProxy; | 108 @property(weak, nonatomic, readonly) CRWWebViewProxyImpl* contentViewProxy; |
Eugene But (OOO till 7-30)
2017/06/14 01:27:59
Really nit: (nonatomic, weak, readonly)
PL
2017/06/15 22:51:32
Done!
| |
114 | 109 |
115 // Returns |self.bounds| after being inset at the top by the header height | 110 // Returns |self.bounds| after being inset at the top by the header height |
116 // returned by the delegate. This is only used to lay out native controllers, | 111 // returned by the delegate. This is only used to lay out native controllers, |
117 // as the header height is already accounted for in the scroll view content | 112 // as the header height is already accounted for in the scroll view content |
118 // insets for other CRWContentViews. | 113 // insets for other CRWContentViews. |
119 @property(nonatomic, readonly) CGRect visibleFrame; | 114 @property(nonatomic, readonly) CGRect visibleFrame; |
120 | 115 |
121 @end | 116 @end |
122 | 117 |
123 @implementation CRWWebControllerContainerView | 118 @implementation CRWWebControllerContainerView |
124 | 119 |
120 @synthesize webViewContentView = _webViewContentView; | |
121 @synthesize nativeController = _nativeController; | |
122 @synthesize transientContentView = _transientContentView; | |
123 @synthesize toolbarContainerView = _toolbarContainerView; | |
124 @synthesize delegate = _delegate; | |
125 | |
125 - (instancetype)initWithDelegate: | 126 - (instancetype)initWithDelegate: |
126 (id<CRWWebControllerContainerViewDelegate>)delegate { | 127 (id<CRWWebControllerContainerViewDelegate>)delegate { |
127 self = [super initWithFrame:CGRectZero]; | 128 self = [super initWithFrame:CGRectZero]; |
128 if (self) { | 129 if (self) { |
129 DCHECK(delegate); | 130 DCHECK(delegate); |
130 _delegate.reset(delegate); | 131 _delegate = delegate; |
131 self.backgroundColor = [UIColor whiteColor]; | 132 self.backgroundColor = [UIColor whiteColor]; |
132 self.autoresizingMask = | 133 self.autoresizingMask = |
133 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 134 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
134 } | 135 } |
135 return self; | 136 return self; |
136 } | 137 } |
137 | 138 |
138 - (instancetype)initWithCoder:(NSCoder*)decoder { | 139 - (instancetype)initWithCoder:(NSCoder*)decoder { |
139 NOTREACHED(); | 140 NOTREACHED(); |
140 return nil; | 141 return nil; |
141 } | 142 } |
142 | 143 |
143 - (instancetype)initWithFrame:(CGRect)frame { | 144 - (instancetype)initWithFrame:(CGRect)frame { |
144 NOTREACHED(); | 145 NOTREACHED(); |
145 return nil; | 146 return nil; |
146 } | 147 } |
147 | 148 |
148 - (void)dealloc { | 149 - (void)dealloc { |
149 self.contentViewProxy.contentView = nil; | 150 self.contentViewProxy.contentView = nil; |
150 [super dealloc]; | |
151 } | 151 } |
152 | 152 |
153 #pragma mark Accessors | 153 #pragma mark Accessors |
154 | 154 |
155 - (CRWWebViewContentView*)webViewContentView { | |
156 return _webViewContentView.get(); | |
157 } | |
158 | |
159 - (void)setWebViewContentView:(CRWWebViewContentView*)webViewContentView { | 155 - (void)setWebViewContentView:(CRWWebViewContentView*)webViewContentView { |
160 if (![_webViewContentView isEqual:webViewContentView]) { | 156 if (![_webViewContentView isEqual:webViewContentView]) { |
161 [_webViewContentView removeFromSuperview]; | 157 [_webViewContentView removeFromSuperview]; |
162 _webViewContentView.reset([webViewContentView retain]); | 158 _webViewContentView = webViewContentView; |
163 [_webViewContentView setFrame:self.bounds]; | 159 [_webViewContentView setFrame:self.bounds]; |
164 [self addSubview:_webViewContentView]; | 160 [self addSubview:_webViewContentView]; |
165 } | 161 } |
166 } | 162 } |
167 | 163 |
168 - (id<CRWNativeContent>)nativeController { | |
169 return _nativeController.get(); | |
170 } | |
171 | |
172 - (void)setNativeController:(id<CRWNativeContent>)nativeController { | 164 - (void)setNativeController:(id<CRWNativeContent>)nativeController { |
173 if (![_nativeController isEqual:nativeController]) { | 165 if (![_nativeController isEqual:nativeController]) { |
174 base::WeakNSProtocol<id> oldController(_nativeController); | 166 __weak id oldController = _nativeController; |
175 if ([oldController respondsToSelector:@selector(willBeDismissed)]) { | 167 if ([oldController respondsToSelector:@selector(willBeDismissed)]) { |
176 [oldController willBeDismissed]; | 168 [oldController willBeDismissed]; |
177 } | 169 } |
178 [[oldController view] removeFromSuperview]; | 170 [[oldController view] removeFromSuperview]; |
179 _nativeController.reset([nativeController retain]); | 171 _nativeController = nativeController; |
180 // TODO(crbug.com/503297): Re-enable this DCHECK once native controller | 172 // TODO(crbug.com/503297): Re-enable this DCHECK once native controller |
181 // leaks are fixed. | 173 // leaks are fixed. |
182 // DCHECK(!oldController); | 174 // DCHECK(!oldController); |
183 } | 175 } |
184 } | 176 } |
185 | 177 |
186 - (CRWContentView*)transientContentView { | |
187 return _transientContentView.get(); | |
188 } | |
189 | |
190 - (void)setTransientContentView:(CRWContentView*)transientContentView { | 178 - (void)setTransientContentView:(CRWContentView*)transientContentView { |
191 if (![_transientContentView isEqual:transientContentView]) { | 179 if (![_transientContentView isEqual:transientContentView]) { |
192 [_transientContentView removeFromSuperview]; | 180 [_transientContentView removeFromSuperview]; |
193 _transientContentView.reset([transientContentView retain]); | 181 _transientContentView = transientContentView; |
194 } | 182 } |
195 } | 183 } |
196 | 184 |
197 - (void)setToolbarContainerView:(CRWToolbarContainerView*)toolbarContainerView { | 185 - (void)setToolbarContainerView:(CRWToolbarContainerView*)toolbarContainerView { |
198 if (![_toolbarContainerView isEqual:toolbarContainerView]) { | 186 if (![_toolbarContainerView isEqual:toolbarContainerView]) { |
199 [_toolbarContainerView removeFromSuperview]; | 187 [_toolbarContainerView removeFromSuperview]; |
200 _toolbarContainerView.reset([toolbarContainerView retain]); | 188 _toolbarContainerView = toolbarContainerView; |
201 } | 189 } |
202 } | 190 } |
203 | 191 |
204 - (UIView*)toolbarContainerView { | |
205 return _toolbarContainerView.get(); | |
206 } | |
207 | |
208 - (CRWWebViewProxyImpl*)contentViewProxy { | 192 - (CRWWebViewProxyImpl*)contentViewProxy { |
209 return [_delegate contentViewProxyForContainerView:self]; | 193 return [_delegate contentViewProxyForContainerView:self]; |
210 } | 194 } |
211 | 195 |
212 - (CGRect)visibleFrame { | 196 - (CGRect)visibleFrame { |
213 CGFloat headerHeight = [_delegate headerHeightForContainerView:self]; | 197 CGFloat headerHeight = [_delegate headerHeightForContainerView:self]; |
214 return UIEdgeInsetsInsetRect(self.bounds, | 198 return UIEdgeInsetsInsetRect(self.bounds, |
215 UIEdgeInsetsMake(headerHeight, 0, 0, 0)); | 199 UIEdgeInsetsMake(headerHeight, 0, 0, 0)); |
216 } | 200 } |
217 | 201 |
218 - (id<CRWWebControllerContainerViewDelegate>)delegate { | |
219 return _delegate.get(); | |
220 } | |
221 | |
222 - (void)setDelegate:(id<CRWWebControllerContainerViewDelegate>)delegate { | |
223 _delegate.reset(delegate); | |
224 } | |
225 | |
226 #pragma mark Layout | 202 #pragma mark Layout |
227 | 203 |
228 - (void)layoutSubviews { | 204 - (void)layoutSubviews { |
229 [super layoutSubviews]; | 205 [super layoutSubviews]; |
230 | 206 |
231 self.webViewContentView.frame = self.bounds; | 207 self.webViewContentView.frame = self.bounds; |
232 | 208 |
233 // TODO(crbug.com/570114): Move adding of the following subviews to another | 209 // TODO(crbug.com/570114): Move adding of the following subviews to another |
234 // place. | 210 // place. |
235 | 211 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 - (void)clearTransientContentView { | 284 - (void)clearTransientContentView { |
309 self.transientContentView = nil; | 285 self.transientContentView = nil; |
310 self.contentViewProxy.contentView = self.webViewContentView; | 286 self.contentViewProxy.contentView = self.webViewContentView; |
311 } | 287 } |
312 | 288 |
313 #pragma mark Toolbars | 289 #pragma mark Toolbars |
314 | 290 |
315 - (void)addToolbar:(UIView*)toolbar { | 291 - (void)addToolbar:(UIView*)toolbar { |
316 // Create toolbar container if necessary. | 292 // Create toolbar container if necessary. |
317 if (!self.toolbarContainerView) { | 293 if (!self.toolbarContainerView) { |
318 self.toolbarContainerView = [ | 294 self.toolbarContainerView = |
319 [[CRWToolbarContainerView alloc] initWithFrame:CGRectZero] autorelease]; | 295 [[CRWToolbarContainerView alloc] initWithFrame:CGRectZero]; |
320 } | 296 } |
321 // Add the toolbar to the container. | 297 // Add the toolbar to the container. |
322 [self.toolbarContainerView addToolbar:toolbar]; | 298 [self.toolbarContainerView addToolbar:toolbar]; |
323 [self setNeedsLayout]; | 299 [self setNeedsLayout]; |
324 } | 300 } |
325 | 301 |
326 - (void)addToolbars:(NSArray*)toolbars { | 302 - (void)addToolbars:(NSArray*)toolbars { |
327 DCHECK(toolbars); | 303 DCHECK(toolbars); |
328 for (UIView* toolbar in toolbars) | 304 for (UIView* toolbar in toolbars) |
329 [self addToolbar:toolbar]; | 305 [self addToolbar:toolbar]; |
330 } | 306 } |
331 | 307 |
332 - (void)removeToolbar:(UIView*)toolbar { | 308 - (void)removeToolbar:(UIView*)toolbar { |
333 // Remove the toolbar from the container view. | 309 // Remove the toolbar from the container view. |
334 [self.toolbarContainerView removeToolbar:toolbar]; | 310 [self.toolbarContainerView removeToolbar:toolbar]; |
335 // Reset the container if there are no more toolbars. | 311 // Reset the container if there are no more toolbars. |
336 if ([self.toolbarContainerView.toolbars count]) | 312 if ([self.toolbarContainerView.toolbars count]) |
337 [self setNeedsLayout]; | 313 [self setNeedsLayout]; |
338 else | 314 else |
339 self.toolbarContainerView = nil; | 315 self.toolbarContainerView = nil; |
340 } | 316 } |
341 | 317 |
342 - (void)removeAllToolbars { | 318 - (void)removeAllToolbars { |
343 // Resetting the property will remove the toolbars from the hierarchy. | 319 // Resetting the property will remove the toolbars from the hierarchy. |
344 self.toolbarContainerView = nil; | 320 self.toolbarContainerView = nil; |
345 } | 321 } |
346 | 322 |
347 @end | 323 @end |
OLD | NEW |