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

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 code. Created 6 years, 4 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 c5b696e933c2721bda73b265aeddc2e89b5d1a89..e5370dafaf48f04bcacd0ede9b76c8c2283a47c9 100644
--- a/components/autofill/core/browser/autofill_field.cc
+++ b/components/autofill/core/browser/autofill_field.cc
@@ -280,21 +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);
- }
- }
+ base::string16 value;
+ AutofillField::GetPhoneNumberValue(field, number, field_data, &value);
field_data->value = value;
Ilya Sherman 2014/09/03 00:55:49 nit: You can shorten this to AutofillField::Ge
ziran.sun 2014/09/04 13:10:25 Done.
}
@@ -493,4 +480,27 @@ 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.
+void AutofillField::GetPhoneNumberValue(const AutofillField& field,
+ const base::string16& number,
+ FormFieldData* field_data,
+ base::string16* value) {
+ // Check to see if the size field matches the "prefix" or "suffix" sizes and
+ // substract the value accordingly.
Ilya Sherman 2014/09/03 00:55:49 nit: Let's update this to something like "Check to
ziran.sun 2014/09/04 13:10:25 Done.
+ *value = number;
+ if (number.length() ==
+ PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) {
Ilya Sherman 2014/09/03 00:55:49 nit: Please indent this line by four more spaces.
ziran.sun 2014/09/04 13:10:25 Done.
+ 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);
+ }
+ }
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698