Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: ios/web/web_state/ui/crw_web_controller_container_view.mm

Issue 2396553002: [ARC] Converts part of ios/web/ui to ARC.
Patch Set: co Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "base/ios/weak_nsobject.h"
8 #include "base/logging.h" 7 #include "base/logging.h"
9 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
10 #import "ios/web/public/web_state/ui/crw_content_view.h" 9 #import "ios/web/public/web_state/ui/crw_content_view.h"
11 #import "ios/web/public/web_state/ui/crw_native_content.h" 10 #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" 11 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h"
13 #import "ios/web/web_state/crw_web_view_proxy_impl.h" 12 #import "ios/web/web_state/crw_web_view_proxy_impl.h"
14 13
14 #if !defined(__has_feature) || !__has_feature(objc_arc)
15 #error "This file requires ARC support."
16 #endif
17
15 #pragma mark - CRWToolbarContainerView 18 #pragma mark - CRWToolbarContainerView
16 19
17 // Class that manages the display of toolbars. 20 // Class that manages the display of toolbars.
18 @interface CRWToolbarContainerView : UIView { 21 @interface CRWToolbarContainerView : UIView {
19 // Backing object for |self.toolbars|. 22 // Backing object for |self.toolbars|.
20 base::scoped_nsobject<NSMutableArray> _toolbars; 23 base::scoped_nsobject<NSMutableArray> _toolbars;
21 } 24 }
22 25
23 // The toolbars currently managed by this view. 26 // The toolbars currently managed by this view.
24 @property(nonatomic, retain, readonly) NSMutableArray* toolbars; 27 @property(nonatomic, strong, readonly) NSMutableArray* toolbars;
25 28
26 // Adds |toolbar| as a subview and bottom aligns to any previously added 29 // Adds |toolbar| as a subview and bottom aligns to any previously added
27 // toolbars. 30 // toolbars.
28 - (void)addToolbar:(UIView*)toolbar; 31 - (void)addToolbar:(UIView*)toolbar;
29 32
30 // Removes |toolbar| from the container view. 33 // Removes |toolbar| from the container view.
31 - (void)removeToolbar:(UIView*)toolbar; 34 - (void)removeToolbar:(UIView*)toolbar;
32 35
33 @end 36 @end
34 37
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 [self.toolbars removeObject:toolbar]; 86 [self.toolbars removeObject:toolbar];
84 [toolbar removeFromSuperview]; 87 [toolbar removeFromSuperview];
85 } 88 }
86 89
87 @end 90 @end
88 91
89 #pragma mark - CRWWebControllerContainerView 92 #pragma mark - CRWWebControllerContainerView
90 93
91 @interface CRWWebControllerContainerView () { 94 @interface CRWWebControllerContainerView () {
92 // The delegate passed on initialization. 95 // The delegate passed on initialization.
93 base::WeakNSProtocol<id<CRWWebControllerContainerViewDelegate>> _delegate; 96 __weak id<CRWWebControllerContainerViewDelegate> _delegate;
94 // Backing objects for corresponding properties. 97 // Backing objects for corresponding properties.
95 base::scoped_nsobject<CRWWebViewContentView> _webViewContentView; 98 base::scoped_nsobject<CRWWebViewContentView> _webViewContentView;
96 base::scoped_nsprotocol<id<CRWNativeContent>> _nativeController; 99 base::scoped_nsprotocol<id<CRWNativeContent>> _nativeController;
97 base::scoped_nsobject<CRWContentView> _transientContentView; 100 base::scoped_nsobject<CRWContentView> _transientContentView;
98 base::scoped_nsobject<CRWToolbarContainerView> _toolbarContainerView; 101 base::scoped_nsobject<CRWToolbarContainerView> _toolbarContainerView;
99 } 102 }
100 103
101 // Redefine properties as readwrite. 104 // Redefine properties as readwrite.
102 @property(nonatomic, retain, readwrite) 105 @property(nonatomic, strong, readwrite)
103 CRWWebViewContentView* webViewContentView; 106 CRWWebViewContentView* webViewContentView;
104 @property(nonatomic, retain, readwrite) id<CRWNativeContent> nativeController; 107 @property(nonatomic, strong, readwrite) id<CRWNativeContent> nativeController;
105 @property(nonatomic, retain, readwrite) CRWContentView* transientContentView; 108 @property(nonatomic, strong, readwrite) CRWContentView* transientContentView;
106 109
107 // Container view that displays any added toolbars. It is always the top-most 110 // Container view that displays any added toolbars. It is always the top-most
108 // subview, and is bottom aligned with the CRWWebControllerContainerView. 111 // subview, and is bottom aligned with the CRWWebControllerContainerView.
109 @property(nonatomic, retain, readonly) 112 @property(nonatomic, strong, readonly)
110 CRWToolbarContainerView* toolbarContainerView; 113 CRWToolbarContainerView* toolbarContainerView;
111 114
112 // Convenience getter for the proxy object. 115 // Convenience getter for the proxy object.
113 @property(nonatomic, readonly) CRWWebViewProxyImpl* contentViewProxy; 116 @property(weak, nonatomic, readonly) CRWWebViewProxyImpl* contentViewProxy;
114 117
115 // Returns |self.bounds| after being inset at the top by the header height 118 // 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, 119 // 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 120 // as the header height is already accounted for in the scroll view content
118 // insets for other CRWContentViews. 121 // insets for other CRWContentViews.
119 @property(nonatomic, readonly) CGRect visibleFrame; 122 @property(nonatomic, readonly) CGRect visibleFrame;
120 123
121 @end 124 @end
122 125
123 @implementation CRWWebControllerContainerView 126 @implementation CRWWebControllerContainerView
(...skipping 16 matching lines...) Expand all
140 return nil; 143 return nil;
141 } 144 }
142 145
143 - (instancetype)initWithFrame:(CGRect)frame { 146 - (instancetype)initWithFrame:(CGRect)frame {
144 NOTREACHED(); 147 NOTREACHED();
145 return nil; 148 return nil;
146 } 149 }
147 150
148 - (void)dealloc { 151 - (void)dealloc {
149 self.contentViewProxy.contentView = nil; 152 self.contentViewProxy.contentView = nil;
150 [super dealloc];
151 } 153 }
152 154
153 #pragma mark Accessors 155 #pragma mark Accessors
154 156
155 - (CRWWebViewContentView*)webViewContentView { 157 - (CRWWebViewContentView*)webViewContentView {
156 return _webViewContentView.get(); 158 return _webViewContentView.get();
157 } 159 }
158 160
159 - (void)setWebViewContentView:(CRWWebViewContentView*)webViewContentView { 161 - (void)setWebViewContentView:(CRWWebViewContentView*)webViewContentView {
160 if (![_webViewContentView isEqual:webViewContentView]) { 162 if (![_webViewContentView isEqual:webViewContentView]) {
161 [_webViewContentView removeFromSuperview]; 163 [_webViewContentView removeFromSuperview];
162 _webViewContentView.reset([webViewContentView retain]); 164 _webViewContentView.reset(webViewContentView);
163 [_webViewContentView setFrame:self.bounds]; 165 [_webViewContentView setFrame:self.bounds];
164 [self addSubview:_webViewContentView]; 166 [self addSubview:_webViewContentView];
165 } 167 }
166 } 168 }
167 169
168 - (id<CRWNativeContent>)nativeController { 170 - (id<CRWNativeContent>)nativeController {
169 return _nativeController.get(); 171 return _nativeController.get();
170 } 172 }
171 173
172 - (void)setNativeController:(id<CRWNativeContent>)nativeController { 174 - (void)setNativeController:(id<CRWNativeContent>)nativeController {
173 if (![_nativeController isEqual:nativeController]) { 175 if (![_nativeController isEqual:nativeController]) {
174 base::WeakNSProtocol<id> oldController(_nativeController); 176 __weak id oldController = _nativeController;
175 [[oldController view] removeFromSuperview]; 177 [[oldController view] removeFromSuperview];
176 _nativeController.reset([nativeController retain]); 178 _nativeController.reset(nativeController);
177 // TODO(crbug.com/503297): Re-enable this DCHECK once native controller 179 // TODO(crbug.com/503297): Re-enable this DCHECK once native controller
178 // leaks are fixed. 180 // leaks are fixed.
179 // DCHECK(!oldController); 181 // DCHECK(!oldController);
180 } 182 }
181 } 183 }
182 184
183 - (CRWContentView*)transientContentView { 185 - (CRWContentView*)transientContentView {
184 return _transientContentView.get(); 186 return _transientContentView.get();
185 } 187 }
186 188
187 - (void)setTransientContentView:(CRWContentView*)transientContentView { 189 - (void)setTransientContentView:(CRWContentView*)transientContentView {
188 if (![_transientContentView isEqual:transientContentView]) { 190 if (![_transientContentView isEqual:transientContentView]) {
189 [_transientContentView removeFromSuperview]; 191 [_transientContentView removeFromSuperview];
190 _transientContentView.reset([transientContentView retain]); 192 _transientContentView.reset(transientContentView);
191 } 193 }
192 } 194 }
193 195
194 - (void)setToolbarContainerView:(CRWToolbarContainerView*)toolbarContainerView { 196 - (void)setToolbarContainerView:(CRWToolbarContainerView*)toolbarContainerView {
195 if (![_toolbarContainerView isEqual:toolbarContainerView]) { 197 if (![_toolbarContainerView isEqual:toolbarContainerView]) {
196 [_toolbarContainerView removeFromSuperview]; 198 [_toolbarContainerView removeFromSuperview];
197 _toolbarContainerView.reset([toolbarContainerView retain]); 199 _toolbarContainerView.reset(toolbarContainerView);
198 } 200 }
199 } 201 }
200 202
201 - (UIView*)toolbarContainerView { 203 - (UIView*)toolbarContainerView {
202 return _toolbarContainerView.get(); 204 return _toolbarContainerView.get();
203 } 205 }
204 206
205 - (CRWWebViewProxyImpl*)contentViewProxy { 207 - (CRWWebViewProxyImpl*)contentViewProxy {
206 return [_delegate contentViewProxyForContainerView:self]; 208 return [_delegate contentViewProxyForContainerView:self];
207 } 209 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 self.transientContentView = transientContentView; 294 self.transientContentView = transientContentView;
293 self.contentViewProxy.contentView = self.transientContentView; 295 self.contentViewProxy.contentView = self.transientContentView;
294 [self setNeedsLayout]; 296 [self setNeedsLayout];
295 } 297 }
296 298
297 - (void)clearTransientContentView { 299 - (void)clearTransientContentView {
298 self.transientContentView = nil; 300 self.transientContentView = nil;
299 self.contentViewProxy.contentView = self.webViewContentView; 301 self.contentViewProxy.contentView = self.webViewContentView;
300 } 302 }
301 303
304 - (void)setDelegate:(id<CRWWebControllerContainerViewDelegate>)delegate {
305 _delegate.reset(delegate);
306 }
307
302 #pragma mark Toolbars 308 #pragma mark Toolbars
303 309
304 - (void)addToolbar:(UIView*)toolbar { 310 - (void)addToolbar:(UIView*)toolbar {
305 // Create toolbar container if necessary. 311 // Create toolbar container if necessary.
306 if (!self.toolbarContainerView) { 312 if (!self.toolbarContainerView) {
307 self.toolbarContainerView = [ 313 self.toolbarContainerView =
308 [[CRWToolbarContainerView alloc] initWithFrame:CGRectZero] autorelease]; 314 [[CRWToolbarContainerView alloc] initWithFrame:CGRectZero];
309 } 315 }
310 // Add the toolbar to the container. 316 // Add the toolbar to the container.
311 [self.toolbarContainerView addToolbar:toolbar]; 317 [self.toolbarContainerView addToolbar:toolbar];
312 [self setNeedsLayout]; 318 [self setNeedsLayout];
313 } 319 }
314 320
315 - (void)addToolbars:(NSArray*)toolbars { 321 - (void)addToolbars:(NSArray*)toolbars {
316 DCHECK(toolbars); 322 DCHECK(toolbars);
317 for (UIView* toolbar in toolbars) 323 for (UIView* toolbar in toolbars)
318 [self addToolbar:toolbar]; 324 [self addToolbar:toolbar];
319 } 325 }
320 326
321 - (void)removeToolbar:(UIView*)toolbar { 327 - (void)removeToolbar:(UIView*)toolbar {
322 // Remove the toolbar from the container view. 328 // Remove the toolbar from the container view.
323 [self.toolbarContainerView removeToolbar:toolbar]; 329 [self.toolbarContainerView removeToolbar:toolbar];
324 // Reset the container if there are no more toolbars. 330 // Reset the container if there are no more toolbars.
325 if ([self.toolbarContainerView.toolbars count]) 331 if ([self.toolbarContainerView.toolbars count])
326 [self setNeedsLayout]; 332 [self setNeedsLayout];
327 else 333 else
328 self.toolbarContainerView = nil; 334 self.toolbarContainerView = nil;
329 } 335 }
330 336
331 - (void)removeAllToolbars { 337 - (void)removeAllToolbars {
332 // Resetting the property will remove the toolbars from the hierarchy. 338 // Resetting the property will remove the toolbars from the hierarchy.
333 self.toolbarContainerView = nil; 339 self.toolbarContainerView = nil;
334 } 340 }
335 341
336 @end 342 @end
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller_container_view.h ('k') | ios/web/web_state/ui/crw_web_view_content_view.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698