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

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: 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 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. |amount_label_id| is specified to recall the view later, e.g. in
39 // tests.
38 std::unique_ptr<views::View> CreateLineItemView(const base::string16& label, 40 std::unique_ptr<views::View> CreateLineItemView(const base::string16& label,
39 const base::string16& amount, 41 const base::string16& amount,
40 bool bold_amount) { 42 bool bold_amount,
43 DialogViewID amount_label_id) {
41 std::unique_ptr<views::View> row = base::MakeUnique<views::View>(); 44 std::unique_ptr<views::View> row = base::MakeUnique<views::View>();
42 45
43 row->SetBorder(views::CreateSolidSidedBorder(0, 0, 1, 0, SK_ColorLTGRAY)); 46 row->SetBorder(views::CreateSolidSidedBorder(0, 0, 1, 0, SK_ColorLTGRAY));
44 47
45 views::GridLayout* layout = new views::GridLayout(row.get()); 48 views::GridLayout* layout = new views::GridLayout(row.get());
46 49
47 constexpr int kRowVerticalInset = 12; 50 constexpr int kRowVerticalInset = 12;
48 layout->SetInsets(kRowVerticalInset, 0, kRowVerticalInset, 0); 51 layout->SetInsets(kRowVerticalInset, 0, kRowVerticalInset, 0);
49 52
50 row->SetLayoutManager(layout); 53 row->SetLayoutManager(layout);
51 views::ColumnSet* columns = layout->AddColumnSet(0); 54 views::ColumnSet* columns = layout->AddColumnSet(0);
52 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 55 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
53 0, views::GridLayout::USE_PREF, 0, 0); 56 0, views::GridLayout::USE_PREF, 0, 0);
54 columns->AddPaddingColumn(1, 0); 57 columns->AddPaddingColumn(1, 0);
55 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 58 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
56 0, views::GridLayout::USE_PREF, 0, 0); 59 0, views::GridLayout::USE_PREF, 0, 0);
57 60
58 layout->StartRow(0, 0); 61 layout->StartRow(0, 0);
59 layout->AddView(new views::Label(label)); 62 layout->AddView(new views::Label(label));
60 views::StyledLabel::RangeStyleInfo style_info; 63 views::StyledLabel::RangeStyleInfo style_info;
61 if (bold_amount) 64 if (bold_amount)
62 style_info.weight = gfx::Font::Weight::BOLD; 65 style_info.weight = gfx::Font::Weight::BOLD;
63 66
64 std::unique_ptr<views::StyledLabel> amount_label = 67 std::unique_ptr<views::StyledLabel> amount_label =
65 base::MakeUnique<views::StyledLabel>(amount, nullptr); 68 base::MakeUnique<views::StyledLabel>(amount, nullptr);
69 amount_label->set_id(static_cast<int>(amount_label_id));
66 amount_label->SetDefaultStyle(style_info); 70 amount_label->SetDefaultStyle(style_info);
67 amount_label->SizeToFit(0); 71 amount_label->SizeToFit(0);
68 layout->AddView(amount_label.release()); 72 layout->AddView(amount_label.release());
69 73
70 return row; 74 return row;
71 } 75 }
72 76
73 } // namespace 77 } // namespace
74 78
75 OrderSummaryViewController::OrderSummaryViewController( 79 OrderSummaryViewController::OrderSummaryViewController(
(...skipping 11 matching lines...) Expand all
87 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); 91 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
88 layout->set_cross_axis_alignment( 92 layout->set_cross_axis_alignment(
89 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); 93 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
90 content_view->SetLayoutManager(layout); 94 content_view->SetLayoutManager(layout);
91 95
92 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter( 96 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter(
93 request()->details()->total->amount->currency, 97 request()->details()->total->amount->currency,
94 request()->details()->total->amount->currency_system, 98 request()->details()->total->amount->currency_system,
95 g_browser_process->GetApplicationLocale()); 99 g_browser_process->GetApplicationLocale());
96 100
97 for (const auto& item: request()->details()->display_items) { 101 // Set the ID for the first few line items labels, for testing.
102 const std::vector<DialogViewID> line_items{
103 DialogViewID::ORDER_SUMMARY_LINE_ITEM_1,
104 DialogViewID::ORDER_SUMMARY_LINE_ITEM_2,
105 DialogViewID::ORDER_SUMMARY_LINE_ITEM_3};
106 for (size_t i = 0; i < request()->details()->display_items.size(); i++) {
107 DialogViewID view_id =
108 i < line_items.size() ? line_items[i] : DialogViewID::VIEW_ID_NONE;
98 content_view->AddChildView( 109 content_view->AddChildView(
99 CreateLineItemView(base::UTF8ToUTF16(item->label), 110 CreateLineItemView(
100 formatter->Format(item->amount->value), 111 base::UTF8ToUTF16(request()->details()->display_items[i]->label),
101 false).release()); 112 formatter->Format(
113 request()->details()->display_items[i]->amount->value),
114 false, view_id)
115 .release());
102 } 116 }
103 117
104 base::string16 total_label_value = l10n_util::GetStringFUTF16( 118 base::string16 total_label_value = l10n_util::GetStringFUTF16(
105 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, 119 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT,
106 base::UTF8ToUTF16(request()->details()->total->amount->currency), 120 base::UTF8ToUTF16(request()->details()->total->amount->currency),
107 formatter->Format(request()->details()->total->amount->value)); 121 formatter->Format(request()->details()->total->amount->value));
108 122
109 content_view->AddChildView( 123 content_view->AddChildView(
110 CreateLineItemView(base::UTF8ToUTF16(request()->details()->total->label), 124 CreateLineItemView(base::UTF8ToUTF16(request()->details()->total->label),
111 total_label_value, 125 total_label_value, true,
112 true).release()); 126 DialogViewID::ORDER_SUMMARY_TOTAL_AMOUNT_LABEL)
127 .release());
113 128
114 return payments::CreatePaymentView( 129 return payments::CreatePaymentView(
115 CreateSheetHeaderView( 130 CreateSheetHeaderView(
116 true, 131 true,
117 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE), 132 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE),
118 this), 133 this),
119 std::move(content_view)); 134 std::move(content_view));
120 } 135 }
121 136
122 void OrderSummaryViewController::ButtonPressed( 137 void OrderSummaryViewController::ButtonPressed(
123 views::Button* sender, const ui::Event& event) { 138 views::Button* sender, const ui::Event& event) {
124 switch (sender->tag()) { 139 switch (sender->tag()) {
125 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG): 140 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG):
126 dialog()->CloseDialog(); 141 dialog()->CloseDialog();
127 break; 142 break;
128 case static_cast<int>(PaymentRequestCommonTags::BACK_BUTTON_TAG): 143 case static_cast<int>(PaymentRequestCommonTags::BACK_BUTTON_TAG):
129 dialog()->GoBack(); 144 dialog()->GoBack();
130 break; 145 break;
131 default: 146 default:
132 NOTREACHED(); 147 NOTREACHED();
133 } 148 }
134 } 149 }
135 150
136 } // namespace payments 151 } // namespace payments
OLDNEW
« no previous file with comments | « chrome/browser/ui/BUILD.gn ('k') | chrome/browser/ui/views/payments/payment_request_dialog_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698