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