Commit b69acc5b authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][MF] Hide favicons with no image

Bug: 942107
Change-Id: Ic675a55bf775d8531585cf7d2b62ce3a8ca35755
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1543262
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#645402}
parent a9fc0e4e
......@@ -9,6 +9,7 @@
#import "ios/chrome/browser/ui/table_view/cells/table_view_item.h"
@class FaviconAttributes;
@class FaviconView;
class GURL;
@protocol ManualFillContentDelegate;
......@@ -23,6 +24,10 @@ class GURL;
// Identifier to match a URLItem with its URLCell.
@property(nonatomic, readonly) NSString* uniqueIdentifier;
// The cell won't show a title (site name) label if it is connected to the
// previous password item.
@property(nonatomic, readonly) BOOL isConnectedToPreviousItem;
- (instancetype)initWithCredential:(ManualFillCredential*)credential
isConnectedToPreviousItem:(BOOL)isConnectedToPreviousItem
isConnectedToNextItem:(BOOL)isConnectedToNextItem
......@@ -37,9 +42,6 @@ class GURL;
// and send the data to the delegate.
@interface ManualFillPasswordCell : TableViewCell
// The favicon for the credential.
@property(nonatomic, readonly) FaviconView* faviconView;
// Identifier to match a URLItem with its URLCell.
@property(nonatomic, readonly) NSString* uniqueIdentifier;
......@@ -50,6 +52,9 @@ class GURL;
isConnectedToNextCell:(BOOL)isConnectedToNextCell
delegate:(id<ManualFillContentDelegate>)delegate;
// Configures the cell for the passed favicon attributes.
- (void)configureWithFaviconAttributes:(FaviconAttributes*)attributes;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_MANUAL_FILL_PASSWORD_CELL_H_
......@@ -96,8 +96,11 @@ static const CGFloat NoMultiplier = 1.0;
@property(nonatomic, strong)
NSMutableArray<NSLayoutConstraint*>* dynamicConstraints;
// The constraints for the visible favicon.
@property(nonatomic, strong) NSArray<NSLayoutConstraint*>* faviconContraints;
// The favicon for the credential.
@property(nonatomic, readwrite) FaviconView* faviconView;
@property(nonatomic, strong) FaviconView* faviconView;
// The label with the site name and host.
@property(nonatomic, strong) UILabel* siteNameLabel;
......@@ -122,6 +125,9 @@ static const CGFloat NoMultiplier = 1.0;
- (void)prepareForReuse {
[super prepareForReuse];
[NSLayoutConstraint deactivateConstraints:self.faviconContraints];
self.faviconView.hidden = YES;
[NSLayoutConstraint deactivateConstraints:self.dynamicConstraints];
[self.dynamicConstraints removeAllObjects];
......@@ -230,6 +236,17 @@ static const CGFloat NoMultiplier = 1.0;
return base::SysUTF8ToNSString(self.credential.URL.spec());
}
- (void)configureWithFaviconAttributes:(FaviconAttributes*)attributes {
if (attributes.faviconImage) {
self.faviconView.hidden = NO;
[NSLayoutConstraint activateConstraints:self.faviconContraints];
[self.faviconView configureWithAttributes:attributes];
return;
}
[NSLayoutConstraint deactivateConstraints:self.faviconContraints];
self.faviconView.hidden = YES;
}
#pragma mark - Private
// Creates and sets up the view hierarchy.
......@@ -243,23 +260,30 @@ static const CGFloat NoMultiplier = 1.0;
self.faviconView = [[FaviconView alloc] init];
self.faviconView.translatesAutoresizingMaskIntoConstraints = NO;
self.faviconView.clipsToBounds = YES;
self.faviconView.hidden = YES;
[self.contentView addSubview:self.faviconView];
self.faviconContraints = @[
[self.faviconView.widthAnchor constraintEqualToConstant:gfx::kFaviconSize],
[self.faviconView.heightAnchor
constraintEqualToAnchor:self.faviconView.widthAnchor],
];
self.siteNameLabel = CreateLabel();
self.siteNameLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.siteNameLabel.adjustsFontForContentSizeCategory = YES;
[self.contentView addSubview:self.siteNameLabel];
AppendHorizontalConstraintsForViews(
staticConstraints, @[ self.faviconView, self.siteNameLabel ],
self.contentView, kButtonHorizontalMargin);
[NSLayoutConstraint activateConstraints:@[
[self.faviconView.widthAnchor constraintEqualToConstant:gfx::kFaviconSize],
[self.faviconView.heightAnchor
constraintEqualToAnchor:self.faviconView.widthAnchor],
[self.faviconView.centerYAnchor
constraintEqualToAnchor:self.siteNameLabel.centerYAnchor],
]];
UIStackView* stackView = [[UIStackView alloc] init];
stackView.translatesAutoresizingMaskIntoConstraints = NO;
stackView.spacing = kButtonHorizontalMargin;
[stackView addArrangedSubview:self.faviconView];
[stackView addArrangedSubview:self.siteNameLabel];
[self.contentView addSubview:stackView];
AppendHorizontalConstraintsForViews(staticConstraints, @[ stackView ],
self.contentView,
kButtonHorizontalMargin);
self.usernameButton = CreateChipWithSelectorAndTarget(
@selector(userDidTapUsernameButton:), self);
[self.contentView addSubview:self.usernameButton];
......
......@@ -171,6 +171,10 @@ NSString* const PasswordTableViewAccessibilityIdentifier =
ManualFillCredentialItem* passwordItem =
base::mac::ObjCCastStrict<ManualFillCredentialItem>(item);
if (passwordItem.isConnectedToPreviousItem) {
return;
}
ManualFillPasswordCell* passwordCell =
base::mac::ObjCCastStrict<ManualFillPasswordCell>(cell);
......@@ -181,11 +185,11 @@ NSString* const PasswordTableViewAccessibilityIdentifier =
// Only set favicon if the cell hasn't been reused.
if ([passwordCell.uniqueIdentifier isEqualToString:itemIdentifier]) {
DCHECK(attributes);
[passwordCell.faviconView configureWithAttributes:attributes];
[passwordCell configureWithFaviconAttributes:attributes];
}
}];
DCHECK(cachedAttributes);
[passwordCell.faviconView configureWithAttributes:cachedAttributes];
[passwordCell configureWithFaviconAttributes:cachedAttributes];
}
@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