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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 131 |
132 // An editor can optionally have a header view specific to it. | 132 // An editor can optionally have a header view specific to it. |
133 std::unique_ptr<views::View> header_view = CreateHeaderView(); | 133 std::unique_ptr<views::View> header_view = CreateHeaderView(); |
134 if (header_view.get()) | 134 if (header_view.get()) |
135 content_view->AddChildView(header_view.release()); | 135 content_view->AddChildView(header_view.release()); |
136 | 136 |
137 // The heart of the editor dialog: all the input fields with their labels. | 137 // The heart of the editor dialog: all the input fields with their labels. |
138 content_view->AddChildView(CreateEditorView().release()); | 138 content_view->AddChildView(CreateEditorView().release()); |
139 } | 139 } |
140 | 140 |
141 // Adds the "required fields" label in disabled text, to obtain this result. | 141 base::string16 EditorViewController::GetSecondaryButtonLabel() { |
142 // +---------------------------------------------------------+ | 142 return l10n_util::GetStringUTF16(IDS_PAYMENTS_CANCEL_PAYMENT); |
143 // | "* indicates required fields" | CANCEL | DONE | | |
144 // +---------------------------------------------------------+ | |
145 std::unique_ptr<views::View> EditorViewController::CreateExtraFooterView() { | |
146 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); | |
147 | |
148 views::BoxLayout* layout = | |
149 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | |
150 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | |
151 layout->set_cross_axis_alignment( | |
152 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | |
153 content_view->SetLayoutManager(layout); | |
154 | |
155 // Adds the "* indicates a required field" label in "disabled" grey text. | |
156 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( | |
157 l10n_util::GetStringUTF16(IDS_PAYMENTS_REQUIRED_FIELD_MESSAGE)); | |
158 label->SetDisabledColor(label->GetNativeTheme()->GetSystemColor( | |
159 ui::NativeTheme::kColorId_LabelDisabledColor)); | |
160 label->SetEnabled(false); | |
161 content_view->AddChildView(label.release()); | |
162 return content_view; | |
163 } | 143 } |
164 | 144 |
165 void EditorViewController::UpdateEditorView() { | 145 void EditorViewController::UpdateEditorView() { |
166 UpdateContentView(); | 146 UpdateContentView(); |
167 // TODO(crbug.com/704254): Find how to update the parent view bounds so that | 147 // TODO(crbug.com/704254): Find how to update the parent view bounds so that |
168 // the vertical scrollbar size gets updated. | 148 // the vertical scrollbar size gets updated. |
169 dialog()->EditorViewUpdated(); | 149 dialog()->EditorViewUpdated(); |
170 } | 150 } |
171 | 151 |
172 void EditorViewController::ButtonPressed(views::Button* sender, | 152 void EditorViewController::ButtonPressed(views::Button* sender, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 0, views::GridLayout::FIXED, long_extra_view_width, | 254 0, views::GridLayout::FIXED, long_extra_view_width, |
275 0); | 255 0); |
276 // The padding at the end is fixed, computed to make sure the long field | 256 // The padding at the end is fixed, computed to make sure the long field |
277 // maintains its minimum width. | 257 // maintains its minimum width. |
278 int long_padding = kDialogMinWidth - kLongFieldMinimumWidth - kLabelWidth - | 258 int long_padding = kDialogMinWidth - kLongFieldMinimumWidth - kLabelWidth - |
279 (2 * kPaymentRequestRowHorizontalInsets) - | 259 (2 * kPaymentRequestRowHorizontalInsets) - |
280 kLabelInputFieldHorizontalPadding - | 260 kLabelInputFieldHorizontalPadding - |
281 kFieldExtraViewHorizontalPadding - long_extra_view_width; | 261 kFieldExtraViewHorizontalPadding - long_extra_view_width; |
282 columns_long->AddPaddingColumn(0, long_padding); | 262 columns_long->AddPaddingColumn(0, long_padding); |
283 | 263 |
| 264 for (const auto& field : GetFieldDefinitions()) |
| 265 CreateInputField(editor_layout.get(), field); |
| 266 |
| 267 // Adds the "* indicates a required field" label in "disabled" grey text. |
| 268 std::unique_ptr<views::Label> required_field = base::MakeUnique<views::Label>( |
| 269 l10n_util::GetStringUTF16(IDS_PAYMENTS_REQUIRED_FIELD_MESSAGE)); |
| 270 required_field->SetDisabledColor( |
| 271 required_field->GetNativeTheme()->GetSystemColor( |
| 272 ui::NativeTheme::kColorId_LabelDisabledColor)); |
| 273 required_field->SetEnabled(false); |
| 274 |
| 275 views::ColumnSet* required_field_columns = editor_layout->AddColumnSet(2); |
| 276 required_field_columns->AddColumn(views::GridLayout::LEADING, |
| 277 views::GridLayout::CENTER, 1, |
| 278 views::GridLayout::USE_PREF, 0, 0); |
| 279 editor_layout->StartRow(0, 2); |
| 280 editor_layout->AddView(required_field.release()); |
| 281 |
284 editor_view->SetLayoutManager(editor_layout.release()); | 282 editor_view->SetLayoutManager(editor_layout.release()); |
285 for (const auto& field : GetFieldDefinitions()) { | |
286 CreateInputField( | |
287 static_cast<views::GridLayout*>(editor_view->GetLayoutManager()), | |
288 field); | |
289 } | |
290 | 283 |
291 return editor_view; | 284 return editor_view; |
292 } | 285 } |
293 | 286 |
294 // Each input field is a 4-quadrant grid. | 287 // Each input field is a 4-quadrant grid. |
295 // +----------------------------------------------------------+ | 288 // +----------------------------------------------------------+ |
296 // | Field Label | Input field (textfield/combobox) | | 289 // | Field Label | Input field (textfield/combobox) | |
297 // |_______________________|__________________________________| | 290 // |_______________________|__________________________________| |
298 // | (empty) | Error label | | 291 // | (empty) | Error label | |
299 // +----------------------------------------------------------+ | 292 // +----------------------------------------------------------+ |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 CreateExtraViewForField(field.type); | 378 CreateExtraViewForField(field.type); |
386 if (!extra_view) | 379 if (!extra_view) |
387 continue; | 380 continue; |
388 widest_column_width = | 381 widest_column_width = |
389 std::max(extra_view->GetPreferredSize().width(), widest_column_width); | 382 std::max(extra_view->GetPreferredSize().width(), widest_column_width); |
390 } | 383 } |
391 return widest_column_width; | 384 return widest_column_width; |
392 } | 385 } |
393 | 386 |
394 } // namespace payments | 387 } // namespace payments |
OLD | NEW |