Chromium Code Reviews| Index: chrome/browser/ui/views/payments/order_summary_view_controller.cc |
| diff --git a/chrome/browser/ui/views/payments/order_summary_view_controller.cc b/chrome/browser/ui/views/payments/order_summary_view_controller.cc |
| index 38e576e48d9eaf97eecde250c98331f740095840..d70b650101c877355347ac3237cb0a8b8343f74b 100644 |
| --- a/chrome/browser/ui/views/payments/order_summary_view_controller.cc |
| +++ b/chrome/browser/ui/views/payments/order_summary_view_controller.cc |
| @@ -18,12 +18,60 @@ |
| #include "components/payments/payment_request.h" |
| #include "components/strings/grit/components_strings.h" |
| #include "ui/base/l10n/l10n_util.h" |
| +#include "ui/gfx/font.h" |
| +#include "ui/views/border.h" |
| #include "ui/views/controls/label.h" |
| +#include "ui/views/controls/styled_label.h" |
| +#include "ui/views/layout/box_layout.h" |
| #include "ui/views/layout/grid_layout.h" |
| #include "ui/views/view.h" |
| namespace payments { |
| +namespace { |
| + |
| +// Creates a view for a line item to be displayed in the Order Summary Sheet. |
| +// |label| is the text in the left-aligned label and |amount| is the text of the |
| +// right-aliged label in the row. The |amount| text is bold if |bold_amount| is |
| +// true, which is only the case for the last row containing the total of the |
| +// order. |
| +std::unique_ptr<views::View> CreateLineItemView(const base::string16& label, |
| + const base::string16& amount, |
| + bool bold_amount) { |
| + std::unique_ptr<views::View> row = base::MakeUnique<views::View>(); |
| + |
| + row->SetBorder(views::CreateSolidSidedBorder(0, 0, 1, 0, SK_ColorLTGRAY)); |
| + |
| + views::GridLayout* layout = new views::GridLayout(row.get()); |
| + |
| + constexpr int kRowVerticalInset = 12; |
|
sky
2017/01/17 17:51:33
Where does the 12 come from? Is there an existing
anthonyvd
2017/01/17 19:43:22
It comes from the PaymentRequest mocks and this sc
|
| + layout->SetInsets(kRowVerticalInset, 0, kRowVerticalInset, 0); |
| + |
| + row->SetLayoutManager(layout); |
| + views::ColumnSet* columns = layout->AddColumnSet(0); |
| + columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
| + 0, views::GridLayout::USE_PREF, 0, 0); |
| + columns->AddPaddingColumn(1, 0); |
| + columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
| + 0, views::GridLayout::USE_PREF, 0, 0); |
| + |
| + layout->StartRow(0, 0); |
| + layout->AddView(new views::Label(label)); |
| + views::StyledLabel::RangeStyleInfo style_info; |
| + if (bold_amount) |
| + style_info.weight = gfx::Font::Weight::BOLD; |
| + |
| + std::unique_ptr<views::StyledLabel> amount_label = |
| + base::MakeUnique<views::StyledLabel>(amount, nullptr); |
| + amount_label->SetDefaultStyle(style_info); |
| + amount_label->SizeToFit(0); |
| + layout->AddView(amount_label.release()); |
| + |
| + return row; |
| +} |
| + |
| +} // namespace |
| + |
| OrderSummaryViewController::OrderSummaryViewController( |
| PaymentRequest* request, |
| PaymentRequestDialog* dialog) |
| @@ -34,22 +82,34 @@ OrderSummaryViewController::~OrderSummaryViewController() {} |
| std::unique_ptr<views::View> OrderSummaryViewController::CreateView() { |
| std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); |
| - views::GridLayout* layout = new views::GridLayout(content_view.get()); |
| + views::BoxLayout* layout = new views::BoxLayout( |
| + views::BoxLayout::kVertical, 0, 0, 0); |
| + layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); |
| + layout->set_cross_axis_alignment( |
| + views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); |
| content_view->SetLayoutManager(layout); |
| - views::ColumnSet* columns = layout->AddColumnSet(0); |
| - columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
| - 0, views::GridLayout::USE_PREF, 0, 0); |
| CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter( |
| request()->details()->total->amount->currency, |
| request()->details()->total->amount->currencySystem, |
| g_browser_process->GetApplicationLocale()); |
| - layout->StartRow(0, 0); |
| - layout->AddView(new views::Label(l10n_util::GetStringFUTF16( |
| - IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT, |
| - base::UTF8ToUTF16(request()->details()->total->label), |
| + |
| + for (const auto& item: request()->details()->display_items) { |
| + content_view->AddChildView( |
| + CreateLineItemView(base::UTF8ToUTF16(item->label), |
| + formatter->Format(item->amount->value), |
| + false).release()); |
| + } |
| + |
| + base::string16 total_label_value = l10n_util::GetStringFUTF16( |
| + IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, |
| base::UTF8ToUTF16(request()->details()->total->amount->currency), |
| - formatter->Format(request()->details()->total->amount->value)))); |
| + formatter->Format(request()->details()->total->amount->value)); |
| + |
| + content_view->AddChildView( |
| + CreateLineItemView(base::UTF8ToUTF16(request()->details()->total->label), |
| + total_label_value, |
| + true).release()); |
| return payments::CreatePaymentView( |
| CreateSheetHeaderView( |