OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" | 15 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" |
16 #include "chrome/browser/ui/views/payments/validating_textfield.h" | |
16 #include "components/autofill/core/browser/field_types.h" | 17 #include "components/autofill/core/browser/field_types.h" |
17 #include "ui/views/controls/button/vector_icon_button_delegate.h" | 18 #include "ui/views/controls/button/vector_icon_button_delegate.h" |
18 #include "ui/views/controls/textfield/textfield_controller.h" | 19 #include "ui/views/controls/textfield/textfield_controller.h" |
19 | 20 |
20 namespace views { | 21 namespace views { |
21 class Textfield; | 22 class Textfield; |
22 class View; | 23 class View; |
23 } // namespace views | 24 } // namespace views |
24 | 25 |
25 namespace payments { | 26 namespace payments { |
(...skipping 11 matching lines...) Expand all Loading... | |
37 : type(type), label(label), length_hint(length_hint) {} | 38 : type(type), label(label), length_hint(length_hint) {} |
38 | 39 |
39 const autofill::ServerFieldType type; | 40 const autofill::ServerFieldType type; |
40 const base::string16 label; | 41 const base::string16 label; |
41 LengthHint length_hint; | 42 LengthHint length_hint; |
42 }; | 43 }; |
43 | 44 |
44 // The PaymentRequestSheetController subtype for the editor screens of the | 45 // The PaymentRequestSheetController subtype for the editor screens of the |
45 // Payment Request flow. | 46 // Payment Request flow. |
46 class EditorViewController : public PaymentRequestSheetController, | 47 class EditorViewController : public PaymentRequestSheetController, |
47 public views::TextfieldController { | 48 public views::TextfieldController, |
49 public ValidatingTextfield::Delegate { | |
48 public: | 50 public: |
51 using TextFieldsMap = | |
52 std::unordered_map<ValidatingTextfield*, const EditorField>; | |
please use gerrit instead
2017/02/08 18:50:54
This might make copies of EditorField. I'd prefer
Mathieu
2017/02/08 21:21:50
Discussed offline, EditorField is cheap and copies
| |
49 // Does not take ownership of the arguments, which should outlive this object. | 53 // Does not take ownership of the arguments, which should outlive this object. |
50 EditorViewController(PaymentRequest* request, | 54 EditorViewController(PaymentRequest* request, |
51 PaymentRequestDialogView* dialog); | 55 PaymentRequestDialogView* dialog); |
52 ~EditorViewController() override; | 56 ~EditorViewController() override; |
53 | 57 |
54 // PaymentRequestSheetController: | 58 // PaymentRequestSheetController: |
55 std::unique_ptr<views::View> CreateView() override; | 59 std::unique_ptr<views::View> CreateView() override; |
56 | 60 |
57 // Returns the field definitions used to build the UI. | 61 // Returns the field definitions used to build the UI. |
58 virtual std::vector<EditorField> GetFieldDefinitions() = 0; | 62 virtual std::vector<EditorField> GetFieldDefinitions() = 0; |
59 // Validates the data entered and attempts to save; returns true on success. | 63 // Validates the data entered and attempts to save; returns true on success. |
60 virtual bool ValidateModelAndSave() = 0; | 64 virtual bool ValidateModelAndSave() = 0; |
61 | 65 |
66 // ValidatingTextfield::Delegate implementation. | |
anthonyvd
2017/02/08 15:28:28
For consistency, maybe just "// ValidatingTextfiel
Mathieu
2017/02/08 21:21:50
Done.
| |
67 bool ValidateTextfield(ValidatingTextfield* textfield) override; | |
68 | |
69 const TextFieldsMap& text_fields() { return text_fields_; } | |
please use gerrit instead
2017/02/08 18:50:54
Make this method const please.
Mathieu
2017/02/08 21:21:50
Done.
| |
70 | |
71 protected: | |
72 // PaymentRequestSheetController; | |
73 std::unique_ptr<views::Button> CreatePrimaryButton() override; | |
74 | |
62 private: | 75 private: |
63 // PaymentRequestSheetController: | 76 // PaymentRequestSheetController: |
64 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 77 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
65 | 78 |
66 // views::TextfieldController | 79 // views::TextfieldController |
67 void ContentsChanged(views::Textfield* sender, | 80 void ContentsChanged(views::Textfield* sender, |
68 const base::string16& new_contents) override; | 81 const base::string16& new_contents) override; |
69 | 82 |
70 // Creates a view for an input field to be added in the editor sheet. |field| | 83 // Creates a view for an input field to be added in the editor sheet. |field| |
71 // is the field definition, which contains the label and the hint about | 84 // is the field definition, which contains the label and the hint about |
72 // the length of the input field. | 85 // the length of the input field. |
73 std::unique_ptr<views::View> CreateInputField(const EditorField& field, | 86 std::unique_ptr<views::View> CreateInputField( |
74 views::Textfield** text_field); | 87 const EditorField& field, |
88 ValidatingTextfield** text_field); | |
75 | 89 |
76 // Used to remember the association between the input field UI element and the | 90 // Used to remember the association between the input field UI element and the |
77 // original field definition. The Textfield* are owned by their parent view, | 91 // original field definition. The ValidatingTextfield* are owned by their |
78 // this only keeps a reference that is good as long as the Textfield is | 92 // parent view, this only keeps a reference that is good as long as the |
79 // visible. | 93 // textfield is visible. |
80 std::unordered_map<views::Textfield*, const EditorField> text_fields_; | 94 TextFieldsMap text_fields_; |
81 | 95 |
82 DISALLOW_COPY_AND_ASSIGN(EditorViewController); | 96 DISALLOW_COPY_AND_ASSIGN(EditorViewController); |
83 }; | 97 }; |
84 | 98 |
85 } // namespace payments | 99 } // namespace payments |
86 | 100 |
87 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ | 101 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ |
OLD | NEW |