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

Side by Side Diff: ios/chrome/browser/ui/authentication/signin_confirmation_view_controller.mm

Issue 2936583002: [ObjC ARC] Converts ios/chrome/browser/ui/authentication:authentication to ARC. (Closed)
Patch Set: Review fixes. Created 3 years, 6 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "ios/chrome/browser/ui/authentication/signin_confirmation_view_controll er.h" 5 #include "ios/chrome/browser/ui/authentication/signin_confirmation_view_controll er.h"
6 6
7 #import "base/ios/weak_nsobject.h"
8 #import "base/mac/foundation_util.h" 7 #import "base/mac/foundation_util.h"
9 #import "base/mac/scoped_nsobject.h"
10 #include "base/metrics/user_metrics.h" 8 #include "base/metrics/user_metrics.h"
11 #import "base/strings/sys_string_conversions.h" 9 #import "base/strings/sys_string_conversions.h"
12 #include "components/google/core/browser/google_util.h" 10 #include "components/google/core/browser/google_util.h"
13 #include "ios/chrome/browser/application_context.h" 11 #include "ios/chrome/browser/application_context.h"
14 #include "ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h" 12 #include "ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h"
15 #import "ios/chrome/browser/ui/authentication/account_control_item.h" 13 #import "ios/chrome/browser/ui/authentication/account_control_item.h"
16 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 14 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h" 15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item .h"
18 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 16 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
19 #import "ios/chrome/browser/ui/uikit_ui_util.h" 17 #import "ios/chrome/browser/ui/uikit_ui_util.h"
20 #import "ios/chrome/common/string_util.h" 18 #import "ios/chrome/common/string_util.h"
21 #include "ios/chrome/grit/ios_chromium_strings.h" 19 #include "ios/chrome/grit/ios_chromium_strings.h"
22 #include "ios/chrome/grit/ios_strings.h" 20 #include "ios/chrome/grit/ios_strings.h"
23 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" 21 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
24 #include "ios/public/provider/chrome/browser/images/branded_image_provider.h" 22 #include "ios/public/provider/chrome/browser/images/branded_image_provider.h"
25 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" 23 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h"
26 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" 24 #import "ios/public/provider/chrome/browser/signin/chrome_identity_service.h"
27 #include "ios/public/provider/chrome/browser/signin/signin_resources_provider.h" 25 #include "ios/public/provider/chrome/browser/signin/signin_resources_provider.h"
28 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater ialAppBar.h" 26 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater ialAppBar.h"
29 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" 27 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
30 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 28 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
31 #import "ui/base/l10n/l10n_util.h" 29 #import "ui/base/l10n/l10n_util.h"
32 #include "url/gurl.h" 30 #include "url/gurl.h"
33 31
32 #if !defined(__has_feature) || !__has_feature(objc_arc)
33 #error "This file requires ARC support."
34 #endif
35
34 namespace { 36 namespace {
35 const CGFloat kAccountImageDimension = 64.; 37 const CGFloat kAccountImageDimension = 64.;
36 const CGFloat kHeaderViewMinHeight = 170.; 38 const CGFloat kHeaderViewMinHeight = 170.;
37 const CGFloat kHeaderViewHeightMultiplier = 0.33; 39 const CGFloat kHeaderViewHeightMultiplier = 0.33;
38 const CGFloat kContentViewBottomInset = 40.; 40 const CGFloat kContentViewBottomInset = 40.;
39 // Leading separator inset. 41 // Leading separator inset.
40 const CGFloat kLeadingSeparatorInset = 30.; 42 const CGFloat kLeadingSeparatorInset = 30.;
41 // Trailing separator inset. 43 // Trailing separator inset.
42 const CGFloat kTrailingSeparatorInset = 16.; 44 const CGFloat kTrailingSeparatorInset = 16.;
43 45
(...skipping 24 matching lines...) Expand all
68 ItemTypeGoogleServices, 70 ItemTypeGoogleServices,
69 ItemTypeFooter, 71 ItemTypeFooter,
70 }; 72 };
71 } 73 }
72 74
73 #pragma mark - SigninConfirmationViewController 75 #pragma mark - SigninConfirmationViewController
74 76
75 @interface SigninConfirmationViewController ()< 77 @interface SigninConfirmationViewController ()<
76 ChromeIdentityServiceObserver, 78 ChromeIdentityServiceObserver,
77 CollectionViewFooterLinkDelegate> { 79 CollectionViewFooterLinkDelegate> {
78 base::scoped_nsobject<ChromeIdentity> _identity; 80 ChromeIdentity* _identity;
79 std::unique_ptr<ChromeIdentityServiceObserverBridge> _identityServiceObserver; 81 std::unique_ptr<ChromeIdentityServiceObserverBridge> _identityServiceObserver;
80 base::WeakNSObject<UIImage> _oldImage; 82 __weak UIImage* _oldImage;
81 base::scoped_nsobject<UIImageView> _imageView; 83 UIImageView* _imageView;
82 base::scoped_nsobject<UILabel> _titleLabel; 84 UILabel* _titleLabel;
83 base::scoped_nsobject<UILabel> _emailLabel; 85 UILabel* _emailLabel;
84 } 86 }
85 @end 87 @end
86 88
87 @implementation SigninConfirmationViewController 89 @implementation SigninConfirmationViewController
88 90
89 @synthesize delegate; 91 @synthesize delegate;
90 92
91 - (instancetype)initWithIdentity:(ChromeIdentity*)identity { 93 - (instancetype)initWithIdentity:(ChromeIdentity*)identity {
92 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; 94 self = [super initWithStyle:CollectionViewControllerStyleAppBar];
93 if (self) { 95 if (self) {
94 _identity.reset([identity retain]); 96 _identity = identity;
95 _identityServiceObserver.reset( 97 _identityServiceObserver.reset(
96 new ChromeIdentityServiceObserverBridge(self)); 98 new ChromeIdentityServiceObserverBridge(self));
97 } 99 }
98 return self; 100 return self;
99 } 101 }
100 102
101 - (void)scrollToBottom { 103 - (void)scrollToBottom {
102 CGPoint bottomOffset = CGPointMake( 104 CGPoint bottomOffset = CGPointMake(
103 0, self.collectionView.contentSize.height - 105 0, self.collectionView.contentSize.height -
104 self.collectionView.bounds.size.height + kContentViewBottomInset); 106 self.collectionView.bounds.size.height + kContentViewBottomInset);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 .collectionViewContentSize.height]; 140 .collectionViewContentSize.height];
139 if (!didSend && [self isMovingToParentViewController]) { 141 if (!didSend && [self isMovingToParentViewController]) {
140 // The confirmation screen just appeared and there wasn't enough space to 142 // The confirmation screen just appeared and there wasn't enough space to
141 // show the full screen (since the scroll hasn't reach the botton). This 143 // show the full screen (since the scroll hasn't reach the botton). This
142 // means the "More" button is actually necessary. 144 // means the "More" button is actually necessary.
143 base::RecordAction(base::UserMetricsAction("Signin_MoreButton_Shown")); 145 base::RecordAction(base::UserMetricsAction("Signin_MoreButton_Shown"));
144 } 146 }
145 } 147 }
146 148
147 - (UIView*)contentViewWithFrame:(CGRect)frame { 149 - (UIView*)contentViewWithFrame:(CGRect)frame {
148 base::scoped_nsobject<UIView> contentView( 150 UIView* contentView = [[UIView alloc] initWithFrame:frame];
149 [[UIView alloc] initWithFrame:frame]); 151 contentView.autoresizingMask =
150 contentView.get().autoresizingMask =
151 (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 152 (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
152 contentView.get().clipsToBounds = YES; 153 contentView.clipsToBounds = YES;
153 _imageView.reset([[UIImageView alloc] init]); 154 _imageView = [[UIImageView alloc] init];
154 _imageView.get().translatesAutoresizingMaskIntoConstraints = NO; 155 _imageView.translatesAutoresizingMaskIntoConstraints = NO;
155 156
156 _titleLabel.reset([[UILabel alloc] initWithFrame:CGRectZero]); 157 _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
157 _titleLabel.get().textColor = [[MDCPalette greyPalette] tint900]; 158 _titleLabel.textColor = [[MDCPalette greyPalette] tint900];
158 _titleLabel.get().font = [MDCTypography headlineFont]; 159 _titleLabel.font = [MDCTypography headlineFont];
159 _titleLabel.get().translatesAutoresizingMaskIntoConstraints = NO; 160 _titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
160 161
161 _emailLabel.reset([[UILabel alloc] initWithFrame:CGRectZero]); 162 _emailLabel = [[UILabel alloc] initWithFrame:CGRectZero];
162 _emailLabel.get().textColor = [[MDCPalette greyPalette] tint700]; 163 _emailLabel.textColor = [[MDCPalette greyPalette] tint700];
163 _emailLabel.get().font = [MDCTypography body1Font]; 164 _emailLabel.font = [MDCTypography body1Font];
164 _emailLabel.get().translatesAutoresizingMaskIntoConstraints = NO; 165 _emailLabel.translatesAutoresizingMaskIntoConstraints = NO;
165 166
166 [self updateViewWithIdentity:_identity]; 167 [self updateViewWithIdentity:_identity];
167 168
168 base::scoped_nsobject<UIView> divider( 169 UIView* divider = [[UIView alloc] initWithFrame:CGRectZero];
169 [[UIView alloc] initWithFrame:CGRectZero]); 170 divider.backgroundColor = [[MDCPalette greyPalette] tint300];
170 divider.get().backgroundColor = [[MDCPalette greyPalette] tint300]; 171 divider.translatesAutoresizingMaskIntoConstraints = NO;
171 divider.get().translatesAutoresizingMaskIntoConstraints = NO;
172 172
173 base::scoped_nsobject<UILayoutGuide> layoutGuide1( 173 UILayoutGuide* layoutGuide1 = [[UILayoutGuide alloc] init];
174 [[UILayoutGuide alloc] init]); 174 UILayoutGuide* layoutGuide2 = [[UILayoutGuide alloc] init];
175 base::scoped_nsobject<UILayoutGuide> layoutGuide2(
176 [[UILayoutGuide alloc] init]);
177 175
178 [contentView addSubview:_imageView]; 176 [contentView addSubview:_imageView];
179 [contentView addSubview:_titleLabel]; 177 [contentView addSubview:_titleLabel];
180 [contentView addSubview:_emailLabel]; 178 [contentView addSubview:_emailLabel];
181 [contentView addSubview:divider]; 179 [contentView addSubview:divider];
182 [contentView addLayoutGuide:layoutGuide1]; 180 [contentView addLayoutGuide:layoutGuide1];
183 [contentView addLayoutGuide:layoutGuide2]; 181 [contentView addLayoutGuide:layoutGuide2];
184 182
185 NSDictionary* views = @{ 183 NSDictionary* views = @{
186 @"image" : _imageView, 184 @"image" : _imageView,
187 @"title" : _titleLabel, 185 @"title" : _titleLabel,
188 @"email" : _emailLabel, 186 @"email" : _emailLabel,
189 @"divider" : divider, 187 @"divider" : divider,
190 @"v1" : layoutGuide1, 188 @"v1" : layoutGuide1,
191 @"v2" : layoutGuide2 189 @"v2" : layoutGuide2
192 }; 190 };
193 NSArray* constraints = @[ 191 NSArray* constraints = @[
194 @"V:[image]-(24)-[title]-(8)-[email]-(16)-[divider(==1)]|", 192 @"V:[image]-(24)-[title]-(8)-[email]-(16)-[divider(==1)]|",
195 @"H:|[v1][image]", 193 @"H:|[v1][image]",
196 @"H:|[v1(16)][title(<=440)][v2(>=v1)]|", 194 @"H:|[v1(16)][title(<=440)][v2(>=v1)]|",
197 @"H:|[v1][email]", 195 @"H:|[v1][email]",
198 @"H:|[divider]|", 196 @"H:|[divider]|",
199 ]; 197 ];
200 ApplyVisualConstraints(constraints, views); 198 ApplyVisualConstraints(constraints, views);
201 return contentView.autorelease(); 199 return contentView;
202 } 200 }
203 201
204 - (void)viewWillLayoutSubviews { 202 - (void)viewWillLayoutSubviews {
205 CGSize viewSize = self.view.bounds.size; 203 CGSize viewSize = self.view.bounds.size;
206 MDCFlexibleHeaderView* headerView = 204 MDCFlexibleHeaderView* headerView =
207 self.appBar.headerViewController.headerView; 205 self.appBar.headerViewController.headerView;
208 headerView.maximumHeight = 206 headerView.maximumHeight =
209 MAX(kHeaderViewMinHeight, kHeaderViewHeightMultiplier * viewSize.height); 207 MAX(kHeaderViewMinHeight, kHeaderViewHeightMultiplier * viewSize.height);
210 } 208 }
211 209
212 - (void)updateViewWithIdentity:(ChromeIdentity*)identity { 210 - (void)updateViewWithIdentity:(ChromeIdentity*)identity {
213 UIImage* identityImage = GetImageForIdentity(identity); 211 UIImage* identityImage = GetImageForIdentity(identity);
214 if (_oldImage.get() != identityImage) { 212 if (_oldImage != identityImage) {
215 _oldImage.reset(identityImage); 213 _oldImage = identityImage;
216 identityImage = 214 identityImage =
217 ResizeImage(identityImage, 215 ResizeImage(identityImage,
218 CGSizeMake(kAccountImageDimension, kAccountImageDimension), 216 CGSizeMake(kAccountImageDimension, kAccountImageDimension),
219 ProjectionMode::kAspectFit); 217 ProjectionMode::kAspectFit);
220 identityImage = 218 identityImage =
221 CircularImageFromImage(identityImage, kAccountImageDimension); 219 CircularImageFromImage(identityImage, kAccountImageDimension);
222 _imageView.get().image = identityImage; 220 _imageView.image = identityImage;
223 } 221 }
224 222
225 _titleLabel.get().text = l10n_util::GetNSStringF( 223 _titleLabel.text = l10n_util::GetNSStringF(
226 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_TITLE, 224 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_TITLE,
227 base::SysNSStringToUTF16([identity userFullName])); 225 base::SysNSStringToUTF16([identity userFullName]));
228 226
229 _emailLabel.get().text = [identity userEmail]; 227 _emailLabel.text = [identity userEmail];
230 } 228 }
231 229
232 #pragma mark - Model 230 #pragma mark - Model
233 231
234 - (void)loadModel { 232 - (void)loadModel {
235 [super loadModel]; 233 [super loadModel];
236 CollectionViewModel* model = self.collectionViewModel; 234 CollectionViewModel* model = self.collectionViewModel;
237 235
238 [model addSectionWithIdentifier:SectionIdentifierInfo]; 236 [model addSectionWithIdentifier:SectionIdentifierInfo];
239 [model addItem:[self syncItem] toSectionWithIdentifier:SectionIdentifierInfo]; 237 [model addItem:[self syncItem] toSectionWithIdentifier:SectionIdentifierInfo];
240 [model addItem:[self googleServicesItem] 238 [model addItem:[self googleServicesItem]
241 toSectionWithIdentifier:SectionIdentifierInfo]; 239 toSectionWithIdentifier:SectionIdentifierInfo];
242 [model addItem:[self openSettingsItem] 240 [model addItem:[self openSettingsItem]
243 toSectionWithIdentifier:SectionIdentifierInfo]; 241 toSectionWithIdentifier:SectionIdentifierInfo];
244 } 242 }
245 243
246 #pragma mark - Model items 244 #pragma mark - Model items
247 245
248 - (CollectionViewItem*)syncItem { 246 - (CollectionViewItem*)syncItem {
249 AccountControlItem* item = 247 AccountControlItem* item =
250 [[[AccountControlItem alloc] initWithType:ItemTypeSync] autorelease]; 248 [[AccountControlItem alloc] initWithType:ItemTypeSync];
251 item.text = l10n_util::GetNSString( 249 item.text = l10n_util::GetNSString(
252 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_SYNC_TITLE); 250 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_SYNC_TITLE);
253 item.detailText = l10n_util::GetNSString( 251 item.detailText = l10n_util::GetNSString(
254 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_SYNC_DESCRIPTION); 252 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_SYNC_DESCRIPTION);
255 item.image = ios::GetChromeBrowserProvider() 253 item.image = ios::GetChromeBrowserProvider()
256 ->GetBrandedImageProvider() 254 ->GetBrandedImageProvider()
257 ->GetSigninConfirmationSyncSettingsImage(); 255 ->GetSigninConfirmationSyncSettingsImage();
258 return item; 256 return item;
259 } 257 }
260 258
261 - (CollectionViewItem*)googleServicesItem { 259 - (CollectionViewItem*)googleServicesItem {
262 AccountControlItem* item = [[[AccountControlItem alloc] 260 AccountControlItem* item =
263 initWithType:ItemTypeGoogleServices] autorelease]; 261 [[AccountControlItem alloc] initWithType:ItemTypeGoogleServices];
264 item.text = l10n_util::GetNSString( 262 item.text = l10n_util::GetNSString(
265 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_SERVICES_TITLE); 263 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_SERVICES_TITLE);
266 item.detailText = l10n_util::GetNSString( 264 item.detailText = l10n_util::GetNSString(
267 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_SERVICES_DESCRIPTION); 265 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_SERVICES_DESCRIPTION);
268 item.image = ios::GetChromeBrowserProvider() 266 item.image = ios::GetChromeBrowserProvider()
269 ->GetBrandedImageProvider() 267 ->GetBrandedImageProvider()
270 ->GetSigninConfirmationPersonalizeServicesImage(); 268 ->GetSigninConfirmationPersonalizeServicesImage();
271 return item; 269 return item;
272 } 270 }
273 271
274 - (CollectionViewItem*)openSettingsItem { 272 - (CollectionViewItem*)openSettingsItem {
275 CollectionViewFooterItem* item = [[[CollectionViewFooterItem alloc] 273 CollectionViewFooterItem* item =
276 initWithType:ItemTypeFooter] autorelease]; 274 [[CollectionViewFooterItem alloc] initWithType:ItemTypeFooter];
277 item.text = l10n_util::GetNSString( 275 item.text = l10n_util::GetNSString(
278 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OPEN_SETTINGS); 276 IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_OPEN_SETTINGS);
279 item.linkURL = google_util::AppendGoogleLocaleParam( 277 item.linkURL = google_util::AppendGoogleLocaleParam(
280 GURL("internal://settings-sync"), 278 GURL("internal://settings-sync"),
281 GetApplicationContext()->GetApplicationLocale()); 279 GetApplicationContext()->GetApplicationLocale());
282 item.linkDelegate = self; 280 item.linkDelegate = self;
283 return item; 281 return item;
284 } 282 }
285 283
286 #pragma mark - Helpers 284 #pragma mark - Helpers
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 kTrailingSeparatorInset); 334 kTrailingSeparatorInset);
337 break; 335 break;
338 case ItemTypeGoogleServices: 336 case ItemTypeGoogleServices:
339 cell.shouldHideSeparator = YES; 337 cell.shouldHideSeparator = YES;
340 break; 338 break;
341 case ItemTypeFooter: { 339 case ItemTypeFooter: {
342 CollectionViewFooterCell* footerCell = 340 CollectionViewFooterCell* footerCell =
343 base::mac::ObjCCastStrict<CollectionViewFooterCell>(cell); 341 base::mac::ObjCCastStrict<CollectionViewFooterCell>(cell);
344 // TODO(crbug.com/664648): Must use atomic text formatting operation due 342 // TODO(crbug.com/664648): Must use atomic text formatting operation due
345 // to LabelLinkController bug. 343 // to LabelLinkController bug.
346 footerCell.textLabel.attributedText = [[[NSAttributedString alloc] 344 footerCell.textLabel.attributedText = [[NSAttributedString alloc]
347 initWithString:footerCell.textLabel.text 345 initWithString:footerCell.textLabel.text
348 attributes:@{ 346 attributes:@{
349 NSFontAttributeName : [MDCTypography body1Font], 347 NSFontAttributeName : [MDCTypography body1Font],
350 NSForegroundColorAttributeName : 348 NSForegroundColorAttributeName :
351 [[MDCPalette greyPalette] tint700] 349 [[MDCPalette greyPalette] tint700]
352 }] autorelease]; 350 }];
353 footerCell.horizontalPadding = 16; 351 footerCell.horizontalPadding = 16;
354 break; 352 break;
355 } 353 }
356 354
357 default: 355 default:
358 break; 356 break;
359 } 357 }
360 return cell; 358 return cell;
361 } 359 }
362 360
(...skipping 21 matching lines...) Expand all
384 return YES; 382 return YES;
385 } 383 }
386 384
387 #pragma mark - CollectionViewFooterLinkDelegate 385 #pragma mark - CollectionViewFooterLinkDelegate
388 386
389 - (void)cell:(CollectionViewFooterCell*)cell didTapLinkURL:(GURL)URL { 387 - (void)cell:(CollectionViewFooterCell*)cell didTapLinkURL:(GURL)URL {
390 [[self delegate] signinConfirmationControllerDidTapSettingsLink:self]; 388 [[self delegate] signinConfirmationControllerDidTapSettingsLink:self];
391 } 389 }
392 390
393 @end 391 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698