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 29 matching lines...) Expand all Loading... | |
40 class PaymentRequestState; | 40 class PaymentRequestState; |
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, |
Mathieu
2017/03/21 17:08:35
Let's change it like so:
EditorField(autofill::
MAD
2017/03/21 19:28:34
Done.
| |
51 const base::string16& label, | 51 const 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(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 const autofill::ServerFieldType type; |
Mathieu
2017/03/21 17:08:35
we can remove const here and on |label|
MAD
2017/03/21 19:28:34
Done.
| |
69 // Label to be shown alongside the field. | 69 // Label to be shown alongside the field. |
70 const base::string16 label; | 70 const 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 |
(...skipping 39 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 protected: | |
129 // The editor content view, owned by the client so the derived classes can | |
130 // refresh it when some user interactions cause layout changes. | |
131 std::unique_ptr<views::View> editor_view_; | |
132 | |
133 // Update the editor view by removing all it's child views and recreating | |
134 // the input fields returned by GetFieldDefinitions. Note that | |
135 // CreateEditorView MUST have been called at least once before calling | |
136 // UpdateEditorView. | |
137 virtual void UpdateEditorView(); | |
138 | |
139 // views::ComboboxListener: | |
140 void OnPerformAction(views::Combobox* combobox) override; | |
141 | |
128 private: | 142 private: |
129 // PaymentRequestSheetController: | 143 // PaymentRequestSheetController: |
130 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 144 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
131 | 145 |
132 // views::TextfieldController: | 146 // views::TextfieldController: |
133 void ContentsChanged(views::Textfield* sender, | 147 void ContentsChanged(views::Textfield* sender, |
134 const base::string16& new_contents) override; | 148 const base::string16& new_contents) override; |
135 | 149 |
136 // views::ComboboxListener: | |
137 void OnPerformAction(views::Combobox* combobox) override; | |
138 | |
139 // Creates the whole editor view to go within the editor dialog. It | 150 // Creates the whole editor view to go within the editor dialog. It |
140 // encompasses all the input fields created by CreateInputField(). | 151 // encompasses all the input fields created by CreateInputField(). |
141 std::unique_ptr<views::View> CreateEditorView(); | 152 void CreateEditorView(); |
142 | 153 |
143 // Adds some views to |layout|, to represent an input field and its labels. | 154 // 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 | 155 // |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 | 156 // about the length of the input field. A placeholder error label is also |
146 // added (see implementation). | 157 // added (see implementation). |
147 void CreateInputField(views::GridLayout* layout, const EditorField& field); | 158 void CreateInputField(views::GridLayout* layout, const EditorField& field); |
148 | 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 |