diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-10 01:55:50 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-10 01:55:50 +0000 |
commit | 80e800e5ddd6d448d6ed992347faa93c9cd79208 (patch) | |
tree | 53c70fdda86a93d30ccd5dcafba501294ec4db60 | |
parent | 4dc4aeae2ccf360592b6f1f63d0af9271895111d (diff) | |
download | chromium_src-80e800e5ddd6d448d6ed992347faa93c9cd79208.zip chromium_src-80e800e5ddd6d448d6ed992347faa93c9cd79208.tar.gz chromium_src-80e800e5ddd6d448d6ed992347faa93c9cd79208.tar.bz2 |
rAc: don't clobber user input when accepting autofill popup suggestion
BUG=226347
Review URL: https://chromiumcodereview.appspot.com/13607006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193282 0039d316-1c4b-4281-b951-d872f2087c98
10 files changed, 37 insertions, 17 deletions
diff --git a/chrome/browser/ui/android/autofill/autofill_dialog_view_android.cc b/chrome/browser/ui/android/autofill/autofill_dialog_view_android.cc index 09c3a9e..79ae439 100644 --- a/chrome/browser/ui/android/autofill/autofill_dialog_view_android.cc +++ b/chrome/browser/ui/android/autofill/autofill_dialog_view_android.cc @@ -104,7 +104,10 @@ void AutofillDialogViewAndroid::UpdateButtonStrip() { NOTIMPLEMENTED(); } -void AutofillDialogViewAndroid::UpdateSection(DialogSection section) { +void AutofillDialogViewAndroid::UpdateSection(DialogSection section, + UserInputAction action) { + // TODO(estade): respect |action|. + JNIEnv* env = base::android::AttachCurrentThread(); const DetailInputs& updated_inputs = controller_->RequestedFieldsForSection(section); @@ -251,11 +254,11 @@ void AutofillDialogViewAndroid::ModelChanged() { Java_AutofillDialogGlue_modelChanged( env, java_object_.obj(), controller_->ShouldShowSpinner()); - UpdateSection(SECTION_EMAIL); - UpdateSection(SECTION_CC); - UpdateSection(SECTION_BILLING); - UpdateSection(SECTION_CC_BILLING); - UpdateSection(SECTION_SHIPPING); + UpdateSection(SECTION_EMAIL, CLEAR_USER_INPUT); + UpdateSection(SECTION_CC, CLEAR_USER_INPUT); + UpdateSection(SECTION_BILLING, CLEAR_USER_INPUT); + UpdateSection(SECTION_CC_BILLING, CLEAR_USER_INPUT); + UpdateSection(SECTION_SHIPPING, CLEAR_USER_INPUT); } void AutofillDialogViewAndroid::SubmitForTesting() { diff --git a/chrome/browser/ui/android/autofill/autofill_dialog_view_android.h b/chrome/browser/ui/android/autofill/autofill_dialog_view_android.h index 17894a4..aac7a60 100644 --- a/chrome/browser/ui/android/autofill/autofill_dialog_view_android.h +++ b/chrome/browser/ui/android/autofill/autofill_dialog_view_android.h @@ -27,7 +27,8 @@ class AutofillDialogViewAndroid : public AutofillDialogView { virtual void UpdateNotificationArea() OVERRIDE; virtual void UpdateAccountChooser() OVERRIDE; virtual void UpdateButtonStrip() OVERRIDE; - virtual void UpdateSection(DialogSection section) OVERRIDE; + virtual void UpdateSection(DialogSection section, + UserInputAction action) OVERRIDE; virtual void GetUserInput(DialogSection section, DetailOutputMap* output) OVERRIDE; virtual string16 GetCvc() OVERRIDE; diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc index 219cbc0..6f8a3a8 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc @@ -857,13 +857,13 @@ void AutofillDialogControllerImpl::EditClickedForSection( scoped_ptr<DataModelWrapper> model = CreateWrapper(section); model->FillInputs(inputs); section_editing_state_[section] = true; - view_->UpdateSection(section); + view_->UpdateSection(section, CLEAR_USER_INPUT); } void AutofillDialogControllerImpl::EditCancelledForSection( DialogSection section) { ResetManualInputForSection(section); - view_->UpdateSection(section); + view_->UpdateSection(section, CLEAR_USER_INPUT); } gfx::Image AutofillDialogControllerImpl::IconForField( @@ -1281,7 +1281,7 @@ void AutofillDialogControllerImpl::DidAcceptSuggestion(const string16& value, for (size_t i = 0; i < arraysize(sections); ++i) { DialogSection section = sections[i]; wrapper->FillInputs(MutableRequestedFieldsForSection(section)); - view_->UpdateSection(section); + view_->UpdateSection(section, KEEP_USER_INPUT); } GetMetricLogger().LogDialogPopupEvent( diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc index d47e991..66a82af 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc @@ -47,7 +47,8 @@ class TestAutofillDialogView : public AutofillDialogView { virtual void UpdateNotificationArea() OVERRIDE {} virtual void UpdateAccountChooser() OVERRIDE {} virtual void UpdateButtonStrip() OVERRIDE {} - virtual void UpdateSection(DialogSection section) OVERRIDE {} + virtual void UpdateSection(DialogSection section, UserInputAction action) + OVERRIDE {} virtual void GetUserInput(DialogSection section, DetailOutputMap* output) OVERRIDE {} virtual string16 GetCvc() OVERRIDE { return string16(); } diff --git a/chrome/browser/ui/autofill/autofill_dialog_models.cc b/chrome/browser/ui/autofill/autofill_dialog_models.cc index e00d58b..0727783 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_models.cc +++ b/chrome/browser/ui/autofill/autofill_dialog_models.cc @@ -195,7 +195,7 @@ int MonthComboboxModel::GetItemCount() const { // static string16 MonthComboboxModel::FormatMonth(int index) { - return ASCIIToUTF16(base::StringPrintf("%2d", index)); + return ASCIIToUTF16(base::StringPrintf("%.2d", index)); } string16 MonthComboboxModel::GetItemAt(int index) { diff --git a/chrome/browser/ui/autofill/autofill_dialog_types.h b/chrome/browser/ui/autofill/autofill_dialog_types.h index 10877f4..f144d8c3 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_types.h +++ b/chrome/browser/ui/autofill/autofill_dialog_types.h @@ -54,6 +54,13 @@ enum DialogSection { SECTION_SHIPPING, }; +// Used by UpdateSection() to indicate what to do with data that the user has +// already input into textfields. +enum UserInputAction { + CLEAR_USER_INPUT, + KEEP_USER_INPUT, +}; + // A notification to show in the autofill dialog. Ranges from information to // seriously scary security messages, and will give you the color it should be // displayed (if you ask it). diff --git a/chrome/browser/ui/autofill/autofill_dialog_view.h b/chrome/browser/ui/autofill/autofill_dialog_view.h index fdcbf6a..0eea9e9 100644 --- a/chrome/browser/ui/autofill/autofill_dialog_view.h +++ b/chrome/browser/ui/autofill/autofill_dialog_view.h @@ -35,8 +35,9 @@ class AutofillDialogView { // Updates the button strip based on the current controller state. virtual void UpdateButtonStrip() = 0; - // Called when the contents of a section have changed. - virtual void UpdateSection(DialogSection section) = 0; + // Called when the contents of a section have changed. Depending on |action|, + // the view may also clobber all manual inputs. + virtual void UpdateSection(DialogSection section, UserInputAction action) = 0; // Fills |output| with data the user manually input. virtual void GetUserInput(DialogSection section, DetailOutputMap* output) = 0; diff --git a/chrome/browser/ui/views/autofill/autofill_dialog_views.cc b/chrome/browser/ui/views/autofill/autofill_dialog_views.cc index a73c469..dbc0ad9 100644 --- a/chrome/browser/ui/views/autofill/autofill_dialog_views.cc +++ b/chrome/browser/ui/views/autofill/autofill_dialog_views.cc @@ -652,7 +652,8 @@ void AutofillDialogViews::UpdateNotificationArea() { ContentsPreferredSizeChanged(); } -void AutofillDialogViews::UpdateSection(DialogSection section) { +void AutofillDialogViews::UpdateSection(DialogSection section, + UserInputAction action) { const DetailInputs& updated_inputs = controller_->RequestedFieldsForSection(section); DetailsGroup* group = GroupForSection(section); @@ -661,8 +662,12 @@ void AutofillDialogViews::UpdateSection(DialogSection section) { iter != updated_inputs.end(); ++iter) { const DetailInput& input = *iter; TextfieldMap::iterator text_mapping = group->textfields.find(&input); - if (text_mapping != group->textfields.end()) + + if (text_mapping != group->textfields.end() && + (text_mapping->second->textfield()->text().empty() || + action == CLEAR_USER_INPUT)) { text_mapping->second->textfield()->SetText(iter->initial_value); + } ComboboxMap::iterator combo_mapping = group->comboboxes.find(&input); if (combo_mapping != group->comboboxes.end()) { diff --git a/chrome/browser/ui/views/autofill/autofill_dialog_views.h b/chrome/browser/ui/views/autofill/autofill_dialog_views.h index 9b6dadd..1f5eacc 100644 --- a/chrome/browser/ui/views/autofill/autofill_dialog_views.h +++ b/chrome/browser/ui/views/autofill/autofill_dialog_views.h @@ -73,7 +73,8 @@ class AutofillDialogViews : public AutofillDialogView, virtual void UpdateAccountChooser() OVERRIDE; virtual void UpdateButtonStrip() OVERRIDE; virtual void UpdateNotificationArea() OVERRIDE; - virtual void UpdateSection(DialogSection section) OVERRIDE; + virtual void UpdateSection(DialogSection section, + UserInputAction action) OVERRIDE; virtual void GetUserInput(DialogSection section, DetailOutputMap* output) OVERRIDE; virtual string16 GetCvc() OVERRIDE; diff --git a/ui/views/controls/combobox/native_combobox_views.cc b/ui/views/controls/combobox/native_combobox_views.cc index 203f5ff..63d254e 100644 --- a/ui/views/controls/combobox/native_combobox_views.cc +++ b/ui/views/controls/combobox/native_combobox_views.cc @@ -219,6 +219,7 @@ void NativeComboboxViews::UpdateFromModel() { void NativeComboboxViews::UpdateSelectedIndex() { selected_index_ = combobox_->selected_index(); + SchedulePaint(); } void NativeComboboxViews::UpdateEnabled() { |