blob: 1714ec293c89b26ec535fd9c51eda657fdf9a605 [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
mad5044aac2017-03-14 20:42:5217class ValidatingCombobox : public views::Combobox,
18 public ui::ComboboxModelObserver {
mathp0e338682017-02-16 17:39:2519 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;
mathp2fc9dc02017-05-09 14:57:2227 // Used to keep track of our own destruction.
28 void ViewHierarchyChanged(
Peter Boström8384b142019-03-21 00:30:1329 const views::ViewHierarchyChangedDetails& details) override;
mathp0e338682017-02-16 17:39:2530
31 // Called when the combobox contents is changed. May do validation.
32 void OnContentsChanged();
33
mad5044aac2017-03-14 20:42:5234 // ui::ComboboxModelObserver:
35 void OnComboboxModelChanged(ui::ComboboxModel* model) override;
36
mad7bd806242017-05-19 17:16:4337 // Identifies whether the current content if valid or not.
38 bool IsValid();
39
mathp0e338682017-02-16 17:39:2540 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_;
mathp2fc9dc02017-05-09 14:57:2246 bool being_removed_ = false;
mathp0e338682017-02-16 17:39:2547
48 DISALLOW_COPY_AND_ASSIGN(ValidatingCombobox);
49};
50
51} // namespace payments
52
53#endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_COMBOBOX_H_