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

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

Issue 2625183002: [WebPayments] Adding Shipping Address and Contact Info display to order summary (Closed)
Patch Set: sky comments 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/payment_sheet_view_controller.h" 5 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 #include <vector>
10 11
11 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/ui/views/payments/payment_request_dialog.h" 16 #include "chrome/browser/ui/views/payments/payment_request_dialog.h"
15 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 17 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
16 #include "chrome/grit/generated_resources.h" 18 #include "chrome/grit/generated_resources.h"
17 #include "components/autofill/core/browser/autofill_data_util.h" 19 #include "components/autofill/core/browser/autofill_data_util.h"
18 #include "components/autofill/core/browser/autofill_type.h" 20 #include "components/autofill/core/browser/autofill_type.h"
19 #include "components/autofill/core/browser/credit_card.h" 21 #include "components/autofill/core/browser/credit_card.h"
20 #include "components/autofill/core/browser/field_types.h" 22 #include "components/autofill/core/browser/field_types.h"
21 #include "components/autofill/core/browser/personal_data_manager.h" 23 #include "components/autofill/core/browser/personal_data_manager.h"
(...skipping 17 matching lines...) Expand all
39 #include "ui/views/controls/label.h" 41 #include "ui/views/controls/label.h"
40 #include "ui/views/controls/styled_label.h" 42 #include "ui/views/controls/styled_label.h"
41 #include "ui/views/layout/fill_layout.h" 43 #include "ui/views/layout/fill_layout.h"
42 #include "ui/views/layout/grid_layout.h" 44 #include "ui/views/layout/grid_layout.h"
43 #include "ui/views/resources/vector_icons/vector_icons.h" 45 #include "ui/views/resources/vector_icons/vector_icons.h"
44 #include "ui/views/view.h" 46 #include "ui/views/view.h"
45 47
46 namespace payments { 48 namespace payments {
47 namespace { 49 namespace {
48 50
51 constexpr int kFirstTagValue = static_cast<int>(
52 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX);
53
49 enum class PaymentSheetViewControllerTags { 54 enum class PaymentSheetViewControllerTags {
50 // The tag for the button that navigates to the Order Summary sheet. 55 // The tag for the button that navigates to the Order Summary sheet.
51 SHOW_ORDER_SUMMARY_BUTTON = static_cast<int>( 56 SHOW_ORDER_SUMMARY_BUTTON = kFirstTagValue,
52 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX), 57 SHOW_SHIPPING_BUTTON,
53 SHOW_PAYMENT_METHOD_BUTTON, 58 SHOW_PAYMENT_METHOD_BUTTON,
59 SHOW_CONTACT_INFO_BUTTON,
54 }; 60 };
55 61
56 // Creates a clickable row to be displayed in the Payment Sheet. It contains 62 // Creates a clickable row to be displayed in the Payment Sheet. It contains
57 // a section name and some content, followed by a chevron as a clickability 63 // a section name and some content, followed by a chevron as a clickability
58 // affordance. Both, either, or none of |content_view| and |extra_content_view| 64 // affordance. Both, either, or none of |content_view| and |extra_content_view|
59 // may be present, the difference between the two being that content is pinned 65 // may be present, the difference between the two being that content is pinned
60 // to the left and extra_content is pinned to the right. 66 // to the left and extra_content is pinned to the right.
61 // The row also displays a light gray horizontal ruler on its lower boundary. 67 // The row also displays a light gray horizontal ruler on its lower boundary.
62 // The name column has a fixed width equal to |name_column_width|. 68 // The name column has a fixed width equal to |name_column_width|.
63 // +----------------------------+ 69 // +----------------------------+
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 layout->SkipColumns(1); 128 layout->SkipColumns(1);
123 } 129 }
124 130
125 views::ImageView* chevron = new views::ImageView(); 131 views::ImageView* chevron = new views::ImageView();
126 chevron->SetImage(gfx::CreateVectorIcon( 132 chevron->SetImage(gfx::CreateVectorIcon(
127 views::kSubmenuArrowIcon, 133 views::kSubmenuArrowIcon,
128 color_utils::DeriveDefaultIconColor(name_label->enabled_color()))); 134 color_utils::DeriveDefaultIconColor(name_label->enabled_color())));
129 layout->AddView(chevron); 135 layout->AddView(chevron);
130 } 136 }
131 137
138 private:
132 DISALLOW_COPY_AND_ASSIGN(PaymentSheetRow); 139 DISALLOW_COPY_AND_ASSIGN(PaymentSheetRow);
133 }; 140 };
134 141
135 int ComputeWidestNameColumnViewWidth() { 142 int ComputeWidestNameColumnViewWidth() {
136 // The name colums in each row should all have the same width, large enough to 143 // The name colums in each row should all have the same width, large enough to
137 // accomodate the longest piece of text they contain. Because of this, each 144 // accomodate the longest piece of text they contain. Because of this, each
138 // row's GridLayout requires its first column to have a fixed width of the 145 // row's GridLayout requires its first column to have a fixed width of the
139 // correct size. To measure the required size, layout a label with each 146 // correct size. To measure the required size, layout a label with each
140 // section name, measure its width, then initialize |widest_column_width| 147 // section name, measure its width, then initialize |widest_column_width|
141 // with the largest value. 148 // with the largest value.
142 std::vector<int> section_names { 149 std::vector<int> section_names{
143 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME, 150 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME,
144 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME, 151 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME,
145 }; 152 IDS_PAYMENT_REQUEST_SHIPPING_SECTION_NAME};
146 153
147 int widest_column_width = 0; 154 int widest_column_width = 0;
148 155
149 views::Label label(base::ASCIIToUTF16("")); 156 views::Label label(base::ASCIIToUTF16(""));
150 for (int name_id : section_names) { 157 for (int name_id : section_names) {
151 label.SetText(l10n_util::GetStringUTF16(name_id)); 158 label.SetText(l10n_util::GetStringUTF16(name_id));
152 widest_column_width = std::max( 159 widest_column_width = std::max(
153 label.GetPreferredSize().width(), 160 label.GetPreferredSize().width(),
154 widest_column_width); 161 widest_column_width);
155 } 162 }
(...skipping 15 matching lines...) Expand all
171 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); 178 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>();
172 179
173 views::GridLayout* layout = new views::GridLayout(content_view.get()); 180 views::GridLayout* layout = new views::GridLayout(content_view.get());
174 content_view->SetLayoutManager(layout); 181 content_view->SetLayoutManager(layout);
175 views::ColumnSet* columns = layout->AddColumnSet(0); 182 views::ColumnSet* columns = layout->AddColumnSet(0);
176 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 183 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
177 1, views::GridLayout::USE_PREF, 0, 0); 184 1, views::GridLayout::USE_PREF, 0, 0);
178 185
179 layout->StartRow(0, 0); 186 layout->StartRow(0, 0);
180 layout->AddView(CreatePaymentSheetSummaryRow().release()); 187 layout->AddView(CreatePaymentSheetSummaryRow().release());
188 layout->StartRow(1, 0);
189 layout->AddView(CreateShippingRow().release());
181 layout->StartRow(0, 0); 190 layout->StartRow(0, 0);
182 layout->AddView(CreatePaymentMethodRow().release()); 191 layout->AddView(CreatePaymentMethodRow().release());
192 layout->StartRow(1, 0);
193 layout->AddView(CreateContactInfoRow().release());
183 194
184 return CreatePaymentView( 195 return CreatePaymentView(
185 CreateSheetHeaderView( 196 CreateSheetHeaderView(
186 false, 197 false,
187 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE), 198 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE),
188 this), 199 this),
189 std::move(content_view)); 200 std::move(content_view));
190 } 201 }
191 202
192 void PaymentSheetViewController::ButtonPressed( 203 void PaymentSheetViewController::ButtonPressed(
193 views::Button* sender, const ui::Event& event) { 204 views::Button* sender, const ui::Event& event) {
194 switch (sender->tag()) { 205 switch (sender->tag()) {
195 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG): 206 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG):
196 dialog()->CloseDialog(); 207 dialog()->CloseDialog();
197 break; 208 break;
209
198 case static_cast<int>( 210 case static_cast<int>(
199 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON): 211 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON):
200 dialog()->ShowOrderSummary(); 212 dialog()->ShowOrderSummary();
201 break; 213 break;
214
215 case static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON):
216 // TODO(tmartino): Transition to shipping page once it exists.
217 break;
218
202 case static_cast<int>( 219 case static_cast<int>(
203 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON): 220 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON):
204 dialog()->ShowPaymentMethodSheet(); 221 dialog()->ShowPaymentMethodSheet();
205 break; 222 break;
223
224 case static_cast<int>(
225 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON):
226 // TODO(tmartino): Transition to contact info page once it exists.
227 break;
228
206 default: 229 default:
207 NOTREACHED(); 230 NOTREACHED();
208 } 231 }
209 } 232 }
210 233
211 std::unique_ptr<views::View> 234 std::unique_ptr<views::View>
212 PaymentSheetViewController::CreateOrderSummarySectionContent() { 235 PaymentSheetViewController::CreateOrderSummarySectionContent() {
213 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter( 236 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter(
214 request()->details()->total->amount->currency, 237 request()->details()->total->amount->currency,
215 request()->details()->total->amount->currency_system, 238 request()->details()->total->amount->currency_system,
(...skipping 18 matching lines...) Expand all
234 this, 257 this,
235 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), 258 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME),
236 std::unique_ptr<views::View>(nullptr), 259 std::unique_ptr<views::View>(nullptr),
237 CreateOrderSummarySectionContent(), 260 CreateOrderSummarySectionContent(),
238 widest_name_column_view_width_); 261 widest_name_column_view_width_);
239 section->set_tag(static_cast<int>( 262 section->set_tag(static_cast<int>(
240 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); 263 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON));
241 return section; 264 return section;
242 } 265 }
243 266
267 std::unique_ptr<views::View>
268 PaymentSheetViewController::CreateShippingSectionContent() {
269 auto profile = request()->GetCurrentlySelectedProfile();
270
271 // TODO(tmartino): Empty string param is app locale; this should be passed
272 // at construct-time and stored as a member in a future CL.
273 return profile ? payments::GetShippingAddressLabel(AddressStyleType::SUMMARY,
274 std::string(), *profile)
275 : base::MakeUnique<views::Label>(base::string16());
276 }
277
278 // Creates the Shipping row, which contains a "Shipping address" label, the
279 // user's selected shipping address, and a chevron.
280 // +----------------------------------------------+
281 // | Shipping Address Barack Obama |
282 // | 1600 Pennsylvania Ave. > |
283 // | 1800MYPOTUS |
284 // +----------------------------------------------+
285 std::unique_ptr<views::Button> PaymentSheetViewController::CreateShippingRow() {
286 std::unique_ptr<views::Button> section = base::MakeUnique<PaymentSheetRow>(
287 this,
288 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_SHIPPING_SECTION_NAME),
289 CreateShippingSectionContent(), std::unique_ptr<views::View>(nullptr),
290 widest_name_column_view_width_);
291 section->set_tag(
292 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON));
293 return section;
294 }
295
244 // Creates the Payment Method row, which contains a "Payment" label, the user's 296 // Creates the Payment Method row, which contains a "Payment" label, the user's
245 // masked Credit Card details, the icon for the selected card, and a chevron. 297 // masked Credit Card details, the icon for the selected card, and a chevron.
246 // +----------------------------------------------+ 298 // +----------------------------------------------+
247 // | Payment Visa ****0000 | 299 // | Payment Visa ****0000 |
248 // | John Smith | VISA | > | 300 // | John Smith | VISA | > |
249 // | | 301 // | |
250 // +----------------------------------------------+ 302 // +----------------------------------------------+
251 std::unique_ptr<views::Button> 303 std::unique_ptr<views::Button>
252 PaymentSheetViewController::CreatePaymentMethodRow() { 304 PaymentSheetViewController::CreatePaymentMethodRow() {
253 autofill::CreditCard* selected_card = 305 autofill::CreditCard* selected_card =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 l10n_util::GetStringUTF16( 342 l10n_util::GetStringUTF16(
291 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), 343 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME),
292 std::move(content_view), 344 std::move(content_view),
293 std::move(card_icon_view), 345 std::move(card_icon_view),
294 widest_name_column_view_width_); 346 widest_name_column_view_width_);
295 section->set_tag(static_cast<int>( 347 section->set_tag(static_cast<int>(
296 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON)); 348 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON));
297 return section; 349 return section;
298 } 350 }
299 351
352 std::unique_ptr<views::View>
353 PaymentSheetViewController::CreateContactInfoSectionContent() {
354 auto profile = request()->GetCurrentlySelectedProfile();
355 // TODO(tmartino): Replace empty string with app locale.
356 return profile ? payments::GetContactInfoLabel(AddressStyleType::SUMMARY,
357 std::string(), *profile, true,
358 true, true)
359 : base::MakeUnique<views::Label>(base::string16());
360 }
361
362 // Creates the Contact Info row, which contains a "Contact info" label; the
363 // name, email address, and/or phone number; and a chevron.
364 // +----------------------------------------------+
365 // | Contact info Barack Obama |
366 // | 1800MYPOTUS > |
367 // | potus@whitehouse.gov |
368 // +----------------------------------------------+
369 std::unique_ptr<views::Button>
370 PaymentSheetViewController::CreateContactInfoRow() {
371 std::unique_ptr<views::Button> section = base::MakeUnique<PaymentSheetRow>(
372 this,
373 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME),
374 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr),
375 widest_name_column_view_width_);
376 section->set_tag(static_cast<int>(
377 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON));
378 return section;
379 }
380
300 } // namespace payments 381 } // namespace payments
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/payments/payment_sheet_view_controller.h ('k') | components/autofill_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698