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 30 matching lines...) Expand all Loading... | |
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. | 94 // The delegate passed on initialization. |
93 base::WeakNSProtocol<id<CRWWebControllerContainerViewDelegate>> _delegate; | 95 __weak id<CRWWebControllerContainerViewDelegate> _delegate; |
94 // Backing objects for corresponding properties. | 96 // Backing objects for corresponding properties. |
95 base::scoped_nsobject<CRWWebViewContentView> _webViewContentView; | 97 CRWWebViewContentView* _webViewContentView; |
96 base::scoped_nsprotocol<id<CRWNativeContent>> _nativeController; | 98 id<CRWNativeContent> _nativeController; |
97 base::scoped_nsobject<CRWContentView> _transientContentView; | 99 CRWContentView* _transientContentView; |
98 base::scoped_nsobject<CRWToolbarContainerView> _toolbarContainerView; | 100 CRWToolbarContainerView* _toolbarContainerView; |
99 } | 101 } |
100 | 102 |
101 // Redefine properties as readwrite. | 103 // Redefine properties as readwrite. |
102 @property(nonatomic, retain, readwrite) | 104 @property(nonatomic, strong, readwrite) |
103 CRWWebViewContentView* webViewContentView; | 105 CRWWebViewContentView* webViewContentView; |
104 @property(nonatomic, retain, readwrite) id<CRWNativeContent> nativeController; | 106 @property(nonatomic, strong, readwrite) id<CRWNativeContent> nativeController; |
105 @property(nonatomic, retain, readwrite) CRWContentView* transientContentView; | 107 @property(nonatomic, strong, readwrite) CRWContentView* transientContentView; |
106 | 108 |
107 // Container view that displays any added toolbars. It is always the top-most | 109 // Container view that displays any added toolbars. It is always the top-most |
108 // subview, and is bottom aligned with the CRWWebControllerContainerView. | 110 // subview, and is bottom aligned with the CRWWebControllerContainerView. |
109 @property(nonatomic, retain, readonly) | 111 @property(nonatomic, strong, readonly) |
110 CRWToolbarContainerView* toolbarContainerView; | 112 CRWToolbarContainerView* toolbarContainerView; |
111 | 113 |
112 // Convenience getter for the proxy object. | 114 // Convenience getter for the proxy object. |
113 @property(nonatomic, readonly) CRWWebViewProxyImpl* contentViewProxy; | 115 @property(weak, nonatomic, readonly) CRWWebViewProxyImpl* contentViewProxy; |
114 | 116 |
115 // Returns |self.bounds| after being inset at the top by the header height | 117 // 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, | 118 // 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 | 119 // as the header height is already accounted for in the scroll view content |
118 // insets for other CRWContentViews. | 120 // insets for other CRWContentViews. |
119 @property(nonatomic, readonly) CGRect visibleFrame; | 121 @property(nonatomic, readonly) CGRect visibleFrame; |
120 | 122 |
121 @end | 123 @end |
122 | 124 |
123 @implementation CRWWebControllerContainerView | 125 @implementation CRWWebControllerContainerView |
124 | 126 |
125 - (instancetype)initWithDelegate: | 127 - (instancetype)initWithDelegate: |
126 (id<CRWWebControllerContainerViewDelegate>)delegate { | 128 (id<CRWWebControllerContainerViewDelegate>)delegate { |
127 self = [super initWithFrame:CGRectZero]; | 129 self = [super initWithFrame:CGRectZero]; |
128 if (self) { | 130 if (self) { |
129 DCHECK(delegate); | 131 DCHECK(delegate); |
130 _delegate.reset(delegate); | 132 _delegate = delegate; |
131 self.backgroundColor = [UIColor whiteColor]; | 133 self.backgroundColor = [UIColor whiteColor]; |
132 self.autoresizingMask = | 134 self.autoresizingMask = |
133 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 135 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
134 } | 136 } |
135 return self; | 137 return self; |
136 } | 138 } |
137 | 139 |
138 - (instancetype)initWithCoder:(NSCoder*)decoder { | 140 - (instancetype)initWithCoder:(NSCoder*)decoder { |
139 NOTREACHED(); | 141 NOTREACHED(); |
140 return nil; | 142 return nil; |
141 } | 143 } |
142 | 144 |
143 - (instancetype)initWithFrame:(CGRect)frame { | 145 - (instancetype)initWithFrame:(CGRect)frame { |
144 NOTREACHED(); | 146 NOTREACHED(); |
145 return nil; | 147 return nil; |
146 } | 148 } |
147 | 149 |
148 - (void)dealloc { | 150 - (void)dealloc { |
149 self.contentViewProxy.contentView = nil; | 151 self.contentViewProxy.contentView = nil; |
150 [super dealloc]; | |
151 } | 152 } |
152 | 153 |
153 #pragma mark Accessors | 154 #pragma mark Accessors |
154 | 155 |
155 - (CRWWebViewContentView*)webViewContentView { | 156 - (CRWWebViewContentView*)webViewContentView { |
Eugene But (OOO till 7-30)
2017/06/12 06:12:51
Should we synthesize this method instead?
PL
2017/06/14 00:31:11
Yes! Done!
| |
156 return _webViewContentView.get(); | 157 return _webViewContentView; |
157 } | 158 } |
158 | 159 |
159 - (void)setWebViewContentView:(CRWWebViewContentView*)webViewContentView { | 160 - (void)setWebViewContentView:(CRWWebViewContentView*)webViewContentView { |
160 if (![_webViewContentView isEqual:webViewContentView]) { | 161 if (![_webViewContentView isEqual:webViewContentView]) { |
161 [_webViewContentView removeFromSuperview]; | 162 [_webViewContentView removeFromSuperview]; |
162 _webViewContentView.reset([webViewContentView retain]); | 163 _webViewContentView = webViewContentView; |
163 [_webViewContentView setFrame:self.bounds]; | 164 [_webViewContentView setFrame:self.bounds]; |
164 [self addSubview:_webViewContentView]; | 165 [self addSubview:_webViewContentView]; |
165 } | 166 } |
166 } | 167 } |
167 | 168 |
168 - (id<CRWNativeContent>)nativeController { | 169 - (id<CRWNativeContent>)nativeController { |
Eugene But (OOO till 7-30)
2017/06/12 06:12:51
ditto
PL
2017/06/14 00:31:11
Done!
| |
169 return _nativeController.get(); | 170 return _nativeController; |
170 } | 171 } |
171 | 172 |
172 - (void)setNativeController:(id<CRWNativeContent>)nativeController { | 173 - (void)setNativeController:(id<CRWNativeContent>)nativeController { |
173 if (![_nativeController isEqual:nativeController]) { | 174 if (![_nativeController isEqual:nativeController]) { |
174 base::WeakNSProtocol<id> oldController(_nativeController); | 175 __weak id oldController = _nativeController; |
175 if ([oldController respondsToSelector:@selector(willBeDismissed)]) { | 176 if ([oldController respondsToSelector:@selector(willBeDismissed)]) { |
176 [oldController willBeDismissed]; | 177 [oldController willBeDismissed]; |
177 } | 178 } |
178 [[oldController view] removeFromSuperview]; | 179 [[oldController view] removeFromSuperview]; |
179 _nativeController.reset([nativeController retain]); | 180 _nativeController = nativeController; |
180 // TODO(crbug.com/503297): Re-enable this DCHECK once native controller | 181 // TODO(crbug.com/503297): Re-enable this DCHECK once native controller |
181 // leaks are fixed. | 182 // leaks are fixed. |
182 // DCHECK(!oldController); | 183 // DCHECK(!oldController); |
183 } | 184 } |
184 } | 185 } |
185 | 186 |
186 - (CRWContentView*)transientContentView { | 187 - (CRWContentView*)transientContentView { |
Eugene But (OOO till 7-30)
2017/06/12 06:12:51
ditto
PL
2017/06/14 00:31:11
Done!
| |
187 return _transientContentView.get(); | 188 return _transientContentView; |
188 } | 189 } |
189 | 190 |
190 - (void)setTransientContentView:(CRWContentView*)transientContentView { | 191 - (void)setTransientContentView:(CRWContentView*)transientContentView { |
191 if (![_transientContentView isEqual:transientContentView]) { | 192 if (![_transientContentView isEqual:transientContentView]) { |
192 [_transientContentView removeFromSuperview]; | 193 [_transientContentView removeFromSuperview]; |
193 _transientContentView.reset([transientContentView retain]); | 194 _transientContentView = transientContentView; |
194 } | 195 } |
195 } | 196 } |
196 | 197 |
197 - (void)setToolbarContainerView:(CRWToolbarContainerView*)toolbarContainerView { | 198 - (void)setToolbarContainerView:(CRWToolbarContainerView*)toolbarContainerView { |
198 if (![_toolbarContainerView isEqual:toolbarContainerView]) { | 199 if (![_toolbarContainerView isEqual:toolbarContainerView]) { |
199 [_toolbarContainerView removeFromSuperview]; | 200 [_toolbarContainerView removeFromSuperview]; |
200 _toolbarContainerView.reset([toolbarContainerView retain]); | 201 _toolbarContainerView = toolbarContainerView; |
201 } | 202 } |
202 } | 203 } |
203 | 204 |
204 - (UIView*)toolbarContainerView { | 205 - (UIView*)toolbarContainerView { |
Eugene But (OOO till 7-30)
2017/06/12 06:12:51
ditto
PL
2017/06/14 00:31:11
Done!
| |
205 return _toolbarContainerView.get(); | 206 return _toolbarContainerView; |
206 } | 207 } |
207 | 208 |
208 - (CRWWebViewProxyImpl*)contentViewProxy { | 209 - (CRWWebViewProxyImpl*)contentViewProxy { |
209 return [_delegate contentViewProxyForContainerView:self]; | 210 return [_delegate contentViewProxyForContainerView:self]; |
210 } | 211 } |
211 | 212 |
212 - (CGRect)visibleFrame { | 213 - (CGRect)visibleFrame { |
213 CGFloat headerHeight = [_delegate headerHeightForContainerView:self]; | 214 CGFloat headerHeight = [_delegate headerHeightForContainerView:self]; |
214 return UIEdgeInsetsInsetRect(self.bounds, | 215 return UIEdgeInsetsInsetRect(self.bounds, |
215 UIEdgeInsetsMake(headerHeight, 0, 0, 0)); | 216 UIEdgeInsetsMake(headerHeight, 0, 0, 0)); |
216 } | 217 } |
217 | 218 |
218 - (id<CRWWebControllerContainerViewDelegate>)delegate { | 219 - (id<CRWWebControllerContainerViewDelegate>)delegate { |
Eugene But (OOO till 7-30)
2017/06/12 06:12:52
Should we synthesize getter and setter instead? Sa
PL
2017/06/14 00:31:11
Done! We can do it easily for delegate, toolbarCon
| |
219 return _delegate.get(); | 220 return _delegate; |
220 } | 221 } |
221 | 222 |
222 - (void)setDelegate:(id<CRWWebControllerContainerViewDelegate>)delegate { | 223 - (void)setDelegate:(id<CRWWebControllerContainerViewDelegate>)delegate { |
223 _delegate.reset(delegate); | 224 _delegate = delegate; |
224 } | 225 } |
225 | 226 |
226 #pragma mark Layout | 227 #pragma mark Layout |
227 | 228 |
228 - (void)layoutSubviews { | 229 - (void)layoutSubviews { |
229 [super layoutSubviews]; | 230 [super layoutSubviews]; |
230 | 231 |
231 self.webViewContentView.frame = self.bounds; | 232 self.webViewContentView.frame = self.bounds; |
232 | 233 |
233 // TODO(crbug.com/570114): Move adding of the following subviews to another | 234 // TODO(crbug.com/570114): Move adding of the following subviews to another |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 - (void)clearTransientContentView { | 309 - (void)clearTransientContentView { |
309 self.transientContentView = nil; | 310 self.transientContentView = nil; |
310 self.contentViewProxy.contentView = self.webViewContentView; | 311 self.contentViewProxy.contentView = self.webViewContentView; |
311 } | 312 } |
312 | 313 |
313 #pragma mark Toolbars | 314 #pragma mark Toolbars |
314 | 315 |
315 - (void)addToolbar:(UIView*)toolbar { | 316 - (void)addToolbar:(UIView*)toolbar { |
316 // Create toolbar container if necessary. | 317 // Create toolbar container if necessary. |
317 if (!self.toolbarContainerView) { | 318 if (!self.toolbarContainerView) { |
318 self.toolbarContainerView = [ | 319 self.toolbarContainerView = |
319 [[CRWToolbarContainerView alloc] initWithFrame:CGRectZero] autorelease]; | 320 [[CRWToolbarContainerView alloc] initWithFrame:CGRectZero]; |
320 } | 321 } |
321 // Add the toolbar to the container. | 322 // Add the toolbar to the container. |
322 [self.toolbarContainerView addToolbar:toolbar]; | 323 [self.toolbarContainerView addToolbar:toolbar]; |
323 [self setNeedsLayout]; | 324 [self setNeedsLayout]; |
324 } | 325 } |
325 | 326 |
326 - (void)addToolbars:(NSArray*)toolbars { | 327 - (void)addToolbars:(NSArray*)toolbars { |
327 DCHECK(toolbars); | 328 DCHECK(toolbars); |
328 for (UIView* toolbar in toolbars) | 329 for (UIView* toolbar in toolbars) |
329 [self addToolbar:toolbar]; | 330 [self addToolbar:toolbar]; |
330 } | 331 } |
331 | 332 |
332 - (void)removeToolbar:(UIView*)toolbar { | 333 - (void)removeToolbar:(UIView*)toolbar { |
333 // Remove the toolbar from the container view. | 334 // Remove the toolbar from the container view. |
334 [self.toolbarContainerView removeToolbar:toolbar]; | 335 [self.toolbarContainerView removeToolbar:toolbar]; |
335 // Reset the container if there are no more toolbars. | 336 // Reset the container if there are no more toolbars. |
336 if ([self.toolbarContainerView.toolbars count]) | 337 if ([self.toolbarContainerView.toolbars count]) |
337 [self setNeedsLayout]; | 338 [self setNeedsLayout]; |
338 else | 339 else |
339 self.toolbarContainerView = nil; | 340 self.toolbarContainerView = nil; |
340 } | 341 } |
341 | 342 |
342 - (void)removeAllToolbars { | 343 - (void)removeAllToolbars { |
343 // Resetting the property will remove the toolbars from the hierarchy. | 344 // Resetting the property will remove the toolbars from the hierarchy. |
344 self.toolbarContainerView = nil; | 345 self.toolbarContainerView = nil; |
345 } | 346 } |
346 | 347 |
347 @end | 348 @end |
OLD | NEW |