Commit e6842e2e authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] make manual fallback action cells full width

Also allow them to be disabled to be used as message cells.

Change-Id: I545a0849fa4656e1959c8f01ad456e2b0a52cd78
Reviewed-on: https://chromium-review.googlesource.com/c/1350618
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611122}
parent 377a0f0f
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
- (instancetype)initWithType:(NSInteger)type NS_UNAVAILABLE; - (instancetype)initWithType:(NSInteger)type NS_UNAVAILABLE;
// Set enable to NO to create a message line cell.
@property(nonatomic, assign) BOOL enabled;
@end @end
// A table view cell which contains a button and holds an action block, which // A table view cell which contains a button and holds an action block, which
...@@ -25,7 +28,8 @@ ...@@ -25,7 +28,8 @@
// Updates the cell with the passed title and action block. // Updates the cell with the passed title and action block.
- (void)setUpWithTitle:(NSString*)title - (void)setUpWithTitle:(NSString*)title
accessibilityID:(NSString*)accessibilityID accessibilityID:(NSString*)accessibilityID
action:(void (^)(void))action; action:(void (^)(void))action
enabled:(BOOL)enabled;
@end @end
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/autofill/manual_fill/action_cell.h" #import "ios/chrome/browser/ui/autofill/manual_fill/action_cell.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_cell_utils.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/uicolor_manualfill.h" #import "ios/chrome/browser/ui/autofill/manual_fill/uicolor_manualfill.h"
#import "ios/chrome/browser/ui/list_model/list_model.h" #import "ios/chrome/browser/ui/list_model/list_model.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h" #import "ios/chrome/common/ui_util/constraints_ui_util.h"
...@@ -13,19 +14,23 @@ ...@@ -13,19 +14,23 @@
#endif #endif
namespace { namespace {
// Left and right margins of the cell contents.
static const CGFloat sideMargins = 16;
// The multiplier for the base system spacing at the top margin. // The multiplier for the base system spacing at the top margin.
static const CGFloat TopBaseSystemSpacingMultiplier = 1.1; static const CGFloat TopBaseSystemSpacingMultiplier = 1.1;
// The multiplier for the base system spacing at the bottom margin. // The multiplier for the base system spacing at the bottom margin.
static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5; static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5;
} // namespace } // namespace
@interface ManualFillActionItem () @interface ManualFillActionItem ()
// The action block to be called when the user taps the title. // The action block to be called when the user taps the title.
@property(nonatomic, copy, readonly) void (^action)(void); @property(nonatomic, copy, readonly) void (^action)(void);
// The title for the action. // The title for the action.
@property(nonatomic, copy, readonly) NSString* title; @property(nonatomic, copy, readonly) NSString* title;
@end @end
@implementation ManualFillActionItem @implementation ManualFillActionItem
...@@ -35,6 +40,7 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5; ...@@ -35,6 +40,7 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5;
if (self) { if (self) {
_title = [title copy]; _title = [title copy];
_action = [action copy]; _action = [action copy];
_enabled = YES;
self.cellClass = [ManualFillActionCell class]; self.cellClass = [ManualFillActionCell class];
} }
return self; return self;
...@@ -46,7 +52,8 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5; ...@@ -46,7 +52,8 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5;
cell.accessibilityIdentifier = nil; cell.accessibilityIdentifier = nil;
[cell setUpWithTitle:self.title [cell setUpWithTitle:self.title
accessibilityID:self.accessibilityIdentifier accessibilityID:self.accessibilityIdentifier
action:self.action]; action:self.action
enabled:self.enabled];
} }
@end @end
...@@ -59,8 +66,6 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5; ...@@ -59,8 +66,6 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5;
@end @end
@implementation ManualFillActionCell @implementation ManualFillActionCell
@synthesize action = _action;
@synthesize titleButton = _titleButton;
#pragma mark - Public #pragma mark - Public
...@@ -69,17 +74,26 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5; ...@@ -69,17 +74,26 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5;
self.action = nil; self.action = nil;
[self.titleButton setTitle:nil forState:UIControlStateNormal]; [self.titleButton setTitle:nil forState:UIControlStateNormal];
self.titleButton.accessibilityIdentifier = nil; self.titleButton.accessibilityIdentifier = nil;
[self.titleButton setTitleColor:UIColor.cr_manualFillTintColor
forState:UIControlStateNormal];
self.titleButton.enabled = YES;
} }
- (void)setUpWithTitle:(NSString*)title - (void)setUpWithTitle:(NSString*)title
accessibilityID:(NSString*)accessibilityID accessibilityID:(NSString*)accessibilityID
action:(void (^)(void))action { action:(void (^)(void))action
enabled:(BOOL)enabled {
if (self.contentView.subviews.count == 0) { if (self.contentView.subviews.count == 0) {
[self createView]; [self createView];
} }
[self.titleButton setTitle:title forState:UIControlStateNormal]; [self.titleButton setTitle:title forState:UIControlStateNormal];
self.titleButton.accessibilityIdentifier = accessibilityID; self.titleButton.accessibilityIdentifier = accessibilityID;
self.titleButton.enabled = enabled;
if (!enabled) {
[self.titleButton setTitleColor:UIColor.lightGrayColor
forState:UIControlStateNormal];
}
self.action = action; self.action = action;
} }
...@@ -88,45 +102,17 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5; ...@@ -88,45 +102,17 @@ static const CGFloat BottomBaseSystemSpacingMultiplier = 1.5;
- (void)createView { - (void)createView {
self.selectionStyle = UITableViewCellSelectionStyleNone; self.selectionStyle = UITableViewCellSelectionStyleNone;
self.titleButton = [UIButton buttonWithType:UIButtonTypeSystem]; UIView* guide = self.contentView;
[self.titleButton setTitleColor:UIColor.cr_manualFillTintColor
forState:UIControlStateNormal]; self.titleButton = CreateButtonWithSelectorAndTarget(
self.titleButton.translatesAutoresizingMaskIntoConstraints = NO; @selector(userDidTapTitleButton:), self);
self.titleButton.titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleBody];
self.titleButton.titleLabel.adjustsFontForContentSizeCategory = YES;
[self.titleButton addTarget:self
action:@selector(userDidTapTitleButton:)
forControlEvents:UIControlEventTouchUpInside];
self.titleButton.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail; self.titleButton.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
[self.contentView addSubview:self.titleButton]; [self.contentView addSubview:self.titleButton];
id<LayoutGuideProvider> safeArea = self.contentView.safeAreaLayoutGuide; HorizontalConstraintsForViewsOnGuideWithShift(@[ self.titleButton ], guide,
0);
NSArray* verticalConstraints; VerticalConstraintsSpacingForViewsInContainerWithMultipliers(
// Multipliers of these constraints are calculated based on a 24 base @[ self.titleButton ], self.contentView, TopBaseSystemSpacingMultiplier,
// system spacing. 0, BottomBaseSystemSpacingMultiplier);
verticalConstraints = @[
// Vertical constraints.
[self.titleButton.firstBaselineAnchor
constraintEqualToSystemSpacingBelowAnchor:self.contentView.topAnchor
multiplier:
TopBaseSystemSpacingMultiplier],
[self.contentView.bottomAnchor
constraintEqualToSystemSpacingBelowAnchor:self.titleButton
.lastBaselineAnchor
multiplier:
BottomBaseSystemSpacingMultiplier],
];
[NSLayoutConstraint activateConstraints:verticalConstraints];
// Horizontal constraints.
[NSLayoutConstraint activateConstraints:@[
[self.titleButton.leadingAnchor
constraintEqualToAnchor:safeArea.leadingAnchor
constant:sideMargins],
[safeArea.trailingAnchor
constraintGreaterThanOrEqualToAnchor:self.titleButton.trailingAnchor
constant:sideMargins],
]];
} }
- (void)userDidTapTitleButton:(UIButton*)sender { - (void)userDidTapTitleButton:(UIButton*)sender {
......
...@@ -113,6 +113,8 @@ static const CGFloat NoMultiplier = 1.0; ...@@ -113,6 +113,8 @@ static const CGFloat NoMultiplier = 1.0;
self.siteNameLabel.text = @""; self.siteNameLabel.text = @"";
[self.usernameButton setTitle:@"" forState:UIControlStateNormal]; [self.usernameButton setTitle:@"" forState:UIControlStateNormal];
self.usernameButton.enabled = YES; self.usernameButton.enabled = YES;
[self.usernameButton setTitleColor:UIColor.cr_manualFillTintColor
forState:UIControlStateNormal];
[self.passwordButton setTitle:@"" forState:UIControlStateNormal]; [self.passwordButton setTitle:@"" forState:UIControlStateNormal];
self.manualFillCredential = nil; self.manualFillCredential = nil;
} }
......
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