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

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 124533003: Add country combobox to change country and rebuild address inputs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test Created 6 years, 11 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: 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 5e368da4752d06f70866e13ed76abdcb61da6949..d014c4370686a6e32c0ec89a630b359f85a6a1af 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc
@@ -604,21 +604,16 @@ void AutofillDialogControllerImpl::Show() {
AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME);
}
- // TODO(dbeam): use GetManager()->GetDefaultCountryCodeForNewAddress()
- // instead when the country combobox is visible. http://crbug.com/331544
- std::string country_code = "US";
- common::BuildInputsForSection(SECTION_CC,
- country_code,
- &requested_cc_fields_);
- common::BuildInputsForSection(SECTION_BILLING,
- country_code,
- &requested_billing_fields_);
- common::BuildInputsForSection(SECTION_CC_BILLING,
- country_code,
- &requested_cc_billing_fields_);
- common::BuildInputsForSection(SECTION_SHIPPING,
- country_code,
- &requested_shipping_fields_);
+ account_chooser_model_.reset(
+ new AccountChooserModel(this,
+ profile_,
+ !ShouldShowAccountChooser(),
+ metric_logger_));
+
+ // TODO(dbeam): does SECTION_CC need to be internationalized?
+ common::BuildInputsForSection(SECTION_CC, "US", &requested_cc_fields_);
+ OnCountryComboboxModelChanged(shipping_country_combobox_model_);
+ OnCountryComboboxModelChanged(billing_country_combobox_model_);
// Test whether we need to show the shipping section. If filling that section
// would be a no-op, don't show it.
@@ -628,12 +623,6 @@ void AutofillDialogControllerImpl::Show() {
base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING),
&form_structure_);
- account_chooser_model_.reset(
- new AccountChooserModel(this,
- profile_,
- !ShouldShowAccountChooser(),
- metric_logger_));
-
if (account_chooser_model_->WalletIsSelected())
FetchWalletCookie();
@@ -1101,6 +1090,16 @@ void AutofillDialogControllerImpl::ConstructLegalDocumentsText() {
void AutofillDialogControllerImpl::ResetSectionInput(DialogSection section) {
SetEditingExistingData(section, false);
+ if (i18ninput::Enabled()) {
+ if (section == SECTION_SHIPPING) {
+ shipping_country_combobox_model_.SelectDefaultIndex();
+ OnCountryComboboxModelChanged(shipping_country_combobox_model_);
+ } else if (section == SECTION_BILLING || section == SECTION_CC_BILLING) {
+ billing_country_combobox_model_.SelectDefaultIndex();
+ OnCountryComboboxModelChanged(billing_country_combobox_model_);
+ }
Dan Beam 2014/01/11 04:16:58 note for myself: SuggestionsUpdated is taking a sn
+ }
+
DetailInputs* inputs = MutableRequestedFieldsForSection(section);
for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) {
it->initial_value = common::GetHardcodedValueForType(it->type);
@@ -1304,9 +1303,11 @@ ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType(
case CREDIT_CARD_EXP_4_DIGIT_YEAR:
return &cc_exp_year_combobox_model_;
- case ADDRESS_HOME_COUNTRY:
case ADDRESS_BILLING_COUNTRY:
- return &country_combobox_model_;
+ return &billing_country_combobox_model_;
+
+ case ADDRESS_HOME_COUNTRY:
+ return &shipping_country_combobox_model_;
default:
return NULL;
@@ -1700,23 +1701,29 @@ base::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;
case ADDRESS_HOME_STATE:
- if (!value.empty() && !autofill::IsValidState(value)) {
+ if (!value.empty() && !autofill::IsValidState(value) &&
+ CountryCodeForSection(section) == "US") {
return l10n_util::GetStringUTF16(
IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_REGION);
}
break;
case ADDRESS_HOME_ZIP:
- if (!value.empty() && !autofill::IsValidZip(value)) {
+ if (!value.empty() && !autofill::IsValidZip(value) &&
+ CountryCodeForSection(section) == "US") {
return l10n_util::GetStringUTF16(
IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_ZIP_CODE);
}
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() &&
@@ -1755,11 +1762,11 @@ ValidityMessages AutofillDialogControllerImpl::InputsAreValid(
base::string16 text = InputValidityMessage(section, type, iter->second);
- // Skip empty/unchanged fields in edit mode. Ignore country code as it
- // always has a value. If the individual field does not have validation
- // errors, assume it to be valid unless later proven otherwise.
+ // Skip empty/unchanged fields in edit mode. Ignore country as it always has
+ // a value. If the individual field does not have validation errors, assume
+ // it to be valid unless later proven otherwise.
bool sure = InputWasEdited(type, iter->second) ||
- ComboboxModelForAutofillType(type) == &country_combobox_model_;
+ AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY;
// Consider only individually valid fields for inter-field validation.
if (text.empty()) {
@@ -1854,6 +1861,26 @@ void AutofillDialogControllerImpl::UserEditedOrActivatedInput(
const gfx::Rect& content_bounds,
const base::string16& field_contents,
bool was_edit) {
+ ScopedViewUpdates updates(view_.get());
+
+ if (type == ADDRESS_BILLING_COUNTRY) {
+ billing_country_combobox_model_.SelectCountry(
+ AutofillCountry::GetCountryCode(
+ field_contents, g_browser_process->GetApplicationLocale()));
+ OnCountryComboboxModelChanged(billing_country_combobox_model_);
+ UpdateSection(IsPayingWithWallet() ? SECTION_CC_BILLING : SECTION_BILLING);
+ } else if (type == ADDRESS_HOME_COUNTRY) {
+ shipping_country_combobox_model_.SelectCountry(
+ AutofillCountry::GetCountryCode(
+ field_contents, g_browser_process->GetApplicationLocale()));
+ OnCountryComboboxModelChanged(shipping_country_combobox_model_);
+ UpdateSection(SECTION_SHIPPING);
+ }
+
+ // The rest of this method applies only to textfields. If a combobox, bail.
+ if (ComboboxModelForAutofillType(type))
+ return;
+
// If the field is edited down to empty, don't show a popup.
if (was_edit && field_contents.empty()) {
HidePopup();
@@ -2161,6 +2188,33 @@ void AutofillDialogControllerImpl::DidAcceptSuggestion(
for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
DialogSection section = static_cast<DialogSection>(i);
+
+ if (i18ninput::Enabled()) {
+ if ((section == SECTION_BILLING || section == SECTION_CC_BILLING) &&
+ billing_country_combobox_model_.IsDefaultIndexSelected()) {
+ base::string16 country_name =
+ wrapper->GetInfo(AutofillType(ADDRESS_BILLING_COUNTRY));
+ if (!country_name.empty()) {
+ billing_country_combobox_model_.SelectCountry(
+ AutofillCountry::GetCountryCode(
+ country_name, g_browser_process->GetApplicationLocale()));
+ OnCountryComboboxModelChanged(billing_country_combobox_model_);
+ UpdateSection(section);
+ }
+ } else if (section == SECTION_SHIPPING &&
+ shipping_country_combobox_model_.IsDefaultIndexSelected()) {
+ base::string16 country_name =
+ wrapper->GetInfo(AutofillType(ADDRESS_HOME_COUNTRY));
+ if (!country_name.empty()) {
+ shipping_country_combobox_model_.SelectCountry(
+ AutofillCountry::GetCountryCode(
+ country_name, g_browser_process->GetApplicationLocale()));
+ OnCountryComboboxModelChanged(shipping_country_combobox_model_);
+ UpdateSection(section);
+ }
+ }
+ }
+
wrapper->FillInputs(MutableRequestedFieldsForSection(section));
view_->FillSection(section, popup_input_type_);
}
@@ -2522,7 +2576,8 @@ AutofillDialogControllerImpl::AutofillDialogControllerImpl(
wallet_items_requested_(false),
handling_use_wallet_link_click_(false),
passive_failed_(false),
- country_combobox_model_(*GetManager()),
+ billing_country_combobox_model_(*GetManager()),
+ shipping_country_combobox_model_(*GetManager()),
suggested_cc_(this),
suggested_billing_(this),
suggested_cc_billing_(this),
@@ -2845,11 +2900,13 @@ void AutofillDialogControllerImpl::FillOutputForSectionWithComparator(
if (!SectionIsActive(section))
return;
- const DetailInputs& inputs = RequestedFieldsForSection(section);
+ DetailInputs inputs;
+ std::string country_code = CountryCodeForSection(section);
+ common::BuildInputsForSection(section, country_code, &inputs);
+
scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
if (wrapper) {
// Only fill in data that is associated with this section.
- const DetailInputs& inputs = RequestedFieldsForSection(section);
wrapper->FillFormStructure(inputs, compare, &form_structure_);
// CVC needs special-casing because the CreditCard class doesn't store or
@@ -2992,6 +3049,51 @@ DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection(
return const_cast<DetailInputs*>(&RequestedFieldsForSection(section));
}
+void AutofillDialogControllerImpl::OnCountryComboboxModelChanged(
+ const CountryComboboxModel& model) {
+ const FieldValueMap snapshot = TakeUserInputSnapshot();
+
+ const bool is_shipping = &model == &shipping_country_combobox_model_;
+ for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
+ DialogSection section = static_cast<DialogSection>(i);
+
+ if ((is_shipping && section != SECTION_SHIPPING) ||
+ (!is_shipping && (section != SECTION_BILLING &&
+ section != SECTION_CC_BILLING))) {
+ continue;
+ }
+
+ DetailInputs* inputs = MutableRequestedFieldsForSection(section);
+ inputs->clear();
+
+ std::string country_code = CountryCodeForSection(section);
+ common::BuildInputsForSection(section, country_code, inputs);
+ }
+
+ RestoreUserInputFromSnapshot(snapshot);
+}
+
+std::string AutofillDialogControllerImpl::CountryCodeForSection(
+ DialogSection section) {
+ if (section != SECTION_CC) {
+ scoped_ptr<DataModelWrapper> wrapper = CreateWrapper(section);
+ if (wrapper) {
+ return AutofillCountry::GetCountryCode(
+ wrapper->GetInfo(AutofillType(section == SECTION_SHIPPING ?
+ ADDRESS_HOME_COUNTRY : ADDRESS_BILLING_COUNTRY)),
+ g_browser_process->GetApplicationLocale());
+ }
+ }
+
+ if (section == SECTION_BILLING || section == SECTION_CC_BILLING)
+ return billing_country_combobox_model_.GetSelectedCountryCode();
+
+ if (section == SECTION_SHIPPING)
+ return shipping_country_combobox_model_.GetSelectedCountryCode();
+
+ return "US";
+}
+
void AutofillDialogControllerImpl::HidePopup() {
if (popup_controller_.get())
popup_controller_->Hide();

Powered by Google App Engine
This is Rietveld 408576698