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 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_TEXTFIELD_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_TEXTFIELD_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_TEXTFIELD_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_TEXTFIELD_H_ |
7 | 7 |
| 8 #include <memory> |
| 9 |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "chrome/browser/ui/views/payments/validation_delegate.h" | 11 #include "chrome/browser/ui/views/payments/validation_delegate.h" |
10 #include "ui/views/controls/textfield/textfield.h" | 12 #include "ui/views/controls/textfield/textfield.h" |
11 | 13 |
12 namespace payments { | 14 namespace payments { |
13 | 15 |
14 class ValidatingTextfield : public views::Textfield { | 16 class ValidatingTextfield : public views::Textfield { |
15 public: | 17 public: |
16 explicit ValidatingTextfield(std::unique_ptr<ValidationDelegate> delegate); | 18 explicit ValidatingTextfield(std::unique_ptr<ValidationDelegate> delegate); |
17 ~ValidatingTextfield() override; | 19 ~ValidatingTextfield() override; |
18 | 20 |
19 // Textfield: | 21 // Textfield: |
20 // The first validation will happen on blur. | 22 // The first validation will happen on blur. |
21 void OnBlur() override; | 23 void OnBlur() override; |
22 // Used to keep track of our own destruction. | 24 // Used to keep track of our own destruction. |
23 void ViewHierarchyChanged( | 25 void ViewHierarchyChanged( |
24 const ViewHierarchyChangedDetails& details) override; | 26 const ViewHierarchyChangedDetails& details) override; |
25 | 27 |
26 // Called when the textfield contents is changed. May do validation. | 28 // Called when the textfield contents is changed. May do validation. |
27 void OnContentsChanged(); | 29 void OnContentsChanged(); |
28 | 30 |
| 31 // Identifies whether the current content if valid or not. |
| 32 bool IsValid(); |
| 33 |
29 private: | 34 private: |
30 // Will call to the ValidationDelegate to validate the contents of the | 35 // Will call to the ValidationDelegate to validate the contents of the |
31 // textfield. | 36 // textfield. |
32 void Validate(); | 37 void Validate(); |
33 | 38 |
34 std::unique_ptr<ValidationDelegate> delegate_; | 39 std::unique_ptr<ValidationDelegate> delegate_; |
35 bool was_blurred_ = false; | 40 bool was_blurred_ = false; |
36 bool being_removed_ = false; | 41 bool being_removed_ = false; |
37 | 42 |
38 DISALLOW_COPY_AND_ASSIGN(ValidatingTextfield); | 43 DISALLOW_COPY_AND_ASSIGN(ValidatingTextfield); |
39 }; | 44 }; |
40 | 45 |
41 } // namespace payments | 46 } // namespace payments |
42 | 47 |
43 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_TEXTFIELD_H_ | 48 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_TEXTFIELD_H_ |
OLD | NEW |