mathp | 0e33868 | 2017-02-16 17:39:25 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_COMBOBOX_H_ |
| 6 | #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_COMBOBOX_H_ |
| 7 | |
mad | 5044aac | 2017-03-14 20:42:52 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
mathp | 0e33868 | 2017-02-16 17:39:25 | [diff] [blame] | 10 | #include "base/macros.h" |
| 11 | #include "chrome/browser/ui/views/payments/validation_delegate.h" |
mad | 5044aac | 2017-03-14 20:42:52 | [diff] [blame] | 12 | #include "ui/base/models/combobox_model_observer.h" |
mathp | 0e33868 | 2017-02-16 17:39:25 | [diff] [blame] | 13 | #include "ui/views/controls/combobox/combobox.h" |
| 14 | |
| 15 | namespace payments { |
| 16 | |
Robert Liao | b6724743 | 2019-05-14 21:58:26 | [diff] [blame] | 17 | class ValidatingCombobox : public views::Combobox { |
mathp | 0e33868 | 2017-02-16 17:39:25 | [diff] [blame] | 18 | public: |
| 19 | ValidatingCombobox(std::unique_ptr<ui::ComboboxModel> model, |
| 20 | std::unique_ptr<ValidationDelegate> delegate); |
| 21 | ~ValidatingCombobox() override; |
| 22 | |
| 23 | // Combobox: |
| 24 | // The first validation will happen on blur. |
| 25 | void OnBlur() override; |
mathp | 2fc9dc0 | 2017-05-09 14:57:22 | [diff] [blame] | 26 | // Used to keep track of our own destruction. |
| 27 | void ViewHierarchyChanged( |
Peter Boström | 8384b14 | 2019-03-21 00:30:13 | [diff] [blame] | 28 | const views::ViewHierarchyChangedDetails& details) override; |
mathp | 0e33868 | 2017-02-16 17:39:25 | [diff] [blame] | 29 | |
| 30 | // Called when the combobox contents is changed. May do validation. |
| 31 | void OnContentsChanged(); |
| 32 | |
Robert Liao | b6724743 | 2019-05-14 21:58:26 | [diff] [blame] | 33 | // views::Combobox: |
mad | 5044aac | 2017-03-14 20:42:52 | [diff] [blame] | 34 | void OnComboboxModelChanged(ui::ComboboxModel* model) override; |
| 35 | |
mad | 7bd80624 | 2017-05-19 17:16:43 | [diff] [blame] | 36 | // Identifies whether the current content if valid or not. |
| 37 | bool IsValid(); |
| 38 | |
mathp | 0e33868 | 2017-02-16 17:39:25 | [diff] [blame] | 39 | private: |
| 40 | // Will call to the ValidationDelegate to validate the contents of the |
| 41 | // combobox. |
| 42 | void Validate(); |
| 43 | |
| 44 | std::unique_ptr<ValidationDelegate> delegate_; |
mathp | 2fc9dc0 | 2017-05-09 14:57:22 | [diff] [blame] | 45 | bool being_removed_ = false; |
mathp | 0e33868 | 2017-02-16 17:39:25 | [diff] [blame] | 46 | |
| 47 | DISALLOW_COPY_AND_ASSIGN(ValidatingCombobox); |
| 48 | }; |
| 49 | |
| 50 | } // namespace payments |
| 51 | |
| 52 | #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_COMBOBOX_H_ |