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

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

Issue 2843533002: [Web Payments] Add placeholders in non-selected payment sheet rows (Closed)
Patch Set: Created 3 years, 8 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 <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/i18n/message_formatter.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
15 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" 20 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
20 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 21 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
21 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" 22 #include "chrome/browser/ui/views/payments/payment_request_row_view.h"
22 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 23 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
23 #include "chrome/grit/generated_resources.h" 24 #include "chrome/grit/generated_resources.h"
24 #include "components/autofill/core/browser/field_types.h" 25 #include "components/autofill/core/browser/field_types.h"
25 #include "components/autofill/core/browser/personal_data_manager.h" 26 #include "components/autofill/core/browser/personal_data_manager.h"
26 #include "components/payments/content/payment_request_spec.h" 27 #include "components/payments/content/payment_request_spec.h"
27 #include "components/payments/content/payment_request_state.h" 28 #include "components/payments/content/payment_request_state.h"
28 #include "components/payments/core/currency_formatter.h" 29 #include "components/payments/core/currency_formatter.h"
29 #include "components/payments/core/payment_instrument.h" 30 #include "components/payments/core/payment_instrument.h"
30 #include "components/payments/core/strings_util.h" 31 #include "components/payments/core/strings_util.h"
31 #include "components/strings/grit/components_strings.h" 32 #include "components/strings/grit/components_strings.h"
32 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
33 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/base/resource/resource_bundle.h" 35 #include "ui/base/resource/resource_bundle.h"
35 #include "ui/gfx/color_utils.h" 36 #include "ui/gfx/color_utils.h"
36 #include "ui/gfx/font.h" 37 #include "ui/gfx/font.h"
37 #include "ui/gfx/paint_vector_icon.h" 38 #include "ui/gfx/paint_vector_icon.h"
38 #include "ui/gfx/range/range.h" 39 #include "ui/gfx/range/range.h"
40 #include "ui/gfx/text_elider.h"
41 #include "ui/gfx/text_utils.h"
39 #include "ui/views/controls/button/md_text_button.h" 42 #include "ui/views/controls/button/md_text_button.h"
40 #include "ui/views/controls/image_view.h" 43 #include "ui/views/controls/image_view.h"
41 #include "ui/views/controls/label.h" 44 #include "ui/views/controls/label.h"
42 #include "ui/views/controls/styled_label.h" 45 #include "ui/views/controls/styled_label.h"
43 #include "ui/views/layout/box_layout.h" 46 #include "ui/views/layout/box_layout.h"
44 #include "ui/views/layout/fill_layout.h" 47 #include "ui/views/layout/fill_layout.h"
45 #include "ui/views/layout/grid_layout.h" 48 #include "ui/views/layout/grid_layout.h"
46 #include "ui/views/vector_icons.h" 49 #include "ui/views/vector_icons.h"
47 #include "ui/views/view.h" 50 #include "ui/views/view.h"
48 51
49 namespace payments { 52 namespace payments {
50 namespace { 53 namespace {
51 54
52 constexpr int kFirstTagValue = static_cast<int>( 55 constexpr int kFirstTagValue = static_cast<int>(
53 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX); 56 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX);
54 57
55 enum class PaymentSheetViewControllerTags { 58 enum class PaymentSheetViewControllerTags {
56 // The tag for the button that navigates to the Order Summary sheet. 59 // The tag for the button that navigates to the Order Summary sheet.
57 SHOW_ORDER_SUMMARY_BUTTON = kFirstTagValue, 60 SHOW_ORDER_SUMMARY_BUTTON = kFirstTagValue,
58 SHOW_SHIPPING_BUTTON, 61 SHOW_SHIPPING_BUTTON,
59 SHOW_PAYMENT_METHOD_BUTTON, 62 SHOW_PAYMENT_METHOD_BUTTON,
60 SHOW_CONTACT_INFO_BUTTON, 63 SHOW_CONTACT_INFO_BUTTON,
61 SHOW_SHIPPING_OPTION_BUTTON, 64 SHOW_SHIPPING_OPTION_BUTTON,
62 PAY_BUTTON 65 PAY_BUTTON
63 }; 66 };
64 67
68 // A class that ensures proper elision of labels in the form
69 // "[preview] and N more" where preview might be elided to allow "and N more" to
70 // be always visible.
71 class PreviewEliderLabel : public views::Label {
72 public:
73 // Creates a PreviewEliderLabel where |preview_text| might be elided,
74 // |format_string| is a the string with format argument numbers in ICU syntax
Mathieu 2017/04/24 19:09:01 *is the
anthonyvd 2017/04/24 20:24:25 Done.
75 // and |n| is the "N more" item count.
76 PreviewEliderLabel(const base::string16& preview_text,
77 const base::string16& format_string,
78 int n)
79 : views::Label(base::ASCIIToUTF16("")),
80 preview_text_(preview_text),
81 format_string_(format_string),
82 n_(n) {}
83
84 private:
85 // Formats |preview_text_|, |format_string_|, and |n_| into a string that fits
86 // inside of |pixel_width|, eliding |preview_text_| as required.
87 base::string16 CreateElidedString(int pixel_width) {
88 for (int preview_length = preview_text_.size(); preview_length > 0;
89 --preview_length) {
90 base::string16 elided_preview;
91 gfx::ElideRectangleString(preview_text_, 1, preview_length,
92 /*strict=*/false, &elided_preview);
93 base::string16 elided_string =
94 base::i18n::MessageFormatter::FormatWithNumberedArgs(
95 format_string_, "", elided_preview, n_);
96 if (gfx::GetStringWidth(elided_string, font_list()) <= width())
97 return elided_string;
98 }
99
100 // TODO(anthonyvd): Display something meaningful if the preview can't be
Mathieu 2017/04/24 19:09:01 let's have a crbug for it :)
anthonyvd 2017/04/24 20:24:25 Done.
101 // elided enough for the string to fit.
102 return base::ASCIIToUTF16("");
103 }
104
105 // views::View:
106 void OnBoundsChanged(const gfx::Rect& previous_bounds) override {
107 SetText(CreateElidedString(width()));
108 views::Label::OnBoundsChanged(previous_bounds);
109 }
110
111 base::string16 preview_text_;
112 base::string16 format_string_;
113 int n_;
114
115 DISALLOW_COPY_AND_ASSIGN(PreviewEliderLabel);
116 };
117
65 int ComputeWidestNameColumnViewWidth() { 118 int ComputeWidestNameColumnViewWidth() {
66 // The name colums in each row should all have the same width, large enough to 119 // The name colums in each row should all have the same width, large enough to
67 // accomodate the longest piece of text they contain. Because of this, each 120 // accomodate the longest piece of text they contain. Because of this, each
68 // row's GridLayout requires its first column to have a fixed width of the 121 // row's GridLayout requires its first column to have a fixed width of the
69 // correct size. To measure the required size, layout a label with each 122 // correct size. To measure the required size, layout a label with each
70 // section name, measure its width, then initialize |widest_column_width| 123 // section name, measure its width, then initialize |widest_column_width|
71 // with the largest value. 124 // with the largest value.
72 std::vector<int> section_names{ 125 std::vector<int> section_names{
73 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME, 126 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME,
74 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME, 127 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return std::move(row); 207 return std::move(row);
155 } 208 }
156 209
157 // Creates a row with a button in place of the chevron. 210 // Creates a row with a button in place of the chevron.
158 // +------------------------------------------+ 211 // +------------------------------------------+
159 // | Name | truncated_content | button_string | 212 // | Name | truncated_content | button_string |
160 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ 213 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
161 std::unique_ptr<views::Button> CreatePaymentSheetRowWithButton( 214 std::unique_ptr<views::Button> CreatePaymentSheetRowWithButton(
162 views::ButtonListener* listener, 215 views::ButtonListener* listener,
163 const base::string16& section_name, 216 const base::string16& section_name,
164 const base::string16& truncated_content, 217 std::unique_ptr<views::View> content_view,
165 const base::string16& button_string, 218 const base::string16& button_string,
166 int button_tag, 219 int button_tag,
167 int button_id, 220 int button_id,
168 int name_column_width) { 221 int name_column_width) {
169 std::unique_ptr<views::Button> button( 222 std::unique_ptr<views::Button> button(
170 views::MdTextButton::CreateSecondaryUiBlueButton(listener, 223 views::MdTextButton::CreateSecondaryUiBlueButton(listener,
171 button_string)); 224 button_string));
172 button->set_tag(button_tag); 225 button->set_tag(button_tag);
173 button->set_id(button_id); 226 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), 227 return CreatePaymentSheetRow(listener, section_name, std::move(content_view),
177 nullptr, std::move(button), 228 nullptr, std::move(button),
178 /*clickable=*/false, name_column_width); 229 /*clickable=*/false, name_column_width);
179 } 230 }
180 231
232 std::unique_ptr<views::Button> CreatePaymentSheetRowWithButton(
233 views::ButtonListener* listener,
234 const base::string16& section_name,
235 const base::string16& truncated_content,
236 const base::string16& button_string,
237 int button_tag,
238 int button_id,
239 int name_column_width) {
240 std::unique_ptr<views::Label> content_view =
241 base::MakeUnique<views::Label>(truncated_content);
242 content_view->SetHorizontalAlignment(gfx::ALIGN_LEFT);
243 return CreatePaymentSheetRowWithButton(
244 listener, section_name, std::move(content_view), button_string,
245 button_tag, button_id, name_column_width);
246 }
247
248 std::unique_ptr<views::Button> CreatePaymentSheetRowWithButton(
Mathieu 2017/04/24 19:09:01 CreatePaymentSheetRowWithButtonAndPreview ?
anthonyvd 2017/04/24 20:24:25 The other one has a preview as well, it's just not
249 views::ButtonListener* listener,
250 const base::string16& section_name,
251 const base::string16& preview_text,
252 const base::string16& format_string,
253 int n,
254 const base::string16& button_string,
255 int button_tag,
256 int button_id,
257 int name_column_width) {
258 std::unique_ptr<PreviewEliderLabel> content_view =
259 base::MakeUnique<PreviewEliderLabel>(preview_text, format_string, n);
260 content_view->SetHorizontalAlignment(gfx::ALIGN_LEFT);
261 return CreatePaymentSheetRowWithButton(
262 listener, section_name, std::move(content_view), button_string,
263 button_tag, button_id, name_column_width);
264 }
265
181 // Creates a clickable row to be displayed in the Payment Sheet. It contains 266 // 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 267 // 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| 268 // 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 269 // 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. 270 // 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. 271 // 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|. 272 // The name column has a fixed width equal to |name_column_width|.
188 // +----------------------------+ 273 // +----------------------------+
189 // | Name | Content | Extra | > | 274 // | Name | Content | Extra | > |
190 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ <-- ruler 275 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ <-- ruler
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 this, GetShippingAddressSectionString(spec()->shipping_type()), 593 this, GetShippingAddressSectionString(spec()->shipping_type()),
509 CreateShippingSectionContent(), nullptr, 594 CreateShippingSectionContent(), nullptr,
510 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON), 595 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON),
511 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION), 596 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION),
512 widest_name_column_view_width_); 597 widest_name_column_view_width_);
513 } else { 598 } else {
514 base::string16 button_string = state()->shipping_profiles().size() 599 base::string16 button_string = state()->shipping_profiles().size()
515 ? l10n_util::GetStringUTF16(IDS_CHOOSE) 600 ? l10n_util::GetStringUTF16(IDS_CHOOSE)
516 : l10n_util::GetStringUTF16(IDS_ADD); 601 : l10n_util::GetStringUTF16(IDS_ADD);
517 602
518 section = CreatePaymentSheetRowWithButton( 603 if (state()->shipping_profiles().size() == 0) {
519 this, GetShippingAddressSectionString(spec()->shipping_type()), 604 section = CreatePaymentSheetRowWithButton(
520 base::ASCIIToUTF16(""), button_string, 605 this, GetShippingAddressSectionString(spec()->shipping_type()),
521 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON), 606 base::ASCIIToUTF16(""), button_string,
522 static_cast<int>( 607 static_cast<int>(
523 DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION_BUTTON), 608 PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON),
524 widest_name_column_view_width_); 609 static_cast<int>(
610 DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION_BUTTON),
611 widest_name_column_view_width_);
612 } else if (state()->shipping_profiles().size() == 1) {
613 base::string16 truncated_content =
614 state()->shipping_profiles()[0]->ConstructInferredLabel(
615 {
616 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2,
617 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE,
618 autofill::ADDRESS_HOME_COUNTRY,
619 },
620 6, state()->GetApplicationLocale());
621 section = CreatePaymentSheetRowWithButton(
622 this, GetShippingAddressSectionString(spec()->shipping_type()),
623 truncated_content, button_string,
624 static_cast<int>(
625 PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON),
626 static_cast<int>(
627 DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION_BUTTON),
628 widest_name_column_view_width_);
629 } else {
630 base::string16 format = l10n_util::GetPluralStringFUTF16(
631 IDS_PAYMENT_REQUEST_SHIPPING_ADDRESSES_PREVIEW,
632 state()->shipping_profiles().size() - 1);
633 base::string16 label =
634 state()->shipping_profiles()[0]->ConstructInferredLabel(
635 {
636 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2,
637 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE,
638 autofill::ADDRESS_HOME_COUNTRY,
639 },
640 6, state()->GetApplicationLocale());
641 section = CreatePaymentSheetRowWithButton(
642 this, GetShippingAddressSectionString(spec()->shipping_type()), label,
643 format, state()->shipping_profiles().size() - 1, button_string,
644 static_cast<int>(
645 PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON),
646 static_cast<int>(
647 DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION_BUTTON),
648 widest_name_column_view_width_);
649 }
525 } 650 }
526 651
527 return section; 652 return section;
528 } 653 }
529 654
530 // Creates the Payment Method row, which contains a "Payment" label, the user's 655 // Creates the Payment Method row, which contains a "Payment" label, the user's
531 // masked Credit Card details, the icon for the selected card, and a chevron. 656 // 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 657 // If no option is selected or none is available, the Chevron and icon are
533 // replaced with a button 658 // replaced with a button
534 // +----------------------------------------------+ 659 // +----------------------------------------------+
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 std::move(content_view), std::move(card_icon_view), 693 std::move(content_view), std::move(card_icon_view),
569 static_cast<int>( 694 static_cast<int>(
570 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON), 695 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON),
571 static_cast<int>(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION), 696 static_cast<int>(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION),
572 widest_name_column_view_width_); 697 widest_name_column_view_width_);
573 } else { 698 } else {
574 base::string16 button_string = state()->available_instruments().size() 699 base::string16 button_string = state()->available_instruments().size()
575 ? l10n_util::GetStringUTF16(IDS_CHOOSE) 700 ? l10n_util::GetStringUTF16(IDS_CHOOSE)
576 : l10n_util::GetStringUTF16(IDS_ADD); 701 : l10n_util::GetStringUTF16(IDS_ADD);
577 702
578 section = CreatePaymentSheetRowWithButton( 703 if (state()->available_instruments().size() == 0) {
Mathieu 2017/04/24 19:09:01 I like .empty()
anthonyvd 2017/04/24 20:24:26 Done.
579 this, 704 section = CreatePaymentSheetRowWithButton(
580 l10n_util::GetStringUTF16( 705 this,
581 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), 706 l10n_util::GetStringUTF16(
582 base::ASCIIToUTF16(""), button_string, 707 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME),
583 static_cast<int>( 708 base::ASCIIToUTF16(""), button_string,
584 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON), 709 static_cast<int>(
585 static_cast<int>( 710 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON),
586 DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION_BUTTON), 711 static_cast<int>(
587 widest_name_column_view_width_); 712 DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION_BUTTON),
713 widest_name_column_view_width_);
714 } else if (state()->available_instruments().size() == 1) {
715 section = CreatePaymentSheetRowWithButton(
716 this,
717 l10n_util::GetStringUTF16(
718 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME),
719 state()->available_instruments()[0]->label(), button_string,
720 static_cast<int>(
721 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON),
722 static_cast<int>(
723 DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION_BUTTON),
724 widest_name_column_view_width_);
725 } else {
726 base::string16 format = l10n_util::GetPluralStringFUTF16(
727 IDS_PAYMENT_REQUEST_PAYMENT_METHODS_PREVIEW,
728 state()->available_instruments().size() - 1);
729 section = CreatePaymentSheetRowWithButton(
730 this,
731 l10n_util::GetStringUTF16(
732 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME),
733 state()->available_instruments()[0]->label(), format,
734 state()->available_instruments().size() - 1, button_string,
735 static_cast<int>(
736 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON),
737 static_cast<int>(
738 DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION_BUTTON),
739 widest_name_column_view_width_);
740 }
588 } 741 }
589 742
590 return section; 743 return section;
591 } 744 }
592 745
593 std::unique_ptr<views::View> 746 std::unique_ptr<views::View>
594 PaymentSheetViewController::CreateContactInfoSectionContent() { 747 PaymentSheetViewController::CreateContactInfoSectionContent() {
595 autofill::AutofillProfile* profile = state()->selected_contact_profile(); 748 autofill::AutofillProfile* profile = state()->selected_contact_profile();
596 return profile ? payments::GetContactInfoLabel( 749 return profile ? payments::GetContactInfoLabel(
597 AddressStyleType::SUMMARY, 750 AddressStyleType::SUMMARY,
(...skipping 19 matching lines...) Expand all
617 CreateContactInfoSectionContent(), nullptr, 770 CreateContactInfoSectionContent(), nullptr,
618 static_cast<int>( 771 static_cast<int>(
619 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON), 772 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON),
620 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION), 773 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION),
621 widest_name_column_view_width_); 774 widest_name_column_view_width_);
622 } else { 775 } else {
623 base::string16 button_string = state()->contact_profiles().size() 776 base::string16 button_string = state()->contact_profiles().size()
624 ? l10n_util::GetStringUTF16(IDS_CHOOSE) 777 ? l10n_util::GetStringUTF16(IDS_CHOOSE)
625 : l10n_util::GetStringUTF16(IDS_ADD); 778 : l10n_util::GetStringUTF16(IDS_ADD);
626 779
627 section = CreatePaymentSheetRowWithButton( 780 if (state()->contact_profiles().size() == 0) {
628 this, 781 section = CreatePaymentSheetRowWithButton(
629 l10n_util::GetStringUTF16( 782 this,
630 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), 783 l10n_util::GetStringUTF16(
631 base::ASCIIToUTF16(""), button_string, 784 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME),
632 static_cast<int>( 785 base::ASCIIToUTF16(""), button_string,
633 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON), 786 static_cast<int>(
634 static_cast<int>( 787 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON),
635 DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION_BUTTON), 788 static_cast<int>(
636 widest_name_column_view_width_); 789 DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION_BUTTON),
790 widest_name_column_view_width_);
791 } else if (state()->contact_profiles().size() == 1) {
792 base::string16 truncated_content =
793 state()->contact_profiles()[0]->ConstructInferredLabel(
794 {
795 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2,
796 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE,
797 autofill::ADDRESS_HOME_COUNTRY,
798 },
799 6, state()->GetApplicationLocale());
800 section = CreatePaymentSheetRowWithButton(
801 this,
802 l10n_util::GetStringUTF16(
803 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME),
804 truncated_content, button_string,
805 static_cast<int>(
806 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON),
807 static_cast<int>(
808 DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION_BUTTON),
809 widest_name_column_view_width_);
810 } else {
811 base::string16 preview =
812 state()->contact_profiles()[0]->ConstructInferredLabel(
813 {
814 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2,
815 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE,
816 autofill::ADDRESS_HOME_COUNTRY,
817 },
818 6, state()->GetApplicationLocale());
819 base::string16 format = l10n_util::GetPluralStringFUTF16(
820 IDS_PAYMENT_REQUEST_CONTACTS_PREVIEW,
821 state()->contact_profiles().size() - 1);
822 section = CreatePaymentSheetRowWithButton(
823 this,
824 l10n_util::GetStringUTF16(
825 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME),
826 preview, format, state()->contact_profiles().size() - 1,
827 button_string,
828 static_cast<int>(
829 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON),
830 static_cast<int>(
831 DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION_BUTTON),
832 widest_name_column_view_width_);
833 }
637 } 834 }
638 835
639 return section; 836 return section;
640 } 837 }
641 838
642 std::unique_ptr<views::Button> 839 std::unique_ptr<views::Button>
643 PaymentSheetViewController::CreateShippingOptionRow() { 840 PaymentSheetViewController::CreateShippingOptionRow() {
644 mojom::PaymentShippingOption* selected_option = 841 mojom::PaymentShippingOption* selected_option =
645 spec()->selected_shipping_option(); 842 spec()->selected_shipping_option();
646 // The shipping option section displays the currently selected option if there 843 // The shipping option section displays the currently selected option if there
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON), 877 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON),
681 static_cast<int>( 878 static_cast<int>(
682 DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION_BUTTON), 879 DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION_BUTTON),
683 widest_name_column_view_width_); 880 widest_name_column_view_width_);
684 } 881 }
685 882
686 return section; 883 return section;
687 } 884 }
688 885
689 } // namespace payments 886 } // namespace payments
OLDNEW
« no previous file with comments | « chrome/android/java/strings/android_chrome_strings.grd ('k') | components/payments_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698