Chromium Code Reviews| 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 // It's possible for the dialog to get wider than the minimum, in which case | |
| 203 // we use the extra whitespace for the field width. | |
| 204 constexpr int kShortInputFieldFixedWidth = 176; | |
| 205 int short_input_width = | |
|
anthonyvd
2017/05/10 15:03:56
Ok so one last thing to simplify this code. Curren
| |
| 206 kShortInputFieldFixedWidth + (GetActualDialogWidth() - kDialogMinWidth); | |
| 207 columns_short->AddColumn(views::GridLayout::LEADING, | |
| 208 views::GridLayout::CENTER, 0, | |
| 209 views::GridLayout::FIXED, short_input_width, 0); | |
| 200 | 210 |
| 201 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | 211 // Column set for long fields. |
| 202 views::GridLayout::USE_PREF, 0, 0); | 212 views::ColumnSet* columns_long = editor_layout->AddColumnSet(1); |
| 213 columns_long->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, | |
| 214 0, views::GridLayout::FIXED, kLabelWidth, 0); | |
| 215 columns_long->AddPaddingColumn(0, kLabelInputFieldHorizontalPadding); | |
| 216 // It's possible for the dialog to get wider than the minimum, in which case | |
| 217 // we use the extra whitespace for the field width. | |
| 218 constexpr int kLongInputFieldFixedWidth = 272; | |
| 219 int long_input_width = | |
| 220 kLongInputFieldFixedWidth + (GetActualDialogWidth() - kDialogMinWidth); | |
| 221 columns_long->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, | |
| 222 0, views::GridLayout::FIXED, long_input_width, 0); | |
| 203 | 223 |
| 204 // The LayoutManager needs to be set before input fields are created, so we | 224 // 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. | 225 // keep a handle to it before we release it to the view. |
| 206 views::GridLayout* layout_handle = editor_layout.get(); | 226 views::GridLayout* layout_handle = editor_layout.get(); |
| 207 editor_view->SetLayoutManager(editor_layout.release()); | 227 editor_view->SetLayoutManager(editor_layout.release()); |
| 208 std::vector<EditorField> fields = GetFieldDefinitions(); | 228 std::vector<EditorField> fields = GetFieldDefinitions(); |
| 209 for (const auto& field : fields) | 229 for (const auto& field : fields) |
| 210 CreateInputField(layout_handle, field); | 230 CreateInputField(layout_handle, field); |
| 211 | 231 |
| 212 return editor_view; | 232 return editor_view; |
| 213 } | 233 } |
| 214 | 234 |
| 215 // Each input field is a 4-quadrant grid. | 235 // Each input field is a 4-quadrant grid. |
| 216 // +----------------------------------------------------------+ | 236 // +----------------------------------------------------------+ |
| 217 // | Field Label | Input field (textfield/combobox) | | 237 // | Field Label | Input field (textfield/combobox) | |
| 218 // |_______________________|__________________________________| | 238 // |_______________________|__________________________________| |
| 219 // | (empty) | Error label | | 239 // | (empty) | Error label | |
| 220 // +----------------------------------------------------------+ | 240 // +----------------------------------------------------------+ |
| 221 void EditorViewController::CreateInputField(views::GridLayout* layout, | 241 void EditorViewController::CreateInputField(views::GridLayout* layout, |
| 222 const EditorField& field) { | 242 const EditorField& field) { |
| 243 int column_set = | |
| 244 field.length_hint == EditorField::LengthHint::HINT_SHORT ? 0 : 1; | |
| 245 | |
| 223 // This is the top padding for every row. | 246 // This is the top padding for every row. |
| 224 constexpr int kInputRowSpacing = 6; | 247 constexpr int kInputRowSpacing = 6; |
| 225 layout->StartRowWithPadding(0, 0, 0, kInputRowSpacing); | 248 layout->StartRowWithPadding(0, column_set, 0, kInputRowSpacing); |
| 226 | 249 |
| 227 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( | 250 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( |
| 228 field.required ? field.label + base::ASCIIToUTF16("*") : field.label); | 251 field.required ? field.label + base::ASCIIToUTF16("*") : field.label); |
| 229 // A very long label will wrap. Value picked so that left + right label | 252 // 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). | 253 // padding bring the label to half-way in the dialog (~225). |
| 231 constexpr int kMaximumLabelWidth = 192; | 254 constexpr int kMaximumLabelWidth = 192; |
| 232 label->SetMultiLine(true); | 255 label->SetMultiLine(true); |
| 233 label->SetMaximumWidth(kMaximumLabelWidth); | 256 label->SetMaximumWidth(kMaximumLabelWidth); |
| 234 layout->AddView(label.release()); | 257 layout->AddView(label.release()); |
| 235 | 258 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 263 if (!first_field_view_) | 286 if (!first_field_view_) |
| 264 first_field_view_ = combobox; | 287 first_field_view_ = combobox; |
| 265 | 288 |
| 266 // |combobox| will now be owned by |row|. | 289 // |combobox| will now be owned by |row|. |
| 267 layout->AddView(combobox, 1, 1, views::GridLayout::FILL, | 290 layout->AddView(combobox, 1, 1, views::GridLayout::FILL, |
| 268 views::GridLayout::FILL, 0, kInputFieldHeight); | 291 views::GridLayout::FILL, 0, kInputFieldHeight); |
| 269 } else { | 292 } else { |
| 270 NOTREACHED(); | 293 NOTREACHED(); |
| 271 } | 294 } |
| 272 | 295 |
| 273 layout->StartRow(0, 0); | 296 layout->StartRow(0, column_set); |
| 274 layout->SkipColumns(1); | 297 layout->SkipColumns(1); |
| 275 std::unique_ptr<views::View> error_label_view = | 298 std::unique_ptr<views::View> error_label_view = |
| 276 base::MakeUnique<views::View>(); | 299 base::MakeUnique<views::View>(); |
| 277 error_label_view->SetLayoutManager(new views::FillLayout); | 300 error_label_view->SetLayoutManager(new views::FillLayout); |
| 278 error_labels_[field] = error_label_view.get(); | 301 error_labels_[field] = error_label_view.get(); |
| 279 layout->AddView(error_label_view.release()); | 302 layout->AddView(error_label_view.release()); |
| 280 | 303 |
| 281 // Bottom padding for the row. | 304 // Bottom padding for the row. |
| 282 layout->AddPaddingRow(0, kInputRowSpacing); | 305 layout->AddPaddingRow(0, kInputRowSpacing); |
| 283 } | 306 } |
| 284 | 307 |
| 285 } // namespace payments | 308 } // namespace payments |
| OLD | NEW |