Commit 0e87e869 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Enhances TableViewTextButton to work with the Passwords Infobar Modal

Makes changes to TableViewTextButton so it can be used with the Password
Infobar Modal.
Adds these buttons to InfobarPasswordTableViewController and hooks them
to their actions.

Screenshot:
https://drive.google.com/open?id=1CAJc2tT_oyL9Xyrm6b6krtZo1fxcey7T

Bug: 945478
Change-Id: Iadfdec6081a5742ec786102e040cf7a38396c17b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1572962Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Reviewed-by: default avatarChris Lu <thegreenfrog@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652540}
parent d6198c6c
......@@ -93,9 +93,14 @@
withString:@"•"
startingAtIndex:0];
self.modalViewController.unmaskedPassword = password;
self.modalViewController.detailsTextMessage =
self.passwordInfoBarDelegate->GetDetailsMessageText();
self.modalViewController.saveButtonText =
base::SysUTF16ToNSString(self.passwordInfoBarDelegate->GetButtonLabel(
ConfirmInfoBarDelegate::BUTTON_OK));
self.modalViewController.cancelButtonText =
base::SysUTF16ToNSString(self.passwordInfoBarDelegate->GetButtonLabel(
ConfirmInfoBarDelegate::BUTTON_CANCEL));
self.modalViewController.URL = self.passwordInfoBarDelegate->GetURLHostText();
}
......@@ -121,4 +126,9 @@
[self dismissInfobarModal:self completion:nil];
}
- (void)neverSaveCredentialsForCurrentSite {
self.passwordInfoBarDelegate->Cancel();
[self dismissInfobarModal:self completion:nil];
}
@end
......@@ -8,7 +8,7 @@ source_set("modals") {
"infobar_modal_delegate.h",
"infobar_modal_view_controller.h",
"infobar_modal_view_controller.mm",
"infobar_password_modal_delegate",
"infobar_password_modal_delegate.h",
"infobar_password_table_view_controller.h",
"infobar_password_table_view_controller.mm",
]
......
......@@ -17,6 +17,10 @@
- (void)updateCredentialsWithUsername:(NSString*)username
password:(NSString*)password;
// Blacklists the current site to never prompt the user to save its credentials
// again.
- (void)neverSaveCredentialsForCurrentSite;
@end
#endif // IOS_CHROME_BROWSER_UI_INFOBARS_MODALS_INFOBAR_PASSWORD_MODAL_DELEGATE_H_
......@@ -22,10 +22,14 @@
@property(nonatomic, copy) NSString* maskedPassword;
// The unmasked password for the InfobarModal.
@property(nonatomic, copy) NSString* unmaskedPassword;
// The details text message being displayed in the InfobarModal.
@property(nonatomic, copy) NSString* detailsTextMessage;
// The URL being displayed in the InfobarModal.
@property(nonatomic, copy) NSString* URL;
// The text used for the save credentials button.
@property(nonatomic, copy) NSString* saveButtonText;
// The text used for the cancel button.
@property(nonatomic, copy) NSString* cancelButtonText;
@end
......
......@@ -9,7 +9,6 @@
#import "ios/chrome/browser/ui/infobars/modals/infobar_modal_constants.h"
#import "ios/chrome/browser/ui/infobars/modals/infobar_password_modal_delegate.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_detail_icon_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_button_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_edit_item.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
......@@ -29,6 +28,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeUsername,
ItemTypePassword,
ItemTypeSaveCredentials,
ItemTypeNeverForThisSite,
};
@interface InfobarPasswordTableViewController ()
......@@ -38,6 +38,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
@property(nonatomic, strong) TableViewTextEditItem* passwordItem;
// Item that holds the SaveCredentials Button information.
@property(nonatomic, strong) TableViewTextButtonItem* saveCredentialsItem;
// Item that holds the Never Save for this site Button information.
@property(nonatomic, strong) TableViewTextButtonItem* neverForThisSiteItem;
@end
@implementation InfobarPasswordTableViewController
......@@ -81,12 +83,12 @@ typedef NS_ENUM(NSInteger, ItemType) {
TableViewModel* model = self.tableViewModel;
[model addSectionWithIdentifier:SectionIdentifierContent];
TableViewDetailIconItem* URLDetailItem =
[[TableViewDetailIconItem alloc] initWithType:ItemTypeURL];
URLDetailItem.text = l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_SITE);
URLDetailItem.detailText = self.URL;
[model addItem:URLDetailItem
toSectionWithIdentifier:SectionIdentifierContent];
TableViewTextEditItem* URLItem =
[[TableViewTextEditItem alloc] initWithType:ItemTypeURL];
URLItem.textFieldName =
l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_SITE);
URLItem.textFieldValue = self.URL;
[model addItem:URLItem toSectionWithIdentifier:SectionIdentifierContent];
self.usernameItem =
[[TableViewTextEditItem alloc] initWithType:ItemTypeUsername];
......@@ -103,16 +105,25 @@ typedef NS_ENUM(NSInteger, ItemType) {
self.passwordItem.textFieldName =
l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD);
self.passwordItem.textFieldValue = self.maskedPassword;
self.passwordItem.textFieldEnabled = YES;
self.passwordItem.autoCapitalizationType = UITextAutocapitalizationTypeNone;
[model addItem:self.passwordItem
toSectionWithIdentifier:SectionIdentifierContent];
self.saveCredentialsItem =
[[TableViewTextButtonItem alloc] initWithType:ItemTypeSaveCredentials];
self.saveCredentialsItem.textAlignment = NSTextAlignmentNatural;
self.saveCredentialsItem.text = self.detailsTextMessage;
self.saveCredentialsItem.buttonText = self.saveButtonText;
self.saveCredentialsItem.disableButtonIntrinsicWidth = YES;
[model addItem:self.saveCredentialsItem
toSectionWithIdentifier:SectionIdentifierContent];
self.neverForThisSiteItem =
[[TableViewTextButtonItem alloc] initWithType:ItemTypeNeverForThisSite];
self.neverForThisSiteItem.buttonText = self.cancelButtonText;
self.neverForThisSiteItem.buttonTextColor = [UIColor blueColor];
self.neverForThisSiteItem.buttonBackgroundColor = [UIColor clearColor];
[model addItem:self.neverForThisSiteItem
toSectionWithIdentifier:SectionIdentifierContent];
}
#pragma mark - UITableViewDataSource
......@@ -134,6 +145,15 @@ typedef NS_ENUM(NSInteger, ItemType) {
forControlEvents:UIControlEventTouchUpInside];
break;
}
case ItemTypeNeverForThisSite: {
TableViewTextButtonCell* tableViewTextButtonCell =
base::mac::ObjCCastStrict<TableViewTextButtonCell>(cell);
[tableViewTextButtonCell.button
addTarget:self.infobarModalDelegate
action:@selector(neverSaveCredentialsForCurrentSite)
forControlEvents:UIControlEventTouchUpInside];
break;
}
case ItemTypeUsername:
case ItemTypePassword: {
TableViewTextEditCell* editCell =
......
......@@ -12,7 +12,7 @@
namespace {
// The presented view Height
const CGFloat kPresentedViewHeight = 267.0;
const CGFloat kPresentedViewHeight = 350.0;
// The presented view outer horizontal margins.
const CGFloat kPresentedViewHorizontalMargin = 10.0;
// The presented view maximum width.
......
......@@ -156,11 +156,46 @@ typedef NS_ENUM(NSInteger, ItemType) {
TableViewTextButtonItem* textActionButtonItem =
[[TableViewTextButtonItem alloc] initWithType:ItemTypeTextButton];
textActionButtonItem.text = @"Hello, you should do something.";
textActionButtonItem.text = @"Hello, you should do something. Also as you "
@"can see this text is centered.";
textActionButtonItem.buttonText = @"Do something";
[model addItem:textActionButtonItem
toSectionWithIdentifier:SectionIdentifierText];
TableViewTextButtonItem* textActionButtonAlignmentItem =
[[TableViewTextButtonItem alloc] initWithType:ItemTypeTextButton];
textActionButtonAlignmentItem.text =
@"Hello, you should do something. Also as you can see this text is using "
@"NSTextAlignmentNatural";
textActionButtonAlignmentItem.textAlignment = NSTextAlignmentNatural;
textActionButtonAlignmentItem.buttonText = @"Do something";
[model addItem:textActionButtonAlignmentItem
toSectionWithIdentifier:SectionIdentifierText];
TableViewTextButtonItem* textActionButtoExpandedItem =
[[TableViewTextButtonItem alloc] initWithType:ItemTypeTextButton];
textActionButtoExpandedItem.text = @"Hello, you should do something.";
textActionButtoExpandedItem.disableButtonIntrinsicWidth = YES;
textActionButtoExpandedItem.buttonText = @"Expanded Button";
[model addItem:textActionButtoExpandedItem
toSectionWithIdentifier:SectionIdentifierText];
TableViewTextButtonItem* textActionButtonNoTextItem =
[[TableViewTextButtonItem alloc] initWithType:ItemTypeTextButton];
textActionButtonNoTextItem.buttonText = @"Do something, no Top Text";
[model addItem:textActionButtonNoTextItem
toSectionWithIdentifier:SectionIdentifierText];
TableViewTextButtonItem* textActionButtonColorItem =
[[TableViewTextButtonItem alloc] initWithType:ItemTypeTextButton];
textActionButtonColorItem.text = @"Hello, you should do something.";
textActionButtonColorItem.disableButtonIntrinsicWidth = YES;
textActionButtonColorItem.buttonBackgroundColor = [UIColor lightGrayColor];
textActionButtonColorItem.buttonTextColor = [UIColor greenColor];
textActionButtonColorItem.buttonText = @"Do something, different Colors";
[model addItem:textActionButtonColorItem
toSectionWithIdentifier:SectionIdentifierText];
TableViewDetailTextItem* detailTextItem =
[[TableViewDetailTextItem alloc] initWithType:ItemTypeDetailText];
detailTextItem.text = @"Item with two labels";
......
......@@ -15,9 +15,15 @@
// Text being displayed above the button.
@property(nonatomic, readwrite, strong) NSString* text;
// Text being displayed above the button alignment.
@property(nonatomic, readwrite, assign) NSTextAlignment textAlignment;
// Text for cell button.
@property(nonatomic, readwrite, strong) NSString* buttonText;
// Button text color.
@property(nonatomic, strong) UIColor* buttonTextColor;
// Button background color. Default is custom blue color.
@property(nonatomic, strong) UIColor* buttonBackgroundColor;
......@@ -28,6 +34,10 @@
// default.
@property(nonatomic, assign, getter=isEnabled) BOOL enabled;
// If YES the item's button width will expand to match the cell's. If NO the
// button will maintain its intrinsic size based on its title. NO by default.
@property(nonatomic, assign) BOOL disableButtonIntrinsicWidth;
@end
// TableViewTextButtonCell contains a textLabel and a UIbutton
......@@ -40,6 +50,15 @@
// Action button. Note: Set action method in the TableView datasource method.
@property(nonatomic, strong) UIButton* button;
// Enables spacing between items. If there's only one item (e.g. just a button),
// disable the spacing or an extra top padding will be added.
- (void)enableItemSpacing:(BOOL)enable;
// If |disabled| is YES the button's width will expand to match the cell's
// container. If NO, the button will maintain its intrinsic size based on its
// title.
- (void)disableButtonIntrinsicWidth:(BOOL)disable;
@end
#endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_TEXT_BUTTON_ITEM_H_
......@@ -13,25 +13,29 @@
namespace {
// Text label gray color.
const CGFloat grayHexColor = 0x6d6d72;
const CGFloat kGrayHexColor = 0x6d6d72;
// Action button blue background color.
const CGFloat blueHexColor = 0x1A73E8;
const CGFloat kBlueHexColor = 0x1A73E8;
// Default Button title Color.
const CGFloat kDefaultButtonTitleColor = 0xFFFFFF;
// Alpha value for the disabled action button.
const CGFloat disabledButtonAlpha = 0.5;
const CGFloat kDisabledButtonAlpha = 0.5;
// Vertical spacing between stackView and cell contentView.
const CGFloat stackViewVerticalSpacing = 9.0;
const CGFloat kStackViewVerticalSpacing = 9.0;
// Horizontal spacing between stackView and cell contentView.
const CGFloat stackViewHorizontalSpacing = 16.0;
const CGFloat kStackViewHorizontalSpacing = 16.0;
// SubView spacing within stackView.
const CGFloat stackViewSubViewSpacing = 13.0;
const CGFloat kStackViewSubViewSpacing = 13.0;
// Horizontal Inset between button contents and edge.
const CGFloat buttonTitleHorizontalContentInset = 40.0;
const CGFloat kButtonTitleHorizontalContentInset = 40.0;
// Vertical Inset between button contents and edge.
const CGFloat buttonTitleVerticalContentInset = 8.0;
const CGFloat kButtonTitleVerticalContentInset = 8.0;
// Button corner radius.
const CGFloat buttonCornerRadius = 8;
const CGFloat kButtonCornerRadius = 8;
// Font Size for Button Title Label.
const CGFloat buttonTitleFontSize = 17.0;
const CGFloat kButtonTitleFontSize = 17.0;
const NSTextAlignment kDefaultTextAlignment = NSTextAlignmentCenter;
} // namespace
@implementation TableViewTextButtonItem
......@@ -45,6 +49,7 @@ const CGFloat buttonTitleFontSize = 17.0;
if (self) {
self.cellClass = [TableViewTextButtonCell class];
_enabled = YES;
_textAlignment = kDefaultTextAlignment;
}
return self;
}
......@@ -55,21 +60,35 @@ const CGFloat buttonTitleFontSize = 17.0;
TableViewTextButtonCell* cell =
base::mac::ObjCCastStrict<TableViewTextButtonCell>(tableCell);
cell.textLabel.text = self.text;
[cell enableItemSpacing:[self.text length]];
[cell disableButtonIntrinsicWidth:self.disableButtonIntrinsicWidth];
cell.textLabel.textAlignment = self.textAlignment;
[cell.button setTitle:self.buttonText forState:UIControlStateNormal];
if (self.buttonTextColor) {
[cell.button setTitleColor:self.buttonTextColor
forState:UIControlStateNormal];
}
cell.button.accessibilityIdentifier = self.buttonAccessibilityIdentifier;
cell.button.backgroundColor = self.buttonBackgroundColor
? self.buttonBackgroundColor
: UIColorFromRGB(blueHexColor);
: UIColorFromRGB(kBlueHexColor);
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.button.enabled = self.enabled;
if (!self.enabled) {
cell.button.backgroundColor = [cell.button.backgroundColor
colorWithAlphaComponent:disabledButtonAlpha];
colorWithAlphaComponent:kDisabledButtonAlpha];
}
}
@end
@interface TableViewTextButtonCell ()
// StackView that contains the cell's Button and Label.
@property(nonatomic, strong) UIStackView* verticalStackView;
// Constraints used to match the Button width to the StackView.
@property(nonatomic, strong) NSArray* expandedButtonWidthConstraints;
@end
@implementation TableViewTextButtonCell
@synthesize textLabel = _textLabel;
@synthesize button = _button;
......@@ -85,48 +104,80 @@ const CGFloat buttonTitleFontSize = 17.0;
self.textLabel.textAlignment = NSTextAlignmentCenter;
self.textLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
self.textLabel.textColor = UIColorFromRGB(grayHexColor);
self.textLabel.textColor = UIColorFromRGB(kGrayHexColor);
// Create button.
self.button = [[UIButton alloc] init];
[self.button setTitleColor:[UIColor whiteColor]
[self.button setTitleColor:UIColorFromRGB(kDefaultButtonTitleColor)
forState:UIControlStateNormal];
self.button.translatesAutoresizingMaskIntoConstraints = NO;
[self.button.titleLabel
setFont:[UIFont boldSystemFontOfSize:buttonTitleFontSize]];
self.button.layer.cornerRadius = buttonCornerRadius;
setFont:[UIFont boldSystemFontOfSize:kButtonTitleFontSize]];
self.button.layer.cornerRadius = kButtonCornerRadius;
self.button.clipsToBounds = YES;
self.button.contentEdgeInsets = UIEdgeInsetsMake(
buttonTitleVerticalContentInset, buttonTitleHorizontalContentInset,
buttonTitleVerticalContentInset, buttonTitleHorizontalContentInset);
kButtonTitleVerticalContentInset, kButtonTitleHorizontalContentInset,
kButtonTitleVerticalContentInset, kButtonTitleHorizontalContentInset);
// Vertical stackView to hold label and button.
UIStackView* verticalStackView = [[UIStackView alloc]
self.verticalStackView = [[UIStackView alloc]
initWithArrangedSubviews:@[ self.textLabel, self.button ]];
verticalStackView.alignment = UIStackViewAlignmentCenter;
verticalStackView.axis = UILayoutConstraintAxisVertical;
verticalStackView.spacing = stackViewSubViewSpacing;
verticalStackView.translatesAutoresizingMaskIntoConstraints = NO;
self.verticalStackView.alignment = UIStackViewAlignmentCenter;
self.verticalStackView.axis = UILayoutConstraintAxisVertical;
self.verticalStackView.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:verticalStackView];
[self.contentView addSubview:self.verticalStackView];
// Add constraints for stackView
[NSLayoutConstraint activateConstraints:@[
[verticalStackView.leadingAnchor
[self.verticalStackView.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor
constant:stackViewHorizontalSpacing],
[verticalStackView.trailingAnchor
constant:kStackViewHorizontalSpacing],
[self.verticalStackView.trailingAnchor
constraintEqualToAnchor:self.contentView.trailingAnchor
constant:-stackViewHorizontalSpacing],
[verticalStackView.topAnchor
constant:-kStackViewHorizontalSpacing],
[self.verticalStackView.topAnchor
constraintEqualToAnchor:self.contentView.topAnchor
constant:stackViewVerticalSpacing],
[verticalStackView.bottomAnchor
constant:kStackViewVerticalSpacing],
[self.verticalStackView.bottomAnchor
constraintEqualToAnchor:self.contentView.bottomAnchor
constant:-stackViewVerticalSpacing]
constant:-kStackViewVerticalSpacing]
]];
self.expandedButtonWidthConstraints = @[
[self.button.leadingAnchor
constraintEqualToAnchor:self.verticalStackView.leadingAnchor],
[self.button.trailingAnchor
constraintEqualToAnchor:self.verticalStackView.trailingAnchor],
];
}
return self;
}
#pragma mark - Public Methods
- (void)enableItemSpacing:(BOOL)enable {
self.verticalStackView.spacing = enable ? kStackViewSubViewSpacing : 0;
}
- (void)disableButtonIntrinsicWidth:(BOOL)disable {
if (disable) {
[NSLayoutConstraint
activateConstraints:self.expandedButtonWidthConstraints];
} else {
[NSLayoutConstraint
deactivateConstraints:self.expandedButtonWidthConstraints];
}
}
#pragma mark - UITableViewCell
- (void)prepareForReuse {
[super prepareForReuse];
[self.button setTitleColor:UIColorFromRGB(kDefaultButtonTitleColor)
forState:UIControlStateNormal];
self.textLabel.textAlignment = kDefaultTextAlignment;
[self disableButtonIntrinsicWidth:NO];
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment