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/password_details_collection_view_control ler.h" | 5 #import "ios/chrome/browser/ui/settings/password_details_collection_view_control ler.h" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "components/autofill/core/common/password_form.h" | 9 #include "components/autofill/core/common/password_form.h" |
10 #include "components/password_manager/core/browser/affiliation_utils.h" | 10 #include "components/password_manager/core/browser/affiliation_utils.h" |
11 #include "components/password_manager/core/browser/password_store.h" | 11 #include "components/password_manager/core/browser/password_store.h" |
12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
13 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" | 13 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" |
14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_cell.h " | |
15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " | 16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " |
16 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 17 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
17 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 18 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
18 #import "ios/chrome/browser/ui/settings/cells/password_details_item.h" | 19 #import "ios/chrome/browser/ui/settings/cells/password_details_item.h" |
19 #import "ios/chrome/browser/ui/settings/reauthentication_module.h" | 20 #import "ios/chrome/browser/ui/settings/reauthentication_module.h" |
20 #import "ios/chrome/browser/ui/settings/save_passwords_collection_view_controlle r.h" | 21 #import "ios/chrome/browser/ui/settings/save_passwords_collection_view_controlle r.h" |
21 #include "ios/chrome/browser/ui/uikit_ui_util.h" | 22 #include "ios/chrome/browser/ui/uikit_ui_util.h" |
22 #include "ios/chrome/grit/ios_strings.h" | 23 #include "ios/chrome/grit/ios_strings.h" |
23 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h" | 24 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h" |
24 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" | 25 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" |
25 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat erialSnackbar.h" | 26 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat erialSnackbar.h" |
27 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" | |
26 #include "ui/base/l10n/l10n_util_mac.h" | 28 #include "ui/base/l10n/l10n_util_mac.h" |
27 | 29 |
28 #if !defined(__has_feature) || !__has_feature(objc_arc) | 30 #if !defined(__has_feature) || !__has_feature(objc_arc) |
29 #error "This file requires ARC support." | 31 #error "This file requires ARC support." |
30 #endif | 32 #endif |
31 | 33 |
32 namespace { | 34 namespace { |
33 | 35 |
34 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 36 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
35 SectionIdentifierUsername = kSectionIdentifierEnumZero, | 37 SectionIdentifierUsername = kSectionIdentifierEnumZero, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 | 118 |
117 - (void)loadModel { | 119 - (void)loadModel { |
118 [super loadModel]; | 120 [super loadModel]; |
119 CollectionViewModel* model = self.collectionViewModel; | 121 CollectionViewModel* model = self.collectionViewModel; |
120 | 122 |
121 [model addSectionWithIdentifier:SectionIdentifierUsername]; | 123 [model addSectionWithIdentifier:SectionIdentifierUsername]; |
122 CollectionViewTextItem* usernameHeader = | 124 CollectionViewTextItem* usernameHeader = |
123 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; | 125 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; |
124 usernameHeader.text = | 126 usernameHeader.text = |
125 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME); | 127 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME); |
126 usernameHeader.textColor = [[MDCPalette greyPalette] tint500]; | |
127 [model setHeader:usernameHeader | 128 [model setHeader:usernameHeader |
128 forSectionWithIdentifier:SectionIdentifierUsername]; | 129 forSectionWithIdentifier:SectionIdentifierUsername]; |
129 PasswordDetailsItem* usernameItem = | 130 PasswordDetailsItem* usernameItem = |
130 [[PasswordDetailsItem alloc] initWithType:ItemTypeUsername]; | 131 [[PasswordDetailsItem alloc] initWithType:ItemTypeUsername]; |
131 usernameItem.text = _username; | 132 usernameItem.text = _username; |
132 usernameItem.showingText = YES; | 133 usernameItem.showingText = YES; |
133 [model addItem:usernameItem | 134 [model addItem:usernameItem |
134 toSectionWithIdentifier:SectionIdentifierUsername]; | 135 toSectionWithIdentifier:SectionIdentifierUsername]; |
135 | 136 |
136 [model addSectionWithIdentifier:SectionIdentifierPassword]; | 137 [model addSectionWithIdentifier:SectionIdentifierPassword]; |
137 CollectionViewTextItem* passwordHeader = | 138 CollectionViewTextItem* passwordHeader = |
138 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; | 139 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader]; |
139 passwordHeader.text = | 140 passwordHeader.text = |
140 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD); | 141 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD); |
141 passwordHeader.textColor = [[MDCPalette greyPalette] tint500]; | |
142 [model setHeader:passwordHeader | 142 [model setHeader:passwordHeader |
143 forSectionWithIdentifier:SectionIdentifierPassword]; | 143 forSectionWithIdentifier:SectionIdentifierPassword]; |
144 _passwordItem = [[PasswordDetailsItem alloc] initWithType:ItemTypePassword]; | 144 _passwordItem = [[PasswordDetailsItem alloc] initWithType:ItemTypePassword]; |
145 _passwordItem.text = _password; | 145 _passwordItem.text = _password; |
146 _passwordItem.showingText = NO; | 146 _passwordItem.showingText = NO; |
147 [model addItem:_passwordItem | 147 [model addItem:_passwordItem |
148 toSectionWithIdentifier:SectionIdentifierPassword]; | 148 toSectionWithIdentifier:SectionIdentifierPassword]; |
149 | 149 |
150 // TODO(crbug.com/159166): Change the style of the buttons once there are | 150 // TODO(crbug.com/159166): Change the style of the buttons once there are |
151 // final mocks. | 151 // final mocks. |
(...skipping 24 matching lines...) Expand all Loading... | |
176 [[CollectionViewTextItem alloc] initWithType:ItemTypeShowHide]; | 176 [[CollectionViewTextItem alloc] initWithType:ItemTypeShowHide]; |
177 item.text = [self showHideButtonText]; | 177 item.text = [self showHideButtonText]; |
178 item.accessibilityTraits |= UIAccessibilityTraitButton; | 178 item.accessibilityTraits |= UIAccessibilityTraitButton; |
179 return item; | 179 return item; |
180 } | 180 } |
181 | 181 |
182 - (CollectionViewItem*)deletePasswordButtonItem { | 182 - (CollectionViewItem*)deletePasswordButtonItem { |
183 CollectionViewTextItem* item = | 183 CollectionViewTextItem* item = |
184 [[CollectionViewTextItem alloc] initWithType:ItemTypeDelete]; | 184 [[CollectionViewTextItem alloc] initWithType:ItemTypeDelete]; |
185 item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_DELETE_BUTTON); | 185 item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_DELETE_BUTTON); |
186 item.textColor = [[MDCPalette cr_redPalette] tint500]; | |
gambard
2017/04/14 07:04:03
This one is red
| |
187 item.accessibilityTraits |= UIAccessibilityTraitButton; | 186 item.accessibilityTraits |= UIAccessibilityTraitButton; |
188 return item; | 187 return item; |
189 } | 188 } |
190 | 189 |
191 #pragma mark - Actions | 190 #pragma mark - Actions |
192 | 191 |
193 - (NSString*)showHideButtonText { | 192 - (NSString*)showHideButtonText { |
194 if (_plainTextPasswordShown) { | 193 if (_plainTextPasswordShown) { |
195 return l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_HIDE_BUTTON); | 194 return l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_HIDE_BUTTON); |
196 } | 195 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 - (void)showCopyPasswordResultToast:(NSString*)message { | 291 - (void)showCopyPasswordResultToast:(NSString*)message { |
293 MDCSnackbarMessage* copyPasswordResultMessage = | 292 MDCSnackbarMessage* copyPasswordResultMessage = |
294 [MDCSnackbarMessage messageWithText:message]; | 293 [MDCSnackbarMessage messageWithText:message]; |
295 [MDCSnackbarManager showMessage:copyPasswordResultMessage]; | 294 [MDCSnackbarManager showMessage:copyPasswordResultMessage]; |
296 } | 295 } |
297 | 296 |
298 - (void)deletePassword { | 297 - (void)deletePassword { |
299 [_weakDelegate deletePassword:_passwordForm]; | 298 [_weakDelegate deletePassword:_passwordForm]; |
300 } | 299 } |
301 | 300 |
301 #pragma mark - UICollectionViewDataSource | |
302 | |
303 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | |
304 cellForItemAtIndexPath:(NSIndexPath*)indexPath { | |
305 UICollectionViewCell* cell = | |
306 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; | |
307 | |
308 NSInteger itemType = | |
309 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | |
310 switch (itemType) { | |
311 case ItemTypeHeader: | |
312 case ItemTypeDelete: { | |
313 CollectionViewTextCell* textCell = | |
314 base::mac::ObjCCastStrict<CollectionViewTextCell>(cell); | |
315 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint500]; | |
316 break; | |
317 } | |
318 default: | |
319 break; | |
320 } | |
321 return cell; | |
322 } | |
323 | |
302 #pragma mark - UICollectionViewDelegate | 324 #pragma mark - UICollectionViewDelegate |
303 | 325 |
304 - (void)collectionView:(UICollectionView*)collectionView | 326 - (void)collectionView:(UICollectionView*)collectionView |
305 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 327 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
306 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 328 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
307 NSInteger itemType = | 329 NSInteger itemType = |
308 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 330 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
309 switch (itemType) { | 331 switch (itemType) { |
310 case ItemTypeShowHide: | 332 case ItemTypeShowHide: |
311 if (_plainTextPasswordShown) { | 333 if (_plainTextPasswordShown) { |
(...skipping 24 matching lines...) Expand all Loading... | |
336 case ItemTypePassword: | 358 case ItemTypePassword: |
337 return [MDCCollectionViewCell | 359 return [MDCCollectionViewCell |
338 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) | 360 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) |
339 forItem:item]; | 361 forItem:item]; |
340 default: | 362 default: |
341 return MDCCellDefaultOneLineHeight; | 363 return MDCCellDefaultOneLineHeight; |
342 } | 364 } |
343 } | 365 } |
344 | 366 |
345 @end | 367 @end |
OLD | NEW |