OLD | NEW |
---|---|
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 <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 for (int name_id : section_names) { | 80 for (int name_id : section_names) { |
81 label.SetText(l10n_util::GetStringUTF16(name_id)); | 81 label.SetText(l10n_util::GetStringUTF16(name_id)); |
82 widest_column_width = std::max( | 82 widest_column_width = std::max( |
83 label.GetPreferredSize().width(), | 83 label.GetPreferredSize().width(), |
84 widest_column_width); | 84 widest_column_width); |
85 } | 85 } |
86 | 86 |
87 return widest_column_width; | 87 return widest_column_width; |
88 } | 88 } |
89 | 89 |
90 // Creates a clickable row to be displayed in the Payment Sheet. It contains | |
91 // a section name and some content, followed by a chevron as a clickability | |
92 // affordance. Both, either, or none of |content_view| and |extra_content_view| | |
93 // may be present, the difference between the two being that content is pinned | |
94 // to the left and extra_content is pinned to the right. | |
95 // The row also displays a light gray horizontal ruler on its lower boundary. | |
96 // The name column has a fixed width equal to |name_column_width|. | |
97 // +----------------------------+ | |
98 // | Name | Content | Extra | > | | |
99 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ <-- ruler | |
100 std::unique_ptr<views::Button> CreatePaymentSheetRow( | 90 std::unique_ptr<views::Button> CreatePaymentSheetRow( |
101 views::ButtonListener* listener, | 91 views::ButtonListener* listener, |
102 const base::string16& section_name, | 92 const base::string16& section_name, |
103 std::unique_ptr<views::View> content_view, | 93 std::unique_ptr<views::View> content_view, |
104 std::unique_ptr<views::View> extra_content_view, | 94 std::unique_ptr<views::View> extra_content_view, |
95 std::unique_ptr<views::View> trailing_button, | |
96 bool clickable, | |
105 int name_column_width) { | 97 int name_column_width) { |
106 std::unique_ptr<PaymentRequestRowView> row = | 98 std::unique_ptr<PaymentRequestRowView> row = |
107 base::MakeUnique<PaymentRequestRowView>(listener); | 99 base::MakeUnique<PaymentRequestRowView>(listener, clickable); |
108 views::GridLayout* layout = new views::GridLayout(row.get()); | 100 views::GridLayout* layout = new views::GridLayout(row.get()); |
109 | 101 |
110 // The rows have extra inset compared to the header so that their right edge | 102 // The rows have extra inset compared to the header so that their right edge |
111 // lines up with the close button's X rather than its invisible right edge. | 103 // lines up with the close button's X rather than its invisible right edge. |
112 layout->SetInsets( | 104 layout->SetInsets( |
113 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets, | 105 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets, |
114 kPaymentRequestRowVerticalInsets, | 106 kPaymentRequestRowVerticalInsets, |
115 kPaymentRequestRowHorizontalInsets + kPaymentRequestRowExtraRightInset); | 107 kPaymentRequestRowHorizontalInsets + kPaymentRequestRowExtraRightInset); |
116 row->SetLayoutManager(layout); | 108 row->SetLayoutManager(layout); |
117 | 109 |
(...skipping 10 matching lines...) Expand all Loading... | |
128 columns->AddPaddingColumn(0, kPaddingColumnsWidth); | 120 columns->AddPaddingColumn(0, kPaddingColumnsWidth); |
129 | 121 |
130 // A column for the content. | 122 // A column for the content. |
131 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, | 123 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, |
132 1, views::GridLayout::USE_PREF, 0, 0); | 124 1, views::GridLayout::USE_PREF, 0, 0); |
133 // A column for the extra content. | 125 // A column for the extra content. |
134 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | 126 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
135 0, views::GridLayout::USE_PREF, 0, 0); | 127 0, views::GridLayout::USE_PREF, 0, 0); |
136 | 128 |
137 columns->AddPaddingColumn(0, kPaddingColumnsWidth); | 129 columns->AddPaddingColumn(0, kPaddingColumnsWidth); |
138 // A column for the chevron. | 130 // A column for the trailing_button. |
139 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | 131 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
140 0, views::GridLayout::USE_PREF, 0, 0); | 132 0, views::GridLayout::USE_PREF, 0, 0); |
141 | 133 |
142 layout->StartRow(0, 0); | 134 layout->StartRow(0, 0); |
143 views::Label* name_label = new views::Label(section_name); | 135 views::Label* name_label = new views::Label(section_name); |
144 layout->AddView(name_label); | 136 layout->AddView(name_label); |
145 | 137 |
146 if (content_view) { | 138 if (content_view) { |
147 content_view->set_can_process_events_within_subtree(false); | 139 content_view->set_can_process_events_within_subtree(false); |
148 layout->AddView(content_view.release()); | 140 layout->AddView(content_view.release()); |
149 } else { | 141 } else { |
150 layout->SkipColumns(1); | 142 layout->SkipColumns(1); |
151 } | 143 } |
152 | 144 |
153 if (extra_content_view) { | 145 if (extra_content_view) { |
154 extra_content_view->set_can_process_events_within_subtree(false); | 146 extra_content_view->set_can_process_events_within_subtree(false); |
155 layout->AddView(extra_content_view.release()); | 147 layout->AddView(extra_content_view.release()); |
156 } else { | 148 } else { |
157 layout->SkipColumns(1); | 149 layout->SkipColumns(1); |
158 } | 150 } |
159 | 151 |
160 views::ImageView* chevron = new views::ImageView(); | 152 layout->AddView(trailing_button.release()); |
161 chevron->set_can_process_events_within_subtree(false); | |
162 chevron->SetImage(gfx::CreateVectorIcon( | |
163 views::kSubmenuArrowIcon, | |
164 color_utils::DeriveDefaultIconColor(name_label->enabled_color()))); | |
165 layout->AddView(chevron); | |
166 | 153 |
167 return std::move(row); | 154 return std::move(row); |
168 } | 155 } |
169 | 156 |
157 std::unique_ptr<views::Button> CreatePaymentSheetRowWithButton( | |
Mathieu
2017/04/13 00:12:45
would be great to have some ASCII here too
anthonyvd
2017/04/13 18:33:33
Done.
| |
158 views::ButtonListener* listener, | |
159 const base::string16& section_name, | |
160 const base::string16& truncated_content, | |
161 const base::string16& button_string, | |
162 int button_tag, | |
163 int button_id, | |
164 int name_column_width) { | |
165 std::unique_ptr<views::Button> button( | |
166 views::MdTextButton::CreateSecondaryUiBlueButton(listener, | |
167 button_string)); | |
168 button->set_tag(button_tag); | |
169 button->set_id(button_id); | |
170 std::unique_ptr<views::Label> content_view = | |
171 base::MakeUnique<views::Label>(truncated_content); | |
172 return CreatePaymentSheetRow(listener, section_name, std::move(content_view), | |
173 nullptr, std::move(button), | |
174 /* clickable= */ false, name_column_width); | |
Mathieu
2017/04/13 00:12:45
very nit: I prefer /*clickable=*/false because the
anthonyvd
2017/04/13 18:33:33
Done.
| |
175 } | |
176 | |
177 // Creates a clickable row to be displayed in the Payment Sheet. It contains | |
178 // a section name and some content, followed by a chevron as a clickability | |
179 // affordance. Both, either, or none of |content_view| and |extra_content_view| | |
180 // may be present, the difference between the two being that content is pinned | |
181 // to the left and extra_content is pinned to the right. | |
182 // The row also displays a light gray horizontal ruler on its lower boundary. | |
183 // The name column has a fixed width equal to |name_column_width|. | |
184 // +----------------------------+ | |
185 // | Name | Content | Extra | > | | |
186 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ <-- ruler | |
187 std::unique_ptr<views::Button> CreatePaymentSheetRowWithChevron( | |
188 views::ButtonListener* listener, | |
189 const base::string16& section_name, | |
190 std::unique_ptr<views::View> content_view, | |
191 std::unique_ptr<views::View> extra_content_view, | |
192 int name_column_width) { | |
Mathieu
2017/04/13 00:12:45
could we also accept the section_tag and section_i
anthonyvd
2017/04/13 18:33:33
Done.
| |
193 std::unique_ptr<views::ImageView> chevron = | |
194 base::MakeUnique<views::ImageView>(); | |
195 chevron->set_can_process_events_within_subtree(false); | |
196 std::unique_ptr<views::Label> label = | |
197 base::MakeUnique<views::Label>(section_name); | |
198 chevron->SetImage(gfx::CreateVectorIcon( | |
199 views::kSubmenuArrowIcon, | |
200 color_utils::DeriveDefaultIconColor(label->enabled_color()))); | |
201 return CreatePaymentSheetRow(listener, section_name, std::move(content_view), | |
202 std::move(extra_content_view), | |
203 std::move(chevron), /* clickable= */ true, | |
204 name_column_width); | |
205 } | |
206 | |
170 // Creates a GridLayout object to be used in the Order Summary section's list of | 207 // Creates a GridLayout object to be used in the Order Summary section's list of |
171 // items and the list of prices. |host| is the view that will be assigned the | 208 // items and the list of prices. |host| is the view that will be assigned the |
172 // returned Layout Manager and |trailing| indicates whether the elements added | 209 // returned Layout Manager and |trailing| indicates whether the elements added |
173 // to the manager should have trailing horizontal alignment. If trailing is | 210 // to the manager should have trailing horizontal alignment. If trailing is |
174 // |false|, their horizontal alignment is leading. | 211 // |false|, their horizontal alignment is leading. |
175 std::unique_ptr<views::GridLayout> CreateOrderSummarySectionContainerLayout( | 212 std::unique_ptr<views::GridLayout> CreateOrderSummarySectionContainerLayout( |
176 views::View* host, | 213 views::View* host, |
177 bool trailing) { | 214 bool trailing) { |
178 std::unique_ptr<views::GridLayout> layout = | 215 std::unique_ptr<views::GridLayout> layout = |
179 base::MakeUnique<views::GridLayout>(host); | 216 base::MakeUnique<views::GridLayout>(host); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 CreateBoldLabel(l10n_util::GetStringFUTF16( | 410 CreateBoldLabel(l10n_util::GetStringFUTF16( |
374 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, | 411 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, |
375 base::UTF8ToUTF16(spec()->GetFormattedCurrencyCode()), | 412 base::UTF8ToUTF16(spec()->GetFormattedCurrencyCode()), |
376 spec()->GetFormattedCurrencyAmount( | 413 spec()->GetFormattedCurrencyAmount( |
377 spec()->details().total->amount->value))) | 414 spec()->details().total->amount->value))) |
378 .release()); | 415 .release()); |
379 | 416 |
380 item_summaries->SetLayoutManager(item_summaries_layout.release()); | 417 item_summaries->SetLayoutManager(item_summaries_layout.release()); |
381 item_amounts->SetLayoutManager(item_amounts_layout.release()); | 418 item_amounts->SetLayoutManager(item_amounts_layout.release()); |
382 | 419 |
383 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 420 std::unique_ptr<views::Button> section = CreatePaymentSheetRowWithChevron( |
384 this, | 421 this, |
385 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), | 422 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), |
386 std::move(item_summaries), std::move(item_amounts), | 423 std::move(item_summaries), std::move(item_amounts), |
387 widest_name_column_view_width_); | 424 widest_name_column_view_width_); |
388 section->set_tag(static_cast<int>( | 425 section->set_tag(static_cast<int>( |
389 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); | 426 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); |
390 section->set_id( | 427 section->set_id( |
391 static_cast<int>(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION)); | 428 static_cast<int>(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION)); |
392 return section; | 429 return section; |
393 } | 430 } |
394 | 431 |
395 std::unique_ptr<views::View> | 432 std::unique_ptr<views::View> |
396 PaymentSheetViewController::CreateShippingSectionContent() { | 433 PaymentSheetViewController::CreateShippingSectionContent() { |
397 auto* profile = state()->selected_shipping_profile(); | 434 auto* profile = state()->selected_shipping_profile(); |
398 | 435 |
399 return profile ? GetShippingAddressLabel(AddressStyleType::SUMMARY, | 436 return profile ? GetShippingAddressLabel(AddressStyleType::SUMMARY, |
400 state()->GetApplicationLocale(), | 437 state()->GetApplicationLocale(), |
401 *profile) | 438 *profile) |
402 : base::MakeUnique<views::Label>(base::string16()); | 439 : base::MakeUnique<views::Label>(base::string16()); |
403 } | 440 } |
404 | 441 |
405 // Creates the Shipping row, which contains a "Shipping address" label, the | 442 // Creates the Shipping row, which contains a "Shipping address" label, the |
406 // user's selected shipping address, and a chevron. | 443 // user's selected shipping address, and a chevron. |
407 // +----------------------------------------------+ | 444 // +----------------------------------------------+ |
408 // | Shipping Address Barack Obama | | 445 // | Shipping Address Barack Obama | |
409 // | 1600 Pennsylvania Ave. > | | 446 // | 1600 Pennsylvania Ave. > | |
410 // | 1800MYPOTUS | | 447 // | 1800MYPOTUS | |
411 // +----------------------------------------------+ | 448 // +----------------------------------------------+ |
412 std::unique_ptr<views::Button> PaymentSheetViewController::CreateShippingRow() { | 449 std::unique_ptr<views::Button> PaymentSheetViewController::CreateShippingRow() { |
413 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 450 std::unique_ptr<views::Button> section; |
414 this, GetShippingAddressSectionString(spec()->shipping_type()), | 451 if (state()->selected_shipping_profile()) { |
415 CreateShippingSectionContent(), std::unique_ptr<views::View>(nullptr), | 452 section = CreatePaymentSheetRowWithChevron( |
416 widest_name_column_view_width_); | 453 this, GetShippingAddressSectionString(spec()->shipping_type()), |
417 section->set_tag( | 454 CreateShippingSectionContent(), std::unique_ptr<views::View>(nullptr), |
Mathieu
2017/04/13 00:12:45
I'm curious, we're the only ones that do std::uniq
anthonyvd
2017/04/13 18:33:33
I think just nullptr is fine and we have that in o
| |
418 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON)); | 455 widest_name_column_view_width_); |
419 section->set_id( | 456 section->set_tag( |
420 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION)); | 457 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON)); |
458 section->set_id( | |
459 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION)); | |
460 } else { | |
461 base::string16 button_string = | |
462 state()->shipping_profiles().size() | |
463 ? l10n_util::GetStringUTF16( | |
464 IDS_PAYMENT_REQUEST_CHOOSE_SECTION_BUTTON) | |
465 : l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ADD_SECTION_BUTTON); | |
466 | |
467 section = CreatePaymentSheetRowWithButton( | |
468 this, GetShippingAddressSectionString(spec()->shipping_type()), | |
469 base::ASCIIToUTF16(""), button_string, | |
470 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON), | |
471 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION), | |
Mathieu
2017/04/13 00:12:45
I think we should create a different DialogViewID
anthonyvd
2017/04/13 18:33:33
Done.
| |
472 widest_name_column_view_width_); | |
473 } | |
474 | |
421 return section; | 475 return section; |
422 } | 476 } |
423 | 477 |
424 // Creates the Payment Method row, which contains a "Payment" label, the user's | 478 // Creates the Payment Method row, which contains a "Payment" label, the user's |
425 // masked Credit Card details, the icon for the selected card, and a chevron. | 479 // masked Credit Card details, the icon for the selected card, and a chevron. |
426 // +----------------------------------------------+ | 480 // +----------------------------------------------+ |
427 // | Payment Visa ****0000 | | 481 // | Payment Visa ****0000 | |
428 // | John Smith | VISA | > | | 482 // | John Smith | VISA | > | |
Mathieu
2017/04/13 00:12:45
update comment to mention button
anthonyvd
2017/04/13 18:33:33
Done.
| |
429 // | | | 483 // | | |
430 // +----------------------------------------------+ | 484 // +----------------------------------------------+ |
431 std::unique_ptr<views::Button> | 485 std::unique_ptr<views::Button> |
432 PaymentSheetViewController::CreatePaymentMethodRow() { | 486 PaymentSheetViewController::CreatePaymentMethodRow() { |
433 PaymentInstrument* selected_instrument = state()->selected_instrument(); | 487 PaymentInstrument* selected_instrument = state()->selected_instrument(); |
434 | 488 |
435 std::unique_ptr<views::View> content_view; | 489 std::unique_ptr<views::View> content_view; |
436 std::unique_ptr<views::ImageView> card_icon_view; | 490 std::unique_ptr<views::ImageView> card_icon_view; |
491 std::unique_ptr<views::Button> section; | |
437 if (selected_instrument) { | 492 if (selected_instrument) { |
438 content_view = base::MakeUnique<views::View>(); | 493 content_view = base::MakeUnique<views::View>(); |
439 | 494 |
440 views::GridLayout* layout = new views::GridLayout(content_view.get()); | 495 views::GridLayout* layout = new views::GridLayout(content_view.get()); |
441 content_view->SetLayoutManager(layout); | 496 content_view->SetLayoutManager(layout); |
442 views::ColumnSet* columns = layout->AddColumnSet(0); | 497 views::ColumnSet* columns = layout->AddColumnSet(0); |
443 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, | 498 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
444 1, views::GridLayout::USE_PREF, 0, 0); | 499 1, views::GridLayout::USE_PREF, 0, 0); |
445 | 500 |
446 layout->StartRow(0, 0); | 501 layout->StartRow(0, 0); |
447 layout->AddView(new views::Label(selected_instrument->label())); | 502 layout->AddView(new views::Label(selected_instrument->label())); |
448 layout->StartRow(0, 0); | 503 layout->StartRow(0, 0); |
449 layout->AddView(new views::Label(selected_instrument->sublabel())); | 504 layout->AddView(new views::Label(selected_instrument->sublabel())); |
450 | 505 |
451 card_icon_view = CreateInstrumentIconView( | 506 card_icon_view = CreateInstrumentIconView( |
452 selected_instrument->icon_resource_id(), selected_instrument->label()); | 507 selected_instrument->icon_resource_id(), selected_instrument->label()); |
453 card_icon_view->SetImageSize(gfx::Size(32, 20)); | 508 card_icon_view->SetImageSize(gfx::Size(32, 20)); |
509 | |
510 section = CreatePaymentSheetRowWithChevron( | |
511 this, | |
512 l10n_util::GetStringUTF16( | |
513 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), | |
514 std::move(content_view), std::move(card_icon_view), | |
515 widest_name_column_view_width_); | |
516 section->set_tag(static_cast<int>( | |
517 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON)); | |
518 section->set_id( | |
519 static_cast<int>(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION)); | |
520 } else { | |
521 base::string16 button_string = | |
522 state()->available_instruments().size() | |
523 ? l10n_util::GetStringUTF16( | |
524 IDS_PAYMENT_REQUEST_CHOOSE_SECTION_BUTTON) | |
525 : l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ADD_SECTION_BUTTON); | |
526 | |
527 section = CreatePaymentSheetRowWithButton( | |
528 this, | |
529 l10n_util::GetStringUTF16( | |
530 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), | |
531 base::ASCIIToUTF16(""), button_string, | |
532 static_cast<int>( | |
533 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON), | |
534 static_cast<int>(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION), | |
535 widest_name_column_view_width_); | |
454 } | 536 } |
455 | 537 |
456 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | |
457 this, | |
458 l10n_util::GetStringUTF16( | |
459 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), | |
460 std::move(content_view), | |
461 std::move(card_icon_view), | |
462 widest_name_column_view_width_); | |
463 section->set_tag(static_cast<int>( | |
464 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON)); | |
465 section->set_id( | |
466 static_cast<int>(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION)); | |
467 return section; | 538 return section; |
468 } | 539 } |
469 | 540 |
470 std::unique_ptr<views::View> | 541 std::unique_ptr<views::View> |
471 PaymentSheetViewController::CreateContactInfoSectionContent() { | 542 PaymentSheetViewController::CreateContactInfoSectionContent() { |
472 autofill::AutofillProfile* profile = state()->selected_contact_profile(); | 543 autofill::AutofillProfile* profile = state()->selected_contact_profile(); |
473 return profile ? payments::GetContactInfoLabel( | 544 return profile ? payments::GetContactInfoLabel( |
474 AddressStyleType::SUMMARY, | 545 AddressStyleType::SUMMARY, |
475 state()->GetApplicationLocale(), *profile, *spec()) | 546 state()->GetApplicationLocale(), *profile, *spec()) |
476 : base::MakeUnique<views::Label>(base::string16()); | 547 : base::MakeUnique<views::Label>(base::string16()); |
477 } | 548 } |
478 | 549 |
479 // Creates the Contact Info row, which contains a "Contact info" label; the | 550 // Creates the Contact Info row, which contains a "Contact info" label; the |
480 // name, email address, and/or phone number; and a chevron. | 551 // name, email address, and/or phone number; and a chevron. |
481 // +----------------------------------------------+ | 552 // +----------------------------------------------+ |
482 // | Contact info Barack Obama | | 553 // | Contact info Barack Obama | |
483 // | 1800MYPOTUS > | | 554 // | 1800MYPOTUS > | |
484 // | potus@whitehouse.gov | | 555 // | potus@whitehouse.gov | |
485 // +----------------------------------------------+ | 556 // +----------------------------------------------+ |
486 std::unique_ptr<views::Button> | 557 std::unique_ptr<views::Button> |
487 PaymentSheetViewController::CreateContactInfoRow() { | 558 PaymentSheetViewController::CreateContactInfoRow() { |
488 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 559 std::unique_ptr<views::Button> section; |
489 this, | 560 if (state()->selected_contact_profile()) { |
490 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), | 561 section = CreatePaymentSheetRowWithChevron( |
491 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), | 562 this, |
492 widest_name_column_view_width_); | 563 l10n_util::GetStringUTF16( |
493 section->set_tag(static_cast<int>( | 564 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), |
494 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); | 565 CreateContactInfoSectionContent(), |
495 section->set_id( | 566 std::unique_ptr<views::View>(nullptr), widest_name_column_view_width_); |
496 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); | 567 section->set_tag(static_cast<int>( |
568 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); | |
569 section->set_id( | |
570 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); | |
571 } else { | |
572 base::string16 button_string = | |
573 state()->contact_profiles().size() | |
574 ? l10n_util::GetStringUTF16( | |
575 IDS_PAYMENT_REQUEST_CHOOSE_SECTION_BUTTON) | |
576 : l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ADD_SECTION_BUTTON); | |
577 | |
578 section = CreatePaymentSheetRowWithButton( | |
579 this, | |
580 l10n_util::GetStringUTF16( | |
581 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), | |
582 base::ASCIIToUTF16(""), button_string, | |
583 static_cast<int>( | |
584 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON), | |
585 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION), | |
586 widest_name_column_view_width_); | |
587 } | |
588 | |
497 return section; | 589 return section; |
498 } | 590 } |
499 | 591 |
500 std::unique_ptr<views::Button> | 592 std::unique_ptr<views::Button> |
501 PaymentSheetViewController::CreateShippingOptionRow() { | 593 PaymentSheetViewController::CreateShippingOptionRow() { |
502 mojom::PaymentShippingOption* selected_option = | 594 mojom::PaymentShippingOption* selected_option = |
503 spec()->selected_shipping_option(); | 595 spec()->selected_shipping_option(); |
504 if (!selected_option) | |
505 return nullptr; | |
506 | 596 |
507 std::unique_ptr<views::View> option_label = CreateShippingOptionLabel( | 597 // The shipping option section displays the currently selected option if there |
508 selected_option, selected_option ? spec()->GetFormattedCurrencyAmount( | 598 // is one. It's not possible to select an option without selecting an address |
509 selected_option->amount->value) | 599 // first. |
510 : base::ASCIIToUTF16("")); | 600 std::unique_ptr<views::Button> section; |
511 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 601 if (state()->selected_shipping_profile()) { |
512 this, GetShippingOptionSectionString(spec()->shipping_type()), | 602 if (spec()->details().shipping_options.size()) { |
Mathieu
2017/04/13 00:12:45
if (!... or .empty()
anthonyvd
2017/04/13 18:33:33
Done.
| |
513 std::move(option_label), std::unique_ptr<views::View>(nullptr), | 603 // TODO(anthonyvd): Display placeholder if there's no available shipping |
514 widest_name_column_view_width_); | 604 // option. |
515 section->set_tag(static_cast<int>( | 605 return nullptr; |
516 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); | 606 } |
517 section->set_id( | 607 |
518 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); | 608 std::unique_ptr<views::View> option_label = CreateShippingOptionLabel( |
609 selected_option, selected_option ? spec()->GetFormattedCurrencyAmount( | |
610 selected_option->amount->value) | |
611 : base::ASCIIToUTF16("")); | |
612 section = CreatePaymentSheetRowWithChevron( | |
613 this, GetShippingOptionSectionString(spec()->shipping_type()), | |
614 std::move(option_label), std::unique_ptr<views::View>(nullptr), | |
615 widest_name_column_view_width_); | |
616 section->set_tag(static_cast<int>( | |
617 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); | |
618 section->set_id( | |
619 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); | |
620 } else { | |
621 // TODO(anthonyvd): This should be a disabled row with a disabled button and | |
622 // some text to indicate that an address must be selected first. | |
623 section = CreatePaymentSheetRowWithButton( | |
624 this, GetShippingOptionSectionString(spec()->shipping_type()), | |
625 base::ASCIIToUTF16(""), | |
626 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CHOOSE_SECTION_BUTTON), | |
627 static_cast<int>( | |
628 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON), | |
629 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION), | |
630 widest_name_column_view_width_); | |
631 } | |
632 | |
519 return section; | 633 return section; |
520 } | 634 } |
521 | 635 |
522 } // namespace payments | 636 } // namespace payments |
OLD | NEW |