Commit 474e119f authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] Plug in obj-c address object in manual fill

Bug: 845472
Change-Id: Iac666731ad90f3ac69ed668406ca80e722c9c5cb
Reviewed-on: https://chromium-review.googlesource.com/c/1335574Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Commit-Queue: David Jean <djean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608296}
parent 4f5cf795
...@@ -7,21 +7,18 @@ ...@@ -7,21 +7,18 @@
#include <vector> #include <vector>
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/strings/sys_string_conversions.h"
#include "components/autofill/core/browser/autofill_manager.h"
#include "components/autofill/core/browser/autofill_profile.h" #include "components/autofill/core/browser/autofill_profile.h"
#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/address.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/address_consumer.h" #import "ios/chrome/browser/ui/autofill/manual_fill/address_consumer.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/address_form.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/address_list_delegate.h" #import "ios/chrome/browser/ui/autofill/manual_fill/address_list_delegate.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_address_cell.h" #import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_address_cell.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_content_delegate.h" #import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_content_delegate.h"
#import "ios/chrome/browser/ui/list_model/list_model.h" #import "ios/chrome/browser/ui/list_model/list_model.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h" #import "ios/chrome/browser/ui/table_view/table_view_model.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/web/public/web_state/web_state.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -35,7 +32,7 @@ NSString* const ManageAddressAccessibilityIdentifier = ...@@ -35,7 +32,7 @@ NSString* const ManageAddressAccessibilityIdentifier =
@interface ManualFillAddressMediator () @interface ManualFillAddressMediator ()
// All available addresses. // All available addresses.
@property(nonatomic, assign) std::vector<autofill::AutofillProfile*> profiles; @property(nonatomic, strong) NSArray<ManualFillAddress*>* addresses;
@end @end
...@@ -45,7 +42,13 @@ NSString* const ManageAddressAccessibilityIdentifier = ...@@ -45,7 +42,13 @@ NSString* const ManageAddressAccessibilityIdentifier =
(std::vector<autofill::AutofillProfile*>)profiles { (std::vector<autofill::AutofillProfile*>)profiles {
self = [super init]; self = [super init];
if (self) { if (self) {
_profiles = profiles; NSMutableArray<ManualFillAddress*>* manualFillAddresses =
[[NSMutableArray alloc] initWithCapacity:profiles.size()];
for (autofill::AutofillProfile* profile : profiles) {
[manualFillAddresses
addObject:[[ManualFillAddress alloc] initWithProfile:*profile]];
}
_addresses = manualFillAddresses;
} }
return self; return self;
} }
...@@ -68,11 +71,11 @@ NSString* const ManageAddressAccessibilityIdentifier = ...@@ -68,11 +71,11 @@ NSString* const ManageAddressAccessibilityIdentifier =
} }
NSMutableArray* items = NSMutableArray* items =
[[NSMutableArray alloc] initWithCapacity:self.profiles.size()]; [[NSMutableArray alloc] initWithCapacity:self.addresses.count];
for (autofill::AutofillProfile* profile : self.profiles) { for (ManualFillAddress* address in self.addresses) {
auto item = [[ManualFillAddressItem alloc] auto item =
initWithAutofillProfile:*profile [[ManualFillAddressItem alloc] initWithAddress:address
delegate:self.contentDelegate]; delegate:self.contentDelegate];
[items addObject:item]; [items addObject:item];
} }
......
...@@ -7,12 +7,9 @@ ...@@ -7,12 +7,9 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/autofill/manual_fill/address.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_item.h"
namespace autofill {
class AutofillProfile;
} // namespace autofill
// TODO(crbug.com/845472): rename, see // TODO(crbug.com/845472): rename, see
// https://crrev.com/c/1317853/7/ios/chrome/browser/ui/autofill/manual_fill/manual_fill_address_cell.h#17. // https://crrev.com/c/1317853/7/ios/chrome/browser/ui/autofill/manual_fill/manual_fill_address_cell.h#17.
@protocol ManualFillContentDelegate; @protocol ManualFillContentDelegate;
...@@ -21,9 +18,8 @@ class AutofillProfile; ...@@ -21,9 +18,8 @@ class AutofillProfile;
@interface ManualFillAddressItem : TableViewItem @interface ManualFillAddressItem : TableViewItem
// Inits an address with a |profile| and the |delegate| for user selection. // Inits an address with a |profile| and the |delegate| for user selection.
- (instancetype)initWithAutofillProfile: - (instancetype)initWithAddress:(ManualFillAddress*)address
(const autofill::AutofillProfile&)profile delegate:(id<ManualFillContentDelegate>)delegate
delegate:(id<ManualFillContentDelegate>)delegate
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithType:(NSInteger)type NS_UNAVAILABLE; - (instancetype)initWithType:(NSInteger)type NS_UNAVAILABLE;
...@@ -35,8 +31,8 @@ class AutofillProfile; ...@@ -35,8 +31,8 @@ class AutofillProfile;
@interface ManualFillAddressCell : UITableViewCell @interface ManualFillAddressCell : UITableViewCell
// Updates the cell with address and the |delegate| to be notified. // Updates the cell with address and the |delegate| to be notified.
- (void)setUpWithAutofillProfile:(const autofill::AutofillProfile&)profile - (void)setUpWithAddress:(ManualFillAddress*)profile
delegate:(id<ManualFillContentDelegate>)delegate; delegate:(id<ManualFillContentDelegate>)delegate;
@end @end
......
...@@ -4,18 +4,11 @@ ...@@ -4,18 +4,11 @@
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_address_cell.h" #import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_address_cell.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "ios/chrome/browser/application_context.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/address_list_delegate.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_cell_utils.h" #import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_cell_utils.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_content_delegate.h" #import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_content_delegate.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"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -27,19 +20,18 @@ ...@@ -27,19 +20,18 @@
@property(nonatomic, weak, readonly) id<ManualFillContentDelegate> delegate; @property(nonatomic, weak, readonly) id<ManualFillContentDelegate> delegate;
// The address/profile for this item. // The address/profile for this item.
@property(nonatomic, readonly) autofill::AutofillProfile profile; @property(nonatomic, readonly) ManualFillAddress* address;
@end @end
@implementation ManualFillAddressItem @implementation ManualFillAddressItem
- (instancetype) - (instancetype)initWithAddress:(ManualFillAddress*)address
initWithAutofillProfile:(const autofill::AutofillProfile&)profile delegate:(id<ManualFillContentDelegate>)delegate {
delegate:(id<ManualFillContentDelegate>)delegate {
self = [super initWithType:kItemTypeEnumZero]; self = [super initWithType:kItemTypeEnumZero];
if (self) { if (self) {
_delegate = delegate; _delegate = delegate;
_profile = profile; _address = address;
self.cellClass = [ManualFillAddressCell class]; self.cellClass = [ManualFillAddressCell class];
} }
return self; return self;
...@@ -48,7 +40,7 @@ initWithAutofillProfile:(const autofill::AutofillProfile&)profile ...@@ -48,7 +40,7 @@ initWithAutofillProfile:(const autofill::AutofillProfile&)profile
- (void)configureCell:(ManualFillAddressCell*)cell - (void)configureCell:(ManualFillAddressCell*)cell
withStyler:(ChromeTableViewStyler*)styler { withStyler:(ChromeTableViewStyler*)styler {
[super configureCell:cell withStyler:styler]; [super configureCell:cell withStyler:styler];
[cell setUpWithAutofillProfile:self.profile delegate:self.delegate]; [cell setUpWithAddress:self.address delegate:self.delegate];
} }
@end @end
...@@ -127,10 +119,6 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -127,10 +119,6 @@ static const CGFloat InnerMarginWidth = 16.0;
// The content delegate for this item. // The content delegate for this item.
@property(nonatomic, weak) id<ManualFillContentDelegate> delegate; @property(nonatomic, weak) id<ManualFillContentDelegate> delegate;
// The credit address/profile data for this cell.
// TODO(crbug.com/845472): move to cocoa model.
@property(nonatomic, assign) autofill::AutofillProfile profile;
@end @end
@implementation ManualFillAddressCell @implementation ManualFillAddressCell
...@@ -160,32 +148,29 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -160,32 +148,29 @@ static const CGFloat InnerMarginWidth = 16.0;
[self.countryButton setTitle:@"" forState:UIControlStateNormal]; [self.countryButton setTitle:@"" forState:UIControlStateNormal];
[self.line2Button setTitle:@"" forState:UIControlStateNormal]; [self.line2Button setTitle:@"" forState:UIControlStateNormal];
self.delegate = nil; self.delegate = nil;
// TODO(crbug.com/845472): clear profile.
} }
- (void)setUpWithAutofillProfile:(const autofill::AutofillProfile&)profile - (void)setUpWithAddress:(ManualFillAddress*)address
delegate:(id<ManualFillContentDelegate>)delegate { delegate:(id<ManualFillContentDelegate>)delegate {
if (self.contentView.subviews.count == 0) { if (self.contentView.subviews.count == 0) {
[self createViewHierarchy]; [self createViewHierarchy];
} }
self.delegate = delegate; self.delegate = delegate;
self.profile = profile;
NSMutableArray<UIView*>* verticalLeadViews = [[NSMutableArray alloc] init]; NSMutableArray<UIView*>* verticalLeadViews = [[NSMutableArray alloc] init];
NSString* line1 = [self fieldValueOfType:autofill::ADDRESS_HOME_LINE1];
NSString* line2 = [self fieldValueOfType:autofill::ADDRESS_HOME_LINE2];
// Top label, summary of line 1 and 2. // Top label, summary of line 1 and 2.
NSMutableAttributedString* attributedString = NSMutableAttributedString* attributedString =
[[NSMutableAttributedString alloc] [[NSMutableAttributedString alloc]
initWithString:line1 ? line1 : @"" initWithString:address.line1 ? address.line1 : @""
attributes:@{ attributes:@{
NSForegroundColorAttributeName : UIColor.blackColor, NSForegroundColorAttributeName : UIColor.blackColor,
NSFontAttributeName : NSFontAttributeName :
[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline] [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]
}]; }];
if (line2.length) { if (address.line2.length) {
NSString* line2String = [NSString stringWithFormat:@" –– %@", line2]; NSString* line2String =
[NSString stringWithFormat:@" –– %@", address.line2];
NSDictionary* attributes = @{ NSDictionary* attributes = @{
NSForegroundColorAttributeName : UIColor.lightGrayColor, NSForegroundColorAttributeName : UIColor.lightGrayColor,
NSFontAttributeName : NSFontAttributeName :
...@@ -201,19 +186,14 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -201,19 +186,14 @@ static const CGFloat InnerMarginWidth = 16.0;
// Name line, first middle and last. // Name line, first middle and last.
NSMutableArray<UIView*>* nameLineViews = [[NSMutableArray alloc] init]; NSMutableArray<UIView*>* nameLineViews = [[NSMutableArray alloc] init];
NSString* firstName = [self fieldValueOfType:autofill::NAME_FIRST];
NSString* lastName = [self fieldValueOfType:autofill::NAME_LAST];
NSString* middleName = [self fieldValueOfType:autofill::NAME_MIDDLE];
if (!middleName || middleName.length == 0) {
middleName = [self fieldValueOfType:autofill::NAME_MIDDLE_INITIAL];
}
bool showFirstName = firstName.length; bool showFirstName = address.firstName.length;
bool showMiddleName = middleName.length; bool showMiddleName = address.middleNameOrInitial.length;
bool showLastName = lastName.length; bool showLastName = address.lastName.length;
if (showFirstName) { if (showFirstName) {
[self.firstNameButton setTitle:firstName forState:UIControlStateNormal]; [self.firstNameButton setTitle:address.firstName
forState:UIControlStateNormal];
[nameLineViews addObject:self.firstNameButton]; [nameLineViews addObject:self.firstNameButton];
self.firstNameButton.hidden = NO; self.firstNameButton.hidden = NO;
} else { } else {
...@@ -228,7 +208,8 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -228,7 +208,8 @@ static const CGFloat InnerMarginWidth = 16.0;
} }
if (showMiddleName) { if (showMiddleName) {
[self.middleNameButton setTitle:middleName forState:UIControlStateNormal]; [self.middleNameButton setTitle:address.middleNameOrInitial
forState:UIControlStateNormal];
[nameLineViews addObject:self.middleNameButton]; [nameLineViews addObject:self.middleNameButton];
self.middleNameButton.hidden = NO; self.middleNameButton.hidden = NO;
} else { } else {
...@@ -243,7 +224,8 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -243,7 +224,8 @@ static const CGFloat InnerMarginWidth = 16.0;
} }
if (showLastName) { if (showLastName) {
[self.lastNameButton setTitle:lastName forState:UIControlStateNormal]; [self.lastNameButton setTitle:address.lastName
forState:UIControlStateNormal];
[nameLineViews addObject:self.lastNameButton]; [nameLineViews addObject:self.lastNameButton];
self.lastNameButton.hidden = NO; self.lastNameButton.hidden = NO;
} else { } else {
...@@ -258,8 +240,8 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -258,8 +240,8 @@ static const CGFloat InnerMarginWidth = 16.0;
} }
// Address line 1. // Address line 1.
if (line1.length) { if (address.line1.length) {
[self.line1Button setTitle:line1 forState:UIControlStateNormal]; [self.line1Button setTitle:address.line1 forState:UIControlStateNormal];
[verticalLeadViews addObject:self.line1Button]; [verticalLeadViews addObject:self.line1Button];
self.line1Button.hidden = NO; self.line1Button.hidden = NO;
} else { } else {
...@@ -267,8 +249,8 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -267,8 +249,8 @@ static const CGFloat InnerMarginWidth = 16.0;
} }
// Address line 2. // Address line 2.
if (line2.length) { if (address.line2.length) {
[self.line2Button setTitle:line2 forState:UIControlStateNormal]; [self.line2Button setTitle:address.line2 forState:UIControlStateNormal];
[verticalLeadViews addObject:self.line2Button]; [verticalLeadViews addObject:self.line2Button];
self.line2Button.hidden = NO; self.line2Button.hidden = NO;
} else { } else {
...@@ -277,26 +259,24 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -277,26 +259,24 @@ static const CGFloat InnerMarginWidth = 16.0;
// Zip and city line. // Zip and city line.
NSMutableArray<UIView*>* zipCityLineViews = [[NSMutableArray alloc] init]; NSMutableArray<UIView*>* zipCityLineViews = [[NSMutableArray alloc] init];
NSString* zip = [self fieldValueOfType:autofill::ADDRESS_HOME_ZIP];
NSString* city = [self fieldValueOfType:autofill::ADDRESS_HOME_CITY];
if (zip.length) { if (address.zip.length) {
[self.zipButton setTitle:zip forState:UIControlStateNormal]; [self.zipButton setTitle:address.zip forState:UIControlStateNormal];
[zipCityLineViews addObject:self.zipButton]; [zipCityLineViews addObject:self.zipButton];
self.zipButton.hidden = NO; self.zipButton.hidden = NO;
} else { } else {
self.zipButton.hidden = YES; self.zipButton.hidden = YES;
} }
if (zip.length && city.length) { if (address.zip.length && address.city.length) {
[zipCityLineViews addObject:self.citySeparatorLabel]; [zipCityLineViews addObject:self.citySeparatorLabel];
self.citySeparatorLabel.hidden = NO; self.citySeparatorLabel.hidden = NO;
} else { } else {
self.citySeparatorLabel.hidden = YES; self.citySeparatorLabel.hidden = YES;
} }
if (city.length) { if (address.city.length) {
[self.cityButton setTitle:city forState:UIControlStateNormal]; [self.cityButton setTitle:address.city forState:UIControlStateNormal];
[zipCityLineViews addObject:self.cityButton]; [zipCityLineViews addObject:self.cityButton];
self.cityButton.hidden = NO; self.cityButton.hidden = NO;
} else { } else {
...@@ -312,26 +292,24 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -312,26 +292,24 @@ static const CGFloat InnerMarginWidth = 16.0;
// State and country line. // State and country line.
NSMutableArray<UIView*>* stateCountryLineViews = NSMutableArray<UIView*>* stateCountryLineViews =
[[NSMutableArray alloc] init]; [[NSMutableArray alloc] init];
NSString* state = [self fieldValueOfType:autofill::ADDRESS_HOME_STATE];
NSString* country = [self fieldValueOfType:autofill::ADDRESS_HOME_COUNTRY];
if (state.length) { if (address.state.length) {
[self.stateButton setTitle:state forState:UIControlStateNormal]; [self.stateButton setTitle:address.state forState:UIControlStateNormal];
[stateCountryLineViews addObject:self.stateButton]; [stateCountryLineViews addObject:self.stateButton];
self.stateButton.hidden = NO; self.stateButton.hidden = NO;
} else { } else {
self.stateButton.hidden = YES; self.stateButton.hidden = YES;
} }
if (state.length && country.length) { if (address.state.length && address.country.length) {
[stateCountryLineViews addObject:self.countrySeparatorLabel]; [stateCountryLineViews addObject:self.countrySeparatorLabel];
self.countrySeparatorLabel.hidden = NO; self.countrySeparatorLabel.hidden = NO;
} else { } else {
self.countrySeparatorLabel.hidden = YES; self.countrySeparatorLabel.hidden = YES;
} }
if (country.length) { if (address.country.length) {
[self.countryButton setTitle:country forState:UIControlStateNormal]; [self.countryButton setTitle:address.country forState:UIControlStateNormal];
[stateCountryLineViews addObject:self.countryButton]; [stateCountryLineViews addObject:self.countryButton];
self.countryButton.hidden = NO; self.countryButton.hidden = NO;
} else { } else {
...@@ -470,14 +448,6 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -470,14 +448,6 @@ static const CGFloat InnerMarginWidth = 16.0;
]]; ]];
} }
// Takes in an autofill profile and an autofill field type and returns the
// corresponding field value.
- (NSString*)fieldValueOfType:(autofill::ServerFieldType)fieldType {
return base::SysUTF16ToNSString(
self.profile.GetInfo(autofill::AutofillType(fieldType),
GetApplicationContext()->GetApplicationLocale()));
}
- (void)userDidTapAddressInfo:(UIButton*)sender { - (void)userDidTapAddressInfo:(UIButton*)sender {
[self.delegate userDidPickContent:sender.titleLabel.text isSecure:NO]; [self.delegate userDidPickContent:sender.titleLabel.text isSecure:NO];
} }
......
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