Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ | |
| 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <unordered_map> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/ptr_util.h" | |
| 14 #include "base/strings/string16.h" | |
| 15 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" | |
| 16 #include "components/autofill/core/browser/field_types.h" | |
| 17 #include "ui/views/controls/button/vector_icon_button_delegate.h" | |
| 18 #include "ui/views/controls/textfield/textfield_controller.h" | |
| 19 | |
| 20 namespace views { | |
| 21 class Textfield; | |
| 22 class View; | |
| 23 } // namespace views | |
| 24 | |
| 25 namespace payments { | |
| 26 | |
| 27 class PaymentRequest; | |
| 28 class PaymentRequestDialogView; | |
| 29 | |
| 30 // Field definition for an editor field, used to build the UI. | |
| 31 struct EditorField { | |
| 32 enum LengthHint : int { HINT_LONG, HINT_SHORT }; | |
| 33 | |
|
please use gerrit instead
2017/02/02 20:19:02
enum class?
Mathieu
2017/02/03 02:18:57
Done.
| |
| 34 EditorField(autofill::ServerFieldType type, | |
| 35 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.
| |
| 36 LengthHint length_hint) | |
| 37 : type(type), label(label), length_hint(length_hint) {} | |
| 38 | |
| 39 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.
| |
| 40 | |
| 41 base::string16 label; | |
| 42 | |
|
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.
| |
| 43 LengthHint length_hint; | |
| 44 }; | |
| 45 | |
| 46 // The PaymentRequestSheetController subtype for the editor screens of the | |
| 47 // Payment Request flow. | |
| 48 class EditorViewController : public PaymentRequestSheetController, | |
| 49 public views::VectorIconButtonDelegate, | |
| 50 public views::TextfieldController { | |
| 51 public: | |
| 52 // Does not take ownership of the arguments, which should outlive this object. | |
| 53 EditorViewController(PaymentRequest* request, | |
| 54 PaymentRequestDialogView* dialog); | |
| 55 ~EditorViewController() override; | |
| 56 | |
| 57 // PaymentRequestSheetController: | |
| 58 std::unique_ptr<views::View> CreateView() override; | |
| 59 | |
| 60 // Returns the field definitions used to build the UI. | |
| 61 virtual std::vector<std::unique_ptr<EditorField>> GetFieldDefinitions() = 0; | |
| 62 // Validates the data entered and attempts to save; returns true on success. | |
| 63 virtual bool ValidateModelAndSave() = 0; | |
| 64 | |
| 65 private: | |
| 66 // views::VectorIconButtonDelegate: | |
| 67 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
| 68 | |
| 69 // views::TextfieldController | |
| 70 void ContentsChanged(views::Textfield* sender, | |
| 71 const base::string16& new_contents) override; | |
| 72 | |
| 73 // Creates a view for an input field to be added in the editor sheet. |field| | |
| 74 // is the field definition, which contains the label and the hint about | |
| 75 // the length of the input field. | |
| 76 std::unique_ptr<views::View> CreateInputField(EditorField* field, | |
| 77 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
| |
| 78 | |
| 79 // Used to remember the association between the input field UI element and the | |
| 80 // original field definition. | |
| 81 std::unordered_map<views::Textfield*, std::unique_ptr<EditorField>> | |
| 82 text_fields_; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(EditorViewController); | |
| 85 }; | |
| 86 | |
| 87 } // namespace payments | |
| 88 | |
| 89 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ | |
| OLD | NEW |