diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-12 04:24:08 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-12 04:24:08 +0000 |
commit | 8ebfa3b67a5d756c9fba7f4f4925dd0c30d16e58 (patch) | |
tree | 91f07b26d01569dbc07f00ced3ca45ed3e9e959c /chrome/browser/autofill/autofill_address_model_mac.mm | |
parent | 8b6b3cf3e623d8f48069aa30a23bca58852d0b36 (diff) | |
download | chromium_src-8ebfa3b67a5d756c9fba7f4f4925dd0c30d16e58.zip chromium_src-8ebfa3b67a5d756c9fba7f4f4925dd0c30d16e58.tar.gz chromium_src-8ebfa3b67a5d756c9fba7f4f4925dd0c30d16e58.tar.bz2 |
Autofill dialog for the Mac. This is UI only at this point. The UI is not hooked up to the back end yet. The UI demonstrates manipulation of one address and one credit card record. Eventually buttons will be added to add and remove additional records. The additions in this CL are:
- Preferences dialog has a new "Change autofill settings" button that triggers an autofill settings dialog.
- The autofill settings dialog now exists and allows the user to manipulate form autofill data. Specifically address information and credit card information.
- Each address or credit card record is presented in a disclosure view to allow for summary or detailed views of each record.
- The autofill dialog is layed out dynamically in a vertical list (ordered by y) using the VerticalLayoutView.
- Sections are delimited visually with the SectionSeparatorView. There are currently two sections, one for addresses and one for credit cards.
- Unit tests are present that exercise the invocation of the dialog and check basic functionality. Checks are performed to see that data is flowing from core profile and credit card data structures into Cocoa model data structures used for bindings internally by the UI.
- There are three .xib files (AutoFillDialog.xib, AutoFillAddressFormView.xib, and AutoFillCreditCardFormView.xib) that partition the dialog UI into distinct views, controllers, and model objects.
- Cocoa databinding is utilized to syncronize dependent parts of the UI.
- All strings are stored in internationalized form in .grd files and .xib files (with one small TODO execption, see below).
The things remaining to do are:
- Hook the UI up to the backend model, specifically the PersonalDataManager data.
- Add support for arbitrary number of address and credit card records. I.e. Add and Delete buttons.
- Scroll-to-Point support for autoscrolling when tabbing between fields.
- Billing and shipping address popups in the credit card section.
- Any validation of input (need to circle back with UI folks on this).
- Input validation unit tests.
- String concatenation of the summary label needs to be internationalized.
BUG=33029
TEST=none
Review URL: http://codereview.chromium.org/558066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38873 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill/autofill_address_model_mac.mm')
-rw-r--r-- | chrome/browser/autofill/autofill_address_model_mac.mm | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/chrome/browser/autofill/autofill_address_model_mac.mm b/chrome/browser/autofill/autofill_address_model_mac.mm new file mode 100644 index 0000000..265b055 --- /dev/null +++ b/chrome/browser/autofill/autofill_address_model_mac.mm @@ -0,0 +1,181 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "chrome/browser/autofill/autofill_address_model_mac.h" +#include "app/l10n_util.h" +#include "base/sys_string_conversions.h" +#include "chrome/browser/autofill/autofill_profile.h" +#include "grit/generated_resources.h" + +@implementation AutoFillAddressModel + +@dynamic summary; +@synthesize label = label_; +@synthesize firstName = firstName_; +@synthesize middleName = middleName_; +@synthesize lastName = lastName_; +@synthesize email = email_; +@synthesize companyName = companyName_; +@synthesize addressLine1 = addressLine1_; +@synthesize addressLine2 = addressLine2_; +@synthesize city = city_; +@synthesize state = state_; +@synthesize zip = zip_; +@synthesize country = country_; +@synthesize phoneCountryCode = phoneCountryCode_; +@synthesize phoneAreaCode = phoneAreaCode_; +@synthesize phoneNumber = phoneNumber_; +@synthesize faxCountryCode = faxCountryCode_; +@synthesize faxAreaCode = faxAreaCode_; +@synthesize faxNumber = faxNumber_; + +// Sets up the KVO dependency between "summary" and dependent fields. ++ (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key { + NSSet* keyPaths = [super keyPathsForValuesAffectingValueForKey:key]; + + if ([key isEqualToString:@"summary"]) { + NSSet* affectingKeys = + [NSSet setWithObjects:@"firstName", @"lastName", @"addressLine1", nil]; + keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKeys]; + } + return keyPaths; +} + +- (id)initWithProfile:(const AutoFillProfile&)profile { + if ((self = [super init])) { + [self setLabel:SysUTF16ToNSString(profile.Label())]; + [self setFirstName:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(NAME_FIRST)))]; + [self setMiddleName:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(NAME_MIDDLE)))]; + [self setLastName:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(NAME_LAST)))]; + [self setEmail:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(EMAIL_ADDRESS)))]; + [self setCompanyName:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(COMPANY_NAME)))]; + [self setAddressLine1:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)))]; + [self setAddressLine2:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE2)))]; + [self setCity:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(ADDRESS_HOME_CITY)))]; + [self setState:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(ADDRESS_HOME_STATE)))]; + [self setZip:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP)))]; + [self setCountry:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY)))]; + [self setPhoneCountryCode:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(PHONE_HOME_COUNTRY_CODE)))]; + [self setPhoneAreaCode:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(PHONE_HOME_CITY_CODE)))]; + [self setPhoneNumber:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(PHONE_HOME_NUMBER)))]; + [self setFaxCountryCode:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(PHONE_FAX_COUNTRY_CODE)))]; + [self setFaxAreaCode:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(PHONE_FAX_CITY_CODE)))]; + [self setFaxNumber:SysUTF16ToNSString( + profile.GetFieldText(AutoFillType(PHONE_FAX_NUMBER)))]; + } + return self; +} + +- (void)dealloc { + [label_ release]; + [firstName_ release]; + [middleName_ release]; + [lastName_ release]; + [email_ release]; + [companyName_ release]; + [addressLine1_ release]; + [addressLine2_ release]; + [city_ release]; + [state_ release]; + [zip_ release]; + [country_ release]; + [phoneCountryCode_ release]; + [phoneAreaCode_ release]; + [phoneNumber_ release]; + [faxCountryCode_ release]; + [faxAreaCode_ release]; + [faxNumber_ release]; + [super dealloc]; +} + +- (NSString*)summary { + // Bindings may set these to nil. We normalize here to @"". + if (firstName_ == nil) + firstName_ = @""; + if (lastName_ == nil) + lastName_ = @""; + if (addressLine1_ == nil) + addressLine1_ = @""; + + BOOL haveFirstName = [firstName_ length] > 0; + BOOL haveLastName = [lastName_ length] > 0; + BOOL haveAddress = [addressLine1_ length] > 0; + + NSString* nameSeparator = (haveFirstName && haveLastName) ? + l10n_util::GetNSString(IDS_AUTOFILL_DIALOG_ADDRESS_NAME_SEPARATOR) : + @""; + NSString* nameFormat = + l10n_util::GetNSStringF(IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_NAME_FORMAT, + base::SysNSStringToUTF16(firstName_), + base::SysNSStringToUTF16(nameSeparator), + base::SysNSStringToUTF16(lastName_)); + NSString* summarySeparator = (haveFirstName || haveLastName) && haveAddress ? + l10n_util::GetNSString(IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_SEPARATOR) : + @""; + NSString* summaryFormat = + l10n_util::GetNSStringF(IDS_AUTOFILL_DIALOG_ADDRESS_SUMMARY_FORMAT, + base::SysNSStringToUTF16(nameFormat), + base::SysNSStringToUTF16(summarySeparator), + base::SysNSStringToUTF16(addressLine1_)); + + return summaryFormat; +} + +- (void)copyModelToProfile:(AutoFillProfile*)profile { + DCHECK(profile); + profile->set_label(base::SysNSStringToUTF16([self label])); + + profile->SetInfo(AutoFillType(NAME_FIRST), + base::SysNSStringToUTF16([self firstName])); + profile->SetInfo(AutoFillType(NAME_MIDDLE), + base::SysNSStringToUTF16([self middleName])); + profile->SetInfo(AutoFillType(NAME_LAST), + base::SysNSStringToUTF16([self lastName])); + profile->SetInfo(AutoFillType(EMAIL_ADDRESS), + base::SysNSStringToUTF16([self email])); + profile->SetInfo(AutoFillType(COMPANY_NAME), + base::SysNSStringToUTF16([self companyName])); + profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE1), + base::SysNSStringToUTF16([self addressLine1])); + profile->SetInfo(AutoFillType(ADDRESS_HOME_LINE2), + base::SysNSStringToUTF16([self addressLine2])); + profile->SetInfo(AutoFillType(ADDRESS_HOME_CITY), + base::SysNSStringToUTF16([self city])); + profile->SetInfo(AutoFillType(ADDRESS_HOME_STATE), + base::SysNSStringToUTF16([self state])); + profile->SetInfo(AutoFillType(ADDRESS_HOME_ZIP), + base::SysNSStringToUTF16([self zip])); + profile->SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), + base::SysNSStringToUTF16([self country])); + profile->SetInfo(AutoFillType(PHONE_HOME_COUNTRY_CODE), + base::SysNSStringToUTF16([self phoneCountryCode])); + profile->SetInfo(AutoFillType(PHONE_HOME_CITY_CODE), + base::SysNSStringToUTF16([self phoneAreaCode])); + profile->SetInfo(AutoFillType(PHONE_HOME_NUMBER), + base::SysNSStringToUTF16([self phoneNumber])); + profile->SetInfo(AutoFillType(PHONE_FAX_COUNTRY_CODE), + base::SysNSStringToUTF16([self faxCountryCode])); + profile->SetInfo(AutoFillType(PHONE_FAX_CITY_CODE), + base::SysNSStringToUTF16([self faxAreaCode])); + profile->SetInfo(AutoFillType(PHONE_FAX_NUMBER), + base::SysNSStringToUTF16([self faxNumber])); +} + +@end |