Chromium Code Reviews| 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..13df19c3899de14d09bf4fa64d57126bf826c946 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/payments/editor_view_controller.h |
| @@ -0,0 +1,87 @@ |
| +// 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 class LengthHint : int { HINT_LONG, HINT_SHORT }; |
| + |
| + EditorField(autofill::ServerFieldType type, |
| + const base::string16& label, |
| + LengthHint length_hint) |
| + : type(type), label(label), length_hint(length_hint) {} |
| + |
| + const autofill::ServerFieldType type; |
| + const base::string16 label; |
| + 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); |
| + |
| + // 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>> |
|
sky
2017/02/06 17:05:11
optional: EditorField is cheap, I personally would
Mathieu
2017/02/06 17:46:24
Agree, it simplifies code thanks
|
| + text_fields_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(EditorViewController); |
| +}; |
| + |
| +} // namespace payments |
| + |
| +#endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ |