From 2dd8e7fdab91dfbd1ed6478808f2aae5c2d9c064 Mon Sep 17 00:00:00 2001 From: "jhawkins@chromium.org" Date: Sat, 19 Dec 2009 00:28:55 +0000 Subject: Set the address field type based on how many address fields we encountered. BUG=none TEST=none Review URL: http://codereview.chromium.org/501092 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35011 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/autofill/form_field.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'chrome/browser') diff --git a/chrome/browser/autofill/form_field.cc b/chrome/browser/autofill/form_field.cc index e6e375b..4d4c76f 100644 --- a/chrome/browser/autofill/form_field.cc +++ b/chrome/browser/autofill/form_field.cc @@ -135,6 +135,10 @@ string16 FormField::GetEcmlPattern(const string16& ecml_name1, } FormFieldSet::FormFieldSet(FormStructure* fields) { + std::vector addresses; + + // First, find if there is one form field with an ECML name. If there is, + // then we will match an element only if it is in the standard. bool is_ecml = CheckECML(fields); // Parse fields. @@ -147,6 +151,29 @@ FormFieldSet::FormFieldSet(FormStructure* fields) { } push_back(form_field); + + if (form_field->GetFormFieldType() == kAddressType) { + AddressField* address = static_cast(form_field); + if (address->IsFullAddress()) + addresses.push_back(address); + } + } + + // Now determine an address type for each address. Note, if this is an ECML + // form, then we already got this info from the field names. + if (!is_ecml && !addresses.empty()) { + if (addresses.size() == 1) { + addresses[0]->SetType(addresses[0]->FindType()); + } else { + AddressType type0 = addresses[0]->FindType(); + AddressType type1 = addresses[1]->FindType(); + + // When there are two addresses on a page, they almost always appear in + // the order (billing, shipping). + bool reversed = (type0 == kShippingAddress && type1 == kBillingAddress); + addresses[0]->SetType(reversed ? kShippingAddress : kBillingAddress); + addresses[1]->SetType(reversed ? kBillingAddress : kShippingAddress); + } } } -- cgit v1.1