Commit 5e78df1b authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] Add default icon for cpe list items

Bug: 1045454
Change-Id: I4598f8c15e302a297343fc07eba94fda9980bde1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2145887
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759174}
parent b2ecf020
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#import "ios/chrome/credential_provider_extension/ui/credential_list_view_controller.h" #import "ios/chrome/credential_provider_extension/ui/credential_list_view_controller.h"
#import "base/mac/foundation_util.h"
#import "ios/chrome/common/credential_provider/credential.h" #import "ios/chrome/common/credential_provider/credential.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h" #import "ios/chrome/common/ui/colors/semantic_color_names.h"
...@@ -18,54 +17,6 @@ NSString* kHeaderIdentifier = @"clvcHeader"; ...@@ -18,54 +17,6 @@ NSString* kHeaderIdentifier = @"clvcHeader";
NSString* kCellIdentifier = @"clvcCell"; NSString* kCellIdentifier = @"clvcCell";
const CGFloat kHeaderHeight = 70; const CGFloat kHeaderHeight = 70;
const CGFloat kFallbackIconSize = 24;
const CGFloat kFallbackRoundedCorner = 3;
// Returns an icon with centered letter from given |string| and some
// colors computed from the string.
// TODO(crbug.com/1045454): draw actual icon or default icon.
UIImage* GetFallbackImageWithStringAndColor(NSString* string) {
int hash = string.hash;
UIColor* backgroundColor =
[UIColor colorWithRed:0.5 + (hash & 0xff) / 510.0
green:0.5 + ((hash >> 8) & 0xff) / 510.0
blue:0.5 + ((hash >> 16) & 0xff) / 510.0
alpha:1.0];
UIColor* textColor = [UIColor colorWithRed:(hash & 0xff) / 510.0
green:((hash >> 8) & 0xff) / 510.0
blue:((hash >> 16) & 0xff) / 510.0
alpha:1.0];
CGRect rect = CGRectMake(0, 0, kFallbackIconSize, kFallbackIconSize);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [backgroundColor CGColor]);
CGContextSetStrokeColorWithColor(context, [textColor CGColor]);
UIBezierPath* rounded =
[UIBezierPath bezierPathWithRoundedRect:rect
cornerRadius:kFallbackRoundedCorner];
[rounded fill];
UIFont* font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
font = [font fontWithSize:(kFallbackIconSize / 2)];
CGRect textRect = CGRectMake(0, (kFallbackIconSize - [font lineHeight]) / 2,
kFallbackIconSize, [font lineHeight]);
NSMutableParagraphStyle* paragraphStyle =
[[NSMutableParagraphStyle alloc] init];
[paragraphStyle setAlignment:NSTextAlignmentCenter];
NSMutableDictionary* attributes = [[NSMutableDictionary alloc] init];
[attributes setValue:font forKey:NSFontAttributeName];
[attributes setValue:textColor forKey:NSForegroundColorAttributeName];
[attributes setValue:paragraphStyle forKey:NSParagraphStyleAttributeName];
[[string substringToIndex:1] drawInRect:textRect withAttributes:attributes];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
} }
@interface CredentialListViewController () <UITableViewDataSource, @interface CredentialListViewController () <UITableViewDataSource,
...@@ -158,7 +109,15 @@ UIImage* GetFallbackImageWithStringAndColor(NSString* string) { ...@@ -158,7 +109,15 @@ UIImage* GetFallbackImageWithStringAndColor(NSString* string) {
} }
id<Credential> credential = [self credentialForIndexPath:indexPath]; id<Credential> credential = [self credentialForIndexPath:indexPath];
cell.imageView.image = GetFallbackImageWithStringAndColor(credential.user); if (credential.favicon.length) {
// TODO(crbug.com/1045454): draw actual icon.
cell.imageView.image = [[UIImage imageNamed:@"default_world_favicon"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
} else {
cell.imageView.image = [[UIImage imageNamed:@"default_world_favicon"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
cell.imageView.tintColor = [UIColor colorNamed:kPlaceholderImageTintColor];
}
cell.imageView.contentMode = UIViewContentModeScaleAspectFit; cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
cell.textLabel.text = credential.user; cell.textLabel.text = credential.user;
cell.textLabel.textColor = [UIColor colorNamed:kTextPrimaryColor]; cell.textLabel.textColor = [UIColor colorNamed:kTextPrimaryColor];
......
...@@ -8,6 +8,7 @@ import("//build/config/ios/rules.gni") ...@@ -8,6 +8,7 @@ import("//build/config/ios/rules.gni")
group("resources") { group("resources") {
deps = [ deps = [
":consent_illustration", ":consent_illustration",
":default_world_favicon",
":empty_credentials_illustration", ":empty_credentials_illustration",
":password_hide_icon", ":password_hide_icon",
":password_reveal_icon", ":password_reveal_icon",
...@@ -54,3 +55,12 @@ imageset("password_hide_icon") { ...@@ -54,3 +55,12 @@ imageset("password_hide_icon") {
"password_hide_icon.imageset/password_hide_icon@3x.png", "password_hide_icon.imageset/password_hide_icon@3x.png",
] ]
} }
imageset("default_world_favicon") {
sources = [
"default_world_favicon.imageset/Contents.json",
"default_world_favicon.imageset/default_world_favicon.png",
"default_world_favicon.imageset/default_world_favicon@2x.png",
"default_world_favicon.imageset/default_world_favicon@3x.png",
]
}
{
"images": [
{
"idiom": "universal",
"scale": "1x",
"filename": "default_world_favicon.png"
},
{
"idiom": "universal",
"scale": "2x",
"filename": "default_world_favicon@2x.png"
},
{
"idiom": "universal",
"scale": "3x",
"filename": "default_world_favicon@3x.png"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
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