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

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

Issue 2676663002: [Payments] Implements the credit card editor for Desktop UI (Closed)
Patch Set: Initial Created 3 years, 11 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/editor_view_controller.h
diff --git a/chrome/browser/ui/views/payments/editor_view_controller.h b/chrome/browser/ui/views/payments/editor_view_controller.h
new file mode 100644
index 0000000000000000000000000000000000000000..31b61c6f111587d4f92d8cea1842e80c582b391f
--- /dev/null
+++ b/chrome/browser/ui/views/payments/editor_view_controller.h
@@ -0,0 +1,89 @@
+// 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_EDITOR_VIEW_CONTROLLER_H_
+#define CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_
+
+#include <memory>
+#include <unordered_map>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "base/strings/string16.h"
+#include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h"
+#include "components/autofill/core/browser/field_types.h"
+#include "ui/views/controls/button/vector_icon_button_delegate.h"
+#include "ui/views/controls/textfield/textfield_controller.h"
+
+namespace views {
+class Textfield;
+class View;
+} // namespace views
+
+namespace payments {
+
+class PaymentRequest;
+class PaymentRequestDialogView;
+
+// Field definition for an editor field, used to build the UI.
+struct EditorField {
+ enum LengthHint : int { HINT_LONG, HINT_SHORT };
+
please use gerrit instead 2017/02/02 20:19:02 enum class?
Mathieu 2017/02/03 02:18:57 Done.
+ EditorField(autofill::ServerFieldType type,
+ base::string16 label,
please use gerrit instead 2017/02/02 20:19:02 const-ref to avoid an extra copy.
Mathieu 2017/02/03 02:18:57 Done.
+ LengthHint length_hint)
+ : type(type), label(label), length_hint(length_hint) {}
+
+ autofill::ServerFieldType type;
please use gerrit instead 2017/02/02 20:19:02 Here and below: "const" to make this type immutabl
Mathieu 2017/02/03 02:18:57 Done.
+
+ base::string16 label;
+
please use gerrit instead 2017/02/02 20:19:02 nit: No need for newlines on lines 40 and 42.
Mathieu 2017/02/03 02:18:57 Done.
+ LengthHint length_hint;
+};
+
+// The PaymentRequestSheetController subtype for the editor screens of the
+// Payment Request flow.
+class EditorViewController : public PaymentRequestSheetController,
+ public views::VectorIconButtonDelegate,
+ public views::TextfieldController {
+ public:
+ // Does not take ownership of the arguments, which should outlive this object.
+ EditorViewController(PaymentRequest* request,
+ PaymentRequestDialogView* dialog);
+ ~EditorViewController() override;
+
+ // PaymentRequestSheetController:
+ std::unique_ptr<views::View> CreateView() override;
+
+ // Returns the field definitions used to build the UI.
+ virtual std::vector<std::unique_ptr<EditorField>> GetFieldDefinitions() = 0;
+ // Validates the data entered and attempts to save; returns true on success.
+ virtual bool ValidateModelAndSave() = 0;
+
+ private:
+ // views::VectorIconButtonDelegate:
+ void ButtonPressed(views::Button* sender, const ui::Event& event) override;
+
+ // views::TextfieldController
+ void ContentsChanged(views::Textfield* sender,
+ const base::string16& new_contents) override;
+
+ // Creates a view for an input field to be added in the editor sheet. |field|
+ // is the field definition, which contains the label and the hint about
+ // the length of the input field.
+ std::unique_ptr<views::View> CreateInputField(EditorField* field,
+ views::Textfield** text_field);
please use gerrit instead 2017/02/02 20:19:02 Is |text_field| an output?
Mathieu 2017/02/03 02:18:57 Yes. This is a way for the caller to provide the T
+
+ // Used to remember the association between the input field UI element and the
+ // original field definition.
+ std::unordered_map<views::Textfield*, std::unique_ptr<EditorField>>
+ text_fields_;
+
+ DISALLOW_COPY_AND_ASSIGN(EditorViewController);
+};
+
+} // namespace payments
+
+#endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_

Powered by Google App Engine
This is Rietveld 408576698