diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-22 19:38:28 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-22 19:38:28 +0000 |
commit | 1b38d0b4a83aee2e741297b97181fdded474da82 (patch) | |
tree | f3f56b1770cf50edabd376ff8984d366f6e6d480 | |
parent | 3e7ffcc5a9a5c606b2b3d3f9746e3657855272b5 (diff) | |
download | chromium_src-1b38d0b4a83aee2e741297b97181fdded474da82.zip chromium_src-1b38d0b4a83aee2e741297b97181fdded474da82.tar.gz chromium_src-1b38d0b4a83aee2e741297b97181fdded474da82.tar.bz2 |
Makes the auto fill editor on windows only enable the ok button if at
least one field has text. Also, fixes crash if you double click and
the table is empty.
BUG=47742
TEST=create a new address/credit card in the autofill profile manager
and make sure the ok button is only enabled if at least one field has
text.
Review URL: http://codereview.chromium.org/2809070
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53368 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/views/autofill_profiles_view_win.cc | 53 | ||||
-rw-r--r-- | chrome/browser/views/autofill_profiles_view_win.h | 2 |
2 files changed, 42 insertions, 13 deletions
diff --git a/chrome/browser/views/autofill_profiles_view_win.cc b/chrome/browser/views/autofill_profiles_view_win.cc index 1ea9457..e7ebf7a 100644 --- a/chrome/browser/views/autofill_profiles_view_win.cc +++ b/chrome/browser/views/autofill_profiles_view_win.cc @@ -151,6 +151,8 @@ void AutoFillProfilesView::AddClicked(int group_type) { void AutoFillProfilesView::EditClicked() { DCHECK(scroll_view_); int index = scroll_view_->FirstSelectedRow(); + if (index == -1) + return; // Happens if user double clicks and the table is empty. DCHECK(index >= 0); DCHECK(index < static_cast<int>(profiles_set_.size() + credit_card_set_.size())); @@ -717,19 +719,44 @@ AutoFillProfilesView::EditableSetViewContents::GetDialogButtonLabel( bool AutoFillProfilesView::EditableSetViewContents::IsDialogButtonEnabled( MessageBoxFlags::DialogButton button) const { switch (button) { - case MessageBoxFlags::DIALOGBUTTON_OK: { - bool phones_are_valid = true; - for (std::vector<PhoneSubView*>::const_iterator it = - phone_sub_views_.begin(); - it != phone_sub_views_.end() && phones_are_valid; ++it) - phones_are_valid = (phones_are_valid && (*it)->IsValid()); - - return phones_are_valid; - } - case MessageBoxFlags::DIALOGBUTTON_CANCEL: - return true; - default: - break; + case MessageBoxFlags::DIALOGBUTTON_OK: { + // Enable the ok button if at least one non-phone number field has text, + // or the phone numbers are valid. + bool valid = false; + TextFieldToAutoFill* fields; + int field_count; + if (temporary_info_.is_address) { + fields = address_fields_; + field_count = arraysize(address_fields_); + } else { + fields = credit_card_fields_; + field_count = arraysize(credit_card_fields_); + } + for (int i = 0; i < field_count; ++i) { + DCHECK(text_fields_[fields[i].text_field]); + // Phone and fax are handled separately. + if (fields[i].text_field != TEXT_PHONE_PHONE && + fields[i].text_field != TEXT_FAX_PHONE && + !text_fields_[fields[i].text_field]->text().empty()) { + valid = true; + break; + } + } + for (std::vector<PhoneSubView*>::const_iterator i = + phone_sub_views_.begin(); i != phone_sub_views_.end(); ++i) { + if (!(*i)->IsValid()) { + valid = false; + break; + } else if (!valid && !(*i)->text_phone()->text().empty()) { + valid = true; + } + } + return valid; + } + case MessageBoxFlags::DIALOGBUTTON_CANCEL: + return true; + default: + break; } NOTREACHED(); return false; diff --git a/chrome/browser/views/autofill_profiles_view_win.h b/chrome/browser/views/autofill_profiles_view_win.h index be54e14..57889e5 100644 --- a/chrome/browser/views/autofill_profiles_view_win.h +++ b/chrome/browser/views/autofill_profiles_view_win.h @@ -200,6 +200,8 @@ class AutoFillProfilesView : public views::View, bool IsValid() const; + views::Textfield* text_phone() { return text_phone_; } + protected: // views::View methods: virtual void ViewHierarchyChanged(bool is_add, views::View* parent, |