Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1184)

Unified Diff: chrome/browser/ui/views/payments/validating_textfield.h

Issue 2673753005: [Payments] Basic validation in the credit card editor. (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/payments/validating_textfield.h
diff --git a/chrome/browser/ui/views/payments/validating_textfield.h b/chrome/browser/ui/views/payments/validating_textfield.h
new file mode 100644
index 0000000000000000000000000000000000000000..44cb5af4372dc3d0afb75e139fe3e28cf8c48a53
--- /dev/null
+++ b/chrome/browser/ui/views/payments/validating_textfield.h
@@ -0,0 +1,50 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_TEXTFIELD_H_
+#define CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_TEXTFIELD_H_
+
+#include "base/macros.h"
+#include "ui/views/controls/textfield/textfield.h"
+
+namespace payments {
+
+class ValidatingTextfield : public views::Textfield {
+ public:
+ class Delegate {
+ public:
+ Delegate() {}
+ virtual ~Delegate() {}
+
+ // Only the delegate knows how to validate the textfield.
+ virtual bool ValidateTextfield(views::Textfield* textfield) = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Delegate);
+ };
+
+ explicit ValidatingTextfield(
+ std::unique_ptr<ValidatingTextfield::Delegate> delegate);
+ ~ValidatingTextfield() override;
+
+ // Textfield:
+ // The first validation will happen on blur.
+ void OnBlur() override;
+
+ // Called when the textfield contents is changed. May do validation.
+ void OnContentsChanged();
+
+ private:
+ // Will call to the Delegate to validate the contents of the textfield.
+ void Validate();
+
+ std::unique_ptr<ValidatingTextfield::Delegate> delegate_;
+ bool was_validated_ = false;
+
+ DISALLOW_COPY_AND_ASSIGN(ValidatingTextfield);
+};
+
+} // namespace payments
+
+#endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_VALIDATING_TEXTFIELD_H_

Powered by Google App Engine
This is Rietveld 408576698