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 #import "base/ios/weak_nsobject.h" | 7 #import "base/ios/weak_nsobject.h" |
8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
9 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #include "components/autofill/core/common/password_form.h" | 11 #include "components/autofill/core/common/password_form.h" |
12 #include "components/password_manager/core/browser/affiliation_utils.h" | 12 #include "components/password_manager/core/browser/affiliation_utils.h" |
13 #include "components/password_manager/core/browser/password_store.h" | 13 #include "components/password_manager/core/browser/password_store.h" |
14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 14 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
15 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 15 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
| 17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_cell.h
" |
17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
18 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 19 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
19 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 20 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
20 #import "ios/chrome/browser/ui/settings/cells/password_details_item.h" | 21 #import "ios/chrome/browser/ui/settings/cells/password_details_item.h" |
21 #import "ios/chrome/browser/ui/settings/reauthentication_module.h" | 22 #import "ios/chrome/browser/ui/settings/reauthentication_module.h" |
22 #import "ios/chrome/browser/ui/settings/save_passwords_collection_view_controlle
r.h" | 23 #import "ios/chrome/browser/ui/settings/save_passwords_collection_view_controlle
r.h" |
23 #include "ios/chrome/browser/ui/uikit_ui_util.h" | 24 #include "ios/chrome/browser/ui/uikit_ui_util.h" |
24 #include "ios/chrome/grit/ios_strings.h" | 25 #include "ios/chrome/grit/ios_strings.h" |
25 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" | 26 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" |
26 #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" |
27 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat
erialSnackbar.h" | 28 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat
erialSnackbar.h" |
| 29 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
28 #include "ui/base/l10n/l10n_util_mac.h" | 30 #include "ui/base/l10n/l10n_util_mac.h" |
29 | 31 |
30 namespace { | 32 namespace { |
31 | 33 |
32 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 34 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
33 SectionIdentifierUsername = kSectionIdentifierEnumZero, | 35 SectionIdentifierUsername = kSectionIdentifierEnumZero, |
34 SectionIdentifierPassword, | 36 SectionIdentifierPassword, |
35 }; | 37 }; |
36 | 38 |
37 typedef NS_ENUM(NSInteger, ItemType) { | 39 typedef NS_ENUM(NSInteger, ItemType) { |
(...skipping 78 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] autorelease]; | 125 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; |
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] autorelease]; | 131 [[[PasswordDetailsItem alloc] initWithType:ItemTypeUsername] autorelease]; |
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] autorelease]; | 139 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; |
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.reset( | 144 _passwordItem.reset( |
145 [[PasswordDetailsItem alloc] initWithType:ItemTypePassword]); | 145 [[PasswordDetailsItem alloc] initWithType:ItemTypePassword]); |
146 _passwordItem.get().text = _password; | 146 _passwordItem.get().text = _password; |
147 _passwordItem.get().showingText = NO; | 147 _passwordItem.get().showingText = NO; |
148 [model addItem:_passwordItem | 148 [model addItem:_passwordItem |
149 toSectionWithIdentifier:SectionIdentifierPassword]; | 149 toSectionWithIdentifier:SectionIdentifierPassword]; |
150 | 150 |
151 // TODO(crbug.com/159166): Change the style of the buttons once there are | 151 // TODO(crbug.com/159166): Change the style of the buttons once there are |
(...skipping 26 matching lines...) Expand all Loading... |
178 initWithType:ItemTypeShowHide] autorelease]; | 178 initWithType:ItemTypeShowHide] autorelease]; |
179 item.text = [self showHideButtonText]; | 179 item.text = [self showHideButtonText]; |
180 item.accessibilityTraits |= UIAccessibilityTraitButton; | 180 item.accessibilityTraits |= UIAccessibilityTraitButton; |
181 return item; | 181 return item; |
182 } | 182 } |
183 | 183 |
184 - (CollectionViewItem*)deletePasswordButtonItem { | 184 - (CollectionViewItem*)deletePasswordButtonItem { |
185 CollectionViewTextItem* item = [ | 185 CollectionViewTextItem* item = [ |
186 [[CollectionViewTextItem alloc] initWithType:ItemTypeDelete] autorelease]; | 186 [[CollectionViewTextItem alloc] initWithType:ItemTypeDelete] autorelease]; |
187 item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_DELETE_BUTTON); | 187 item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_DELETE_BUTTON); |
188 item.textColor = [[MDCPalette cr_redPalette] tint500]; | |
189 item.accessibilityTraits |= UIAccessibilityTraitButton; | 188 item.accessibilityTraits |= UIAccessibilityTraitButton; |
190 return item; | 189 return item; |
191 } | 190 } |
192 | 191 |
193 #pragma mark - Actions | 192 #pragma mark - Actions |
194 | 193 |
195 - (NSString*)showHideButtonText { | 194 - (NSString*)showHideButtonText { |
196 if (_plainTextPasswordShown) { | 195 if (_plainTextPasswordShown) { |
197 return l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_HIDE_BUTTON); | 196 return l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_HIDE_BUTTON); |
198 } | 197 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 - (void)showCopyPasswordResultToast:(NSString*)message { | 295 - (void)showCopyPasswordResultToast:(NSString*)message { |
297 MDCSnackbarMessage* copyPasswordResultMessage = | 296 MDCSnackbarMessage* copyPasswordResultMessage = |
298 [MDCSnackbarMessage messageWithText:message]; | 297 [MDCSnackbarMessage messageWithText:message]; |
299 [MDCSnackbarManager showMessage:copyPasswordResultMessage]; | 298 [MDCSnackbarManager showMessage:copyPasswordResultMessage]; |
300 } | 299 } |
301 | 300 |
302 - (void)deletePassword { | 301 - (void)deletePassword { |
303 [_weakDelegate deletePassword:_passwordForm]; | 302 [_weakDelegate deletePassword:_passwordForm]; |
304 } | 303 } |
305 | 304 |
| 305 #pragma mark - UICollectionViewDataSource |
| 306 |
| 307 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
| 308 cellForItemAtIndexPath:(NSIndexPath*)indexPath { |
| 309 UICollectionViewCell* cell = |
| 310 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; |
| 311 |
| 312 NSInteger itemType = |
| 313 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 314 switch (itemType) { |
| 315 case ItemTypeHeader: |
| 316 case ItemTypeCopy: |
| 317 case ItemTypeDelete: { |
| 318 CollectionViewTextCell* textCell = |
| 319 base::mac::ObjCCastStrict<CollectionViewTextCell>(cell); |
| 320 textCell.textLabel.font = [MDCTypography body2Font]; |
| 321 if (itemType == ItemTypeHeader || itemType == ItemTypeDelete) |
| 322 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint500]; |
| 323 else |
| 324 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint900]; |
| 325 textCell.detailTextLabel.font = [MDCTypography body1Font]; |
| 326 textCell.detailTextLabel.textColor = [[MDCPalette greyPalette] tint500]; |
| 327 |
| 328 break; |
| 329 } |
| 330 default: |
| 331 break; |
| 332 } |
| 333 return cell; |
| 334 } |
| 335 |
306 #pragma mark - UICollectionViewDelegate | 336 #pragma mark - UICollectionViewDelegate |
307 | 337 |
308 - (void)collectionView:(UICollectionView*)collectionView | 338 - (void)collectionView:(UICollectionView*)collectionView |
309 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 339 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
310 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 340 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
311 NSInteger itemType = | 341 NSInteger itemType = |
312 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 342 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
313 switch (itemType) { | 343 switch (itemType) { |
314 case ItemTypeShowHide: | 344 case ItemTypeShowHide: |
315 if (_plainTextPasswordShown) { | 345 if (_plainTextPasswordShown) { |
(...skipping 24 matching lines...) Expand all Loading... |
340 case ItemTypePassword: | 370 case ItemTypePassword: |
341 return [MDCCollectionViewCell | 371 return [MDCCollectionViewCell |
342 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) | 372 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) |
343 forItem:item]; | 373 forItem:item]; |
344 default: | 374 default: |
345 return MDCCellDefaultOneLineHeight; | 375 return MDCCellDefaultOneLineHeight; |
346 } | 376 } |
347 } | 377 } |
348 | 378 |
349 @end | 379 @end |
OLD | NEW |