Commit 25709b78 authored by Yi Su's avatar Yi Su Committed by Commit Bot

Add "masked" property to TableViewTextItem to support showing masked text.

PasswordDetailItem can display an uneditable string as plain text("abc")
or masked text("XXX"). This CL add the same functionality in
TableViewTextItem to avoid creating another class like
TableViewPasswordItem. This is a preparation work for migrating Settings
from MDC to UIKit.

Bug: 894791
Change-Id: I34538659d6879246c66e9aafd4d88cb8d7822f3c
Reviewed-on: https://chromium-review.googlesource.com/c/1346151
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Reviewed-by: default avatarEric Noyau <noyau@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610414}
parent 6de76902
...@@ -91,6 +91,11 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -91,6 +91,11 @@ typedef NS_ENUM(NSInteger, ItemType) {
textItem.textColor = [UIColor blackColor]; textItem.textColor = [UIColor blackColor];
[model addItem:textItem toSectionWithIdentifier:SectionIdentifierText]; [model addItem:textItem toSectionWithIdentifier:SectionIdentifierText];
textItem = [[TableViewTextItem alloc] initWithType:ItemTypeText];
textItem.text = @"1234";
textItem.masked = YES;
[model addItem:textItem toSectionWithIdentifier:SectionIdentifierText];
TableViewAccessoryItem* textAccessoryItem = TableViewAccessoryItem* textAccessoryItem =
[[TableViewAccessoryItem alloc] initWithType:ItemTypeTextAccessoryImage]; [[TableViewAccessoryItem alloc] initWithType:ItemTypeTextAccessoryImage];
textAccessoryItem.title = @"Text Accessory with History Image"; textAccessoryItem.title = @"Text Accessory with History Image";
......
...@@ -39,4 +39,7 @@ extern const int kTableViewSecondaryLabelLightGrayTextColor; ...@@ -39,4 +39,7 @@ extern const int kTableViewSecondaryLabelLightGrayTextColor;
// Hex Value for the tint color for switches. // Hex Value for the tint color for switches.
extern const int kTableViewSwitchTintColor; extern const int kTableViewSwitchTintColor;
// A masked password string(e.g. "••••••••").
extern NSString* const kMaskedPassword;
#endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_CELLS_CONSTANTS_H_ #endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_CELLS_CONSTANTS_H_
...@@ -19,3 +19,5 @@ const CGFloat kTableViewLabelVerticalTopSpacing = 13.0; ...@@ -19,3 +19,5 @@ const CGFloat kTableViewLabelVerticalTopSpacing = 13.0;
const int kTableViewTextLabelColorLightGrey = 0x6D6D72; const int kTableViewTextLabelColorLightGrey = 0x6D6D72;
const int kTableViewSecondaryLabelLightGrayTextColor = 0x8E8E93; const int kTableViewSecondaryLabelLightGrayTextColor = 0x8E8E93;
const int kTableViewSwitchTintColor = 0x1A73E8; const int kTableViewSwitchTintColor = 0x1A73E8;
NSString* const kMaskedPassword = @"••••••••";
...@@ -20,7 +20,10 @@ ...@@ -20,7 +20,10 @@
// takes precedence over the default color, but not over |textColor|. // takes precedence over the default color, but not over |textColor|.
@property(nonatomic, assign) UIColor* textColor; @property(nonatomic, assign) UIColor* textColor;
@property(nonatomic, readwrite, strong) NSString* text; @property(nonatomic, strong) NSString* text;
// If set to YES, |text| will be shown as "••••••" with fixed length.
@property(nonatomic, assign) BOOL masked;
@end @end
......
...@@ -21,9 +21,6 @@ const CGFloat kLabelCellVerticalSpacing = 11.0; ...@@ -21,9 +21,6 @@ const CGFloat kLabelCellVerticalSpacing = 11.0;
#pragma mark - TableViewTextItem #pragma mark - TableViewTextItem
@implementation TableViewTextItem @implementation TableViewTextItem
@synthesize text = _text;
@synthesize textAlignment = _textAlignment;
@synthesize textColor = _textColor;
- (instancetype)initWithType:(NSInteger)type { - (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type]; self = [super initWithType:type];
...@@ -38,10 +35,17 @@ const CGFloat kLabelCellVerticalSpacing = 11.0; ...@@ -38,10 +35,17 @@ const CGFloat kLabelCellVerticalSpacing = 11.0;
[super configureCell:tableCell withStyler:styler]; [super configureCell:tableCell withStyler:styler];
TableViewTextCell* cell = TableViewTextCell* cell =
base::mac::ObjCCastStrict<TableViewTextCell>(tableCell); base::mac::ObjCCastStrict<TableViewTextCell>(tableCell);
cell.textLabel.text = self.text; cell.textLabel.text = self.masked ? kMaskedPassword : self.text;
cell.textLabel.backgroundColor = styler.tableViewBackgroundColor; // Decide cell.textLabel.backgroundColor in order:
// This item's text color takes precedence over the global styler. // 1. styler.cellBackgroundColor;
// TODO(crbug.com/854249): redo the logic for this convoluted if clause. // 2. styler.tableViewBackgroundColor.
cell.textLabel.backgroundColor = styler.cellBackgroundColor
? styler.cellBackgroundColor
: styler.tableViewBackgroundColor;
// Decide cell.textLabel.textColor in order:
// 1. this.textColor;
// 2. styler.cellTitleColor;
// 3. kTableViewTextLabelColorLightGrey.
if (self.textColor) { if (self.textColor) {
cell.textLabel.textColor = self.textColor; cell.textLabel.textColor = self.textColor;
} else if (styler.cellTitleColor) { } else if (styler.cellTitleColor) {
......
...@@ -39,6 +39,27 @@ TEST_F(TableViewTextItemTest, TextLabels) { ...@@ -39,6 +39,27 @@ TEST_F(TableViewTextItemTest, TextLabels) {
EXPECT_NSEQ(text, textCell.textLabel.text); EXPECT_NSEQ(text, textCell.textLabel.text);
} }
// Tests that item's text is shown as masked string in UILabel after a call to
// |configureCell:| with item.masked set to YES.
TEST_F(TableViewTextItemTest, MaskedTextLabels) {
NSString* text = @"Cell text";
TableViewTextItem* item = [[TableViewTextItem alloc] initWithType:0];
item.text = text;
item.masked = YES;
id cell = [[[item cellClass] alloc] init];
ASSERT_TRUE([cell isMemberOfClass:[TableViewTextCell class]]);
TableViewTextCell* textCell =
base::mac::ObjCCastStrict<TableViewTextCell>(cell);
EXPECT_FALSE(textCell.textLabel.text);
ChromeTableViewStyler* styler = [[ChromeTableViewStyler alloc] init];
[item configureCell:textCell withStyler:styler];
EXPECT_NSEQ(kMaskedPassword, textCell.textLabel.text);
}
TEST_F(TableViewTextItemTest, ConfigureCellWithStyler) { TEST_F(TableViewTextItemTest, ConfigureCellWithStyler) {
TableViewTextItem* item = [[TableViewTextItem alloc] initWithType:0]; TableViewTextItem* item = [[TableViewTextItem alloc] initWithType:0];
TableViewTextCell* cell = [[[item cellClass] alloc] init]; TableViewTextCell* cell = [[[item cellClass] alloc] init];
......
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