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 #include "chrome/browser/ui/views/payments/editor_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/editor_view_controller.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 text_fields_.clear(); | 183 text_fields_.clear(); |
184 comboboxes_.clear(); | 184 comboboxes_.clear(); |
185 | 185 |
186 std::unique_ptr<views::GridLayout> editor_layout = | 186 std::unique_ptr<views::GridLayout> editor_layout = |
187 base::MakeUnique<views::GridLayout>(editor_view.get()); | 187 base::MakeUnique<views::GridLayout>(editor_view.get()); |
188 | 188 |
189 // The editor grid layout is padded horizontally. | 189 // The editor grid layout is padded horizontally. |
190 editor_layout->SetInsets(0, payments::kPaymentRequestRowHorizontalInsets, 0, | 190 editor_layout->SetInsets(0, payments::kPaymentRequestRowHorizontalInsets, 0, |
191 payments::kPaymentRequestRowHorizontalInsets); | 191 payments::kPaymentRequestRowHorizontalInsets); |
192 | 192 |
193 views::ColumnSet* columns = editor_layout->AddColumnSet(0); | 193 // Column set for short fields. |
194 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | 194 constexpr int kLabelWidth = 140; |
195 views::GridLayout::USE_PREF, 0, 0); | 195 views::ColumnSet* columns_short = editor_layout->AddColumnSet(0); |
196 | 196 columns_short->AddColumn(views::GridLayout::LEADING, |
197 views::GridLayout::CENTER, 0, | |
198 views::GridLayout::FIXED, kLabelWidth, 0); | |
197 // This is the horizontal padding between the label and the input field. | 199 // This is the horizontal padding between the label and the input field. |
198 constexpr int kLabelInputFieldHorizontalPadding = 16; | 200 constexpr int kLabelInputFieldHorizontalPadding = 16; |
199 columns->AddPaddingColumn(0, kLabelInputFieldHorizontalPadding); | 201 columns_short->AddPaddingColumn(0, kLabelInputFieldHorizontalPadding); |
202 constexpr int kShortInputFieldMinimumWidth = 176; | |
203 columns_short->AddColumn( | |
204 views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | |
205 views::GridLayout::FIXED, kShortInputFieldMinimumWidth, 0); | |
anthonyvd
2017/05/09 21:01:21
These variables are named "minimum width" but you'
Mathieu
2017/05/10 12:30:35
Done.
The fixed width for input fields (176/272p
anthonyvd
2017/05/10 13:26:02
It's the opposite: if the strings in buttons are l
| |
200 | 206 |
201 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | 207 // Column set for long fields. |
202 views::GridLayout::USE_PREF, 0, 0); | 208 views::ColumnSet* columns_long = editor_layout->AddColumnSet(1); |
209 columns_long->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, | |
210 0, views::GridLayout::FIXED, kLabelWidth, 0); | |
211 columns_long->AddPaddingColumn(0, kLabelInputFieldHorizontalPadding); | |
212 constexpr int kLongInputFieldMinimumWidth = 272; | |
213 columns_long->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, | |
214 0, views::GridLayout::FIXED, | |
215 kLongInputFieldMinimumWidth, 0); | |
203 | 216 |
204 // The LayoutManager needs to be set before input fields are created, so we | 217 // The LayoutManager needs to be set before input fields are created, so we |
205 // keep a handle to it before we release it to the view. | 218 // keep a handle to it before we release it to the view. |
206 views::GridLayout* layout_handle = editor_layout.get(); | 219 views::GridLayout* layout_handle = editor_layout.get(); |
207 editor_view->SetLayoutManager(editor_layout.release()); | 220 editor_view->SetLayoutManager(editor_layout.release()); |
208 std::vector<EditorField> fields = GetFieldDefinitions(); | 221 std::vector<EditorField> fields = GetFieldDefinitions(); |
209 for (const auto& field : fields) | 222 for (const auto& field : fields) |
210 CreateInputField(layout_handle, field); | 223 CreateInputField(layout_handle, field); |
211 | 224 |
212 return editor_view; | 225 return editor_view; |
213 } | 226 } |
214 | 227 |
215 // Each input field is a 4-quadrant grid. | 228 // Each input field is a 4-quadrant grid. |
216 // +----------------------------------------------------------+ | 229 // +----------------------------------------------------------+ |
217 // | Field Label | Input field (textfield/combobox) | | 230 // | Field Label | Input field (textfield/combobox) | |
218 // |_______________________|__________________________________| | 231 // |_______________________|__________________________________| |
219 // | (empty) | Error label | | 232 // | (empty) | Error label | |
220 // +----------------------------------------------------------+ | 233 // +----------------------------------------------------------+ |
221 void EditorViewController::CreateInputField(views::GridLayout* layout, | 234 void EditorViewController::CreateInputField(views::GridLayout* layout, |
222 const EditorField& field) { | 235 const EditorField& field) { |
236 int column_set = | |
237 field.length_hint == EditorField::LengthHint::HINT_SHORT ? 0 : 1; | |
238 | |
223 // This is the top padding for every row. | 239 // This is the top padding for every row. |
224 constexpr int kInputRowSpacing = 6; | 240 constexpr int kInputRowSpacing = 6; |
225 layout->StartRowWithPadding(0, 0, 0, kInputRowSpacing); | 241 layout->StartRowWithPadding(0, column_set, 0, kInputRowSpacing); |
226 | 242 |
227 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( | 243 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( |
228 field.required ? field.label + base::ASCIIToUTF16("*") : field.label); | 244 field.required ? field.label + base::ASCIIToUTF16("*") : field.label); |
229 // A very long label will wrap. Value picked so that left + right label | 245 // A very long label will wrap. Value picked so that left + right label |
230 // padding bring the label to half-way in the dialog (~225). | 246 // padding bring the label to half-way in the dialog (~225). |
231 constexpr int kMaximumLabelWidth = 192; | 247 constexpr int kMaximumLabelWidth = 192; |
232 label->SetMultiLine(true); | 248 label->SetMultiLine(true); |
233 label->SetMaximumWidth(kMaximumLabelWidth); | 249 label->SetMaximumWidth(kMaximumLabelWidth); |
234 layout->AddView(label.release()); | 250 layout->AddView(label.release()); |
235 | 251 |
(...skipping 27 matching lines...) Expand all Loading... | |
263 if (!first_field_view_) | 279 if (!first_field_view_) |
264 first_field_view_ = combobox; | 280 first_field_view_ = combobox; |
265 | 281 |
266 // |combobox| will now be owned by |row|. | 282 // |combobox| will now be owned by |row|. |
267 layout->AddView(combobox, 1, 1, views::GridLayout::FILL, | 283 layout->AddView(combobox, 1, 1, views::GridLayout::FILL, |
268 views::GridLayout::FILL, 0, kInputFieldHeight); | 284 views::GridLayout::FILL, 0, kInputFieldHeight); |
269 } else { | 285 } else { |
270 NOTREACHED(); | 286 NOTREACHED(); |
271 } | 287 } |
272 | 288 |
273 layout->StartRow(0, 0); | 289 layout->StartRow(0, column_set); |
274 layout->SkipColumns(1); | 290 layout->SkipColumns(1); |
275 std::unique_ptr<views::View> error_label_view = | 291 std::unique_ptr<views::View> error_label_view = |
276 base::MakeUnique<views::View>(); | 292 base::MakeUnique<views::View>(); |
277 error_label_view->SetLayoutManager(new views::FillLayout); | 293 error_label_view->SetLayoutManager(new views::FillLayout); |
278 error_labels_[field] = error_label_view.get(); | 294 error_labels_[field] = error_label_view.get(); |
279 layout->AddView(error_label_view.release()); | 295 layout->AddView(error_label_view.release()); |
280 | 296 |
281 // Bottom padding for the row. | 297 // Bottom padding for the row. |
282 layout->AddPaddingRow(0, kInputRowSpacing); | 298 layout->AddPaddingRow(0, kInputRowSpacing); |
283 } | 299 } |
284 | 300 |
285 } // namespace payments | 301 } // namespace payments |
OLD | NEW |