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

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

Issue 2881643002: Focus first invalid field of payment request editor (Closed)
Patch Set: Rebase 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/credit_card_editor_view_controller.h" 5 #include "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 161 }
162 view->AddChildView(icons_row.release()); 162 view->AddChildView(icons_row.release());
163 163
164 return view; 164 return view;
165 } 165 }
166 166
167 std::unique_ptr<views::View> 167 std::unique_ptr<views::View>
168 CreditCardEditorViewController::CreateExtraViewForField( 168 CreditCardEditorViewController::CreateExtraViewForField(
169 autofill::ServerFieldType type) { 169 autofill::ServerFieldType type) {
170 if (type != kBillingAddressType) 170 if (type != kBillingAddressType)
171 return nullptr; 171 return std::unique_ptr<views::View>();
anthonyvd 2017/05/12 14:19:44 nit: just nullptr was fine and it's what we use el
MAD 2017/05/18 16:01:44 Done.
172 172
173 std::unique_ptr<views::View> button_view = base::MakeUnique<views::View>(); 173 std::unique_ptr<views::View> button_view = base::MakeUnique<views::View>();
174 button_view->SetLayoutManager(new views::FillLayout); 174 button_view->SetLayoutManager(new views::FillLayout);
175 175
176 // The button to add new billing addresses. 176 // The button to add new billing addresses.
177 std::unique_ptr<views::Button> add_button( 177 std::unique_ptr<views::Button> add_button(
178 views::MdTextButton::Create(this, l10n_util::GetStringUTF16(IDS_ADD))); 178 views::MdTextButton::Create(this, l10n_util::GetStringUTF16(IDS_ADD)));
179 add_button->set_id( 179 add_button->set_id(
180 static_cast<int>(DialogViewID::ADD_BILLING_ADDRESS_BUTTON)); 180 static_cast<int>(DialogViewID::ADD_BILLING_ADDRESS_BUTTON));
181 add_button->set_tag(add_billing_address_button_tag_); 181 add_button->set_tag(add_billing_address_button_tag_);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 EditorViewController* controller, 383 EditorViewController* controller,
384 const std::vector<std::string>& supported_card_networks) 384 const std::vector<std::string>& supported_card_networks)
385 : field_(field), 385 : field_(field),
386 controller_(controller), 386 controller_(controller),
387 supported_card_networks_(supported_card_networks.begin(), 387 supported_card_networks_(supported_card_networks.begin(),
388 supported_card_networks.end()) {} 388 supported_card_networks.end()) {}
389 CreditCardEditorViewController::CreditCardValidationDelegate:: 389 CreditCardEditorViewController::CreditCardValidationDelegate::
390 ~CreditCardValidationDelegate() {} 390 ~CreditCardValidationDelegate() {}
391 391
392 bool CreditCardEditorViewController::CreditCardValidationDelegate:: 392 bool CreditCardEditorViewController::CreditCardValidationDelegate::
393 ValidateTextfield(views::Textfield* textfield) { 393 ValidateTextfield(views::Textfield* textfield, bool display_error) {
394 return ValidateValue(textfield->text()); 394 return ValidateValue(textfield->text(), display_error);
395 } 395 }
396 396
397 bool CreditCardEditorViewController::CreditCardValidationDelegate:: 397 bool CreditCardEditorViewController::CreditCardValidationDelegate::
398 ValidateCombobox(views::Combobox* combobox) { 398 ValidateCombobox(views::Combobox* combobox, bool display_error) {
399 // The billing address ID is the selected item identifier and not the combobox 399 // The billing address ID is the selected item identifier and not the combobox
400 // value itself. 400 // value itself.
401 if (field_.type == kBillingAddressType) { 401 if (field_.type == kBillingAddressType) {
402 // TODO(crbug.com/718905) Find a way to deal with existing incomplete 402 // TODO(crbug.com/718905) Find a way to deal with existing incomplete
403 // addresses when choosing them as billing addresses. 403 // addresses when choosing them as billing addresses.
404 autofill::AddressComboboxModel* model = 404 autofill::AddressComboboxModel* model =
405 static_cast<autofill::AddressComboboxModel*>(combobox->model()); 405 static_cast<autofill::AddressComboboxModel*>(combobox->model());
406 return !model->GetItemIdentifierAt(combobox->selected_index()).empty(); 406 return !model->GetItemIdentifierAt(combobox->selected_index()).empty();
407 } 407 }
408 return ValidateValue(combobox->GetTextForRow(combobox->selected_index())); 408 return ValidateValue(combobox->GetTextForRow(combobox->selected_index()),
409 display_error);
409 } 410 }
410 411
411 bool CreditCardEditorViewController::CreditCardValidationDelegate:: 412 bool CreditCardEditorViewController::CreditCardValidationDelegate::
412 ValidateValue(const base::string16& value) { 413 ValidateValue(const base::string16& value, bool display_error) {
413 if (!value.empty()) { 414 if (!value.empty()) {
414 base::string16 error_message; 415 base::string16 error_message;
415 bool is_valid = 416 bool is_valid =
416 field_.type == autofill::CREDIT_CARD_NUMBER 417 field_.type == autofill::CREDIT_CARD_NUMBER
417 ? autofill::IsValidCreditCardNumberForBasicCardNetworks( 418 ? autofill::IsValidCreditCardNumberForBasicCardNetworks(
418 value, supported_card_networks_, &error_message) 419 value, supported_card_networks_, &error_message)
419 : autofill::IsValidForType(value, field_.type, &error_message); 420 : autofill::IsValidForType(value, field_.type, &error_message);
420 controller_->DisplayErrorMessageForField(field_, error_message); 421 if (display_error)
422 controller_->DisplayErrorMessageForField(field_, error_message);
421 return is_valid; 423 return is_valid;
422 } 424 }
423 425
424 bool is_required_valid = !field_.required; 426 bool is_required_valid = !field_.required;
425 const base::string16 displayed_message = 427 const base::string16 displayed_message =
426 is_required_valid ? base::ASCIIToUTF16("") 428 is_required_valid ? base::ASCIIToUTF16("")
427 : l10n_util::GetStringUTF16( 429 : l10n_util::GetStringUTF16(
428 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); 430 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE);
429 controller_->DisplayErrorMessageForField(field_, displayed_message); 431 if (display_error)
432 controller_->DisplayErrorMessageForField(field_, displayed_message);
430 return is_required_valid; 433 return is_required_valid;
431 } 434 }
432 435
433 bool CreditCardEditorViewController::GetSheetId(DialogViewID* sheet_id) { 436 bool CreditCardEditorViewController::GetSheetId(DialogViewID* sheet_id) {
434 *sheet_id = DialogViewID::CREDIT_CARD_EDITOR_SHEET; 437 *sheet_id = DialogViewID::CREDIT_CARD_EDITOR_SHEET;
435 return true; 438 return true;
436 } 439 }
437 440
438 } // namespace payments 441 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698