Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1510)

Unified Diff: chrome/browser/ui/views/payments/order_summary_view_controller.cc

Issue 2632243003: [Web Payments] Add line items in the Order Summary Sheet. (Closed)
Patch Set: Rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/autofill_strings.grdp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 49b3dbf7be369f5108f7516608e0dbb13431c00b..0d0933628ceedeba9c196bb575b78d620a0d64d3 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;
+ 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->currency_system,
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),
- base::UTF8ToUTF16(formatter->formatted_currency_code()),
- formatter->Format(request()->details()->total->amount->value))));
+
+ 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));
+
+ content_view->AddChildView(
+ CreateLineItemView(base::UTF8ToUTF16(request()->details()->total->label),
+ total_label_value,
+ true).release());
return payments::CreatePaymentView(
CreateSheetHeaderView(
« no previous file with comments | « no previous file | components/autofill_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698