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" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 116 |
117 - (void)loadModel { | 117 - (void)loadModel { |
118 [super loadModel]; | 118 [super loadModel]; |
119 CollectionViewModel* model = self.collectionViewModel; | 119 CollectionViewModel* model = self.collectionViewModel; |
120 | 120 |
121 [model addSectionWithIdentifier:SectionIdentifierUsername]; | 121 [model addSectionWithIdentifier:SectionIdentifierUsername]; |
122 CollectionViewTextItem* usernameHeader = [ | 122 CollectionViewTextItem* usernameHeader = [ |
123 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; | 123 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; |
124 usernameHeader.text = | 124 usernameHeader.text = |
125 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME); | 125 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME); |
| 126 usernameHeader.textColor = [[MDCPalette greyPalette] tint500]; |
126 [model setHeader:usernameHeader | 127 [model setHeader:usernameHeader |
127 forSectionWithIdentifier:SectionIdentifierUsername]; | 128 forSectionWithIdentifier:SectionIdentifierUsername]; |
128 PasswordDetailsItem* usernameItem = | 129 PasswordDetailsItem* usernameItem = |
129 [[[PasswordDetailsItem alloc] initWithType:ItemTypeUsername] autorelease]; | 130 [[[PasswordDetailsItem alloc] initWithType:ItemTypeUsername] autorelease]; |
130 usernameItem.text = _username; | 131 usernameItem.text = _username; |
131 usernameItem.showingText = YES; | 132 usernameItem.showingText = YES; |
132 [model addItem:usernameItem | 133 [model addItem:usernameItem |
133 toSectionWithIdentifier:SectionIdentifierUsername]; | 134 toSectionWithIdentifier:SectionIdentifierUsername]; |
134 | 135 |
135 [model addSectionWithIdentifier:SectionIdentifierPassword]; | 136 [model addSectionWithIdentifier:SectionIdentifierPassword]; |
136 CollectionViewTextItem* passwordHeader = [ | 137 CollectionViewTextItem* passwordHeader = [ |
137 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; | 138 [[CollectionViewTextItem alloc] initWithType:ItemTypeHeader] autorelease]; |
138 passwordHeader.text = | 139 passwordHeader.text = |
139 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD); | 140 l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD); |
| 141 passwordHeader.textColor = [[MDCPalette greyPalette] tint500]; |
140 [model setHeader:passwordHeader | 142 [model setHeader:passwordHeader |
141 forSectionWithIdentifier:SectionIdentifierPassword]; | 143 forSectionWithIdentifier:SectionIdentifierPassword]; |
142 _passwordItem.reset( | 144 _passwordItem.reset( |
143 [[PasswordDetailsItem alloc] initWithType:ItemTypePassword]); | 145 [[PasswordDetailsItem alloc] initWithType:ItemTypePassword]); |
144 _passwordItem.get().text = _password; | 146 _passwordItem.get().text = _password; |
145 _passwordItem.get().showingText = NO; | 147 _passwordItem.get().showingText = NO; |
146 [model addItem:_passwordItem | 148 [model addItem:_passwordItem |
147 toSectionWithIdentifier:SectionIdentifierPassword]; | 149 toSectionWithIdentifier:SectionIdentifierPassword]; |
148 | 150 |
149 // 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... |
176 initWithType:ItemTypeShowHide] autorelease]; | 178 initWithType:ItemTypeShowHide] autorelease]; |
177 item.text = [self showHideButtonText]; | 179 item.text = [self showHideButtonText]; |
178 item.accessibilityTraits |= UIAccessibilityTraitButton; | 180 item.accessibilityTraits |= UIAccessibilityTraitButton; |
179 return item; | 181 return item; |
180 } | 182 } |
181 | 183 |
182 - (CollectionViewItem*)deletePasswordButtonItem { | 184 - (CollectionViewItem*)deletePasswordButtonItem { |
183 CollectionViewTextItem* item = [ | 185 CollectionViewTextItem* item = [ |
184 [[CollectionViewTextItem alloc] initWithType:ItemTypeDelete] autorelease]; | 186 [[CollectionViewTextItem alloc] initWithType:ItemTypeDelete] autorelease]; |
185 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]; |
186 item.accessibilityTraits |= UIAccessibilityTraitButton; | 189 item.accessibilityTraits |= UIAccessibilityTraitButton; |
187 return item; | 190 return item; |
188 } | 191 } |
189 | 192 |
190 #pragma mark - Actions | 193 #pragma mark - Actions |
191 | 194 |
192 - (NSString*)showHideButtonText { | 195 - (NSString*)showHideButtonText { |
193 if (_plainTextPasswordShown) { | 196 if (_plainTextPasswordShown) { |
194 return l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_HIDE_BUTTON); | 197 return l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_HIDE_BUTTON); |
195 } | 198 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 - (void)showCopyPasswordResultToast:(NSString*)message { | 296 - (void)showCopyPasswordResultToast:(NSString*)message { |
294 MDCSnackbarMessage* copyPasswordResultMessage = | 297 MDCSnackbarMessage* copyPasswordResultMessage = |
295 [MDCSnackbarMessage messageWithText:message]; | 298 [MDCSnackbarMessage messageWithText:message]; |
296 [MDCSnackbarManager showMessage:copyPasswordResultMessage]; | 299 [MDCSnackbarManager showMessage:copyPasswordResultMessage]; |
297 } | 300 } |
298 | 301 |
299 - (void)deletePassword { | 302 - (void)deletePassword { |
300 [_weakDelegate deletePassword:_passwordForm]; | 303 [_weakDelegate deletePassword:_passwordForm]; |
301 } | 304 } |
302 | 305 |
303 #pragma mark - UICollectionViewDataSource | |
304 | |
305 - (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView | |
306 viewForSupplementaryElementOfKind:(NSString*)kind | |
307 atIndexPath:(NSIndexPath*)indexPath { | |
308 UICollectionReusableView* view = [super collectionView:collectionView | |
309 viewForSupplementaryElementOfKind:kind | |
310 atIndexPath:indexPath]; | |
311 MDCCollectionViewTextCell* textCell = | |
312 base::mac::ObjCCast<MDCCollectionViewTextCell>(view); | |
313 if (textCell) { | |
314 textCell.textLabel.textColor = [[MDCPalette greyPalette] tint500]; | |
315 } | |
316 return view; | |
317 } | |
318 | |
319 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | |
320 cellForItemAtIndexPath:(NSIndexPath*)indexPath { | |
321 UICollectionViewCell* cell = | |
322 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; | |
323 | |
324 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; | |
325 if (type == ItemTypeDelete) { | |
326 MDCCollectionViewTextCell* textCell = | |
327 base::mac::ObjCCastStrict<MDCCollectionViewTextCell>(cell); | |
328 textCell.textLabel.textColor = [[MDCPalette cr_redPalette] tint500]; | |
329 } | |
330 | |
331 return cell; | |
332 } | |
333 | |
334 #pragma mark - UICollectionViewDelegate | 306 #pragma mark - UICollectionViewDelegate |
335 | 307 |
336 - (void)collectionView:(UICollectionView*)collectionView | 308 - (void)collectionView:(UICollectionView*)collectionView |
337 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 309 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
338 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 310 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
339 NSInteger itemType = | 311 NSInteger itemType = |
340 [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 312 [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
341 switch (itemType) { | 313 switch (itemType) { |
342 case ItemTypeShowHide: | 314 case ItemTypeShowHide: |
343 if (_plainTextPasswordShown) { | 315 if (_plainTextPasswordShown) { |
(...skipping 24 matching lines...) Expand all Loading... |
368 case ItemTypePassword: | 340 case ItemTypePassword: |
369 return [MDCCollectionViewCell | 341 return [MDCCollectionViewCell |
370 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) | 342 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) |
371 forItem:item]; | 343 forItem:item]; |
372 default: | 344 default: |
373 return MDCCellDefaultOneLineHeight; | 345 return MDCCellDefaultOneLineHeight; |
374 } | 346 } |
375 } | 347 } |
376 | 348 |
377 @end | 349 @end |
OLD | NEW |