Chromium Code Reviews| Index: ios/chrome/browser/ui/settings/password_details_collection_view_controller.mm |
| diff --git a/ios/chrome/browser/ui/settings/password_details_collection_view_controller.mm b/ios/chrome/browser/ui/settings/password_details_collection_view_controller.mm |
| index 0cf4b1d63a235e727559e9e668ed620943c093c9..a0ffe5392c1739ee98497bf917c13f47d02a7ecc 100644 |
| --- a/ios/chrome/browser/ui/settings/password_details_collection_view_controller.mm |
| +++ b/ios/chrome/browser/ui/settings/password_details_collection_view_controller.mm |
| @@ -39,9 +39,10 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| typedef NS_ENUM(NSInteger, ItemType) { |
| ItemTypeHeader = kItemTypeEnumZero, |
| ItemTypeUsername, |
| + ItemTypeCopyUsername, |
| ItemTypePassword, |
| ItemTypeShowHide, |
| - ItemTypeCopy, |
| + ItemTypeCopyPassword, |
| ItemTypeDelete, |
| }; |
| @@ -132,6 +133,8 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule |
| usernameItem.showingText = YES; |
| [model addItem:usernameItem |
| toSectionWithIdentifier:SectionIdentifierUsername]; |
| + [model addItem:[self usernameCopyButtonItem] |
| + toSectionWithIdentifier:SectionIdentifierUsername]; |
| [model addSectionWithIdentifier:SectionIdentifierPassword]; |
| CollectionViewTextItem* passwordHeader = |
| @@ -163,9 +166,18 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule |
| #pragma mark - Items |
| +- (CollectionViewItem*)usernameCopyButtonItem { |
| + CollectionViewTextItem* item = |
| + [[CollectionViewTextItem alloc] initWithType:ItemTypeCopyUsername]; |
| + item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_USERNAME_COPY_BUTTON); |
|
lpromero
2017/05/02 15:04:52
This might not be sufficient for accessibility. I
vabr (Chromium)
2017/05/02 15:29:09
Oh, so if I set accessibilityLabel here to "Copy U
lpromero
2017/05/02 16:27:20
Indeed. This is an issue. The collection view text
|
| + item.textColor = [[MDCPalette cr_bluePalette] tint500]; |
| + item.accessibilityTraits |= UIAccessibilityTraitButton; |
| + return item; |
| +} |
| + |
| - (CollectionViewItem*)passwordCopyButtonItem { |
| CollectionViewTextItem* item = |
| - [[CollectionViewTextItem alloc] initWithType:ItemTypeCopy]; |
| + [[CollectionViewTextItem alloc] initWithType:ItemTypeCopyPassword]; |
| item.text = l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_COPY_BUTTON); |
| item.textColor = [[MDCPalette cr_bluePalette] tint500]; |
| item.accessibilityTraits |= UIAccessibilityTraitButton; |
| @@ -192,6 +204,13 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule |
| #pragma mark - Actions |
| +- (void)copyUsername { |
| + UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; |
| + generalPasteboard.string = _username; |
| + [self showCopyResultToast:l10n_util::GetNSString( |
| + IDS_IOS_SETTINGS_USERNAME_WAS_COPIED_MESSAGE)]; |
| +} |
| + |
| - (NSString*)showHideButtonText { |
| if (_plainTextPasswordShown) { |
| return l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_HIDE_BUTTON); |
| @@ -262,9 +281,9 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule |
| UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; |
| generalPasteboard.string = _password; |
| TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess); |
| - [self showCopyPasswordResultToast: |
| - l10n_util::GetNSString( |
| - IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE)]; |
| + [self |
| + showCopyResultToast:l10n_util::GetNSString( |
| + IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE)]; |
| } else if ([_weakReauthenticationModule canAttemptReauth]) { |
| __weak PasswordDetailsCollectionViewController* weakSelf = self; |
| void (^copyPasswordHandler)(BOOL) = ^(BOOL success) { |
| @@ -275,12 +294,12 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule |
| UIPasteboard* generalPasteboard = [UIPasteboard generalPasteboard]; |
| generalPasteboard.string = strongSelf->_password; |
| TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess); |
| - [strongSelf showCopyPasswordResultToast: |
| + [strongSelf showCopyResultToast: |
| l10n_util::GetNSString( |
| IDS_IOS_SETTINGS_PASSWORD_WAS_COPIED_MESSAGE)]; |
| } else { |
| TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeError); |
| - [strongSelf showCopyPasswordResultToast: |
| + [strongSelf showCopyResultToast: |
| l10n_util::GetNSString( |
| IDS_IOS_SETTINGS_PASSWORD_WAS_NOT_COPIED_MESSAGE)]; |
| } |
| @@ -292,7 +311,7 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule |
| } |
| } |
| -- (void)showCopyPasswordResultToast:(NSString*)message { |
| +- (void)showCopyResultToast:(NSString*)message { |
| // TODO(crbug.com/159166): Route this through some delegate API to be able |
| // to mock it in the unittest, and avoid having an EGTest just for that? |
| MDCSnackbarMessage* copyPasswordResultMessage = |
| @@ -312,6 +331,9 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule |
| NSInteger itemType = |
| [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| switch (itemType) { |
| + case ItemTypeCopyUsername: |
| + [self copyUsername]; |
| + break; |
| case ItemTypeShowHide: |
| if (_plainTextPasswordShown) { |
| [self hidePassword]; |
| @@ -319,7 +341,7 @@ reauthenticationModule:(id<ReauthenticationProtocol>)reauthenticationModule |
| [self showPassword]; |
| } |
| break; |
| - case ItemTypeCopy: |
| + case ItemTypeCopyPassword: |
| [self copyPassword]; |
| break; |
| case ItemTypeDelete: |