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

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: Address comments. Created 3 years, 7 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
« no previous file with comments | « no previous file | components/payments_strings.grdp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 the string with format argument numbers in ICU syntax
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(crbug.com/714776): Display something meaningful if the preview can't
101 // be 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 layout->SkipColumns(1); 202 layout->SkipColumns(1);
150 } 203 }
151 204
152 layout->AddView(trailing_button.release()); 205 layout->AddView(trailing_button.release());
153 206
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 | content_view | 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 // Creates a row with a button in place of the chevron and |truncated_content|
233 // between |section_name| and the button.
234 // +------------------------------------------+
235 // | Name | truncated_content | button_string |
236 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
237 std::unique_ptr<views::Button> CreatePaymentSheetRowWithButton(
238 views::ButtonListener* listener,
239 const base::string16& section_name,
240 const base::string16& truncated_content,
241 const base::string16& button_string,
242 int button_tag,
243 int button_id,
244 int name_column_width) {
245 std::unique_ptr<views::Label> content_view =
246 base::MakeUnique<views::Label>(truncated_content);
247 content_view->SetHorizontalAlignment(gfx::ALIGN_LEFT);
248 return CreatePaymentSheetRowWithButton(
249 listener, section_name, std::move(content_view), button_string,
250 button_tag, button_id, name_column_width);
251 }
252
253 // Creates a row with a button in place of the chevron with the string between
254 // |section_name| and the button built as "|preview|... and |n| more".
255 // |format_string| is used to assemble the truncated preview and the rest of the
256 // content string.
257 // +----------------------------------------------+
258 // | Name | preview... and N more | button_string |
259 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
260 std::unique_ptr<views::Button> CreatePaymentSheetRowWithButton(
261 views::ButtonListener* listener,
262 const base::string16& section_name,
263 const base::string16& preview_text,
264 const base::string16& format_string,
265 int n,
266 const base::string16& button_string,
267 int button_tag,
268 int button_id,
269 int name_column_width) {
270 std::unique_ptr<PreviewEliderLabel> content_view =
271 base::MakeUnique<PreviewEliderLabel>(preview_text, format_string, n);
272 content_view->SetHorizontalAlignment(gfx::ALIGN_LEFT);
273 return CreatePaymentSheetRowWithButton(
274 listener, section_name, std::move(content_view), button_string,
275 button_tag, button_id, name_column_width);
276 }
277
181 // Creates a clickable row to be displayed in the Payment Sheet. It contains 278 // 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 279 // 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| 280 // 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 281 // 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. 282 // 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. 283 // 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|. 284 // The name column has a fixed width equal to |name_column_width|.
188 // +----------------------------+ 285 // +----------------------------+
189 // | Name | Content | Extra | > | 286 // | Name | Content | Extra | > |
190 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ <-- ruler 287 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ <-- ruler
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 this, GetShippingAddressSectionString(spec()->shipping_type()), 605 this, GetShippingAddressSectionString(spec()->shipping_type()),
509 CreateShippingSectionContent(), nullptr, 606 CreateShippingSectionContent(), nullptr,
510 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON), 607 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON),
511 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION), 608 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION),
512 widest_name_column_view_width_); 609 widest_name_column_view_width_);
513 } else { 610 } else {
514 base::string16 button_string = state()->shipping_profiles().size() 611 base::string16 button_string = state()->shipping_profiles().size()
515 ? l10n_util::GetStringUTF16(IDS_CHOOSE) 612 ? l10n_util::GetStringUTF16(IDS_CHOOSE)
516 : l10n_util::GetStringUTF16(IDS_ADD); 613 : l10n_util::GetStringUTF16(IDS_ADD);
517 614
518 section = CreatePaymentSheetRowWithButton( 615 if (state()->shipping_profiles().empty()) {
519 this, GetShippingAddressSectionString(spec()->shipping_type()), 616 section = CreatePaymentSheetRowWithButton(
520 base::ASCIIToUTF16(""), button_string, 617 this, GetShippingAddressSectionString(spec()->shipping_type()),
521 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON), 618 base::ASCIIToUTF16(""), button_string,
522 static_cast<int>( 619 static_cast<int>(
523 DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION_BUTTON), 620 PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON),
524 widest_name_column_view_width_); 621 static_cast<int>(
622 DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION_BUTTON),
623 widest_name_column_view_width_);
624 } else if (state()->shipping_profiles().size() == 1) {
625 base::string16 truncated_content =
626 state()->shipping_profiles()[0]->ConstructInferredLabel(
627 {
628 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2,
629 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE,
630 autofill::ADDRESS_HOME_COUNTRY,
631 },
632 6, state()->GetApplicationLocale());
633 section = CreatePaymentSheetRowWithButton(
634 this, GetShippingAddressSectionString(spec()->shipping_type()),
635 truncated_content, button_string,
636 static_cast<int>(
637 PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON),
638 static_cast<int>(
639 DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION_BUTTON),
640 widest_name_column_view_width_);
641 } else {
642 base::string16 format = l10n_util::GetPluralStringFUTF16(
643 IDS_PAYMENT_REQUEST_SHIPPING_ADDRESSES_PREVIEW,
644 state()->shipping_profiles().size() - 1);
645 base::string16 label =
646 state()->shipping_profiles()[0]->ConstructInferredLabel(
647 {
648 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2,
649 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE,
650 autofill::ADDRESS_HOME_COUNTRY,
651 },
652 6, state()->GetApplicationLocale());
653 section = CreatePaymentSheetRowWithButton(
654 this, GetShippingAddressSectionString(spec()->shipping_type()), label,
655 format, state()->shipping_profiles().size() - 1, button_string,
656 static_cast<int>(
657 PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON),
658 static_cast<int>(
659 DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION_BUTTON),
660 widest_name_column_view_width_);
661 }
525 } 662 }
526 663
527 return section; 664 return section;
528 } 665 }
529 666
530 // Creates the Payment Method row, which contains a "Payment" label, the user's 667 // 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. 668 // 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 669 // If no option is selected or none is available, the Chevron and icon are
533 // replaced with a button 670 // replaced with a button
534 // +----------------------------------------------+ 671 // +----------------------------------------------+
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 std::move(content_view), std::move(card_icon_view), 705 std::move(content_view), std::move(card_icon_view),
569 static_cast<int>( 706 static_cast<int>(
570 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON), 707 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON),
571 static_cast<int>(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION), 708 static_cast<int>(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION),
572 widest_name_column_view_width_); 709 widest_name_column_view_width_);
573 } else { 710 } else {
574 base::string16 button_string = state()->available_instruments().size() 711 base::string16 button_string = state()->available_instruments().size()
575 ? l10n_util::GetStringUTF16(IDS_CHOOSE) 712 ? l10n_util::GetStringUTF16(IDS_CHOOSE)
576 : l10n_util::GetStringUTF16(IDS_ADD); 713 : l10n_util::GetStringUTF16(IDS_ADD);
577 714
578 section = CreatePaymentSheetRowWithButton( 715 if (state()->available_instruments().empty()) {
579 this, 716 section = CreatePaymentSheetRowWithButton(
580 l10n_util::GetStringUTF16( 717 this,
581 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), 718 l10n_util::GetStringUTF16(
582 base::ASCIIToUTF16(""), button_string, 719 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME),
583 static_cast<int>( 720 base::ASCIIToUTF16(""), button_string,
584 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON), 721 static_cast<int>(
585 static_cast<int>( 722 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON),
586 DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION_BUTTON), 723 static_cast<int>(
587 widest_name_column_view_width_); 724 DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION_BUTTON),
725 widest_name_column_view_width_);
726 } else if (state()->available_instruments().size() == 1) {
727 section = CreatePaymentSheetRowWithButton(
728 this,
729 l10n_util::GetStringUTF16(
730 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME),
731 state()->available_instruments()[0]->label(), button_string,
732 static_cast<int>(
733 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON),
734 static_cast<int>(
735 DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION_BUTTON),
736 widest_name_column_view_width_);
737 } else {
738 base::string16 format = l10n_util::GetPluralStringFUTF16(
739 IDS_PAYMENT_REQUEST_PAYMENT_METHODS_PREVIEW,
740 state()->available_instruments().size() - 1);
741 section = CreatePaymentSheetRowWithButton(
742 this,
743 l10n_util::GetStringUTF16(
744 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME),
745 state()->available_instruments()[0]->label(), format,
746 state()->available_instruments().size() - 1, button_string,
747 static_cast<int>(
748 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON),
749 static_cast<int>(
750 DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION_BUTTON),
751 widest_name_column_view_width_);
752 }
588 } 753 }
589 754
590 return section; 755 return section;
591 } 756 }
592 757
593 std::unique_ptr<views::View> 758 std::unique_ptr<views::View>
594 PaymentSheetViewController::CreateContactInfoSectionContent() { 759 PaymentSheetViewController::CreateContactInfoSectionContent() {
595 autofill::AutofillProfile* profile = state()->selected_contact_profile(); 760 autofill::AutofillProfile* profile = state()->selected_contact_profile();
596 return profile ? payments::GetContactInfoLabel( 761 return profile ? payments::GetContactInfoLabel(
597 AddressStyleType::SUMMARY, 762 AddressStyleType::SUMMARY,
(...skipping 19 matching lines...) Expand all
617 CreateContactInfoSectionContent(), nullptr, 782 CreateContactInfoSectionContent(), nullptr,
618 static_cast<int>( 783 static_cast<int>(
619 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON), 784 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON),
620 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION), 785 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION),
621 widest_name_column_view_width_); 786 widest_name_column_view_width_);
622 } else { 787 } else {
623 base::string16 button_string = state()->contact_profiles().size() 788 base::string16 button_string = state()->contact_profiles().size()
624 ? l10n_util::GetStringUTF16(IDS_CHOOSE) 789 ? l10n_util::GetStringUTF16(IDS_CHOOSE)
625 : l10n_util::GetStringUTF16(IDS_ADD); 790 : l10n_util::GetStringUTF16(IDS_ADD);
626 791
627 section = CreatePaymentSheetRowWithButton( 792 if (state()->contact_profiles().empty()) {
628 this, 793 section = CreatePaymentSheetRowWithButton(
629 l10n_util::GetStringUTF16( 794 this,
630 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), 795 l10n_util::GetStringUTF16(
631 base::ASCIIToUTF16(""), button_string, 796 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME),
632 static_cast<int>( 797 base::ASCIIToUTF16(""), button_string,
633 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON), 798 static_cast<int>(
634 static_cast<int>( 799 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON),
635 DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION_BUTTON), 800 static_cast<int>(
636 widest_name_column_view_width_); 801 DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION_BUTTON),
802 widest_name_column_view_width_);
803 } else if (state()->contact_profiles().size() == 1) {
804 base::string16 truncated_content =
805 state()->contact_profiles()[0]->ConstructInferredLabel(
806 {
807 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2,
808 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE,
809 autofill::ADDRESS_HOME_COUNTRY,
810 },
811 6, state()->GetApplicationLocale());
812 section = CreatePaymentSheetRowWithButton(
813 this,
814 l10n_util::GetStringUTF16(
815 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME),
816 truncated_content, button_string,
817 static_cast<int>(
818 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON),
819 static_cast<int>(
820 DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION_BUTTON),
821 widest_name_column_view_width_);
822 } else {
823 base::string16 preview =
824 state()->contact_profiles()[0]->ConstructInferredLabel(
825 {
826 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2,
827 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE,
828 autofill::ADDRESS_HOME_COUNTRY,
829 },
830 6, state()->GetApplicationLocale());
831 base::string16 format = l10n_util::GetPluralStringFUTF16(
832 IDS_PAYMENT_REQUEST_CONTACTS_PREVIEW,
833 state()->contact_profiles().size() - 1);
834 section = CreatePaymentSheetRowWithButton(
835 this,
836 l10n_util::GetStringUTF16(
837 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME),
838 preview, format, state()->contact_profiles().size() - 1,
839 button_string,
840 static_cast<int>(
841 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON),
842 static_cast<int>(
843 DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION_BUTTON),
844 widest_name_column_view_width_);
845 }
637 } 846 }
638 847
639 return section; 848 return section;
640 } 849 }
641 850
642 std::unique_ptr<views::Button> 851 std::unique_ptr<views::Button>
643 PaymentSheetViewController::CreateShippingOptionRow() { 852 PaymentSheetViewController::CreateShippingOptionRow() {
644 mojom::PaymentShippingOption* selected_option = 853 mojom::PaymentShippingOption* selected_option =
645 spec()->selected_shipping_option(); 854 spec()->selected_shipping_option();
646 // The shipping option section displays the currently selected option if there 855 // 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), 889 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON),
681 static_cast<int>( 890 static_cast<int>(
682 DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION_BUTTON), 891 DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION_BUTTON),
683 widest_name_column_view_width_); 892 widest_name_column_view_width_);
684 } 893 }
685 894
686 return section; 895 return section;
687 } 896 }
688 897
689 } // namespace payments 898 } // namespace payments
OLDNEW
« no previous file with comments | « no previous file | components/payments_strings.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698