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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/autofill_strings.grdp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/order_summary_view_controller.h" 5 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/ui/views/payments/payment_request_dialog.h" 14 #include "chrome/browser/ui/views/payments/payment_request_dialog.h"
15 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 15 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
16 #include "chrome/grit/generated_resources.h" 16 #include "chrome/grit/generated_resources.h"
17 #include "components/payments/currency_formatter.h" 17 #include "components/payments/currency_formatter.h"
18 #include "components/payments/payment_request.h" 18 #include "components/payments/payment_request.h"
19 #include "components/strings/grit/components_strings.h" 19 #include "components/strings/grit/components_strings.h"
20 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/gfx/font.h"
22 #include "ui/views/border.h"
21 #include "ui/views/controls/label.h" 23 #include "ui/views/controls/label.h"
24 #include "ui/views/controls/styled_label.h"
25 #include "ui/views/layout/box_layout.h"
22 #include "ui/views/layout/grid_layout.h" 26 #include "ui/views/layout/grid_layout.h"
23 #include "ui/views/view.h" 27 #include "ui/views/view.h"
24 28
25 namespace payments { 29 namespace payments {
26 30
31 namespace {
32
33 // Creates a view for a line item to be displayed in the Order Summary Sheet.
34 // |label| is the text in the left-aligned label and |amount| is the text of the
35 // right-aliged label in the row. The |amount| text is bold if |bold_amount| is
36 // true, which is only the case for the last row containing the total of the
37 // order.
38 std::unique_ptr<views::View> CreateLineItemView(const base::string16& label,
39 const base::string16& amount,
40 bool bold_amount) {
41 std::unique_ptr<views::View> row = base::MakeUnique<views::View>();
42
43 row->SetBorder(views::CreateSolidSidedBorder(0, 0, 1, 0, SK_ColorLTGRAY));
44
45 views::GridLayout* layout = new views::GridLayout(row.get());
46
47 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
48 layout->SetInsets(kRowVerticalInset, 0, kRowVerticalInset, 0);
49
50 row->SetLayoutManager(layout);
51 views::ColumnSet* columns = layout->AddColumnSet(0);
52 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
53 0, views::GridLayout::USE_PREF, 0, 0);
54 columns->AddPaddingColumn(1, 0);
55 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
56 0, views::GridLayout::USE_PREF, 0, 0);
57
58 layout->StartRow(0, 0);
59 layout->AddView(new views::Label(label));
60 views::StyledLabel::RangeStyleInfo style_info;
61 if (bold_amount)
62 style_info.weight = gfx::Font::Weight::BOLD;
63
64 std::unique_ptr<views::StyledLabel> amount_label =
65 base::MakeUnique<views::StyledLabel>(amount, nullptr);
66 amount_label->SetDefaultStyle(style_info);
67 amount_label->SizeToFit(0);
68 layout->AddView(amount_label.release());
69
70 return row;
71 }
72
73 } // namespace
74
27 OrderSummaryViewController::OrderSummaryViewController( 75 OrderSummaryViewController::OrderSummaryViewController(
28 PaymentRequest* request, 76 PaymentRequest* request,
29 PaymentRequestDialog* dialog) 77 PaymentRequestDialog* dialog)
30 : PaymentRequestSheetController(request, dialog) {} 78 : PaymentRequestSheetController(request, dialog) {}
31 79
32 OrderSummaryViewController::~OrderSummaryViewController() {} 80 OrderSummaryViewController::~OrderSummaryViewController() {}
33 81
34 std::unique_ptr<views::View> OrderSummaryViewController::CreateView() { 82 std::unique_ptr<views::View> OrderSummaryViewController::CreateView() {
35 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); 83 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>();
36 84
37 views::GridLayout* layout = new views::GridLayout(content_view.get()); 85 views::BoxLayout* layout = new views::BoxLayout(
86 views::BoxLayout::kVertical, 0, 0, 0);
87 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
88 layout->set_cross_axis_alignment(
89 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
38 content_view->SetLayoutManager(layout); 90 content_view->SetLayoutManager(layout);
39 views::ColumnSet* columns = layout->AddColumnSet(0);
40 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
41 0, views::GridLayout::USE_PREF, 0, 0);
42 91
43 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter( 92 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter(
44 request()->details()->total->amount->currency, 93 request()->details()->total->amount->currency,
45 request()->details()->total->amount->currencySystem, 94 request()->details()->total->amount->currencySystem,
46 g_browser_process->GetApplicationLocale()); 95 g_browser_process->GetApplicationLocale());
47 layout->StartRow(0, 0); 96
48 layout->AddView(new views::Label(l10n_util::GetStringFUTF16( 97 for (const auto& item: request()->details()->display_items) {
49 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT, 98 content_view->AddChildView(
50 base::UTF8ToUTF16(request()->details()->total->label), 99 CreateLineItemView(base::UTF8ToUTF16(item->label),
100 formatter->Format(item->amount->value),
101 false).release());
102 }
103
104 base::string16 total_label_value = l10n_util::GetStringFUTF16(
105 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT,
51 base::UTF8ToUTF16(request()->details()->total->amount->currency), 106 base::UTF8ToUTF16(request()->details()->total->amount->currency),
52 formatter->Format(request()->details()->total->amount->value)))); 107 formatter->Format(request()->details()->total->amount->value));
108
109 content_view->AddChildView(
110 CreateLineItemView(base::UTF8ToUTF16(request()->details()->total->label),
111 total_label_value,
112 true).release());
53 113
54 return payments::CreatePaymentView( 114 return payments::CreatePaymentView(
55 CreateSheetHeaderView( 115 CreateSheetHeaderView(
56 true, 116 true,
57 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE), 117 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE),
58 this), 118 this),
59 std::move(content_view)); 119 std::move(content_view));
60 } 120 }
61 121
62 void OrderSummaryViewController::ButtonPressed( 122 void OrderSummaryViewController::ButtonPressed(
63 views::Button* sender, const ui::Event& event) { 123 views::Button* sender, const ui::Event& event) {
64 switch (sender->tag()) { 124 switch (sender->tag()) {
65 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG): 125 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG):
66 dialog()->CloseDialog(); 126 dialog()->CloseDialog();
67 break; 127 break;
68 case static_cast<int>(PaymentRequestCommonTags::BACK_BUTTON_TAG): 128 case static_cast<int>(PaymentRequestCommonTags::BACK_BUTTON_TAG):
69 dialog()->GoBack(); 129 dialog()->GoBack();
70 break; 130 break;
71 default: 131 default:
72 NOTREACHED(); 132 NOTREACHED();
73 } 133 }
74 } 134 }
75 135
76 } // namespace payments 136 } // namespace payments
OLDNEW
« 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