| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 19 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 20 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 20 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| 21 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | 21 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
| 22 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 22 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 23 #include "chrome/grit/chromium_strings.h" | 23 #include "chrome/grit/chromium_strings.h" |
| 24 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
| 25 #include "chrome/grit/theme_resources.h" | 25 #include "chrome/grit/theme_resources.h" |
| 26 #include "components/autofill/core/browser/autofill_type.h" | |
| 27 #include "components/autofill/core/browser/credit_card.h" | |
| 28 #include "components/autofill/core/browser/field_types.h" | 26 #include "components/autofill/core/browser/field_types.h" |
| 29 #include "components/autofill/core/browser/personal_data_manager.h" | 27 #include "components/autofill/core/browser/personal_data_manager.h" |
| 30 #include "components/payments/content/payment_request_spec.h" | 28 #include "components/payments/content/payment_request_spec.h" |
| 31 #include "components/payments/content/payment_request_state.h" | 29 #include "components/payments/content/payment_request_state.h" |
| 32 #include "components/payments/core/currency_formatter.h" | 30 #include "components/payments/core/currency_formatter.h" |
| 31 #include "components/payments/core/payment_instrument.h" |
| 33 #include "components/strings/grit/components_strings.h" | 32 #include "components/strings/grit/components_strings.h" |
| 34 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 36 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
| 37 #include "ui/gfx/color_utils.h" | 36 #include "ui/gfx/color_utils.h" |
| 38 #include "ui/gfx/font.h" | 37 #include "ui/gfx/font.h" |
| 39 #include "ui/gfx/paint_vector_icon.h" | 38 #include "ui/gfx/paint_vector_icon.h" |
| 40 #include "ui/gfx/range/range.h" | 39 #include "ui/gfx/range/range.h" |
| 41 #include "ui/views/controls/button/md_text_button.h" | 40 #include "ui/views/controls/button/md_text_button.h" |
| 42 #include "ui/views/controls/image_view.h" | 41 #include "ui/views/controls/image_view.h" |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 430 |
| 432 // Creates the Payment Method row, which contains a "Payment" label, the user's | 431 // Creates the Payment Method row, which contains a "Payment" label, the user's |
| 433 // masked Credit Card details, the icon for the selected card, and a chevron. | 432 // masked Credit Card details, the icon for the selected card, and a chevron. |
| 434 // +----------------------------------------------+ | 433 // +----------------------------------------------+ |
| 435 // | Payment Visa ****0000 | | 434 // | Payment Visa ****0000 | |
| 436 // | John Smith | VISA | > | | 435 // | John Smith | VISA | > | |
| 437 // | | | 436 // | | |
| 438 // +----------------------------------------------+ | 437 // +----------------------------------------------+ |
| 439 std::unique_ptr<views::Button> | 438 std::unique_ptr<views::Button> |
| 440 PaymentSheetViewController::CreatePaymentMethodRow() { | 439 PaymentSheetViewController::CreatePaymentMethodRow() { |
| 441 autofill::CreditCard* selected_card = state()->selected_credit_card(); | 440 PaymentInstrument* selected_instrument = state()->selected_instrument(); |
| 442 | 441 |
| 443 std::unique_ptr<views::View> content_view; | 442 std::unique_ptr<views::View> content_view; |
| 444 std::unique_ptr<views::ImageView> card_icon_view; | 443 std::unique_ptr<views::ImageView> card_icon_view; |
| 445 if (selected_card) { | 444 if (selected_instrument) { |
| 446 content_view = base::MakeUnique<views::View>(); | 445 content_view = base::MakeUnique<views::View>(); |
| 447 | 446 |
| 448 views::GridLayout* layout = new views::GridLayout(content_view.get()); | 447 views::GridLayout* layout = new views::GridLayout(content_view.get()); |
| 449 content_view->SetLayoutManager(layout); | 448 content_view->SetLayoutManager(layout); |
| 450 views::ColumnSet* columns = layout->AddColumnSet(0); | 449 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 451 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, | 450 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
| 452 1, views::GridLayout::USE_PREF, 0, 0); | 451 1, views::GridLayout::USE_PREF, 0, 0); |
| 453 | 452 |
| 454 layout->StartRow(0, 0); | 453 layout->StartRow(0, 0); |
| 455 layout->AddView(new views::Label(selected_card->TypeAndLastFourDigits())); | 454 layout->AddView(new views::Label(selected_instrument->label())); |
| 456 layout->StartRow(0, 0); | 455 layout->StartRow(0, 0); |
| 457 layout->AddView(new views::Label( | 456 layout->AddView(new views::Label(selected_instrument->sublabel())); |
| 458 selected_card->GetInfo( | |
| 459 autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), | |
| 460 g_browser_process->GetApplicationLocale()))); | |
| 461 | 457 |
| 462 card_icon_view = CreateCardIconView(selected_card->type()); | 458 card_icon_view = CreateInstrumentIconView( |
| 459 selected_instrument->icon_resource_id(), selected_instrument->label()); |
| 463 card_icon_view->SetImageSize(gfx::Size(32, 20)); | 460 card_icon_view->SetImageSize(gfx::Size(32, 20)); |
| 464 } | 461 } |
| 465 | 462 |
| 466 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 463 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( |
| 467 this, | 464 this, |
| 468 l10n_util::GetStringUTF16( | 465 l10n_util::GetStringUTF16( |
| 469 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), | 466 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), |
| 470 std::move(content_view), | 467 std::move(content_view), |
| 471 std::move(card_icon_view), | 468 std::move(card_icon_view), |
| 472 widest_name_column_view_width_); | 469 widest_name_column_view_width_); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 std::move(option_label), std::unique_ptr<views::View>(nullptr), | 519 std::move(option_label), std::unique_ptr<views::View>(nullptr), |
| 523 widest_name_column_view_width_); | 520 widest_name_column_view_width_); |
| 524 section->set_tag(static_cast<int>( | 521 section->set_tag(static_cast<int>( |
| 525 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); | 522 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); |
| 526 section->set_id( | 523 section->set_id( |
| 527 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); | 524 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); |
| 528 return section; | 525 return section; |
| 529 } | 526 } |
| 530 | 527 |
| 531 } // namespace payments | 528 } // namespace payments |
| OLD | NEW |