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 <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 30 matching lines...) Expand all Loading... |
41 class PaymentRequestDialogView; | 41 class PaymentRequestDialogView; |
42 class ValidatingCombobox; | 42 class ValidatingCombobox; |
43 class ValidatingTextfield; | 43 class ValidatingTextfield; |
44 | 44 |
45 // Field definition for an editor field, used to build the UI. | 45 // Field definition for an editor field, used to build the UI. |
46 struct EditorField { | 46 struct EditorField { |
47 enum class LengthHint : int { HINT_LONG, HINT_SHORT }; | 47 enum class LengthHint : int { HINT_LONG, HINT_SHORT }; |
48 enum class ControlType : int { TEXTFIELD, COMBOBOX }; | 48 enum class ControlType : int { TEXTFIELD, COMBOBOX }; |
49 | 49 |
50 EditorField(autofill::ServerFieldType type, | 50 EditorField(autofill::ServerFieldType type, |
51 const base::string16& label, | 51 base::string16 label, |
52 LengthHint length_hint, | 52 LengthHint length_hint, |
53 bool required, | 53 bool required, |
54 ControlType control_type = ControlType::TEXTFIELD) | 54 ControlType control_type = ControlType::TEXTFIELD) |
55 : type(type), | 55 : type(type), |
56 label(label), | 56 label(std::move(label)), |
57 length_hint(length_hint), | 57 length_hint(length_hint), |
58 required(required), | 58 required(required), |
59 control_type(control_type) {} | 59 control_type(control_type) {} |
60 | 60 |
61 struct Compare { | 61 struct Compare { |
62 bool operator()(const EditorField& lhs, const EditorField& rhs) const { | 62 bool operator()(const EditorField& lhs, const EditorField& rhs) const { |
63 return std::tie(lhs.type, lhs.label) < std::tie(rhs.type, rhs.label); | 63 return std::tie(lhs.type, lhs.label) < std::tie(rhs.type, rhs.label); |
64 } | 64 } |
65 }; | 65 }; |
66 | 66 |
67 // Data type in the field. | 67 // Data type in the field. |
68 const autofill::ServerFieldType type; | 68 autofill::ServerFieldType type; |
69 // Label to be shown alongside the field. | 69 // Label to be shown alongside the field. |
70 const base::string16 label; | 70 base::string16 label; |
71 // Hint about the length of this field's contents. | 71 // Hint about the length of this field's contents. |
72 LengthHint length_hint; | 72 LengthHint length_hint; |
73 // Whether the field is required. | 73 // Whether the field is required. |
74 bool required; | 74 bool required; |
75 // The control type. | 75 // The control type. |
76 ControlType control_type; | 76 ControlType control_type; |
77 }; | 77 }; |
78 | 78 |
79 // The PaymentRequestSheetController subtype for the editor screens of the | 79 // The PaymentRequestSheetController subtype for the editor screens of the |
80 // Payment Request flow. | 80 // Payment Request flow. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // |field| definition. | 118 // |field| definition. |
119 virtual std::unique_ptr<ValidationDelegate> CreateValidationDelegate( | 119 virtual std::unique_ptr<ValidationDelegate> CreateValidationDelegate( |
120 const EditorField& field) = 0; | 120 const EditorField& field) = 0; |
121 virtual std::unique_ptr<ui::ComboboxModel> GetComboboxModelForType( | 121 virtual std::unique_ptr<ui::ComboboxModel> GetComboboxModelForType( |
122 const autofill::ServerFieldType& type) = 0; | 122 const autofill::ServerFieldType& type) = 0; |
123 | 123 |
124 // PaymentRequestSheetController; | 124 // PaymentRequestSheetController; |
125 std::unique_ptr<views::Button> CreatePrimaryButton() override; | 125 std::unique_ptr<views::Button> CreatePrimaryButton() override; |
126 std::unique_ptr<views::View> CreateExtraFooterView() override; | 126 std::unique_ptr<views::View> CreateExtraFooterView() override; |
127 | 127 |
| 128 // views::ComboboxListener: |
| 129 void OnPerformAction(views::Combobox* combobox) override; |
| 130 |
| 131 // Update the editor view by removing all it's child views and recreating |
| 132 // the input fields returned by GetFieldDefinitions. Note that |
| 133 // CreateEditorView MUST have been called at least once before calling |
| 134 // UpdateEditorView. |
| 135 virtual void UpdateEditorView(); |
| 136 |
128 private: | 137 private: |
129 // PaymentRequestSheetController: | 138 // PaymentRequestSheetController: |
130 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 139 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
131 | 140 |
132 // views::TextfieldController: | 141 // views::TextfieldController: |
133 void ContentsChanged(views::Textfield* sender, | 142 void ContentsChanged(views::Textfield* sender, |
134 const base::string16& new_contents) override; | 143 const base::string16& new_contents) override; |
135 | 144 |
136 // views::ComboboxListener: | |
137 void OnPerformAction(views::Combobox* combobox) override; | |
138 | |
139 // Creates the whole editor view to go within the editor dialog. It | 145 // Creates the whole editor view to go within the editor dialog. It |
140 // encompasses all the input fields created by CreateInputField(). | 146 // encompasses all the input fields created by CreateInputField(). |
141 std::unique_ptr<views::View> CreateEditorView(); | 147 void CreateEditorView(); |
142 | 148 |
143 // Adds some views to |layout|, to represent an input field and its labels. | 149 // Adds some views to |layout|, to represent an input field and its labels. |
144 // |field| is the field definition, which contains the label and the hint | 150 // |field| is the field definition, which contains the label and the hint |
145 // about the length of the input field. A placeholder error label is also | 151 // about the length of the input field. A placeholder error label is also |
146 // added (see implementation). | 152 // added (see implementation). |
147 void CreateInputField(views::GridLayout* layout, const EditorField& field); | 153 void CreateInputField(views::GridLayout* layout, const EditorField& field); |
148 | 154 |
| 155 // The editor content view, owned by the client so the derived classes can |
| 156 // refresh it when some user interactions cause layout changes by calling |
| 157 // UpdateEditorView(). |
| 158 std::unique_ptr<views::View> editor_view_; |
| 159 |
149 // Used to remember the association between the input field UI element and the | 160 // Used to remember the association between the input field UI element and the |
150 // original field definition. The ValidatingTextfield* and ValidatingCombobox* | 161 // original field definition. The ValidatingTextfield* and ValidatingCombobox* |
151 // are owned by their parent view, this only keeps a reference that is good as | 162 // are owned by their parent view, this only keeps a reference that is good as |
152 // long as the input field is visible. | 163 // long as the input field is visible. |
153 TextFieldsMap text_fields_; | 164 TextFieldsMap text_fields_; |
154 ComboboxMap comboboxes_; | 165 ComboboxMap comboboxes_; |
155 // Tracks the relationship between a field and its error label. | 166 // Tracks the relationship between a field and its error label. |
156 ErrorLabelMap error_labels_; | 167 ErrorLabelMap error_labels_; |
157 | 168 |
158 DISALLOW_COPY_AND_ASSIGN(EditorViewController); | 169 DISALLOW_COPY_AND_ASSIGN(EditorViewController); |
159 }; | 170 }; |
160 | 171 |
161 } // namespace payments | 172 } // namespace payments |
162 | 173 |
163 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ | 174 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_EDITOR_VIEW_CONTROLLER_H_ |
OLD | NEW |