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/chrome/browser/ui/settings/sync_create_passphrase_collection_view_c
ontroller.h" | 5 #import "ios/chrome/browser/ui/settings/sync_create_passphrase_collection_view_c
ontroller.h" |
6 | 6 |
7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #import "base/mac/foundation_util.h" | 10 #import "base/mac/foundation_util.h" |
11 #import "base/mac/scoped_nsobject.h" | |
12 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
13 #include "components/strings/grit/components_strings.h" | 12 #include "components/strings/grit/components_strings.h" |
14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
15 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 14 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
16 #import "ios/chrome/browser/ui/settings/cells/byo_textfield_item.h" | 15 #import "ios/chrome/browser/ui/settings/cells/byo_textfield_item.h" |
17 #include "ios/chrome/grit/ios_strings.h" | 16 #include "ios/chrome/grit/ios_strings.h" |
18 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 17 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
19 #include "ui/base/l10n/l10n_util_mac.h" | 18 #include "ui/base/l10n/l10n_util_mac.h" |
20 | 19 |
| 20 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 21 #error "This file requires ARC support." |
| 22 #endif |
| 23 |
21 using namespace ios_internal::sync_encryption_passphrase; | 24 using namespace ios_internal::sync_encryption_passphrase; |
22 | 25 |
23 @interface SyncCreatePassphraseCollectionViewController () { | 26 @interface SyncCreatePassphraseCollectionViewController () { |
24 base::scoped_nsobject<UITextField> confirmPassphrase_; | 27 UITextField* confirmPassphrase_; |
25 } | 28 } |
26 // Returns a confirm passphrase item. | 29 // Returns a confirm passphrase item. |
27 - (CollectionViewItem*)confirmPassphraseItem; | 30 - (CollectionViewItem*)confirmPassphraseItem; |
28 @end | 31 @end |
29 | 32 |
30 @implementation SyncCreatePassphraseCollectionViewController | 33 @implementation SyncCreatePassphraseCollectionViewController |
31 | 34 |
32 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { | 35 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { |
33 self = [super initWithBrowserState:browserState]; | 36 self = [super initWithBrowserState:browserState]; |
34 if (self) { | 37 if (self) { |
35 self.title = | 38 self.title = |
36 l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_CREATE_PASSPHRASE); | 39 l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_CREATE_PASSPHRASE); |
37 self.headerMessage = nil; | 40 self.headerMessage = nil; |
38 self.footerMessage = | 41 self.footerMessage = |
39 l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_PASSPHRASE_INFO), | 42 l10n_util::GetNSString(IDS_IOS_SYNC_ENCRYPTION_PASSPHRASE_INFO), |
40 self.processingMessage = | 43 self.processingMessage = |
41 l10n_util::GetNSString(IDS_IOS_SYNC_PASSPHRASE_ENCRYPTING); | 44 l10n_util::GetNSString(IDS_IOS_SYNC_PASSPHRASE_ENCRYPTING); |
42 | 45 |
43 [self loadModel]; | 46 [self loadModel]; |
44 } | 47 } |
45 return self; | 48 return self; |
46 } | 49 } |
47 | 50 |
48 #pragma mark - View lifecycle | 51 #pragma mark - View lifecycle |
49 | 52 |
50 - (void)didReceiveMemoryWarning { | 53 - (void)didReceiveMemoryWarning { |
51 [super didReceiveMemoryWarning]; | 54 [super didReceiveMemoryWarning]; |
52 if (![self isViewLoaded]) { | 55 if (![self isViewLoaded]) { |
53 confirmPassphrase_.reset(); | 56 confirmPassphrase_ = nil; |
54 } | 57 } |
55 } | 58 } |
56 | 59 |
57 - (void)viewDidDisappear:(BOOL)animated { | 60 - (void)viewDidDisappear:(BOOL)animated { |
58 [super viewDidDisappear:animated]; | 61 [super viewDidDisappear:animated]; |
59 if ([self isMovingFromParentViewController]) { | 62 if ([self isMovingFromParentViewController]) { |
60 [self unregisterTextField:self.confirmPassphrase]; | 63 [self unregisterTextField:self.confirmPassphrase]; |
61 } | 64 } |
62 } | 65 } |
63 | 66 |
64 #pragma mark - SettingsRootCollectionViewController | 67 #pragma mark - SettingsRootCollectionViewController |
65 | 68 |
66 - (void)loadModel { | 69 - (void)loadModel { |
67 [super loadModel]; | 70 [super loadModel]; |
68 CollectionViewModel* model = self.collectionViewModel; | 71 CollectionViewModel* model = self.collectionViewModel; |
69 | 72 |
70 NSInteger enterPassphraseIndex = | 73 NSInteger enterPassphraseIndex = |
71 [model indexPathForItemType:ItemTypeEnterPassphrase | 74 [model indexPathForItemType:ItemTypeEnterPassphrase |
72 sectionIdentifier:SectionIdentifierPassphrase] | 75 sectionIdentifier:SectionIdentifierPassphrase] |
73 .item; | 76 .item; |
74 [model insertItem:[self confirmPassphraseItem] | 77 [model insertItem:[self confirmPassphraseItem] |
75 inSectionWithIdentifier:SectionIdentifierPassphrase | 78 inSectionWithIdentifier:SectionIdentifierPassphrase |
76 atIndex:enterPassphraseIndex + 1]; | 79 atIndex:enterPassphraseIndex + 1]; |
77 } | 80 } |
78 | 81 |
79 #pragma mark - Items | 82 #pragma mark - Items |
80 | 83 |
81 - (CollectionViewItem*)confirmPassphraseItem { | 84 - (CollectionViewItem*)confirmPassphraseItem { |
82 if (!confirmPassphrase_) { | 85 if (!confirmPassphrase_) { |
83 confirmPassphrase_.reset([[UITextField alloc] init]); | 86 confirmPassphrase_ = [[UITextField alloc] init]; |
84 [confirmPassphrase_ setFont:[MDCTypography body1Font]]; | 87 [confirmPassphrase_ setFont:[MDCTypography body1Font]]; |
85 [confirmPassphrase_ setSecureTextEntry:YES]; | 88 [confirmPassphrase_ setSecureTextEntry:YES]; |
86 [confirmPassphrase_ setBackgroundColor:[UIColor clearColor]]; | 89 [confirmPassphrase_ setBackgroundColor:[UIColor clearColor]]; |
87 [confirmPassphrase_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; | 90 [confirmPassphrase_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; |
88 [confirmPassphrase_ setAutocorrectionType:UITextAutocorrectionTypeNo]; | 91 [confirmPassphrase_ setAutocorrectionType:UITextAutocorrectionTypeNo]; |
89 [confirmPassphrase_ | 92 [confirmPassphrase_ |
90 setPlaceholder:l10n_util::GetNSString( | 93 setPlaceholder:l10n_util::GetNSString( |
91 IDS_IOS_SYNC_CONFIRM_PASSPHRASE_LABEL)]; | 94 IDS_IOS_SYNC_CONFIRM_PASSPHRASE_LABEL)]; |
92 [self registerTextField:confirmPassphrase_]; | 95 [self registerTextField:confirmPassphrase_]; |
93 } | 96 } |
94 | 97 |
95 BYOTextFieldItem* item = [[[BYOTextFieldItem alloc] | 98 BYOTextFieldItem* item = |
96 initWithType:ItemTypeConfirmPassphrase] autorelease]; | 99 [[BYOTextFieldItem alloc] initWithType:ItemTypeConfirmPassphrase]; |
97 item.textField = confirmPassphrase_; | 100 item.textField = confirmPassphrase_; |
98 return item; | 101 return item; |
99 } | 102 } |
100 | 103 |
101 #pragma mark UICollectionViewDelegate | 104 #pragma mark UICollectionViewDelegate |
102 | 105 |
103 - (void)collectionView:(UICollectionView*)collectionView | 106 - (void)collectionView:(UICollectionView*)collectionView |
104 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 107 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
105 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 108 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
106 NSInteger itemType = | 109 NSInteger itemType = |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 167 |
165 @end | 168 @end |
166 | 169 |
167 @implementation SyncCreatePassphraseCollectionViewController (UsedForTesting) | 170 @implementation SyncCreatePassphraseCollectionViewController (UsedForTesting) |
168 | 171 |
169 - (UITextField*)confirmPassphrase { | 172 - (UITextField*)confirmPassphrase { |
170 return confirmPassphrase_; | 173 return confirmPassphrase_; |
171 } | 174 } |
172 | 175 |
173 @end | 176 @end |
OLD | NEW |