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_combobox.h" | 5 #include "chrome/browser/ui/views/payments/validating_combobox.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ui/base/models/combobox_model.h" | 9 #include "ui/base/models/combobox_model.h" |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 ValidatingCombobox::~ValidatingCombobox() {} | 21 ValidatingCombobox::~ValidatingCombobox() {} |
22 | 22 |
23 void ValidatingCombobox::OnBlur() { | 23 void ValidatingCombobox::OnBlur() { |
24 Combobox::OnBlur(); | 24 Combobox::OnBlur(); |
25 | 25 |
26 // The first validation should be on a blur. The subsequent validations will | 26 // The first validation should be on a blur. The subsequent validations will |
27 // occur when the content changes. Do not validate if the view is being | 27 // occur when the content changes. Do not validate if the view is being |
28 // removed. | 28 // removed. |
29 if (!was_blurred_ && !being_removed_) { | 29 if (!was_blurred_ && !being_removed_) { |
30 was_blurred_ = true; | 30 was_blurred_ = true; |
31 Validate(); | 31 Validate(/*display_error=*/true); |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 void ValidatingCombobox::ViewHierarchyChanged( | 35 void ValidatingCombobox::ViewHierarchyChanged( |
36 const ViewHierarchyChangedDetails& details) { | 36 const ViewHierarchyChangedDetails& details) { |
37 if (details.child == this && !details.is_add) | 37 if (details.child == this && !details.is_add) |
38 being_removed_ = true; | 38 being_removed_ = true; |
39 } | 39 } |
40 | 40 |
41 void ValidatingCombobox::OnContentsChanged() { | 41 void ValidatingCombobox::OnContentsChanged() { |
42 // Validation on every keystroke only happens if the field has been validated | 42 // Validation on every keystroke only happens if the field has been validated |
43 // before as part of a blur. | 43 // before as part of a blur. |
44 if (!was_blurred_) | 44 if (!was_blurred_) |
45 return; | 45 return; |
46 | 46 |
47 Validate(); | 47 Validate(/*display_error=*/true); |
48 } | 48 } |
49 | 49 |
50 void ValidatingCombobox::OnComboboxModelChanged( | 50 void ValidatingCombobox::OnComboboxModelChanged( |
51 ui::ComboboxModel* unused_model) { | 51 ui::ComboboxModel* unused_model) { |
52 ModelChanged(); | 52 ModelChanged(); |
53 delegate_->ComboboxModelChanged(this); | 53 delegate_->ComboboxModelChanged(this); |
54 } | 54 } |
55 | 55 |
56 void ValidatingCombobox::Validate() { | 56 void ValidatingCombobox::Validate(bool display_error) { |
57 // ValidateCombobox may have side-effects, such as displaying errors. | 57 // ValidateCombobox may have side-effects, such as displaying errors. |
58 SetInvalid(!delegate_->ValidateCombobox(this)); | 58 SetInvalid(!delegate_->ValidateCombobox(this, display_error)); |
59 } | 59 } |
60 | 60 |
61 } // namespace payments | 61 } // namespace payments |
OLD | NEW |