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

Unified Diff: chrome/browser/ui/views/payments/validating_combobox.cc

Issue 2689363004: [Payments] Add combobox support to editors. (Closed)
Patch Set: re-enable test, addressed comments 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_combobox.cc
diff --git a/chrome/browser/ui/views/payments/validating_combobox.cc b/chrome/browser/ui/views/payments/validating_combobox.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ce76d85d1f27f830396a9ee8ca8792454a26f7aa
--- /dev/null
+++ b/chrome/browser/ui/views/payments/validating_combobox.cc
@@ -0,0 +1,45 @@
+// 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.
+
+#include "chrome/browser/ui/views/payments/validating_combobox.h"
+
+#include <utility>
+
+namespace payments {
+
+ValidatingCombobox::ValidatingCombobox(
+ std::unique_ptr<ui::ComboboxModel> model,
+ std::unique_ptr<ValidationDelegate> delegate)
+ : Combobox(std::move(model)),
+ delegate_(std::move(delegate)),
+ was_blurred_(false) {}
+
+ValidatingCombobox::~ValidatingCombobox() {}
+
+void ValidatingCombobox::OnBlur() {
+ Combobox::OnBlur();
+
+ // The first validation should be on a blur. The subsequent validations will
+ // occur when the content changes.
+ if (!was_blurred_) {
+ was_blurred_ = true;
+ Validate();
+ }
+}
+
+void ValidatingCombobox::OnContentsChanged() {
+ // Validation on every keystroke only happens if the field has been validated
+ // before as part of a blur.
+ if (!was_blurred_)
+ return;
+
+ Validate();
+}
+
+void ValidatingCombobox::Validate() {
+ // ValidateCombobox may have side-effects, such as displaying errors.
+ SetInvalid(!delegate_->ValidateCombobox(this));
+}
+
+} // namespace payments
« no previous file with comments | « chrome/browser/ui/views/payments/validating_combobox.h ('k') | chrome/browser/ui/views/payments/validating_textfield.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698