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

Side by Side Diff: chrome/browser/ui/views/payments/shipping_address_editor_view_controller.cc

Issue 2895473005: [Payments] Have expiration date be on the same line in CC editor (Closed)
Patch Set: addressed comments Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/payments/shipping_address_editor_view_controll er.h" 5 #include "chrome/browser/ui/views/payments/shipping_address_editor_view_controll er.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 // the action. 200 // the action.
201 OnDataChanged(/*synchronous=*/false); 201 OnDataChanged(/*synchronous=*/false);
202 } 202 }
203 } 203 }
204 204
205 void ShippingAddressEditorViewController::UpdateEditorView() { 205 void ShippingAddressEditorViewController::UpdateEditorView() {
206 EditorViewController::UpdateEditorView(); 206 EditorViewController::UpdateEditorView();
207 if (chosen_country_index_ > 0UL && 207 if (chosen_country_index_ > 0UL &&
208 chosen_country_index_ < countries_.size()) { 208 chosen_country_index_ < countries_.size()) {
209 views::Combobox* country_combo_box = static_cast<views::Combobox*>( 209 views::Combobox* country_combo_box = static_cast<views::Combobox*>(
210 dialog()->GetViewByID(autofill::ADDRESS_HOME_COUNTRY)); 210 dialog()->GetViewByID(EditorViewController::GetInputFieldViewId(
211 autofill::ADDRESS_HOME_COUNTRY)));
211 DCHECK(country_combo_box); 212 DCHECK(country_combo_box);
212 DCHECK_EQ(countries_.size(), 213 DCHECK_EQ(countries_.size(),
213 static_cast<size_t>(country_combo_box->GetRowCount())); 214 static_cast<size_t>(country_combo_box->GetRowCount()));
214 country_combo_box->SetSelectedIndex(chosen_country_index_); 215 country_combo_box->SetSelectedIndex(chosen_country_index_);
215 } else if (countries_.size() > 0UL) { 216 } else if (countries_.size() > 0UL) {
216 chosen_country_index_ = 0UL; 217 chosen_country_index_ = 0UL;
217 } else { 218 } else {
218 chosen_country_index_ = kInvalidCountryIndex; 219 chosen_country_index_ = kInvalidCountryIndex;
219 } 220 }
220 // Ignore temporary profile once the editor view has been updated. 221 // Ignore temporary profile once the editor view has been updated.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } 381 }
381 } 382 }
382 383
383 bool ShippingAddressEditorViewController::SaveFieldsToProfile( 384 bool ShippingAddressEditorViewController::SaveFieldsToProfile(
384 autofill::AutofillProfile* profile, 385 autofill::AutofillProfile* profile,
385 bool ignore_errors) { 386 bool ignore_errors) {
386 const std::string& locale = state()->GetApplicationLocale(); 387 const std::string& locale = state()->GetApplicationLocale();
387 // The country must be set first, because the profile uses the country to 388 // The country must be set first, because the profile uses the country to
388 // interpret some of the data (e.g., phone numbers) passed to SetInfo. 389 // interpret some of the data (e.g., phone numbers) passed to SetInfo.
389 views::Combobox* combobox = static_cast<views::Combobox*>( 390 views::Combobox* combobox = static_cast<views::Combobox*>(
390 dialog()->GetViewByID(autofill::ADDRESS_HOME_COUNTRY)); 391 dialog()->GetViewByID(EditorViewController::GetInputFieldViewId(
392 autofill::ADDRESS_HOME_COUNTRY)));
391 // The combobox can be null when saving to temporary profile while updating 393 // The combobox can be null when saving to temporary profile while updating
392 // the view. 394 // the view.
393 if (combobox) { 395 if (combobox) {
394 base::string16 country(combobox->GetTextForRow(combobox->selected_index())); 396 base::string16 country(combobox->GetTextForRow(combobox->selected_index()));
395 bool success = 397 bool success =
396 profile->SetInfo(autofill::AutofillType(autofill::ADDRESS_HOME_COUNTRY), 398 profile->SetInfo(autofill::AutofillType(autofill::ADDRESS_HOME_COUNTRY),
397 country, locale); 399 country, locale);
398 LOG_IF(ERROR, !success && !ignore_errors) 400 LOG_IF(ERROR, !success && !ignore_errors)
399 << "Can't set profile country to: " << country; 401 << "Can't set profile country to: " << country;
400 if (!success && !ignore_errors) 402 if (!success && !ignore_errors)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 490
489 bool ShippingAddressEditorViewController::ShippingAddressValidationDelegate:: 491 bool ShippingAddressEditorViewController::ShippingAddressValidationDelegate::
490 ValidateValue(const base::string16& value) { 492 ValidateValue(const base::string16& value) {
491 if (!value.empty()) { 493 if (!value.empty()) {
492 if (field_.type == autofill::PHONE_HOME_WHOLE_NUMBER && 494 if (field_.type == autofill::PHONE_HOME_WHOLE_NUMBER &&
493 controller_->chosen_country_index_ < controller_->countries_.size() && 495 controller_->chosen_country_index_ < controller_->countries_.size() &&
494 !autofill::IsValidPhoneNumber( 496 !autofill::IsValidPhoneNumber(
495 value, controller_->countries_[controller_->chosen_country_index_] 497 value, controller_->countries_[controller_->chosen_country_index_]
496 .first)) { 498 .first)) {
497 controller_->DisplayErrorMessageForField( 499 controller_->DisplayErrorMessageForField(
498 field_, l10n_util::GetStringUTF16( 500 field_.type, l10n_util::GetStringUTF16(
499 IDS_PAYMENTS_PHONE_INVALID_VALIDATION_MESSAGE)); 501 IDS_PAYMENTS_PHONE_INVALID_VALIDATION_MESSAGE));
500 return false; 502 return false;
501 } 503 }
502 // As long as other field types are non-empty, they are valid. 504 // As long as other field types are non-empty, they are valid.
503 controller_->DisplayErrorMessageForField(field_, base::ASCIIToUTF16("")); 505 controller_->DisplayErrorMessageForField(field_.type,
506 base::ASCIIToUTF16(""));
504 return true; 507 return true;
505 } 508 }
506 bool is_required_valid = !field_.required; 509 bool is_required_valid = !field_.required;
507 const base::string16 displayed_message = 510 const base::string16 displayed_message =
508 is_required_valid ? base::ASCIIToUTF16("") 511 is_required_valid ? base::ASCIIToUTF16("")
509 : l10n_util::GetStringUTF16( 512 : l10n_util::GetStringUTF16(
510 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); 513 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE);
511 controller_->DisplayErrorMessageForField(field_, displayed_message); 514 controller_->DisplayErrorMessageForField(field_.type, displayed_message);
512 return is_required_valid; 515 return is_required_valid;
513 } 516 }
514 517
515 } // namespace payments 518 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698