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