Commit 7cfe1330 authored by Mohamad Ahmadi's avatar Mohamad Ahmadi Committed by Commit Bot

[Autofill] Uses credit card icons in components instead of imagesets.

- Adds 3x resources to components/resources/autofill. These missing
  resources where causing the ResourceBundle to load the 1x ones for
  iPhone plus devices which resulted in blurry icons.
- Modifies the 1x and 2x resources for the generic credit card to match
  the 3x one.
- Removes the imagesets from iOS bundle and changes the autofill suggestion
  code to use the resources in the components.

Bug: 763499
Change-Id: I5463bc20c30b884ee4685a3fd2cd28d84625a709
Reviewed-on: https://chromium-review.googlesource.com/660802
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501283}
parent 7bf1119d
...@@ -28,14 +28,6 @@ source_set("autofill") { ...@@ -28,14 +28,6 @@ source_set("autofill") {
"validation_rules_storage_factory.h", "validation_rules_storage_factory.h",
] ]
deps = [ deps = [
"resources:autofill_card_american_express",
"resources:autofill_card_diners",
"resources:autofill_card_discover",
"resources:autofill_card_generic",
"resources:autofill_card_jcb",
"resources:autofill_card_mastercard",
"resources:autofill_card_unionpay",
"resources:autofill_card_visa",
"resources:autofill_close", "resources:autofill_close",
"resources:autofill_close_pressed", "resources:autofill_close_pressed",
"resources:autofill_keyboard_background", "resources:autofill_keyboard_background",
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/credit_card.h" #include "components/autofill/core/browser/credit_card.h"
#import "components/autofill/ios/browser/form_suggestion.h" #import "components/autofill/ios/browser/form_suggestion.h"
#import "ios/chrome/browser/autofill/form_suggestion_view_client.h" #import "ios/chrome/browser/autofill/form_suggestion_view_client.h"
...@@ -53,18 +54,6 @@ struct IconImageMap { ...@@ -53,18 +54,6 @@ struct IconImageMap {
NSString* image_name; NSString* image_name;
}; };
const IconImageMap kCreditCardIconImageMap[] = {
{autofill::kAmericanExpressCard, @"autofill_card_american_express"},
{autofill::kDiscoverCard, @"autofill_card_discover"},
{autofill::kMasterCard, @"autofill_card_mastercard"},
{autofill::kMirCard, @"autofill_card_mir"},
{autofill::kVisaCard, @"autofill_card_visa"},
{autofill::kDinersCard, @"autofill_card_diners"},
{autofill::kGenericCard, @"autofill_card_generic"},
{autofill::kJCBCard, @"autofill_card_jcb"},
{autofill::kUnionPay, @"autofill_card_unionpay"},
};
// Creates a label with the given |text| and |alpha| suitable for use in a // Creates a label with the given |text| and |alpha| suitable for use in a
// suggestion button in the keyboard accessory view. // suggestion button in the keyboard accessory view.
UILabel* TextLabel(NSString* text, CGFloat alpha, BOOL bold) { UILabel* TextLabel(NSString* text, CGFloat alpha, BOOL bold) {
...@@ -82,12 +71,6 @@ UILabel* TextLabel(NSString* text, CGFloat alpha, BOOL bold) { ...@@ -82,12 +71,6 @@ UILabel* TextLabel(NSString* text, CGFloat alpha, BOOL bold) {
} // namespace } // namespace
@interface FormSuggestionLabel ()
// Returns the name of the image for credit card icon.
+ (NSString*)imageNameForCreditCardIcon:(NSString*)icon;
@end
@implementation FormSuggestionLabel { @implementation FormSuggestionLabel {
// Client of this view. // Client of this view.
__weak id<FormSuggestionViewClient> client_; __weak id<FormSuggestionViewClient> client_;
...@@ -109,22 +92,17 @@ UILabel* TextLabel(NSString* text, CGFloat alpha, BOOL bold) { ...@@ -109,22 +92,17 @@ UILabel* TextLabel(NSString* text, CGFloat alpha, BOOL bold) {
const CGFloat frameHeight = CGRectGetHeight(proposedFrame); const CGFloat frameHeight = CGRectGetHeight(proposedFrame);
CGFloat currentX = kBorderWidth; CGFloat currentX = kBorderWidth;
// [UIImage imageNamed:] writes error message if nil is passed. Prevent const int iconImageID = autofill::data_util::GetPaymentRequestData(
// console spam by checking the name first. base::SysNSStringToUTF8(suggestion.icon))
NSString* iconImageName = .icon_resource_id;
[FormSuggestionLabel imageNameForCreditCardIcon:suggestion.icon]; UIImage* iconImage = NativeImage(iconImageID);
UIImage* iconImage = nil; UIImageView* iconView = [[UIImageView alloc] initWithImage:iconImage];
if (iconImageName) const CGFloat iconY =
iconImage = [UIImage imageNamed:iconImageName]; std::floor((frameHeight - iconImage.size.height) / 2.0f);
if (iconImage) { iconView.frame = CGRectMake(currentX, iconY, iconImage.size.width,
UIImageView* iconView = [[UIImageView alloc] initWithImage:iconImage]; iconImage.size.height);
const CGFloat iconY = [self addSubview:iconView];
std::floor((frameHeight - iconImage.size.height) / 2.0f); currentX += CGRectGetWidth(iconView.frame) + kSpacing;
iconView.frame = CGRectMake(currentX, iconY, iconImage.size.width,
iconImage.size.height);
[self addSubview:iconView];
currentX += CGRectGetWidth(iconView.frame) + kSpacing;
}
UILabel* label = TextLabel(suggestion.value, kMainLabelAlpha, YES); UILabel* label = TextLabel(suggestion.value, kMainLabelAlpha, YES);
const CGFloat labelY = const CGFloat labelY =
...@@ -190,20 +168,4 @@ UILabel* TextLabel(NSString* text, CGFloat alpha, BOOL bold) { ...@@ -190,20 +168,4 @@ UILabel* TextLabel(NSString* text, CGFloat alpha, BOOL bold) {
[client_ didSelectSuggestion:suggestion_]; [client_ didSelectSuggestion:suggestion_];
} }
#pragma mark -
#pragma mark Private
+ (NSString*)imageNameForCreditCardIcon:(NSString*)icon {
if (!icon || [icon length] == 0) {
return nil;
}
std::string iconName(base::SysNSStringToUTF8(icon));
for (size_t i = 0; i < arraysize(kCreditCardIconImageMap); ++i) {
if (iconName.compare(kCreditCardIconImageMap[i].icon_name) == 0) {
return kCreditCardIconImageMap[i].image_name;
}
}
return nil;
}
@end @end
...@@ -4,94 +4,6 @@ ...@@ -4,94 +4,6 @@
import("//build/config/ios/imageset.gni") import("//build/config/ios/imageset.gni")
imageset("autofill_card_american_express") {
sources = [
"autofill_card_american_express.imageset/Contents.json",
"autofill_card_american_express.imageset/autofill_card_american_express.png",
"autofill_card_american_express.imageset/autofill_card_american_express@2x.png",
"autofill_card_american_express.imageset/autofill_card_american_express@2x~ipad.png",
"autofill_card_american_express.imageset/autofill_card_american_express@3x.png",
"autofill_card_american_express.imageset/autofill_card_american_express~ipad.png",
]
}
imageset("autofill_card_diners") {
sources = [
"autofill_card_diners.imageset/Contents.json",
"autofill_card_diners.imageset/autofill_card_diners.png",
"autofill_card_diners.imageset/autofill_card_diners@2x.png",
"autofill_card_diners.imageset/autofill_card_diners@2x~ipad.png",
"autofill_card_diners.imageset/autofill_card_diners@3x.png",
"autofill_card_diners.imageset/autofill_card_diners~ipad.png",
]
}
imageset("autofill_card_discover") {
sources = [
"autofill_card_discover.imageset/Contents.json",
"autofill_card_discover.imageset/autofill_card_discover.png",
"autofill_card_discover.imageset/autofill_card_discover@2x.png",
"autofill_card_discover.imageset/autofill_card_discover@2x~ipad.png",
"autofill_card_discover.imageset/autofill_card_discover@3x.png",
"autofill_card_discover.imageset/autofill_card_discover~ipad.png",
]
}
imageset("autofill_card_generic") {
sources = [
"autofill_card_generic.imageset/Contents.json",
"autofill_card_generic.imageset/autofill_card_generic.png",
"autofill_card_generic.imageset/autofill_card_generic@2x.png",
"autofill_card_generic.imageset/autofill_card_generic@2x~ipad.png",
"autofill_card_generic.imageset/autofill_card_generic@3x.png",
"autofill_card_generic.imageset/autofill_card_generic~ipad.png",
]
}
imageset("autofill_card_jcb") {
sources = [
"autofill_card_jcb.imageset/Contents.json",
"autofill_card_jcb.imageset/autofill_card_jcb.png",
"autofill_card_jcb.imageset/autofill_card_jcb@2x.png",
"autofill_card_jcb.imageset/autofill_card_jcb@2x~ipad.png",
"autofill_card_jcb.imageset/autofill_card_jcb@3x.png",
"autofill_card_jcb.imageset/autofill_card_jcb~ipad.png",
]
}
imageset("autofill_card_mastercard") {
sources = [
"autofill_card_mastercard.imageset/Contents.json",
"autofill_card_mastercard.imageset/autofill_card_mastercard.png",
"autofill_card_mastercard.imageset/autofill_card_mastercard@2x.png",
"autofill_card_mastercard.imageset/autofill_card_mastercard@2x~ipad.png",
"autofill_card_mastercard.imageset/autofill_card_mastercard@3x.png",
"autofill_card_mastercard.imageset/autofill_card_mastercard~ipad.png",
]
}
imageset("autofill_card_unionpay") {
sources = [
"autofill_card_unionpay.imageset/Contents.json",
"autofill_card_unionpay.imageset/autofill_card_unionpay.png",
"autofill_card_unionpay.imageset/autofill_card_unionpay@2x.png",
"autofill_card_unionpay.imageset/autofill_card_unionpay@2x~ipad.png",
"autofill_card_unionpay.imageset/autofill_card_unionpay@3x.png",
"autofill_card_unionpay.imageset/autofill_card_unionpay~ipad.png",
]
}
imageset("autofill_card_visa") {
sources = [
"autofill_card_visa.imageset/Contents.json",
"autofill_card_visa.imageset/autofill_card_visa.png",
"autofill_card_visa.imageset/autofill_card_visa@2x.png",
"autofill_card_visa.imageset/autofill_card_visa@2x~ipad.png",
"autofill_card_visa.imageset/autofill_card_visa@3x.png",
"autofill_card_visa.imageset/autofill_card_visa~ipad.png",
]
}
imageset("autofill_close") { imageset("autofill_close") {
sources = [ sources = [
"autofill_close.imageset/Contents.json", "autofill_close.imageset/Contents.json",
......
{
"images": [
{
"idiom": "iphone",
"scale": "1x",
"filename": "autofill_card_american_express.png"
},
{
"idiom": "iphone",
"scale": "2x",
"filename": "autofill_card_american_express@2x.png"
},
{
"idiom": "ipad",
"scale": "2x",
"filename": "autofill_card_american_express@2x~ipad.png"
},
{
"idiom": "iphone",
"scale": "3x",
"filename": "autofill_card_american_express@3x.png"
},
{
"idiom": "ipad",
"scale": "1x",
"filename": "autofill_card_american_express~ipad.png"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
{
"images": [
{
"idiom": "iphone",
"scale": "1x",
"filename": "autofill_card_diners.png"
},
{
"idiom": "iphone",
"scale": "2x",
"filename": "autofill_card_diners@2x.png"
},
{
"idiom": "ipad",
"scale": "2x",
"filename": "autofill_card_diners@2x~ipad.png"
},
{
"idiom": "iphone",
"scale": "3x",
"filename": "autofill_card_diners@3x.png"
},
{
"idiom": "ipad",
"scale": "1x",
"filename": "autofill_card_diners~ipad.png"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
{
"images": [
{
"idiom": "iphone",
"scale": "1x",
"filename": "autofill_card_discover.png"
},
{
"idiom": "iphone",
"scale": "2x",
"filename": "autofill_card_discover@2x.png"
},
{
"idiom": "ipad",
"scale": "2x",
"filename": "autofill_card_discover@2x~ipad.png"
},
{
"idiom": "iphone",
"scale": "3x",
"filename": "autofill_card_discover@3x.png"
},
{
"idiom": "ipad",
"scale": "1x",
"filename": "autofill_card_discover~ipad.png"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
{
"images": [
{
"idiom": "iphone",
"scale": "1x",
"filename": "autofill_card_generic.png"
},
{
"idiom": "iphone",
"scale": "2x",
"filename": "autofill_card_generic@2x.png"
},
{
"idiom": "ipad",
"scale": "2x",
"filename": "autofill_card_generic@2x~ipad.png"
},
{
"idiom": "iphone",
"scale": "3x",
"filename": "autofill_card_generic@3x.png"
},
{
"idiom": "ipad",
"scale": "1x",
"filename": "autofill_card_generic~ipad.png"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
{
"images": [
{
"idiom": "iphone",
"scale": "1x",
"filename": "autofill_card_jcb.png"
},
{
"idiom": "iphone",
"scale": "2x",
"filename": "autofill_card_jcb@2x.png"
},
{
"idiom": "ipad",
"scale": "2x",
"filename": "autofill_card_jcb@2x~ipad.png"
},
{
"idiom": "iphone",
"scale": "3x",
"filename": "autofill_card_jcb@3x.png"
},
{
"idiom": "ipad",
"scale": "1x",
"filename": "autofill_card_jcb~ipad.png"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
{
"images": [
{
"idiom": "iphone",
"scale": "1x",
"filename": "autofill_card_mastercard.png"
},
{
"idiom": "iphone",
"scale": "2x",
"filename": "autofill_card_mastercard@2x.png"
},
{
"idiom": "ipad",
"scale": "2x",
"filename": "autofill_card_mastercard@2x~ipad.png"
},
{
"idiom": "iphone",
"scale": "3x",
"filename": "autofill_card_mastercard@3x.png"
},
{
"idiom": "ipad",
"scale": "1x",
"filename": "autofill_card_mastercard~ipad.png"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
{
"images": [
{
"idiom": "iphone",
"scale": "1x",
"filename": "autofill_card_unionpay.png"
},
{
"idiom": "iphone",
"scale": "2x",
"filename": "autofill_card_unionpay@2x.png"
},
{
"idiom": "ipad",
"scale": "2x",
"filename": "autofill_card_unionpay@2x~ipad.png"
},
{
"idiom": "iphone",
"scale": "3x",
"filename": "autofill_card_unionpay@3x.png"
},
{
"idiom": "ipad",
"scale": "1x",
"filename": "autofill_card_unionpay~ipad.png"
}
],
"info": {
"version": 1,
"author": "xcode"
}
}
{
"images": [
{
"idiom": "iphone",
"scale": "1x",
"filename": "autofill_card_visa.png"
},
{
"idiom": "iphone",
"scale": "2x",
"filename": "autofill_card_visa@2x.png"
},
{
"idiom": "ipad",
"scale": "2x",
"filename": "autofill_card_visa@2x~ipad.png"
},
{
"idiom": "iphone",
"scale": "3x",
"filename": "autofill_card_visa@3x.png"
},
{
"idiom": "ipad",
"scale": "1x",
"filename": "autofill_card_visa~ipad.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