blob: fcc2660fcf3cd5d6f3eadbae3abaad93125af85f [file] [log] [blame]
mathp0e338682017-02-16 17:39:251// 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
mad5044aac2017-03-14 20:42:528#include <memory>
9
mathp0e338682017-02-16 17:39:2510#include "base/macros.h"
11#include "chrome/browser/ui/views/payments/validation_delegate.h"
mad5044aac2017-03-14 20:42:5212#include "ui/base/models/combobox_model_observer.h"
mathp0e338682017-02-16 17:39:2513#include "ui/views/controls/combobox/combobox.h"
14
15namespace payments {
16
Robert Liaob67247432019-05-14 21:58:2617class ValidatingCombobox : public views::Combobox {
mathp0e338682017-02-16 17:39:2518 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;
mathp2fc9dc02017-05-09 14:57:2226 // Used to keep track of our own destruction.
27 void ViewHierarchyChanged(
Peter Boström8384b142019-03-21 00:30:1328 const views::ViewHierarchyChangedDetails& details) override;
mathp0e338682017-02-16 17:39:2529
30 // Called when the combobox contents is changed. May do validation.
31 void OnContentsChanged();
32
Robert Liaob67247432019-05-14 21:58:2633 // views::Combobox:
mad5044aac2017-03-14 20:42:5234 void OnComboboxModelChanged(ui::ComboboxModel* model) override;
35
mad7bd806242017-05-19 17:16:4336 // Identifies whether the current content if valid or not.
37 bool IsValid();
38
mathp0e338682017-02-16 17:39:2539 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_;
mathp2fc9dc02017-05-09 14:57:2245 bool being_removed_ = false;
mathp0e338682017-02-16 17:39:2546
47 DISALLOW_COPY_AND_ASSIGN(ValidatingCombobox);
48};
49
50} // namespace payments
51
52#endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_COMBOBOX_H_