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

Side by Side Diff: chrome/browser/ui/views/payments/order_summary_view_controller.cc

Issue 2656823006: [Payments] PR: Basic test for the order summary section. (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
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_view.h" 14 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
15 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
15 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 16 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
16 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
17 #include "components/payments/currency_formatter.h" 18 #include "components/payments/currency_formatter.h"
18 #include "components/payments/payment_request.h" 19 #include "components/payments/payment_request.h"
19 #include "components/strings/grit/components_strings.h" 20 #include "components/strings/grit/components_strings.h"
20 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/gfx/font.h" 22 #include "ui/gfx/font.h"
22 #include "ui/views/border.h" 23 #include "ui/views/border.h"
23 #include "ui/views/controls/label.h" 24 #include "ui/views/controls/label.h"
24 #include "ui/views/controls/styled_label.h" 25 #include "ui/views/controls/styled_label.h"
25 #include "ui/views/layout/box_layout.h" 26 #include "ui/views/layout/box_layout.h"
26 #include "ui/views/layout/grid_layout.h" 27 #include "ui/views/layout/grid_layout.h"
27 #include "ui/views/view.h" 28 #include "ui/views/view.h"
28 29
29 namespace payments { 30 namespace payments {
30 31
31 namespace { 32 namespace {
32 33
33 // Creates a view for a line item to be displayed in the Order Summary Sheet. 34 // 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 // |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 // 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 // true, which is only the case for the last row containing the total of the
37 // order. 38 // order. Optionally, a |amount_label_id| can be specified to recall the view
38 std::unique_ptr<views::View> CreateLineItemView(const base::string16& label, 39 // later, e.g. in tests.
39 const base::string16& amount, 40 std::unique_ptr<views::View> CreateLineItemView(
40 bool bold_amount) { 41 const base::string16& label,
42 const base::string16& amount,
43 bool bold_amount,
44 DialogViewID amount_label_id = DialogViewID::VIEW_ID_NONE) {
41 std::unique_ptr<views::View> row = base::MakeUnique<views::View>(); 45 std::unique_ptr<views::View> row = base::MakeUnique<views::View>();
42 46
43 row->SetBorder(views::CreateSolidSidedBorder(0, 0, 1, 0, SK_ColorLTGRAY)); 47 row->SetBorder(views::CreateSolidSidedBorder(0, 0, 1, 0, SK_ColorLTGRAY));
44 48
45 views::GridLayout* layout = new views::GridLayout(row.get()); 49 views::GridLayout* layout = new views::GridLayout(row.get());
46 50
47 constexpr int kRowVerticalInset = 12; 51 constexpr int kRowVerticalInset = 12;
48 layout->SetInsets(kRowVerticalInset, 0, kRowVerticalInset, 0); 52 layout->SetInsets(kRowVerticalInset, 0, kRowVerticalInset, 0);
49 53
50 row->SetLayoutManager(layout); 54 row->SetLayoutManager(layout);
51 views::ColumnSet* columns = layout->AddColumnSet(0); 55 views::ColumnSet* columns = layout->AddColumnSet(0);
52 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 56 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
53 0, views::GridLayout::USE_PREF, 0, 0); 57 0, views::GridLayout::USE_PREF, 0, 0);
54 columns->AddPaddingColumn(1, 0); 58 columns->AddPaddingColumn(1, 0);
55 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 59 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
56 0, views::GridLayout::USE_PREF, 0, 0); 60 0, views::GridLayout::USE_PREF, 0, 0);
57 61
58 layout->StartRow(0, 0); 62 layout->StartRow(0, 0);
59 layout->AddView(new views::Label(label)); 63 layout->AddView(new views::Label(label));
60 views::StyledLabel::RangeStyleInfo style_info; 64 views::StyledLabel::RangeStyleInfo style_info;
61 if (bold_amount) 65 if (bold_amount)
62 style_info.weight = gfx::Font::Weight::BOLD; 66 style_info.weight = gfx::Font::Weight::BOLD;
63 67
64 std::unique_ptr<views::StyledLabel> amount_label = 68 std::unique_ptr<views::StyledLabel> amount_label =
65 base::MakeUnique<views::StyledLabel>(amount, nullptr); 69 base::MakeUnique<views::StyledLabel>(amount, nullptr);
70 amount_label->set_id(amount_label_id);
66 amount_label->SetDefaultStyle(style_info); 71 amount_label->SetDefaultStyle(style_info);
67 amount_label->SizeToFit(0); 72 amount_label->SizeToFit(0);
68 layout->AddView(amount_label.release()); 73 layout->AddView(amount_label.release());
69 74
70 return row; 75 return row;
71 } 76 }
72 77
73 } // namespace 78 } // namespace
74 79
75 OrderSummaryViewController::OrderSummaryViewController( 80 OrderSummaryViewController::OrderSummaryViewController(
(...skipping 11 matching lines...) Expand all
87 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); 92 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
88 layout->set_cross_axis_alignment( 93 layout->set_cross_axis_alignment(
89 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); 94 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
90 content_view->SetLayoutManager(layout); 95 content_view->SetLayoutManager(layout);
91 96
92 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter( 97 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter(
93 request()->details()->total->amount->currency, 98 request()->details()->total->amount->currency,
94 request()->details()->total->amount->currency_system, 99 request()->details()->total->amount->currency_system,
95 g_browser_process->GetApplicationLocale()); 100 g_browser_process->GetApplicationLocale());
96 101
97 for (const auto& item: request()->details()->display_items) { 102 // Set the ID for the first few line items labels, for testing.
103 const std::vector<DialogViewID> line_items{
104 DialogViewID::ORDER_SUMMARY_LINE_ITEM_1,
105 DialogViewID::ORDER_SUMMARY_LINE_ITEM_2,
106 DialogViewID::ORDER_SUMMARY_LINE_ITEM_3};
107 for (size_t i = 0; i < request()->details()->display_items.size(); i++) {
108 DialogViewID view_id =
109 i < line_items.size() ? line_items[i] : DialogViewID::VIEW_ID_NONE;
98 content_view->AddChildView( 110 content_view->AddChildView(
99 CreateLineItemView(base::UTF8ToUTF16(item->label), 111 CreateLineItemView(
100 formatter->Format(item->amount->value), 112 base::UTF8ToUTF16(request()->details()->display_items[i]->label),
101 false).release()); 113 formatter->Format(
114 request()->details()->display_items[i]->amount->value),
115 false, view_id)
116 .release());
102 } 117 }
103 118
104 base::string16 total_label_value = l10n_util::GetStringFUTF16( 119 base::string16 total_label_value = l10n_util::GetStringFUTF16(
105 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, 120 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT,
106 base::UTF8ToUTF16(request()->details()->total->amount->currency), 121 base::UTF8ToUTF16(request()->details()->total->amount->currency),
107 formatter->Format(request()->details()->total->amount->value)); 122 formatter->Format(request()->details()->total->amount->value));
108 123
109 content_view->AddChildView( 124 content_view->AddChildView(
110 CreateLineItemView(base::UTF8ToUTF16(request()->details()->total->label), 125 CreateLineItemView(base::UTF8ToUTF16(request()->details()->total->label),
111 total_label_value, 126 total_label_value, true,
112 true).release()); 127 DialogViewID::ORDER_SUMMARY_TOTAL_AMOUNT_LABEL)
128 .release());
113 129
114 return payments::CreatePaymentView( 130 return payments::CreatePaymentView(
115 CreateSheetHeaderView( 131 CreateSheetHeaderView(
116 true, 132 true,
117 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE), 133 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE),
118 this), 134 this),
119 std::move(content_view)); 135 std::move(content_view));
120 } 136 }
121 137
122 void OrderSummaryViewController::ButtonPressed( 138 void OrderSummaryViewController::ButtonPressed(
123 views::Button* sender, const ui::Event& event) { 139 views::Button* sender, const ui::Event& event) {
124 switch (sender->tag()) { 140 switch (sender->tag()) {
125 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG): 141 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG):
126 dialog()->CloseDialog(); 142 dialog()->CloseDialog();
127 break; 143 break;
128 case static_cast<int>(PaymentRequestCommonTags::BACK_BUTTON_TAG): 144 case static_cast<int>(PaymentRequestCommonTags::BACK_BUTTON_TAG):
129 dialog()->GoBack(); 145 dialog()->GoBack();
130 break; 146 break;
131 default: 147 default:
132 NOTREACHED(); 148 NOTREACHED();
133 } 149 }
134 } 150 }
135 151
136 } // namespace payments 152 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698