| 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 "base/macros.h" |   8 #include "base/macros.h" | 
 |   9 #include "chrome/browser/ui/views/payments/validation_delegate.h" | 
|   9 #include "ui/views/controls/textfield/textfield.h" |  10 #include "ui/views/controls/textfield/textfield.h" | 
|  10  |  11  | 
|  11 namespace payments { |  12 namespace payments { | 
|  12  |  13  | 
|  13 class ValidatingTextfield : public views::Textfield { |  14 class ValidatingTextfield : public views::Textfield { | 
|  14  public: |  15  public: | 
|  15   class Delegate { |  16   explicit ValidatingTextfield(std::unique_ptr<ValidationDelegate> delegate); | 
|  16    public: |  | 
|  17     Delegate() {} |  | 
|  18     virtual ~Delegate() {} |  | 
|  19  |  | 
|  20     // Only the delegate knows how to validate the textfield. |  | 
|  21     virtual bool ValidateTextfield(views::Textfield* textfield) = 0; |  | 
|  22  |  | 
|  23    private: |  | 
|  24     DISALLOW_COPY_AND_ASSIGN(Delegate); |  | 
|  25   }; |  | 
|  26  |  | 
|  27   explicit ValidatingTextfield( |  | 
|  28       std::unique_ptr<ValidatingTextfield::Delegate> delegate); |  | 
|  29   ~ValidatingTextfield() override; |  17   ~ValidatingTextfield() override; | 
|  30  |  18  | 
|  31   // Textfield: |  19   // Textfield: | 
|  32   // The first validation will happen on blur. |  20   // The first validation will happen on blur. | 
|  33   void OnBlur() override; |  21   void OnBlur() override; | 
|  34  |  22  | 
|  35   // Called when the textfield contents is changed. May do validation. |  23   // Called when the textfield contents is changed. May do validation. | 
|  36   void OnContentsChanged(); |  24   void OnContentsChanged(); | 
|  37  |  25  | 
|  38  private: |  26  private: | 
|  39   // Will call to the Delegate to validate the contents of the textfield. |  27   // Will call to the ValidationDelegate to validate the contents of the | 
 |  28   // textfield. | 
|  40   void Validate(); |  29   void Validate(); | 
|  41  |  30  | 
|  42   std::unique_ptr<ValidatingTextfield::Delegate> delegate_; |  31   std::unique_ptr<ValidationDelegate> delegate_; | 
|  43   bool was_validated_ = false; |  32   bool was_blurred_; | 
|  44  |  33  | 
|  45   DISALLOW_COPY_AND_ASSIGN(ValidatingTextfield); |  34   DISALLOW_COPY_AND_ASSIGN(ValidatingTextfield); | 
|  46 }; |  35 }; | 
|  47  |  36  | 
|  48 }  // namespace payments |  37 }  // namespace payments | 
|  49  |  38  | 
|  50 #endif  // CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_TEXTFIELD_H_ |  39 #endif  // CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_TEXTFIELD_H_ | 
| OLD | NEW |