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

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

Issue 2838193004: [Web Payments] Implement placeholders in the shipping options row (Closed)
Patch Set: Remove unused variable 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>
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 layout->AddView(extra_content_view.release()); 200 layout->AddView(extra_content_view.release());
201 } else { 201 } else {
202 layout->SkipColumns(1); 202 layout->SkipColumns(1);
203 } 203 }
204 204
205 layout->AddView(trailing_button.release()); 205 layout->AddView(trailing_button.release());
206 206
207 return std::move(row); 207 return std::move(row);
208 } 208 }
209 209
210 // Creates a row with a button in place of the chevron. 210 // A class used to build Payment Sheet Rows. Construct an instance of it, chain
211 // +------------------------------------------+ 211 // calls to argument-setting functions, then call one of the CreateWith*
212 // | Name | content_view | button_string | 212 // functions to create the row view.
213 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ 213 class PaymentSheetRowBuilder {
214 std::unique_ptr<views::Button> CreatePaymentSheetRowWithButton( 214 public:
215 views::ButtonListener* listener, 215 PaymentSheetRowBuilder(views::ButtonListener* listener,
216 const base::string16& section_name, 216 const base::string16& section_name,
217 std::unique_ptr<views::View> content_view, 217 int name_column_width)
218 const base::string16& button_string, 218 : listener_(listener),
219 int button_tag, 219 section_name_(section_name),
220 int button_id, 220 name_column_width_(name_column_width) {}
221 int name_column_width) {
222 std::unique_ptr<views::Button> button(
223 views::MdTextButton::CreateSecondaryUiBlueButton(listener,
224 button_string));
225 button->set_tag(button_tag);
226 button->set_id(button_id);
227 return CreatePaymentSheetRow(listener, section_name, std::move(content_view),
228 nullptr, std::move(button),
229 /*clickable=*/false, name_column_width);
230 }
231 221
232 // Creates a row with a button in place of the chevron and |truncated_content| 222 PaymentSheetRowBuilder& Tag(PaymentSheetViewControllerTags tag) {
233 // between |section_name| and the button. 223 tag_ = static_cast<int>(tag);
234 // +------------------------------------------+ 224 return *this;
235 // | Name | truncated_content | button_string | 225 }
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 226
253 // Creates a row with a button in place of the chevron with the string between 227 PaymentSheetRowBuilder& Id(DialogViewID id) {
254 // |section_name| and the button built as "|preview|... and |n| more". 228 id_ = static_cast<int>(id);
255 // |format_string| is used to assemble the truncated preview and the rest of the 229 return *this;
256 // content string. 230 }
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 231
278 // Creates a clickable row to be displayed in the Payment Sheet. It contains 232 // Creates a clickable row to be displayed in the Payment Sheet. It contains
279 // a section name and some content, followed by a chevron as a clickability 233 // a section name and some content, followed by a chevron as a clickability
280 // affordance. Both, either, or none of |content_view| and |extra_content_view| 234 // affordance. Both, either, or none of |content_view| and
281 // may be present, the difference between the two being that content is pinned 235 // |extra_content_view| may be present, the difference between the two being
282 // to the left and extra_content is pinned to the right. 236 // that content is pinned to the left and extra_content is pinned to the
283 // The row also displays a light gray horizontal ruler on its lower boundary. 237 // right. The row also displays a light gray horizontal ruler on its lower
284 // The name column has a fixed width equal to |name_column_width|. 238 // boundary. The name column has a fixed width equal to |name_column_width|.
285 // +----------------------------+ 239 // +----------------------------+
286 // | Name | Content | Extra | > | 240 // | Name | Content | Extra | > |
287 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ <-- ruler 241 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ <-- ruler
288 std::unique_ptr<views::Button> CreatePaymentSheetRowWithChevron( 242 std::unique_ptr<views::Button> CreateWithChevron(
289 views::ButtonListener* listener, 243 std::unique_ptr<views::View> content_view,
290 const base::string16& section_name, 244 std::unique_ptr<views::View> extra_content_view) {
291 std::unique_ptr<views::View> content_view, 245 std::unique_ptr<views::ImageView> chevron =
292 std::unique_ptr<views::View> extra_content_view, 246 base::MakeUnique<views::ImageView>();
293 int section_tag, 247 chevron->set_can_process_events_within_subtree(false);
294 int section_id, 248 std::unique_ptr<views::Label> label =
295 int name_column_width) { 249 base::MakeUnique<views::Label>(section_name_);
296 std::unique_ptr<views::ImageView> chevron = 250 chevron->SetImage(gfx::CreateVectorIcon(
297 base::MakeUnique<views::ImageView>(); 251 views::kSubmenuArrowIcon,
298 chevron->set_can_process_events_within_subtree(false); 252 color_utils::DeriveDefaultIconColor(label->enabled_color())));
299 std::unique_ptr<views::Label> label = 253 std::unique_ptr<views::Button> section =
300 base::MakeUnique<views::Label>(section_name); 254 CreatePaymentSheetRow(listener_, section_name_, std::move(content_view),
301 chevron->SetImage(gfx::CreateVectorIcon( 255 std::move(extra_content_view), std::move(chevron),
302 views::kSubmenuArrowIcon, 256 /*clickable=*/true, name_column_width_);
303 color_utils::DeriveDefaultIconColor(label->enabled_color()))); 257 section->set_tag(tag_);
304 std::unique_ptr<views::Button> section = 258 section->set_id(id_);
305 CreatePaymentSheetRow(listener, section_name, std::move(content_view), 259 return section;
306 std::move(extra_content_view), std::move(chevron), 260 }
307 /*clickable=*/true, name_column_width); 261
308 section->set_tag(section_tag); 262 // Creates a row with a button in place of the chevron and |truncated_content|
309 section->set_id(section_id); 263 // between |section_name| and the button.
310 return section; 264 // +------------------------------------------+
311 } 265 // | Name | truncated_content | button_string |
266 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
267 std::unique_ptr<views::Button> CreateWithButton(
268 const base::string16& truncated_content,
269 const base::string16& button_string,
270 bool button_enabled) {
271 std::unique_ptr<views::Label> content_view =
272 base::MakeUnique<views::Label>(truncated_content);
273 content_view->SetHorizontalAlignment(gfx::ALIGN_LEFT);
274 return CreateWithButton(std::move(content_view), button_string,
275 button_enabled);
276 }
277
278 // Creates a row with a button in place of the chevron with the string between
279 // |section_name| and the button built as "|preview|... and |n| more".
280 // |format_string| is used to assemble the truncated preview and the rest of
281 // the content string.
282 // +----------------------------------------------+
283 // | Name | preview... and N more | button_string |
284 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
285 std::unique_ptr<views::Button> CreateWithButton(
286 const base::string16& preview_text,
287 const base::string16& format_string,
288 int n,
289 const base::string16& button_string,
290 bool button_enabled) {
291 std::unique_ptr<PreviewEliderLabel> content_view =
292 base::MakeUnique<PreviewEliderLabel>(preview_text, format_string, n);
293 content_view->SetHorizontalAlignment(gfx::ALIGN_LEFT);
294 return CreateWithButton(std::move(content_view), button_string,
295 button_enabled);
296 }
297
298 private:
299 // Creates a row with a button in place of the chevron.
300 // +------------------------------------------+
301 // | Name | content_view | button_string |
302 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
303 std::unique_ptr<views::Button> CreateWithButton(
304 std::unique_ptr<views::View> content_view,
305 const base::string16& button_string,
306 bool button_enabled) {
307 std::unique_ptr<views::Button> button(
308 views::MdTextButton::CreateSecondaryUiBlueButton(listener_,
309 button_string));
310 button->set_tag(tag_);
311 button->set_id(id_);
312 button->SetEnabled(button_enabled);
313 return CreatePaymentSheetRow(listener_, section_name_,
314 std::move(content_view), nullptr,
315 std::move(button),
316 /*clickable=*/false, name_column_width_);
317 }
318
319 views::ButtonListener* listener_;
320 base::string16 section_name_;
321 int name_column_width_;
322 int tag_;
323 int id_;
324 DISALLOW_COPY_AND_ASSIGN(PaymentSheetRowBuilder);
325 };
312 326
313 // Creates a GridLayout object to be used in the Order Summary section's list of 327 // Creates a GridLayout object to be used in the Order Summary section's list of
314 // items and the list of prices. |host| is the view that will be assigned the 328 // items and the list of prices. |host| is the view that will be assigned the
315 // returned Layout Manager and |trailing| indicates whether the elements added 329 // returned Layout Manager and |trailing| indicates whether the elements added
316 // to the manager should have trailing horizontal alignment. If trailing is 330 // to the manager should have trailing horizontal alignment. If trailing is
317 // |false|, their horizontal alignment is leading. 331 // |false|, their horizontal alignment is leading.
318 std::unique_ptr<views::GridLayout> CreateOrderSummarySectionContainerLayout( 332 std::unique_ptr<views::GridLayout> CreateOrderSummarySectionContainerLayout(
319 views::View* host, 333 views::View* host,
320 bool trailing) { 334 bool trailing) {
321 std::unique_ptr<views::GridLayout> layout = 335 std::unique_ptr<views::GridLayout> layout =
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 CreateBoldLabel(l10n_util::GetStringFUTF16( 572 CreateBoldLabel(l10n_util::GetStringFUTF16(
559 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, 573 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT,
560 base::UTF8ToUTF16(spec()->GetFormattedCurrencyCode()), 574 base::UTF8ToUTF16(spec()->GetFormattedCurrencyCode()),
561 spec()->GetFormattedCurrencyAmount( 575 spec()->GetFormattedCurrencyAmount(
562 spec()->details().total->amount->value))) 576 spec()->details().total->amount->value)))
563 .release()); 577 .release());
564 578
565 item_summaries->SetLayoutManager(item_summaries_layout.release()); 579 item_summaries->SetLayoutManager(item_summaries_layout.release());
566 item_amounts->SetLayoutManager(item_amounts_layout.release()); 580 item_amounts->SetLayoutManager(item_amounts_layout.release());
567 581
568 std::unique_ptr<views::Button> section = CreatePaymentSheetRowWithChevron( 582 PaymentSheetRowBuilder builder(
569 this, 583 this,
570 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), 584 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME),
571 std::move(item_summaries), std::move(item_amounts),
572 static_cast<int>(
573 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON),
574 static_cast<int>(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION),
575 widest_name_column_view_width_); 585 widest_name_column_view_width_);
576 return section; 586 builder.Tag(PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)
587 .Id(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION);
588
589 return builder.CreateWithChevron(std::move(item_summaries),
590 std::move(item_amounts));
577 } 591 }
578 592
579 std::unique_ptr<views::View> 593 std::unique_ptr<views::View>
580 PaymentSheetViewController::CreateShippingSectionContent() { 594 PaymentSheetViewController::CreateShippingSectionContent() {
581 if (current_update_reason_ == 595 if (current_update_reason_ ==
582 PaymentRequestSpec::UpdateReason::SHIPPING_ADDRESS) { 596 PaymentRequestSpec::UpdateReason::SHIPPING_ADDRESS) {
583 return CreateCheckingSpinnerView(); 597 return CreateCheckingSpinnerView();
584 } else { 598 } else {
585 auto* profile = state()->selected_shipping_profile(); 599 auto* profile = state()->selected_shipping_profile();
586 600
587 return profile ? GetShippingAddressLabel(AddressStyleType::SUMMARY, 601 return profile ? GetShippingAddressLabel(AddressStyleType::SUMMARY,
588 state()->GetApplicationLocale(), 602 state()->GetApplicationLocale(),
589 *profile) 603 *profile)
590 : base::MakeUnique<views::Label>(base::string16()); 604 : base::MakeUnique<views::Label>(base::string16());
591 } 605 }
592 } 606 }
593 607
594 // Creates the Shipping row, which contains a "Shipping address" label, the 608 // Creates the Shipping row, which contains a "Shipping address" label, the
595 // user's selected shipping address, and a chevron. 609 // user's selected shipping address, and a chevron.
596 // +----------------------------------------------+ 610 // +----------------------------------------------+
597 // | Shipping Address Barack Obama | 611 // | Shipping Address Barack Obama |
598 // | 1600 Pennsylvania Ave. > | 612 // | 1600 Pennsylvania Ave. > |
599 // | 1800MYPOTUS | 613 // | 1800MYPOTUS |
600 // +----------------------------------------------+ 614 // +----------------------------------------------+
601 std::unique_ptr<views::Button> PaymentSheetViewController::CreateShippingRow() { 615 std::unique_ptr<views::Button> PaymentSheetViewController::CreateShippingRow() {
602 std::unique_ptr<views::Button> section; 616 std::unique_ptr<views::Button> section;
617 PaymentSheetRowBuilder builder(
618 this, GetShippingAddressSectionString(spec()->shipping_type()),
619 widest_name_column_view_width_);
620 builder.Tag(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON);
603 if (state()->selected_shipping_profile()) { 621 if (state()->selected_shipping_profile()) {
604 section = CreatePaymentSheetRowWithChevron( 622 builder.Id(DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION);
605 this, GetShippingAddressSectionString(spec()->shipping_type()), 623 return builder.CreateWithChevron(CreateShippingSectionContent(), nullptr);
606 CreateShippingSectionContent(), nullptr,
607 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON),
608 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION),
609 widest_name_column_view_width_);
610 } else { 624 } else {
625 builder.Id(DialogViewID::PAYMENT_SHEET_SHIPPING_ADDRESS_SECTION_BUTTON);
611 base::string16 button_string = state()->shipping_profiles().size() 626 base::string16 button_string = state()->shipping_profiles().size()
612 ? l10n_util::GetStringUTF16(IDS_CHOOSE) 627 ? l10n_util::GetStringUTF16(IDS_CHOOSE)
613 : l10n_util::GetStringUTF16(IDS_ADD); 628 : l10n_util::GetStringUTF16(IDS_ADD);
614
615 if (state()->shipping_profiles().empty()) { 629 if (state()->shipping_profiles().empty()) {
616 section = CreatePaymentSheetRowWithButton( 630 return builder.CreateWithButton(base::ASCIIToUTF16(""), button_string,
617 this, GetShippingAddressSectionString(spec()->shipping_type()), 631 /*button_enabled=*/true);
618 base::ASCIIToUTF16(""), button_string,
619 static_cast<int>(
620 PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON),
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) { 632 } else if (state()->shipping_profiles().size() == 1) {
625 base::string16 truncated_content = 633 base::string16 truncated_content =
626 state()->shipping_profiles()[0]->ConstructInferredLabel( 634 state()->shipping_profiles()[0]->ConstructInferredLabel(
627 { 635 {
628 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2, 636 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2,
629 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE, 637 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE,
630 autofill::ADDRESS_HOME_COUNTRY, 638 autofill::ADDRESS_HOME_COUNTRY,
631 }, 639 },
632 6, state()->GetApplicationLocale()); 640 6, state()->GetApplicationLocale());
633 section = CreatePaymentSheetRowWithButton( 641 return builder.CreateWithButton(truncated_content, button_string,
634 this, GetShippingAddressSectionString(spec()->shipping_type()), 642 /*button_enabled=*/true);
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 { 643 } else {
642 base::string16 format = l10n_util::GetPluralStringFUTF16( 644 base::string16 format = l10n_util::GetPluralStringFUTF16(
643 IDS_PAYMENT_REQUEST_SHIPPING_ADDRESSES_PREVIEW, 645 IDS_PAYMENT_REQUEST_SHIPPING_ADDRESSES_PREVIEW,
644 state()->shipping_profiles().size() - 1); 646 state()->shipping_profiles().size() - 1);
645 base::string16 label = 647 base::string16 label =
646 state()->shipping_profiles()[0]->ConstructInferredLabel( 648 state()->shipping_profiles()[0]->ConstructInferredLabel(
647 { 649 {
648 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2, 650 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2,
649 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE, 651 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE,
650 autofill::ADDRESS_HOME_COUNTRY, 652 autofill::ADDRESS_HOME_COUNTRY,
651 }, 653 },
652 6, state()->GetApplicationLocale()); 654 6, state()->GetApplicationLocale());
653 section = CreatePaymentSheetRowWithButton( 655 return builder.CreateWithButton(
654 this, GetShippingAddressSectionString(spec()->shipping_type()), label, 656 label, format, state()->shipping_profiles().size() - 1, button_string,
655 format, state()->shipping_profiles().size() - 1, button_string, 657 /*button_enabled=*/true);
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 } 658 }
662 } 659 }
663
664 return section;
665 } 660 }
666 661
667 // Creates the Payment Method row, which contains a "Payment" label, the user's 662 // Creates the Payment Method row, which contains a "Payment" label, the user's
668 // masked Credit Card details, the icon for the selected card, and a chevron. 663 // masked Credit Card details, the icon for the selected card, and a chevron.
669 // If no option is selected or none is available, the Chevron and icon are 664 // If no option is selected or none is available, the Chevron and icon are
670 // replaced with a button 665 // replaced with a button
671 // +----------------------------------------------+ 666 // +----------------------------------------------+
672 // | Payment Visa ****0000 | 667 // | Payment Visa ****0000 |
673 // | John Smith | VISA | > | 668 // | John Smith | VISA | > |
674 // | | 669 // | |
675 // +----------------------------------------------+ 670 // +----------------------------------------------+
676 std::unique_ptr<views::Button> 671 std::unique_ptr<views::Button>
677 PaymentSheetViewController::CreatePaymentMethodRow() { 672 PaymentSheetViewController::CreatePaymentMethodRow() {
678 PaymentInstrument* selected_instrument = state()->selected_instrument(); 673 PaymentInstrument* selected_instrument = state()->selected_instrument();
679 674
680 std::unique_ptr<views::View> content_view; 675 PaymentSheetRowBuilder builder(
681 std::unique_ptr<views::ImageView> card_icon_view; 676 this,
682 std::unique_ptr<views::Button> section; 677 l10n_util::GetStringUTF16(
678 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME),
679 widest_name_column_view_width_);
680 builder.Tag(PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON);
681
683 if (selected_instrument) { 682 if (selected_instrument) {
684 content_view = base::MakeUnique<views::View>(); 683 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>();
685 684
686 views::GridLayout* layout = new views::GridLayout(content_view.get()); 685 views::GridLayout* layout = new views::GridLayout(content_view.get());
687 content_view->SetLayoutManager(layout); 686 content_view->SetLayoutManager(layout);
688 views::ColumnSet* columns = layout->AddColumnSet(0); 687 views::ColumnSet* columns = layout->AddColumnSet(0);
689 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 688 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
690 1, views::GridLayout::USE_PREF, 0, 0); 689 1, views::GridLayout::USE_PREF, 0, 0);
691 690
692 layout->StartRow(0, 0); 691 layout->StartRow(0, 0);
693 layout->AddView(new views::Label(selected_instrument->label())); 692 layout->AddView(new views::Label(selected_instrument->label()));
694 layout->StartRow(0, 0); 693 layout->StartRow(0, 0);
695 layout->AddView(new views::Label(selected_instrument->sublabel())); 694 layout->AddView(new views::Label(selected_instrument->sublabel()));
696 695
697 card_icon_view = CreateInstrumentIconView( 696 std::unique_ptr<views::ImageView> card_icon_view = CreateInstrumentIconView(
698 selected_instrument->icon_resource_id(), selected_instrument->label()); 697 selected_instrument->icon_resource_id(), selected_instrument->label());
699 card_icon_view->SetImageSize(gfx::Size(32, 20)); 698 card_icon_view->SetImageSize(gfx::Size(32, 20));
700 699
701 section = CreatePaymentSheetRowWithChevron( 700 return builder.Id(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION)
702 this, 701 .CreateWithChevron(std::move(content_view), std::move(card_icon_view));
703 l10n_util::GetStringUTF16(
704 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME),
705 std::move(content_view), std::move(card_icon_view),
706 static_cast<int>(
707 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON),
708 static_cast<int>(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION),
709 widest_name_column_view_width_);
710 } else { 702 } else {
703 builder.Id(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION_BUTTON);
711 base::string16 button_string = state()->available_instruments().size() 704 base::string16 button_string = state()->available_instruments().size()
712 ? l10n_util::GetStringUTF16(IDS_CHOOSE) 705 ? l10n_util::GetStringUTF16(IDS_CHOOSE)
713 : l10n_util::GetStringUTF16(IDS_ADD); 706 : l10n_util::GetStringUTF16(IDS_ADD);
714 707
715 if (state()->available_instruments().empty()) { 708 if (state()->available_instruments().empty()) {
716 section = CreatePaymentSheetRowWithButton( 709 return builder.CreateWithButton(base::ASCIIToUTF16(""), button_string,
717 this, 710 /*button_enabled=*/true);
718 l10n_util::GetStringUTF16(
719 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME),
720 base::ASCIIToUTF16(""), button_string,
721 static_cast<int>(
722 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON),
723 static_cast<int>(
724 DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION_BUTTON),
725 widest_name_column_view_width_);
726 } else if (state()->available_instruments().size() == 1) { 711 } else if (state()->available_instruments().size() == 1) {
727 section = CreatePaymentSheetRowWithButton( 712 return builder.CreateWithButton(
728 this,
729 l10n_util::GetStringUTF16(
730 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME),
731 state()->available_instruments()[0]->label(), button_string, 713 state()->available_instruments()[0]->label(), button_string,
732 static_cast<int>( 714 /*button_enabled=*/true);
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 { 715 } else {
738 base::string16 format = l10n_util::GetPluralStringFUTF16( 716 base::string16 format = l10n_util::GetPluralStringFUTF16(
739 IDS_PAYMENT_REQUEST_PAYMENT_METHODS_PREVIEW, 717 IDS_PAYMENT_REQUEST_PAYMENT_METHODS_PREVIEW,
740 state()->available_instruments().size() - 1); 718 state()->available_instruments().size() - 1);
741 section = CreatePaymentSheetRowWithButton( 719 return builder.CreateWithButton(
742 this,
743 l10n_util::GetStringUTF16(
744 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME),
745 state()->available_instruments()[0]->label(), format, 720 state()->available_instruments()[0]->label(), format,
746 state()->available_instruments().size() - 1, button_string, 721 state()->available_instruments().size() - 1, button_string,
747 static_cast<int>( 722 /*button_enabled=*/true);
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 } 723 }
753 } 724 }
754
755 return section;
756 } 725 }
757 726
758 std::unique_ptr<views::View> 727 std::unique_ptr<views::View>
759 PaymentSheetViewController::CreateContactInfoSectionContent() { 728 PaymentSheetViewController::CreateContactInfoSectionContent() {
760 autofill::AutofillProfile* profile = state()->selected_contact_profile(); 729 autofill::AutofillProfile* profile = state()->selected_contact_profile();
761 return profile ? payments::GetContactInfoLabel( 730 return profile ? payments::GetContactInfoLabel(
762 AddressStyleType::SUMMARY, 731 AddressStyleType::SUMMARY,
763 state()->GetApplicationLocale(), *profile, *spec()) 732 state()->GetApplicationLocale(), *profile, *spec())
764 : base::MakeUnique<views::Label>(base::string16()); 733 : base::MakeUnique<views::Label>(base::string16());
765 } 734 }
766 735
767 // Creates the Contact Info row, which contains a "Contact info" label; the 736 // Creates the Contact Info row, which contains a "Contact info" label; the
768 // name, email address, and/or phone number; and a chevron. 737 // name, email address, and/or phone number; and a chevron.
769 // +----------------------------------------------+ 738 // +----------------------------------------------+
770 // | Contact info Barack Obama | 739 // | Contact info Barack Obama |
771 // | 1800MYPOTUS > | 740 // | 1800MYPOTUS > |
772 // | potus@whitehouse.gov | 741 // | potus@whitehouse.gov |
773 // +----------------------------------------------+ 742 // +----------------------------------------------+
774 std::unique_ptr<views::Button> 743 std::unique_ptr<views::Button>
775 PaymentSheetViewController::CreateContactInfoRow() { 744 PaymentSheetViewController::CreateContactInfoRow() {
776 std::unique_ptr<views::Button> section; 745 PaymentSheetRowBuilder builder(
746 this,
747 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME),
748 widest_name_column_view_width_);
749 builder.Tag(PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON);
750
777 if (state()->selected_contact_profile()) { 751 if (state()->selected_contact_profile()) {
778 section = CreatePaymentSheetRowWithChevron( 752 return builder.Id(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)
779 this, 753 .CreateWithChevron(CreateContactInfoSectionContent(), nullptr);
780 l10n_util::GetStringUTF16(
781 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME),
782 CreateContactInfoSectionContent(), nullptr,
783 static_cast<int>(
784 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON),
785 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION),
786 widest_name_column_view_width_);
787 } else { 754 } else {
755 builder.Id(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION_BUTTON);
788 base::string16 button_string = state()->contact_profiles().size() 756 base::string16 button_string = state()->contact_profiles().size()
789 ? l10n_util::GetStringUTF16(IDS_CHOOSE) 757 ? l10n_util::GetStringUTF16(IDS_CHOOSE)
790 : l10n_util::GetStringUTF16(IDS_ADD); 758 : l10n_util::GetStringUTF16(IDS_ADD);
791 759
792 if (state()->contact_profiles().empty()) { 760 if (state()->contact_profiles().empty()) {
793 section = CreatePaymentSheetRowWithButton( 761 return builder.CreateWithButton(base::ASCIIToUTF16(""), button_string,
794 this, 762 /*button_enabled=*/true);
795 l10n_util::GetStringUTF16(
796 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME),
797 base::ASCIIToUTF16(""), button_string,
798 static_cast<int>(
799 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON),
800 static_cast<int>(
801 DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION_BUTTON),
802 widest_name_column_view_width_);
803 } else if (state()->contact_profiles().size() == 1) { 763 } else if (state()->contact_profiles().size() == 1) {
804 base::string16 truncated_content = 764 base::string16 truncated_content =
805 state()->contact_profiles()[0]->ConstructInferredLabel( 765 state()->contact_profiles()[0]->ConstructInferredLabel(
806 { 766 {
807 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2, 767 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2,
808 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE, 768 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE,
809 autofill::ADDRESS_HOME_COUNTRY, 769 autofill::ADDRESS_HOME_COUNTRY,
810 }, 770 },
811 6, state()->GetApplicationLocale()); 771 6, state()->GetApplicationLocale());
812 section = CreatePaymentSheetRowWithButton( 772 return builder.CreateWithButton(truncated_content, button_string,
813 this, 773 /*button_enabled=*/true);
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 { 774 } else {
823 base::string16 preview = 775 base::string16 preview =
824 state()->contact_profiles()[0]->ConstructInferredLabel( 776 state()->contact_profiles()[0]->ConstructInferredLabel(
825 { 777 {
826 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2, 778 autofill::ADDRESS_HOME_LINE1, autofill::ADDRESS_HOME_LINE2,
827 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE, 779 autofill::ADDRESS_HOME_CITY, autofill::ADDRESS_HOME_STATE,
828 autofill::ADDRESS_HOME_COUNTRY, 780 autofill::ADDRESS_HOME_COUNTRY,
829 }, 781 },
830 6, state()->GetApplicationLocale()); 782 6, state()->GetApplicationLocale());
831 base::string16 format = l10n_util::GetPluralStringFUTF16( 783 base::string16 format = l10n_util::GetPluralStringFUTF16(
832 IDS_PAYMENT_REQUEST_CONTACTS_PREVIEW, 784 IDS_PAYMENT_REQUEST_CONTACTS_PREVIEW,
833 state()->contact_profiles().size() - 1); 785 state()->contact_profiles().size() - 1);
834 section = CreatePaymentSheetRowWithButton( 786 return builder.CreateWithButton(preview, format,
835 this, 787 state()->contact_profiles().size() - 1,
836 l10n_util::GetStringUTF16( 788 button_string, /*button_enabled=*/true);
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 } 789 }
846 } 790 }
847
848 return section;
849 } 791 }
850 792
851 std::unique_ptr<views::Button> 793 std::unique_ptr<views::Button>
852 PaymentSheetViewController::CreateShippingOptionRow() { 794 PaymentSheetViewController::CreateShippingOptionRow() {
795 // The Shipping Options row has many different ways of being displayed
796 // depending on the state of the dialog and Payment Request.
797 // 1. There is a selected shipping address. The website updated the shipping
798 // options.
799 // 1.1 There are no available shipping options: don't display the row.
800 // 1.2 There are options and one is selected: display the row with the
801 // selection's label and a chevron.
802 // 1.3 There are options and none is selected: display a row with a
803 // choose button and the string "|preview of first option| and N more"
804 // 2. There is no selected shipping address: display a row with the string
805 // "Choose an address" and a disabled Choose button.
853 mojom::PaymentShippingOption* selected_option = 806 mojom::PaymentShippingOption* selected_option =
854 spec()->selected_shipping_option(); 807 spec()->selected_shipping_option();
855 // The shipping option section displays the currently selected option if there 808 // The shipping option section displays the currently selected option if there
856 // is one. It's not possible to select an option without selecting an address 809 // is one. It's not possible to select an option without selecting an address
857 // first. 810 // first.
858 std::unique_ptr<views::Button> section; 811 PaymentSheetRowBuilder builder(
812 this, GetShippingOptionSectionString(spec()->shipping_type()),
813 widest_name_column_view_width_);
814 builder.Tag(PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON);
815
859 if (state()->selected_shipping_profile()) { 816 if (state()->selected_shipping_profile()) {
860 if (spec()->details().shipping_options.empty()) { 817 if (spec()->details().shipping_options.empty()) {
861 // TODO(anthonyvd): Display placeholder if there's no available shipping 818 // TODO(anthonyvd): Display placeholder if there's no available shipping
862 // option. 819 // option.
863 return nullptr; 820 return nullptr;
864 } 821 }
865 822
866 std::unique_ptr<views::View> option_row_content = 823 if (selected_option) {
867 current_update_reason_ == 824 std::unique_ptr<views::View> option_row_content =
868 PaymentRequestSpec::UpdateReason::SHIPPING_OPTION 825 current_update_reason_ ==
869 ? CreateCheckingSpinnerView() 826 PaymentRequestSpec::UpdateReason::SHIPPING_OPTION
870 : CreateShippingOptionLabel( 827 ? CreateCheckingSpinnerView()
871 selected_option, selected_option 828 : CreateShippingOptionLabel(selected_option,
872 ? spec()->GetFormattedCurrencyAmount( 829 spec()->GetFormattedCurrencyAmount(
873 selected_option->amount->value) 830 selected_option->amount->value));
874 : base::ASCIIToUTF16("")); 831 return builder.Id(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)
875 section = CreatePaymentSheetRowWithChevron( 832 .CreateWithChevron(std::move(option_row_content), nullptr);
876 this, GetShippingOptionSectionString(spec()->shipping_type()), 833 } else {
877 std::move(option_row_content), nullptr, 834 return builder
878 static_cast<int>( 835 .Id(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION_BUTTON)
879 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON), 836 .CreateWithButton(
880 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION), 837 base::UTF8ToUTF16(spec()->details().shipping_options[0]->label),
881 widest_name_column_view_width_); 838 l10n_util::GetPluralStringFUTF16(
839 IDS_PAYMENT_REQUEST_SHIPPING_OPTIONS_PREVIEW,
840 spec()->details().shipping_options.size() - 1),
841 spec()->details().shipping_options.size() - 1,
842 l10n_util::GetStringUTF16(IDS_CHOOSE),
843 /*button_enabled=*/true);
844 }
882 } else { 845 } else {
883 // TODO(anthonyvd): This should be a disabled row with a disabled button and 846 return builder
884 // some text to indicate that an address must be selected first. 847 .Id(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION_BUTTON)
885 section = CreatePaymentSheetRowWithButton( 848 .CreateWithButton(
886 this, GetShippingOptionSectionString(spec()->shipping_type()), 849 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CHOOSE_AN_ADDRESS),
887 base::ASCIIToUTF16(""), l10n_util::GetStringUTF16(IDS_CHOOSE), 850 l10n_util::GetStringUTF16(IDS_CHOOSE), /*button_enabled=*/false);
888 static_cast<int>(
889 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON),
890 static_cast<int>(
891 DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION_BUTTON),
892 widest_name_column_view_width_);
893 } 851 }
894
895 return section;
896 } 852 }
897 853
898 } // namespace payments 854 } // 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