Chromium Code Reviews| Index: components/autofill/core/browser/autofill_field.cc |
| diff --git a/components/autofill/core/browser/autofill_field.cc b/components/autofill/core/browser/autofill_field.cc |
| index c5b696e933c2721bda73b265aeddc2e89b5d1a89..671bd66828874218c6647c6d8e12eba71c02a1bf 100644 |
| --- a/components/autofill/core/browser/autofill_field.cc |
| +++ b/components/autofill/core/browser/autofill_field.cc |
| @@ -280,23 +280,8 @@ bool FillCreditCardTypeSelectControl(const base::string16& value, |
| void FillPhoneNumberField(const AutofillField& field, |
| const base::string16& number, |
| FormFieldData* field_data) { |
| - // Check to see if the size field matches the "prefix" or "suffix" sizes and |
| - // fill accordingly. |
| - base::string16 value = number; |
| - if (number.length() == |
| - PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) { |
| - if (field.phone_part() == AutofillField::PHONE_PREFIX || |
| - field_data->max_length == PhoneNumber::kPrefixLength) { |
| - value = number.substr(PhoneNumber::kPrefixOffset, |
| - PhoneNumber::kPrefixLength); |
| - } else if (field.phone_part() == AutofillField::PHONE_SUFFIX || |
| - field_data->max_length == PhoneNumber::kSuffixLength) { |
| - value = number.substr(PhoneNumber::kSuffixOffset, |
| - PhoneNumber::kSuffixLength); |
| - } |
| - } |
| - |
| - field_data->value = value; |
| + field_data->value = |
| + AutofillField::GetPhoneNumberValue(field, number, *field_data); |
| } |
| // Fills in the select control |field| with |value|. If an exact match is not |
| @@ -493,4 +478,28 @@ bool AutofillField::FillFormField(const AutofillField& field, |
| return true; |
| } |
| +// Get value for phone number. The value could be |number|, or possibly an |
| +// appropriate substring of |number| if it's for phone prefix or suffix field. |
| +base::string16 AutofillField::GetPhoneNumberValue( |
| + const AutofillField& field, |
| + const base::string16& number, |
| + const FormFieldData& field_data) { |
| + // Check to see if the size field matches the "prefix" or "suffix" sizes. |
|
Ilya Sherman
2014/09/11 05:32:14
nit: "sizes" -> "size" (my bad for the typo in my
ziran.sun
2014/09/22 13:46:33
Done.
|
| + // If so, return the appropriate substring. |
| + base::string16 value = number; |
| + if (number.length() == |
| + PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) { |
| + if (field.phone_part() == AutofillField::PHONE_PREFIX || |
| + field_data.max_length == PhoneNumber::kPrefixLength) { |
| + value = |
| + number.substr(PhoneNumber::kPrefixOffset, PhoneNumber::kPrefixLength); |
| + } else if (field.phone_part() == AutofillField::PHONE_SUFFIX || |
| + field_data.max_length == PhoneNumber::kSuffixLength) { |
| + value = |
| + number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength); |
| + } |
| + } |
| + return value; |
|
Ilya Sherman
2014/09/11 05:32:14
nit: This method can be made a little bit cleaner
ziran.sun
2014/09/22 13:46:33
Done.
|
| +} |
| + |
| } // namespace autofill |