| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 // request's details, followed by a label indicating "N more items..." if | 345 // request's details, followed by a label indicating "N more items..." if |
| 346 // there are more than 2 items in the details. The total label and amount | 346 // there are more than 2 items in the details. The total label and amount |
| 347 // always follow. | 347 // always follow. |
| 348 constexpr int kMaxNumberOfItemsShown = 2; | 348 constexpr int kMaxNumberOfItemsShown = 2; |
| 349 for (size_t i = 0; i < items.size() && i < kMaxNumberOfItemsShown; ++i) { | 349 for (size_t i = 0; i < items.size() && i < kMaxNumberOfItemsShown; ++i) { |
| 350 item_summaries_layout->StartRow(0, 0); | 350 item_summaries_layout->StartRow(0, 0); |
| 351 item_summaries_layout->AddView( | 351 item_summaries_layout->AddView( |
| 352 new views::Label(base::ASCIIToUTF16(items[i]->label))); | 352 new views::Label(base::ASCIIToUTF16(items[i]->label))); |
| 353 | 353 |
| 354 item_amounts_layout->StartRow(0, 0); | 354 item_amounts_layout->StartRow(0, 0); |
| 355 item_amounts_layout->AddView(new views::Label( | 355 item_amounts_layout->AddView( |
| 356 request()->GetFormattedCurrencyAmount(items[i]->amount->value))); | 356 new views::Label(request()->spec()->GetFormattedCurrencyAmount( |
| 357 items[i]->amount->value))); |
| 357 } | 358 } |
| 358 | 359 |
| 359 int hidden_item_count = items.size() - kMaxNumberOfItemsShown; | 360 int hidden_item_count = items.size() - kMaxNumberOfItemsShown; |
| 360 if (hidden_item_count > 0) { | 361 if (hidden_item_count > 0) { |
| 361 item_summaries_layout->StartRow(0, 0); | 362 item_summaries_layout->StartRow(0, 0); |
| 362 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( | 363 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( |
| 363 l10n_util::GetStringFUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_MORE_ITEMS, | 364 l10n_util::GetStringFUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_MORE_ITEMS, |
| 364 base::IntToString16(hidden_item_count))); | 365 base::IntToString16(hidden_item_count))); |
| 365 label->SetDisabledColor(label->GetNativeTheme()->GetSystemColor( | 366 label->SetDisabledColor(label->GetNativeTheme()->GetSystemColor( |
| 366 ui::NativeTheme::kColorId_LabelDisabledColor)); | 367 ui::NativeTheme::kColorId_LabelDisabledColor)); |
| 367 label->SetEnabled(false); | 368 label->SetEnabled(false); |
| 368 item_summaries_layout->AddView(label.release()); | 369 item_summaries_layout->AddView(label.release()); |
| 369 | 370 |
| 370 item_amounts_layout->StartRow(0, 0); | 371 item_amounts_layout->StartRow(0, 0); |
| 371 item_amounts_layout->AddView(new views::Label(base::ASCIIToUTF16(""))); | 372 item_amounts_layout->AddView(new views::Label(base::ASCIIToUTF16(""))); |
| 372 } | 373 } |
| 373 | 374 |
| 374 item_summaries_layout->StartRow(0, 0); | 375 item_summaries_layout->StartRow(0, 0); |
| 375 item_summaries_layout->AddView( | 376 item_summaries_layout->AddView( |
| 376 CreateBoldLabel( | 377 CreateBoldLabel( |
| 377 base::ASCIIToUTF16(request()->spec()->details().total->label)) | 378 base::ASCIIToUTF16(request()->spec()->details().total->label)) |
| 378 .release()); | 379 .release()); |
| 379 | 380 |
| 380 item_amounts_layout->StartRow(0, 0); | 381 item_amounts_layout->StartRow(0, 0); |
| 381 item_amounts_layout->AddView( | 382 item_amounts_layout->AddView( |
| 382 CreateBoldLabel( | 383 CreateBoldLabel( |
| 383 l10n_util::GetStringFUTF16( | 384 l10n_util::GetStringFUTF16( |
| 384 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, | 385 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, |
| 385 base::UTF8ToUTF16(request()->GetFormattedCurrencyCode()), | 386 base::UTF8ToUTF16(request()->spec()->GetFormattedCurrencyCode()), |
| 386 request()->GetFormattedCurrencyAmount( | 387 request()->spec()->GetFormattedCurrencyAmount( |
| 387 request()->spec()->details().total->amount->value))) | 388 request()->spec()->details().total->amount->value))) |
| 388 .release()); | 389 .release()); |
| 389 | 390 |
| 390 item_summaries->SetLayoutManager(item_summaries_layout.release()); | 391 item_summaries->SetLayoutManager(item_summaries_layout.release()); |
| 391 item_amounts->SetLayoutManager(item_amounts_layout.release()); | 392 item_amounts->SetLayoutManager(item_amounts_layout.release()); |
| 392 | 393 |
| 393 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 394 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( |
| 394 this, | 395 this, |
| 395 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), | 396 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), |
| 396 std::move(item_summaries), std::move(item_amounts), | 397 std::move(item_summaries), std::move(item_amounts), |
| 397 widest_name_column_view_width_); | 398 widest_name_column_view_width_); |
| 398 section->set_tag(static_cast<int>( | 399 section->set_tag(static_cast<int>( |
| 399 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); | 400 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); |
| 400 section->set_id( | 401 section->set_id( |
| 401 static_cast<int>(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION)); | 402 static_cast<int>(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION)); |
| 402 return section; | 403 return section; |
| 403 } | 404 } |
| 404 | 405 |
| 405 std::unique_ptr<views::View> | 406 std::unique_ptr<views::View> |
| 406 PaymentSheetViewController::CreateShippingSectionContent() { | 407 PaymentSheetViewController::CreateShippingSectionContent() { |
| 407 auto* profile = request()->state()->selected_shipping_profile(); | 408 auto* profile = request()->state()->selected_shipping_profile(); |
| 408 | 409 |
| 409 return profile ? payments::GetShippingAddressLabel( | 410 return profile ? payments::GetShippingAddressLabel( |
| 410 AddressStyleType::SUMMARY, | 411 AddressStyleType::SUMMARY, |
| 411 request()->GetApplicationLocale(), *profile) | 412 request()->state()->GetApplicationLocale(), *profile) |
| 412 : base::MakeUnique<views::Label>(base::string16()); | 413 : base::MakeUnique<views::Label>(base::string16()); |
| 413 } | 414 } |
| 414 | 415 |
| 415 // Creates the Shipping row, which contains a "Shipping address" label, the | 416 // Creates the Shipping row, which contains a "Shipping address" label, the |
| 416 // user's selected shipping address, and a chevron. | 417 // user's selected shipping address, and a chevron. |
| 417 // +----------------------------------------------+ | 418 // +----------------------------------------------+ |
| 418 // | Shipping Address Barack Obama | | 419 // | Shipping Address Barack Obama | |
| 419 // | 1600 Pennsylvania Ave. > | | 420 // | 1600 Pennsylvania Ave. > | |
| 420 // | 1800MYPOTUS | | 421 // | 1800MYPOTUS | |
| 421 // +----------------------------------------------+ | 422 // +----------------------------------------------+ |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 widest_name_column_view_width_); | 478 widest_name_column_view_width_); |
| 478 section->set_tag(static_cast<int>( | 479 section->set_tag(static_cast<int>( |
| 479 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON)); | 480 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON)); |
| 480 section->set_id( | 481 section->set_id( |
| 481 static_cast<int>(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION)); | 482 static_cast<int>(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION)); |
| 482 return section; | 483 return section; |
| 483 } | 484 } |
| 484 | 485 |
| 485 std::unique_ptr<views::View> | 486 std::unique_ptr<views::View> |
| 486 PaymentSheetViewController::CreateContactInfoSectionContent() { | 487 PaymentSheetViewController::CreateContactInfoSectionContent() { |
| 487 auto* profile = request()->state()->selected_contact_profile(); | 488 autofill::AutofillProfile* profile = |
| 488 | 489 request()->state()->selected_contact_profile(); |
| 489 return profile | 490 return profile ? payments::GetContactInfoLabel( |
| 490 ? payments::GetContactInfoLabel( | 491 AddressStyleType::SUMMARY, |
| 491 AddressStyleType::SUMMARY, request()->GetApplicationLocale(), | 492 request()->state()->GetApplicationLocale(), *profile, |
| 492 *profile, request()->spec()->request_payer_name(), | 493 request()->spec()->request_payer_name(), |
| 493 request()->spec()->request_payer_phone(), | 494 request()->spec()->request_payer_phone(), |
| 494 request()->spec()->request_payer_email()) | 495 request()->spec()->request_payer_email()) |
| 495 : base::MakeUnique<views::Label>(base::string16()); | 496 : base::MakeUnique<views::Label>(base::string16()); |
| 496 } | 497 } |
| 497 | 498 |
| 498 // Creates the Contact Info row, which contains a "Contact info" label; the | 499 // Creates the Contact Info row, which contains a "Contact info" label; the |
| 499 // name, email address, and/or phone number; and a chevron. | 500 // name, email address, and/or phone number; and a chevron. |
| 500 // +----------------------------------------------+ | 501 // +----------------------------------------------+ |
| 501 // | Contact info Barack Obama | | 502 // | Contact info Barack Obama | |
| 502 // | 1800MYPOTUS > | | 503 // | 1800MYPOTUS > | |
| 503 // | potus@whitehouse.gov | | 504 // | potus@whitehouse.gov | |
| 504 // +----------------------------------------------+ | 505 // +----------------------------------------------+ |
| 505 std::unique_ptr<views::Button> | 506 std::unique_ptr<views::Button> |
| 506 PaymentSheetViewController::CreateContactInfoRow() { | 507 PaymentSheetViewController::CreateContactInfoRow() { |
| 507 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 508 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( |
| 508 this, | 509 this, |
| 509 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), | 510 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), |
| 510 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), | 511 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), |
| 511 widest_name_column_view_width_); | 512 widest_name_column_view_width_); |
| 512 section->set_tag(static_cast<int>( | 513 section->set_tag(static_cast<int>( |
| 513 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); | 514 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); |
| 514 section->set_id( | 515 section->set_id( |
| 515 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); | 516 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); |
| 516 return section; | 517 return section; |
| 517 } | 518 } |
| 518 | 519 |
| 519 std::unique_ptr<views::Button> | 520 std::unique_ptr<views::Button> |
| 520 PaymentSheetViewController::CreateShippingOptionRow() { | 521 PaymentSheetViewController::CreateShippingOptionRow() { |
| 521 payments::mojom::PaymentShippingOption* selected_option = | 522 payments::mojom::PaymentShippingOption* selected_option = |
| 522 request()->state()->selected_shipping_option(); | 523 request()->state()->selected_shipping_option(); |
| 523 std::unique_ptr<views::View> option_label = CreateShippingOptionLabel( | 524 std::unique_ptr<views::View> option_label = CreateShippingOptionLabel( |
| 524 selected_option, selected_option ? request()->GetFormattedCurrencyAmount( | 525 selected_option, selected_option |
| 525 selected_option->amount->value) | 526 ? request()->spec()->GetFormattedCurrencyAmount( |
| 526 : base::ASCIIToUTF16("")); | 527 selected_option->amount->value) |
| 528 : base::ASCIIToUTF16("")); |
| 527 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 529 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( |
| 528 this, | 530 this, |
| 529 GetShippingOptionSectionString( | 531 GetShippingOptionSectionString( |
| 530 request()->spec()->options().shipping_type), | 532 request()->spec()->options().shipping_type), |
| 531 std::move(option_label), std::unique_ptr<views::View>(nullptr), | 533 std::move(option_label), std::unique_ptr<views::View>(nullptr), |
| 532 widest_name_column_view_width_); | 534 widest_name_column_view_width_); |
| 533 section->set_tag(static_cast<int>( | 535 section->set_tag(static_cast<int>( |
| 534 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); | 536 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); |
| 535 section->set_id( | 537 section->set_id( |
| 536 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); | 538 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); |
| 537 return section; | 539 return section; |
| 538 } | 540 } |
| 539 | 541 |
| 540 } // namespace payments | 542 } // namespace payments |
| OLD | NEW |