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 // Creates a row with a button in place of the chevron. |
| 158 // +------------------------------------------+ |
| 159 // | Name | truncated_content | button_string | |
| 160 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ |
| 161 std::unique_ptr<views::Button> CreatePaymentSheetRowWithButton( |
| 162 views::ButtonListener* listener, |
| 163 const base::string16& section_name, |
| 164 const base::string16& truncated_content, |
| 165 const base::string16& button_string, |
| 166 int button_tag, |
| 167 int button_id, |
| 168 int name_column_width) { |
| 169 std::unique_ptr<views::Button> button( |
| 170 views::MdTextButton::CreateSecondaryUiBlueButton(listener, |
| 171 button_string)); |
| 172 button->set_tag(button_tag); |
| 173 button->set_id(button_id); |
| 174 std::unique_ptr<views::Label> content_view = |
| 175 base::MakeUnique<views::Label>(truncated_content); |
| 176 return CreatePaymentSheetRow(listener, section_name, std::move(content_view), |
| 177 nullptr, std::move(button), |
| 178 /*clickable=*/false, name_column_width); |
| 179 } |
| 180 |
| 181 // Creates a clickable row to be displayed in the Payment Sheet. It contains |
| 182 // a section name and some content, followed by a chevron as a clickability |
| 183 // affordance. Both, either, or none of |content_view| and |extra_content_view| |
| 184 // may be present, the difference between the two being that content is pinned |
| 185 // to the left and extra_content is pinned to the right. |
| 186 // The row also displays a light gray horizontal ruler on its lower boundary. |
| 187 // The name column has a fixed width equal to |name_column_width|. |
| 188 // +----------------------------+ |
| 189 // | Name | Content | Extra | > | |
| 190 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ <-- ruler |
| 191 std::unique_ptr<views::Button> CreatePaymentSheetRowWithChevron( |
| 192 views::ButtonListener* listener, |
| 193 const base::string16& section_name, |
| 194 std::unique_ptr<views::View> content_view, |
| 195 std::unique_ptr<views::View> extra_content_view, |
| 196 int section_tag, |
| 197 int section_id, |
| 198 int name_column_width) { |
| 199 std::unique_ptr<views::ImageView> chevron = |
| 200 base::MakeUnique<views::ImageView>(); |
| 201 chevron->set_can_process_events_within_subtree(false); |
| 202 std::unique_ptr<views::Label> label = |
| 203 base::MakeUnique<views::Label>(section_name); |
| 204 chevron->SetImage(gfx::CreateVectorIcon( |
| 205 views::kSubmenuArrowIcon, |
| 206 color_utils::DeriveDefaultIconColor(label->enabled_color()))); |
| 207 std::unique_ptr<views::Button> section = |
| 208 CreatePaymentSheetRow(listener, section_name, std::move(content_view), |
| 209 std::move(extra_content_view), std::move(chevron), |
| 210 /*clickable=*/true, name_column_width); |
| 211 section->set_tag(section_tag); |
| 212 section->set_id(section_id); |
| 213 return section; |
| 214 } |
| 215 |
170 // Creates a GridLayout object to be used in the Order Summary section's list of | 216 // 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 | 217 // 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 | 218 // returned Layout Manager and |trailing| indicates whether the elements added |
173 // to the manager should have trailing horizontal alignment. If trailing is | 219 // to the manager should have trailing horizontal alignment. If trailing is |
174 // |false|, their horizontal alignment is leading. | 220 // |false|, their horizontal alignment is leading. |
175 std::unique_ptr<views::GridLayout> CreateOrderSummarySectionContainerLayout( | 221 std::unique_ptr<views::GridLayout> CreateOrderSummarySectionContainerLayout( |
176 views::View* host, | 222 views::View* host, |
177 bool trailing) { | 223 bool trailing) { |
178 std::unique_ptr<views::GridLayout> layout = | 224 std::unique_ptr<views::GridLayout> layout = |
179 base::MakeUnique<views::GridLayout>(host); | 225 base::MakeUnique<views::GridLayout>(host); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 CreateBoldLabel(l10n_util::GetStringFUTF16( | 461 CreateBoldLabel(l10n_util::GetStringFUTF16( |
416 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, | 462 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, |
417 base::UTF8ToUTF16(spec()->GetFormattedCurrencyCode()), | 463 base::UTF8ToUTF16(spec()->GetFormattedCurrencyCode()), |
418 spec()->GetFormattedCurrencyAmount( | 464 spec()->GetFormattedCurrencyAmount( |
419 spec()->details().total->amount->value))) | 465 spec()->details().total->amount->value))) |
420 .release()); | 466 .release()); |
421 | 467 |
422 item_summaries->SetLayoutManager(item_summaries_layout.release()); | 468 item_summaries->SetLayoutManager(item_summaries_layout.release()); |
423 item_amounts->SetLayoutManager(item_amounts_layout.release()); | 469 item_amounts->SetLayoutManager(item_amounts_layout.release()); |
424 | 470 |
425 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 471 std::unique_ptr<views::Button> section = CreatePaymentSheetRowWithChevron( |
426 this, | 472 this, |
427 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), | 473 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), |
428 std::move(item_summaries), std::move(item_amounts), | 474 std::move(item_summaries), std::move(item_amounts), |
| 475 static_cast<int>( |
| 476 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON), |
| 477 static_cast<int>(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION), |
429 widest_name_column_view_width_); | 478 widest_name_column_view_width_); |
430 section->set_tag(static_cast<int>( | |
431 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); | |
432 section->set_id( | |
433 static_cast<int>(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION)); | |
434 return section; | 479 return section; |
435 } | 480 } |
436 | 481 |
437 std::unique_ptr<views::View> | 482 std::unique_ptr<views::View> |
438 PaymentSheetViewController::CreateShippingSectionContent() { | 483 PaymentSheetViewController::CreateShippingSectionContent() { |
439 if (current_update_reason_ == | 484 if (current_update_reason_ == |
440 PaymentRequestSpec::UpdateReason::SHIPPING_ADDRESS) { | 485 PaymentRequestSpec::UpdateReason::SHIPPING_ADDRESS) { |
441 return CreateCheckingSpinnerView(); | 486 return CreateCheckingSpinnerView(); |
442 } else { | 487 } else { |
443 auto* profile = state()->selected_shipping_profile(); | 488 auto* profile = state()->selected_shipping_profile(); |
444 | 489 |
445 return profile ? GetShippingAddressLabel(AddressStyleType::SUMMARY, | 490 return profile ? GetShippingAddressLabel(AddressStyleType::SUMMARY, |
446 state()->GetApplicationLocale(), | 491 state()->GetApplicationLocale(), |
447 *profile) | 492 *profile) |
448 : base::MakeUnique<views::Label>(base::string16()); | 493 : base::MakeUnique<views::Label>(base::string16()); |
449 } | 494 } |
450 } | 495 } |
451 | 496 |
452 // Creates the Shipping row, which contains a "Shipping address" label, the | 497 // Creates the Shipping row, which contains a "Shipping address" label, the |
453 // user's selected shipping address, and a chevron. | 498 // user's selected shipping address, and a chevron. |
454 // +----------------------------------------------+ | 499 // +----------------------------------------------+ |
455 // | Shipping Address Barack Obama | | 500 // | Shipping Address Barack Obama | |
456 // | 1600 Pennsylvania Ave. > | | 501 // | 1600 Pennsylvania Ave. > | |
457 // | 1800MYPOTUS | | 502 // | 1800MYPOTUS | |
458 // +----------------------------------------------+ | 503 // +----------------------------------------------+ |
459 std::unique_ptr<views::Button> PaymentSheetViewController::CreateShippingRow() { | 504 std::unique_ptr<views::Button> PaymentSheetViewController::CreateShippingRow() { |
460 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 505 std::unique_ptr<views::Button> section; |
461 this, GetShippingAddressSectionString(spec()->shipping_type()), | 506 if (state()->selected_shipping_profile()) { |
462 CreateShippingSectionContent(), std::unique_ptr<views::View>(nullptr), | 507 section = CreatePaymentSheetRowWithChevron( |
463 widest_name_column_view_width_); | 508 this, GetShippingAddressSectionString(spec()->shipping_type()), |
464 section->set_tag( | 509 CreateShippingSectionContent(), nullptr, |
465 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON)); | 510 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON), |
466 section->set_id( | 511 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION), |
467 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION)); | 512 widest_name_column_view_width_); |
| 513 } else { |
| 514 base::string16 button_string = state()->shipping_profiles().size() |
| 515 ? l10n_util::GetStringUTF16(IDS_CHOOSE) |
| 516 : l10n_util::GetStringUTF16(IDS_ADD); |
| 517 |
| 518 section = CreatePaymentSheetRowWithButton( |
| 519 this, GetShippingAddressSectionString(spec()->shipping_type()), |
| 520 base::ASCIIToUTF16(""), button_string, |
| 521 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON), |
| 522 static_cast<int>( |
| 523 DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION_BUTTON), |
| 524 widest_name_column_view_width_); |
| 525 } |
| 526 |
468 return section; | 527 return section; |
469 } | 528 } |
470 | 529 |
471 // Creates the Payment Method row, which contains a "Payment" label, the user's | 530 // Creates the Payment Method row, which contains a "Payment" label, the user's |
472 // masked Credit Card details, the icon for the selected card, and a chevron. | 531 // masked Credit Card details, the icon for the selected card, and a chevron. |
| 532 // If no option is selected or none is available, the Chevron and icon are |
| 533 // replaced with a button |
473 // +----------------------------------------------+ | 534 // +----------------------------------------------+ |
474 // | Payment Visa ****0000 | | 535 // | Payment Visa ****0000 | |
475 // | John Smith | VISA | > | | 536 // | John Smith | VISA | > | |
476 // | | | 537 // | | |
477 // +----------------------------------------------+ | 538 // +----------------------------------------------+ |
478 std::unique_ptr<views::Button> | 539 std::unique_ptr<views::Button> |
479 PaymentSheetViewController::CreatePaymentMethodRow() { | 540 PaymentSheetViewController::CreatePaymentMethodRow() { |
480 PaymentInstrument* selected_instrument = state()->selected_instrument(); | 541 PaymentInstrument* selected_instrument = state()->selected_instrument(); |
481 | 542 |
482 std::unique_ptr<views::View> content_view; | 543 std::unique_ptr<views::View> content_view; |
483 std::unique_ptr<views::ImageView> card_icon_view; | 544 std::unique_ptr<views::ImageView> card_icon_view; |
| 545 std::unique_ptr<views::Button> section; |
484 if (selected_instrument) { | 546 if (selected_instrument) { |
485 content_view = base::MakeUnique<views::View>(); | 547 content_view = base::MakeUnique<views::View>(); |
486 | 548 |
487 views::GridLayout* layout = new views::GridLayout(content_view.get()); | 549 views::GridLayout* layout = new views::GridLayout(content_view.get()); |
488 content_view->SetLayoutManager(layout); | 550 content_view->SetLayoutManager(layout); |
489 views::ColumnSet* columns = layout->AddColumnSet(0); | 551 views::ColumnSet* columns = layout->AddColumnSet(0); |
490 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, | 552 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
491 1, views::GridLayout::USE_PREF, 0, 0); | 553 1, views::GridLayout::USE_PREF, 0, 0); |
492 | 554 |
493 layout->StartRow(0, 0); | 555 layout->StartRow(0, 0); |
494 layout->AddView(new views::Label(selected_instrument->label())); | 556 layout->AddView(new views::Label(selected_instrument->label())); |
495 layout->StartRow(0, 0); | 557 layout->StartRow(0, 0); |
496 layout->AddView(new views::Label(selected_instrument->sublabel())); | 558 layout->AddView(new views::Label(selected_instrument->sublabel())); |
497 | 559 |
498 card_icon_view = CreateInstrumentIconView( | 560 card_icon_view = CreateInstrumentIconView( |
499 selected_instrument->icon_resource_id(), selected_instrument->label()); | 561 selected_instrument->icon_resource_id(), selected_instrument->label()); |
500 card_icon_view->SetImageSize(gfx::Size(32, 20)); | 562 card_icon_view->SetImageSize(gfx::Size(32, 20)); |
| 563 |
| 564 section = CreatePaymentSheetRowWithChevron( |
| 565 this, |
| 566 l10n_util::GetStringUTF16( |
| 567 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), |
| 568 std::move(content_view), std::move(card_icon_view), |
| 569 static_cast<int>( |
| 570 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON), |
| 571 static_cast<int>(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION), |
| 572 widest_name_column_view_width_); |
| 573 } else { |
| 574 base::string16 button_string = state()->available_instruments().size() |
| 575 ? l10n_util::GetStringUTF16(IDS_CHOOSE) |
| 576 : l10n_util::GetStringUTF16(IDS_ADD); |
| 577 |
| 578 section = CreatePaymentSheetRowWithButton( |
| 579 this, |
| 580 l10n_util::GetStringUTF16( |
| 581 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), |
| 582 base::ASCIIToUTF16(""), button_string, |
| 583 static_cast<int>( |
| 584 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON), |
| 585 static_cast<int>( |
| 586 DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION_BUTTON), |
| 587 widest_name_column_view_width_); |
501 } | 588 } |
502 | 589 |
503 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | |
504 this, | |
505 l10n_util::GetStringUTF16( | |
506 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), | |
507 std::move(content_view), | |
508 std::move(card_icon_view), | |
509 widest_name_column_view_width_); | |
510 section->set_tag(static_cast<int>( | |
511 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON)); | |
512 section->set_id( | |
513 static_cast<int>(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION)); | |
514 return section; | 590 return section; |
515 } | 591 } |
516 | 592 |
517 std::unique_ptr<views::View> | 593 std::unique_ptr<views::View> |
518 PaymentSheetViewController::CreateContactInfoSectionContent() { | 594 PaymentSheetViewController::CreateContactInfoSectionContent() { |
519 autofill::AutofillProfile* profile = state()->selected_contact_profile(); | 595 autofill::AutofillProfile* profile = state()->selected_contact_profile(); |
520 return profile ? payments::GetContactInfoLabel( | 596 return profile ? payments::GetContactInfoLabel( |
521 AddressStyleType::SUMMARY, | 597 AddressStyleType::SUMMARY, |
522 state()->GetApplicationLocale(), *profile, *spec()) | 598 state()->GetApplicationLocale(), *profile, *spec()) |
523 : base::MakeUnique<views::Label>(base::string16()); | 599 : base::MakeUnique<views::Label>(base::string16()); |
524 } | 600 } |
525 | 601 |
526 // Creates the Contact Info row, which contains a "Contact info" label; the | 602 // Creates the Contact Info row, which contains a "Contact info" label; the |
527 // name, email address, and/or phone number; and a chevron. | 603 // name, email address, and/or phone number; and a chevron. |
528 // +----------------------------------------------+ | 604 // +----------------------------------------------+ |
529 // | Contact info Barack Obama | | 605 // | Contact info Barack Obama | |
530 // | 1800MYPOTUS > | | 606 // | 1800MYPOTUS > | |
531 // | potus@whitehouse.gov | | 607 // | potus@whitehouse.gov | |
532 // +----------------------------------------------+ | 608 // +----------------------------------------------+ |
533 std::unique_ptr<views::Button> | 609 std::unique_ptr<views::Button> |
534 PaymentSheetViewController::CreateContactInfoRow() { | 610 PaymentSheetViewController::CreateContactInfoRow() { |
535 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 611 std::unique_ptr<views::Button> section; |
536 this, | 612 if (state()->selected_contact_profile()) { |
537 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), | 613 section = CreatePaymentSheetRowWithChevron( |
538 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), | 614 this, |
539 widest_name_column_view_width_); | 615 l10n_util::GetStringUTF16( |
540 section->set_tag(static_cast<int>( | 616 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), |
541 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); | 617 CreateContactInfoSectionContent(), nullptr, |
542 section->set_id( | 618 static_cast<int>( |
543 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); | 619 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON), |
| 620 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION), |
| 621 widest_name_column_view_width_); |
| 622 } else { |
| 623 base::string16 button_string = state()->contact_profiles().size() |
| 624 ? l10n_util::GetStringUTF16(IDS_CHOOSE) |
| 625 : l10n_util::GetStringUTF16(IDS_ADD); |
| 626 |
| 627 section = CreatePaymentSheetRowWithButton( |
| 628 this, |
| 629 l10n_util::GetStringUTF16( |
| 630 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), |
| 631 base::ASCIIToUTF16(""), button_string, |
| 632 static_cast<int>( |
| 633 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON), |
| 634 static_cast<int>( |
| 635 DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION_BUTTON), |
| 636 widest_name_column_view_width_); |
| 637 } |
| 638 |
544 return section; | 639 return section; |
545 } | 640 } |
546 | 641 |
547 std::unique_ptr<views::Button> | 642 std::unique_ptr<views::Button> |
548 PaymentSheetViewController::CreateShippingOptionRow() { | 643 PaymentSheetViewController::CreateShippingOptionRow() { |
549 mojom::PaymentShippingOption* selected_option = | 644 mojom::PaymentShippingOption* selected_option = |
550 spec()->selected_shipping_option(); | 645 spec()->selected_shipping_option(); |
551 if (!selected_option && | 646 // The shipping option section displays the currently selected option if there |
552 current_update_reason_ != | 647 // is one. It's not possible to select an option without selecting an address |
553 PaymentRequestSpec::UpdateReason::SHIPPING_OPTION) { | 648 // first. |
554 return nullptr; | 649 std::unique_ptr<views::Button> section; |
| 650 if (state()->selected_shipping_profile()) { |
| 651 if (spec()->details().shipping_options.empty()) { |
| 652 // TODO(anthonyvd): Display placeholder if there's no available shipping |
| 653 // option. |
| 654 return nullptr; |
| 655 } |
| 656 |
| 657 std::unique_ptr<views::View> option_row_content = |
| 658 current_update_reason_ == |
| 659 PaymentRequestSpec::UpdateReason::SHIPPING_OPTION |
| 660 ? CreateCheckingSpinnerView() |
| 661 : CreateShippingOptionLabel( |
| 662 selected_option, selected_option |
| 663 ? spec()->GetFormattedCurrencyAmount( |
| 664 selected_option->amount->value) |
| 665 : base::ASCIIToUTF16("")); |
| 666 section = CreatePaymentSheetRowWithChevron( |
| 667 this, GetShippingOptionSectionString(spec()->shipping_type()), |
| 668 std::move(option_row_content), nullptr, |
| 669 static_cast<int>( |
| 670 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON), |
| 671 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION), |
| 672 widest_name_column_view_width_); |
| 673 } else { |
| 674 // TODO(anthonyvd): This should be a disabled row with a disabled button and |
| 675 // some text to indicate that an address must be selected first. |
| 676 section = CreatePaymentSheetRowWithButton( |
| 677 this, GetShippingOptionSectionString(spec()->shipping_type()), |
| 678 base::ASCIIToUTF16(""), l10n_util::GetStringUTF16(IDS_CHOOSE), |
| 679 static_cast<int>( |
| 680 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON), |
| 681 static_cast<int>( |
| 682 DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION_BUTTON), |
| 683 widest_name_column_view_width_); |
555 } | 684 } |
556 | 685 |
557 std::unique_ptr<views::View> option_row_content = | |
558 current_update_reason_ == | |
559 PaymentRequestSpec::UpdateReason::SHIPPING_OPTION | |
560 ? CreateCheckingSpinnerView() | |
561 : CreateShippingOptionLabel(selected_option, | |
562 selected_option | |
563 ? spec()->GetFormattedCurrencyAmount( | |
564 selected_option->amount->value) | |
565 : base::ASCIIToUTF16("")); | |
566 | |
567 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | |
568 this, GetShippingOptionSectionString(spec()->shipping_type()), | |
569 std::move(option_row_content), std::unique_ptr<views::View>(nullptr), | |
570 widest_name_column_view_width_); | |
571 section->set_tag(static_cast<int>( | |
572 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); | |
573 section->set_id( | |
574 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); | |
575 return section; | 686 return section; |
576 } | 687 } |
577 | 688 |
578 } // namespace payments | 689 } // namespace payments |
OLD | NEW |