Chromium Code Reviews| Index: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| index 127706e00e66ec3e4b4e5dff3601c6df10de40d0..7a7f47574cc5f33fcbf3abb34fd4486a455415bf 100644 |
| --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc |
| @@ -29,6 +29,7 @@ |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/autofill/autofill_dialog_common.h" |
| +#include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
| #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
| #if !defined(OS_ANDROID) |
| @@ -603,14 +604,11 @@ void AutofillDialogControllerImpl::Show() { |
| return; |
| } |
| - common::BuildInputsForSection(SECTION_CC, |
| - &requested_cc_fields_); |
| - common::BuildInputsForSection(SECTION_BILLING, |
| - &requested_billing_fields_); |
| - common::BuildInputsForSection(SECTION_CC_BILLING, |
| - &requested_cc_billing_fields_); |
| - common::BuildInputsForSection(SECTION_SHIPPING, |
| - &requested_shipping_fields_); |
| + const std::string& country_code = |
| + GetManager()->GetDefaultCountryCodeForNewAddress(); |
| + for (size_t section = SECTION_MIN; section <= SECTION_MAX; ++section) { |
| + SetCountryCodeForSection(static_cast<DialogSection>(section), country_code); |
| + } |
| // Test whether we need to show the shipping section. If filling that section |
| // would be a no-op, don't show it. |
| @@ -1093,8 +1091,9 @@ void AutofillDialogControllerImpl::ResetSectionInput(DialogSection section) { |
| SetEditingExistingData(section, false); |
| DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| + std::string country_code = GetCountryCodeForSection(section); |
| for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { |
| - it->initial_value = common::GetHardcodedValueForType(it->type); |
| + it->initial_value = common::GetInitialValueForType(it->type, country_code); |
|
Evan Stade
2013/12/05 03:09:18
I think it's simpler if you leave this code alone
|
| } |
| } |
| @@ -1115,7 +1114,7 @@ void AutofillDialogControllerImpl::ShowEditUiIfBadSuggestion( |
| DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| if (wrapper && IsEditingExistingData(section)) |
| - wrapper->FillInputs(inputs); |
| + wrapper->FillInputs(inputs, GetCountryCodeForSection(section)); |
| } |
| bool AutofillDialogControllerImpl::InputWasEdited(ServerFieldType type, |
| @@ -1169,7 +1168,7 @@ void AutofillDialogControllerImpl::RestoreUserInputFromSnapshot( |
| continue; |
| DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| - wrapper.FillInputs(inputs); |
| + wrapper.FillInputs(inputs, GetCountryCodeForSection(section)); |
| for (size_t i = 0; i < inputs->size(); ++i) { |
| if (InputWasEdited((*inputs)[i].type, (*inputs)[i].initial_value)) { |
| @@ -1691,6 +1690,7 @@ string16 AutofillDialogControllerImpl::InputValidityMessage( |
| return base::string16(); // Line 2 is optional - always valid. |
| case ADDRESS_HOME_CITY: |
| + case ADDRESS_HOME_DEPENDENT_LOCALITY: |
| case ADDRESS_HOME_COUNTRY: |
| break; |
| @@ -1708,6 +1708,9 @@ string16 AutofillDialogControllerImpl::InputValidityMessage( |
| } |
| break; |
| + case ADDRESS_HOME_SORTING_CODE: |
| + break; |
| + |
| case NAME_FULL: |
| // Wallet requires a first and last billing name. |
| if (section == SECTION_CC_BILLING && !value.empty() && |
| @@ -1718,6 +1721,9 @@ string16 AutofillDialogControllerImpl::InputValidityMessage( |
| } |
| break; |
| + case COMPANY_NAME: |
| + break; |
| + |
| case PHONE_HOME_WHOLE_NUMBER: // Used in shipping section. |
| break; |
| @@ -1923,6 +1929,30 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput( |
| popup_ids); |
| } |
| +void AutofillDialogControllerImpl::ComboboxItemSelected(ServerFieldType type, |
| + int index) { |
| + ui::ComboboxModel* model = ComboboxModelForAutofillType(type); |
| + if (model != &country_combobox_model_ || model->IsItemSeparatorAt(index)) |
|
Evan Stade
2013/12/05 03:09:18
are you sure the isitemseparatorat is necessary? s
|
| + return; |
| + |
| + std::string country_code = |
| + country_combobox_model_.countries()[index]->country_code(); |
| + DialogSection section = AutofillType(type).group() == ADDRESS_BILLING ? |
| + IsPayingWithWallet() ? SECTION_CC_BILLING : SECTION_BILLING : |
| + SECTION_SHIPPING; |
| + if (country_code == GetCountryCodeForSection(section)) |
| + return; |
| + |
| + ScopedViewUpdates updates(view_.get()); |
| + const FieldValueMap snapshot = TakeUserInputSnapshot(); |
| + |
| + SetCountryCodeForSection(section, country_code); |
| + |
| + ResetSectionInput(section); |
| + RestoreUserInputFromSnapshot(snapshot); |
| + UpdateSection(section); |
| +} |
| + |
| void AutofillDialogControllerImpl::FocusMoved() { |
| HidePopup(); |
| } |
| @@ -2164,7 +2194,8 @@ void AutofillDialogControllerImpl::DidAcceptSuggestion(const string16& value, |
| for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| DialogSection section = static_cast<DialogSection>(i); |
| - wrapper->FillInputs(MutableRequestedFieldsForSection(section)); |
| + wrapper->FillInputs(MutableRequestedFieldsForSection(section), |
| + GetCountryCodeForSection(section)); |
| view_->FillSection(section, *input_showing_popup_); |
| } |
| @@ -2763,7 +2794,6 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() { |
| std::vector<base::string16> labels; |
| AutofillProfile::CreateDifferentiatingLabels(profiles, &labels); |
| DCHECK_EQ(labels.size(), profiles.size()); |
| - const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| for (size_t i = 0; i < profiles.size(); ++i) { |
| const AutofillProfile& profile = *profiles[i]; |
| if (!HasCompleteAndVerifiedData(profile, requested_shipping_fields_) || |
| @@ -2849,11 +2879,10 @@ void AutofillDialogControllerImpl::SuggestionsUpdated() { |
| void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( |
| DialogSection section, |
| const InputFieldComparator& compare) { |
| - const DetailInputs& inputs = RequestedFieldsForSection(section); |
| - |
| if (!SectionIsActive(section)) |
| return; |
| + const DetailInputs& inputs = RequestedFieldsForSection(section); |
| scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section); |
| if (wrapper) { |
| // Only fill in data that is associated with this section. |
| @@ -3000,6 +3029,36 @@ DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( |
| return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
| } |
| +std::string AutofillDialogControllerImpl::GetCountryCodeForSection( |
| + DialogSection section) const { |
| + if (section == SECTION_BILLING || section == SECTION_CC_BILLING) |
| + return billing_country_code_; |
| + if (section == SECTION_SHIPPING) |
| + return shipping_country_code_; |
| + return "US"; |
| +} |
| + |
| +void AutofillDialogControllerImpl::SetCountryCodeForSection( |
| + DialogSection section, |
| + const std::string& country_code) { |
| + if (section == SECTION_BILLING || section == SECTION_CC_BILLING) |
| + billing_country_code_ = country_code; |
| + else if (section == SECTION_SHIPPING) |
| + shipping_country_code_ = country_code; |
| + |
| + DetailInputs* inputs = MutableRequestedFieldsForSection(section); |
| + inputs->clear(); |
| + |
| + common::BuildInputsForSection(section, inputs, country_code); |
| + |
| + const std::string& ui_locale = g_browser_process->GetApplicationLocale(); |
| + base::string16 country_name = AutofillCountry(country_code, ui_locale).name(); |
| + for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { |
| + if (AutofillType(it->type).GetStorableType() == ADDRESS_HOME_COUNTRY) |
| + it->initial_value = country_name; |
| + } |
| +} |
| + |
| void AutofillDialogControllerImpl::HidePopup() { |
| if (popup_controller_.get()) |
| popup_controller_->Hide(); |