| 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 |
| 11 namespace payments { | 11 namespace payments { |
| 12 | 12 |
| 13 ValidatingCombobox::ValidatingCombobox( | 13 ValidatingCombobox::ValidatingCombobox( |
| 14 std::unique_ptr<ui::ComboboxModel> model, | 14 std::unique_ptr<ui::ComboboxModel> model, |
| 15 std::unique_ptr<ValidationDelegate> delegate) | 15 std::unique_ptr<ValidationDelegate> delegate) |
| 16 : Combobox(std::move(model)), delegate_(std::move(delegate)) { | 16 : Combobox(std::move(model)), delegate_(std::move(delegate)) { |
| 17 // No need to remove observer on owned model. | 17 // No need to remove observer on owned model. |
| 18 this->model()->AddObserver(this); | 18 this->model()->AddObserver(this); |
| 19 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 19 } | 20 } |
| 20 | 21 |
| 21 ValidatingCombobox::~ValidatingCombobox() {} | 22 ValidatingCombobox::~ValidatingCombobox() {} |
| 22 | 23 |
| 23 void ValidatingCombobox::OnBlur() { | 24 void ValidatingCombobox::OnBlur() { |
| 24 Combobox::OnBlur(); | 25 Combobox::OnBlur(); |
| 25 | 26 |
| 26 // Validations will occur when the content changes. Do not validate if the | 27 // Validations will occur when the content changes. Do not validate if the |
| 27 // view is being removed. | 28 // view is being removed. |
| 28 if (!being_removed_) { | 29 if (!being_removed_) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 49 bool ValidatingCombobox::IsValid() { | 50 bool ValidatingCombobox::IsValid() { |
| 50 return delegate_->IsValidCombobox(this); | 51 return delegate_->IsValidCombobox(this); |
| 51 } | 52 } |
| 52 | 53 |
| 53 void ValidatingCombobox::Validate() { | 54 void ValidatingCombobox::Validate() { |
| 54 // ComboboxValueChanged may have side-effects, such as displaying errors. | 55 // ComboboxValueChanged may have side-effects, such as displaying errors. |
| 55 SetInvalid(!delegate_->ComboboxValueChanged(this)); | 56 SetInvalid(!delegate_->ComboboxValueChanged(this)); |
| 56 } | 57 } |
| 57 | 58 |
| 58 } // namespace payments | 59 } // namespace payments |
| OLD | NEW |