Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1060)

Unified Diff: components/autofill/core/browser/autofill_field.cc

Issue 442403002: Adjust displayed phone number for prefix/suffix case. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove duplicate documentation. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 0bedb8649657d135c8c0facf1b864a834951caf0..8822bd883098f5510d60cc48209e481d71518a1b 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);
}
// Set |field_data|'s value to |number|, or possibly an appropriate substring
@@ -515,4 +500,30 @@ bool AutofillField::FillFormField(const AutofillField& field,
return true;
}
+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" size.
+ // If so, return the appropriate substring.
+ if (number.length() !=
+ PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) {
+ return number;
+ }
+
+ if (field.phone_part() == AutofillField::PHONE_PREFIX ||
+ field_data.max_length == PhoneNumber::kPrefixLength) {
+ return
+ number.substr(PhoneNumber::kPrefixOffset, PhoneNumber::kPrefixLength);
+ }
+
+ if (field.phone_part() == AutofillField::PHONE_SUFFIX ||
+ field_data.max_length == PhoneNumber::kSuffixLength) {
+ return
+ number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength);
+ }
+
+ return number;
+}
+
} // namespace autofill
« no previous file with comments | « components/autofill/core/browser/autofill_field.h ('k') | components/autofill/core/browser/autofill_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698