Commit 6eaf26f5 authored by rouslan@chromium.org's avatar rouslan@chromium.org

Use language-specific street address line separators

Fill street address into a single-line text input field with separators
that depend on the language code of the profile.

TEST=components_unittests:AutofillFieldTest.FillStreetAddress*
BUG=270261

Review URL: https://codereview.chromium.org/397233002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284335 0039d316-1c4b-4281-b951-d872f2087c98
parent 675dd4aa
...@@ -115,10 +115,14 @@ void FillOutputForSectionWithComparator( ...@@ -115,10 +115,14 @@ void FillOutputForSectionWithComparator(
g_browser_process->GetApplicationLocale()); g_browser_process->GetApplicationLocale());
std::vector<ServerFieldType> types = common::TypesFromInputs(inputs); std::vector<ServerFieldType> types = common::TypesFromInputs(inputs);
form_structure.FillFields(types, form_structure.FillFields(
compare, types,
get_info, compare,
g_browser_process->GetApplicationLocale()); get_info,
section == SECTION_CC_BILLING
? full_wallet->billing_address()->language_code()
: full_wallet->shipping_address()->language_code(),
g_browser_process->GetApplicationLocale());
} }
void FillOutputForSection( void FillOutputForSection(
...@@ -345,6 +349,7 @@ void AutofillDialogControllerAndroid::Show() { ...@@ -345,6 +349,7 @@ void AutofillDialogControllerAndroid::Show() {
common::TypesFromInputs(inputs), common::TypesFromInputs(inputs),
base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING),
base::Bind(NullGetInfo), base::Bind(NullGetInfo),
std::string(),
g_browser_process->GetApplicationLocale()); g_browser_process->GetApplicationLocale());
} }
......
...@@ -839,6 +839,7 @@ void AutofillDialogControllerImpl::Show() { ...@@ -839,6 +839,7 @@ void AutofillDialogControllerImpl::Show() {
RequestedTypesForSection(SECTION_SHIPPING), RequestedTypesForSection(SECTION_SHIPPING),
base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING), base::Bind(common::ServerTypeMatchesField, SECTION_SHIPPING),
base::Bind(NullGetInfo), base::Bind(NullGetInfo),
std::string(),
g_browser_process->GetApplicationLocale()); g_browser_process->GetApplicationLocale());
transaction_amount_ = form_structure_.GetUniqueValue( transaction_amount_ = form_structure_.GetUniqueValue(
......
...@@ -91,6 +91,7 @@ bool DataModelWrapper::FillFormStructure( ...@@ -91,6 +91,7 @@ bool DataModelWrapper::FillFormStructure(
types, types,
compare, compare,
base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)), base::Bind(&DataModelWrapper::GetInfo, base::Unretained(this)),
GetLanguageCode(),
g_browser_process->GetApplicationLocale()); g_browser_process->GetApplicationLocale());
} }
......
...@@ -15,8 +15,12 @@ ...@@ -15,8 +15,12 @@
#include "components/autofill/core/browser/phone_number.h" #include "components/autofill/core/browser/phone_number.h"
#include "components/autofill/core/browser/state_names.h" #include "components/autofill/core/browser/state_names.h"
#include "grit/components_strings.h" #include "grit/components_strings.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_formatter.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
using ::i18n::addressinput::AddressData;
using ::i18n::addressinput::GetStreetAddressLinesAsSingleLine;
using base::ASCIIToUTF16; using base::ASCIIToUTF16;
using base::StringToInt; using base::StringToInt;
...@@ -354,18 +358,23 @@ bool FillMonthControl(const base::string16& value, FormFieldData* field) { ...@@ -354,18 +358,23 @@ bool FillMonthControl(const base::string16& value, FormFieldData* field) {
return true; return true;
} }
// Fills |field| with the street address in |value|. Translates newlines into // Fills |field| with the street address in |value|. Translates newlines into
// equivalent separators when necessary, i.e. when filling a single-line field. // equivalent separators when necessary, i.e. when filling a single-line field.
// The separators depend on |address_language_code|.
void FillStreetAddress(const base::string16& value, void FillStreetAddress(const base::string16& value,
const std::string& address_language_code,
FormFieldData* field) { FormFieldData* field) {
if (field->form_control_type == "textarea") { if (field->form_control_type == "textarea") {
field->value = value; field->value = value;
return; return;
} }
const base::string16& separator = AddressData address_data;
l10n_util::GetStringUTF16(IDS_AUTOFILL_ADDRESS_LINE_SEPARATOR); address_data.language_code = address_language_code;
base::ReplaceChars(value, base::ASCIIToUTF16("\n"), separator, &field->value); base::SplitString(base::UTF16ToUTF8(value), '\n', &address_data.address_line);
std::string line;
GetStreetAddressLinesAsSingleLine(address_data, &line);
field->value = base::UTF8ToUTF16(line);
} }
std::string Hash32Bit(const std::string& str) { std::string Hash32Bit(const std::string& str) {
...@@ -462,6 +471,7 @@ bool AutofillField::IsFieldFillable() const { ...@@ -462,6 +471,7 @@ bool AutofillField::IsFieldFillable() const {
// static // static
bool AutofillField::FillFormField(const AutofillField& field, bool AutofillField::FillFormField(const AutofillField& field,
const base::string16& value, const base::string16& value,
const std::string& address_language_code,
const std::string& app_locale, const std::string& app_locale,
FormFieldData* field_data) { FormFieldData* field_data) {
AutofillType type = field.Type(); AutofillType type = field.Type();
...@@ -474,7 +484,7 @@ bool AutofillField::FillFormField(const AutofillField& field, ...@@ -474,7 +484,7 @@ bool AutofillField::FillFormField(const AutofillField& field,
} else if (field_data->form_control_type == "month") { } else if (field_data->form_control_type == "month") {
return FillMonthControl(value, field_data); return FillMonthControl(value, field_data);
} else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) {
FillStreetAddress(value, field_data); FillStreetAddress(value, address_language_code, field_data);
return true; return true;
} }
......
...@@ -65,11 +65,13 @@ class AutofillField : public FormFieldData { ...@@ -65,11 +65,13 @@ class AutofillField : public FormFieldData {
void set_default_value(const std::string& value) { default_value_ = value; } void set_default_value(const std::string& value) { default_value_ = value; }
const std::string& default_value() const { return default_value_; } const std::string& default_value() const { return default_value_; }
// Set |field_data|'s value to |value|. Uses |field| and |app_locale| as // Set |field_data|'s value to |value|. Uses |field|, |address_language_code|,
// hints when filling exceptional cases like phone number values and <select> // and |app_locale| as hints when filling exceptional cases like phone number
// fields. Returns |true| if the field has been filled, |false| otherwise. // values and <select> fields. Returns |true| if the field has been filled,
// |false| otherwise.
static bool FillFormField(const AutofillField& field, static bool FillFormField(const AutofillField& field,
const base::string16& value, const base::string16& value,
const std::string& address_language_code,
const std::string& app_locale, const std::string& app_locale,
FormFieldData* field_data); FormFieldData* field_data);
......
...@@ -550,9 +550,12 @@ void AutofillManager::FillOrPreviewForm( ...@@ -550,9 +550,12 @@ void AutofillManager::FillOrPreviewForm(
FormData result = form; FormData result = form;
base::string16 profile_full_name; base::string16 profile_full_name;
std::string profile_language_code;
if (!is_credit_card) { if (!is_credit_card) {
profile_full_name = data_model->GetInfo( profile_full_name = data_model->GetInfo(
AutofillType(NAME_FULL), app_locale_); AutofillType(NAME_FULL), app_locale_);
profile_language_code =
static_cast<const AutofillProfile*>(data_model)->language_code();
} }
// If the relevant section is auto-filled, we should fill |field| but not the // If the relevant section is auto-filled, we should fill |field| but not the
...@@ -563,8 +566,11 @@ void AutofillManager::FillOrPreviewForm( ...@@ -563,8 +566,11 @@ void AutofillManager::FillOrPreviewForm(
if ((*iter) == field) { if ((*iter) == field) {
base::string16 value = data_model->GetInfoForVariant( base::string16 value = data_model->GetInfoForVariant(
autofill_field->Type(), variant, app_locale_); autofill_field->Type(), variant, app_locale_);
if (AutofillField::FillFormField( if (AutofillField::FillFormField(*autofill_field,
*autofill_field, value, app_locale_, &(*iter))) { value,
profile_language_code,
app_locale_,
&(*iter))) {
// Mark the cached field as autofilled, so that we can detect when a // Mark the cached field as autofilled, so that we can detect when a
// user edits an autofilled field (for metrics). // user edits an autofilled field (for metrics).
autofill_field->is_autofilled = true; autofill_field->is_autofilled = true;
...@@ -620,8 +626,11 @@ void AutofillManager::FillOrPreviewForm( ...@@ -620,8 +626,11 @@ void AutofillManager::FillOrPreviewForm(
(result.fields[i] == field || (result.fields[i] == field ||
result.fields[i].form_control_type == "select-one" || result.fields[i].form_control_type == "select-one" ||
result.fields[i].value.empty()); result.fields[i].value.empty());
if (AutofillField::FillFormField( if (AutofillField::FillFormField(*cached_field,
*cached_field, value, app_locale_, &result.fields[i])) { value,
profile_language_code,
app_locale_,
&result.fields[i])) {
// Mark the cached field as autofilled, so that we can detect when a // Mark the cached field as autofilled, so that we can detect when a
// user edits an autofilled field (for metrics). // user edits an autofilled field (for metrics).
form_structure->field(i)->is_autofilled = true; form_structure->field(i)->is_autofilled = true;
......
...@@ -1107,6 +1107,7 @@ bool FormStructure::FillFields( ...@@ -1107,6 +1107,7 @@ bool FormStructure::FillFields(
const std::vector<ServerFieldType>& types, const std::vector<ServerFieldType>& types,
const InputFieldComparator& matches, const InputFieldComparator& matches,
const base::Callback<base::string16(const AutofillType&)>& get_info, const base::Callback<base::string16(const AutofillType&)>& get_info,
const std::string& address_language_code,
const std::string& app_locale) { const std::string& app_locale) {
bool filled_something = false; bool filled_something = false;
for (size_t i = 0; i < field_count(); ++i) { for (size_t i = 0; i < field_count(); ++i) {
...@@ -1114,6 +1115,7 @@ bool FormStructure::FillFields( ...@@ -1114,6 +1115,7 @@ bool FormStructure::FillFields(
if (matches.Run(types[j], *field(i))) { if (matches.Run(types[j], *field(i))) {
AutofillField::FillFormField(*field(i), AutofillField::FillFormField(*field(i),
get_info.Run(field(i)->Type()), get_info.Run(field(i)->Type()),
address_language_code,
app_locale, app_locale,
field(i)); field(i));
filled_something = true; filled_something = true;
......
...@@ -137,11 +137,13 @@ class FormStructure { ...@@ -137,11 +137,13 @@ class FormStructure {
InputFieldComparator; InputFieldComparator;
// Fills in |fields_| that match |types| (via |matches|) with info from // Fills in |fields_| that match |types| (via |matches|) with info from
// |get_info|. // |get_info|. Uses |address_language_code| to determine line separators when
// collapsing street address lines into a single-line input text field.
bool FillFields( bool FillFields(
const std::vector<ServerFieldType>& types, const std::vector<ServerFieldType>& types,
const InputFieldComparator& matches, const InputFieldComparator& matches,
const base::Callback<base::string16(const AutofillType&)>& get_info, const base::Callback<base::string16(const AutofillType&)>& get_info,
const std::string& address_language_code,
const std::string& app_locale); const std::string& app_locale);
// Returns the values that can be filled into the form structure for the // Returns the values that can be filled into the form structure for the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment