| Index: ios/chrome/browser/ui/settings/cells/password_details_item.mm
|
| diff --git a/ios/chrome/browser/ui/settings/cells/password_details_item.mm b/ios/chrome/browser/ui/settings/cells/password_details_item.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9a59dcde1f2c97227c91fad9069507c458e93421
|
| --- /dev/null
|
| +++ b/ios/chrome/browser/ui/settings/cells/password_details_item.mm
|
| @@ -0,0 +1,113 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#import "ios/chrome/browser/ui/settings/cells/password_details_item.h"
|
| +
|
| +#import <CoreGraphics/CoreGraphics.h>
|
| +#import <UIKit/UIKit.h>
|
| +
|
| +#include "ios/chrome/grit/ios_strings.h"
|
| +#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
|
| +#import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoFontLoader.h"
|
| +#include "ui/base/l10n/l10n_util_mac.h"
|
| +
|
| +#if !defined(__has_feature) || !__has_feature(objc_arc)
|
| +#error "This file requires ARC support."
|
| +#endif
|
| +
|
| +namespace {
|
| +// Padding used on the leading and trailing edges of the cell.
|
| +const CGFloat kHorizontalPadding = 16;
|
| +
|
| +// Padding used on the top and bottom edges of the cell.
|
| +const CGFloat kVerticalPadding = 16;
|
| +} // namespace
|
| +
|
| +@implementation PasswordDetailsItem
|
| +
|
| +@synthesize text = _text;
|
| +@synthesize showingText = _showingText;
|
| +
|
| +- (instancetype)initWithType:(NSInteger)type {
|
| + self = [super initWithType:type];
|
| + if (self) {
|
| + self.cellClass = [PasswordDetailsCell class];
|
| + }
|
| + return self;
|
| +}
|
| +
|
| +- (void)configureCell:(PasswordDetailsCell*)cell {
|
| + [super configureCell:cell];
|
| + if (self.showingText) {
|
| + cell.textLabel.text = self.text;
|
| + cell.accessibilityLabel = self.text;
|
| + } else {
|
| + NSString* obscuredText = [@"" stringByPaddingToLength:[self.text length]
|
| + withString:@"●"
|
| + startingAtIndex:0];
|
| + cell.textLabel.text = obscuredText;
|
| + cell.accessibilityLabel =
|
| + l10n_util::GetNSString(IDS_IOS_SETTINGS_PASSWORD_HIDDEN_LABEL);
|
| + }
|
| +}
|
| +
|
| +@end
|
| +
|
| +@implementation PasswordDetailsCell
|
| +
|
| +@synthesize textLabel = _textLabel;
|
| +
|
| +- (instancetype)initWithFrame:(CGRect)frame {
|
| + self = [super initWithFrame:frame];
|
| + if (self) {
|
| + UIView* contentView = self.contentView;
|
| +
|
| + _textLabel = [[UILabel alloc] init];
|
| + _textLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
| + [contentView addSubview:_textLabel];
|
| +
|
| + _textLabel.font =
|
| + [[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:14];
|
| + _textLabel.textColor = [[MDCPalette greyPalette] tint900];
|
| + _textLabel.numberOfLines = 0;
|
| +
|
| + // Set up the constraints.
|
| + [NSLayoutConstraint activateConstraints:@[
|
| + [_textLabel.leadingAnchor
|
| + constraintEqualToAnchor:contentView.leadingAnchor
|
| + constant:kHorizontalPadding],
|
| + [_textLabel.trailingAnchor
|
| + constraintEqualToAnchor:contentView.trailingAnchor
|
| + constant:-kHorizontalPadding],
|
| + [_textLabel.topAnchor constraintEqualToAnchor:contentView.topAnchor
|
| + constant:kVerticalPadding],
|
| + [_textLabel.bottomAnchor constraintEqualToAnchor:contentView.bottomAnchor
|
| + constant:-kVerticalPadding],
|
| + ]];
|
| + }
|
| + return self;
|
| +}
|
| +
|
| +- (void)prepareForReuse {
|
| + [super prepareForReuse];
|
| + self.textLabel.text = nil;
|
| + self.accessibilityLabel = nil;
|
| +}
|
| +
|
| +// Implements -layoutSubviews as per instructions in documentation for
|
| +// +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:].
|
| +- (void)layoutSubviews {
|
| + [super layoutSubviews];
|
| +
|
| + // Adjust the text label preferredMaxLayoutWidth when the parent's width
|
| + // changes, for instance on screen rotation.
|
| + CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds);
|
| + self.textLabel.preferredMaxLayoutWidth = parentWidth - 2 * kHorizontalPadding;
|
| +
|
| + // Re-layout with the new preferred width to allow the label to adjust its
|
| + // height.
|
| + [super layoutSubviews];
|
| +}
|
| +
|
| +@end
|
|
|