Chromium Code Reviews| OLD | NEW | 
|---|---|
| 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/validating_textfield.h" | 5 #include "chrome/browser/ui/views/payments/validating_combobox.h" | 
| 6 | 6 | 
| 7 #include <utility> | 7 #include <utility> | 
| 8 | 8 | 
| 9 namespace payments { | 9 namespace payments { | 
| 10 | 10 | 
| 11 ValidatingTextfield::ValidatingTextfield( | 11 ValidatingCombobox::ValidatingCombobox( | 
| 12 std::unique_ptr<ValidatingTextfield::Delegate> delegate) | 12 std::unique_ptr<ui::ComboboxModel> model, | 
| 13 : Textfield(), delegate_(std::move(delegate)) {} | 13 std::unique_ptr<ValidationDelegate> delegate) | 
| 14 : Combobox(std::move(model)), delegate_(std::move(delegate)) {} | |
| 14 | 15 | 
| 15 ValidatingTextfield::~ValidatingTextfield() {} | 16 ValidatingCombobox::~ValidatingCombobox() {} | 
| 16 | 17 | 
| 17 void ValidatingTextfield::OnBlur() { | 18 void ValidatingCombobox::OnBlur() { | 
| 18 Textfield::OnBlur(); | 19 Combobox::OnBlur(); | 
| 19 | 20 | 
| 20 // The first validation should be on a blur. The subsequent validations will | 21 // The first validation should be on a blur. The subsequent validations will | 
| 21 // occur when the content changes. | 22 // occur when the content changes. | 
| 22 if (!was_validated_) { | 23 if (!was_validated_) { | 
| 
 
please use gerrit instead
2017/02/15 15:59:39
Perhaps a better name would be "has_blurred_once_"
 
Mathieu
2017/02/15 19:55:51
Done.
 
 | |
| 23 was_validated_ = true; | 24 was_validated_ = true; | 
| 24 Validate(); | 25 Validate(); | 
| 25 } | 26 } | 
| 26 } | 27 } | 
| 27 | 28 | 
| 28 void ValidatingTextfield::OnContentsChanged() { | 29 void ValidatingCombobox::OnContentsChanged() { | 
| 29 // Validation on every keystroke only happens if the field has been validated | 30 // Validation on every keystroke only happens if the field has been validated | 
| 30 // before as part of a blur. | 31 // before as part of a blur. | 
| 31 if (!was_validated_) | 32 if (!was_validated_) | 
| 32 return; | 33 return; | 
| 33 | 34 | 
| 34 Validate(); | 35 Validate(); | 
| 35 } | 36 } | 
| 36 | 37 | 
| 37 void ValidatingTextfield::Validate() { | 38 void ValidatingCombobox::Validate() { | 
| 38 // ValidateTextfield may have side-effects, such as displaying errors. | 39 // ValidateCombobox may have side-effects, such as displaying errors. | 
| 39 SetInvalid(!delegate_->ValidateTextfield(this)); | 40 SetInvalid(!delegate_->ValidateCombobox(this)); | 
| 40 } | 41 } | 
| 41 | 42 | 
| 42 } // namespace payments | 43 } // namespace payments | 
| OLD | NEW |