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 <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 17 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
18 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 18 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
19 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | 19 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
20 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 20 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
21 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
22 #include "components/autofill/core/browser/autofill_data_util.h" | |
23 #include "components/autofill/core/browser/autofill_type.h" | 22 #include "components/autofill/core/browser/autofill_type.h" |
24 #include "components/autofill/core/browser/credit_card.h" | 23 #include "components/autofill/core/browser/credit_card.h" |
25 #include "components/autofill/core/browser/field_types.h" | 24 #include "components/autofill/core/browser/field_types.h" |
26 #include "components/autofill/core/browser/personal_data_manager.h" | 25 #include "components/autofill/core/browser/personal_data_manager.h" |
27 #include "components/payments/currency_formatter.h" | 26 #include "components/payments/currency_formatter.h" |
28 #include "components/payments/payment_request.h" | 27 #include "components/payments/payment_request.h" |
29 #include "components/strings/grit/components_strings.h" | 28 #include "components/strings/grit/components_strings.h" |
30 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
31 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
32 #include "ui/base/resource/resource_bundle.h" | |
33 #include "ui/gfx/color_utils.h" | 31 #include "ui/gfx/color_utils.h" |
34 #include "ui/gfx/font.h" | 32 #include "ui/gfx/font.h" |
35 #include "ui/gfx/paint_vector_icon.h" | 33 #include "ui/gfx/paint_vector_icon.h" |
36 #include "ui/gfx/range/range.h" | 34 #include "ui/gfx/range/range.h" |
37 #include "ui/views/border.h" | 35 #include "ui/views/border.h" |
38 #include "ui/views/controls/button/label_button.h" | 36 #include "ui/views/controls/button/label_button.h" |
39 #include "ui/views/controls/button/md_text_button.h" | 37 #include "ui/views/controls/button/md_text_button.h" |
40 #include "ui/views/controls/image_view.h" | 38 #include "ui/views/controls/image_view.h" |
41 #include "ui/views/controls/label.h" | 39 #include "ui/views/controls/label.h" |
42 #include "ui/views/controls/styled_label.h" | 40 #include "ui/views/controls/styled_label.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 295 |
298 // Creates the Payment Method row, which contains a "Payment" label, the user's | 296 // Creates the Payment Method row, which contains a "Payment" label, the user's |
299 // masked Credit Card details, the icon for the selected card, and a chevron. | 297 // masked Credit Card details, the icon for the selected card, and a chevron. |
300 // +----------------------------------------------+ | 298 // +----------------------------------------------+ |
301 // | Payment Visa ****0000 | | 299 // | Payment Visa ****0000 | |
302 // | John Smith | VISA | > | | 300 // | John Smith | VISA | > | |
303 // | | | 301 // | | |
304 // +----------------------------------------------+ | 302 // +----------------------------------------------+ |
305 std::unique_ptr<views::Button> | 303 std::unique_ptr<views::Button> |
306 PaymentSheetViewController::CreatePaymentMethodRow() { | 304 PaymentSheetViewController::CreatePaymentMethodRow() { |
307 autofill::CreditCard* selected_card = | 305 autofill::CreditCard* selected_card = request()->selected_credit_card(); |
308 request()->GetCurrentlySelectedCreditCard(); | |
309 | 306 |
310 std::unique_ptr<views::View> content_view; | 307 std::unique_ptr<views::View> content_view; |
311 std::unique_ptr<views::ImageView> card_icon_view; | 308 std::unique_ptr<views::View> card_icon_view; |
312 if (selected_card) { | 309 if (selected_card) { |
313 content_view = base::MakeUnique<views::View>(); | 310 content_view = base::MakeUnique<views::View>(); |
314 | 311 |
315 views::GridLayout* layout = new views::GridLayout(content_view.get()); | 312 views::GridLayout* layout = new views::GridLayout(content_view.get()); |
316 content_view->SetLayoutManager(layout); | 313 content_view->SetLayoutManager(layout); |
317 views::ColumnSet* columns = layout->AddColumnSet(0); | 314 views::ColumnSet* columns = layout->AddColumnSet(0); |
318 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, | 315 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
319 1, views::GridLayout::USE_PREF, 0, 0); | 316 1, views::GridLayout::USE_PREF, 0, 0); |
320 | 317 |
321 layout->StartRow(0, 0); | 318 layout->StartRow(0, 0); |
322 layout->AddView(new views::Label(selected_card->TypeAndLastFourDigits())); | 319 layout->AddView(new views::Label(selected_card->TypeAndLastFourDigits())); |
323 layout->StartRow(0, 0); | 320 layout->StartRow(0, 0); |
324 layout->AddView(new views::Label( | 321 layout->AddView(new views::Label( |
325 selected_card->GetInfo( | 322 selected_card->GetInfo( |
326 autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), | 323 autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), |
327 g_browser_process->GetApplicationLocale()))); | 324 g_browser_process->GetApplicationLocale()))); |
328 | 325 |
329 card_icon_view = base::MakeUnique<views::ImageView>(); | 326 card_icon_view = CreateCreditCardIconView(selected_card); |
330 card_icon_view->set_interactive(false); | |
331 card_icon_view->SetImage( | |
332 ResourceBundle::GetSharedInstance() | |
333 .GetImageNamed(autofill::data_util::GetPaymentRequestData( | |
334 selected_card->type()).icon_resource_id) | |
335 .AsImageSkia()); | |
336 card_icon_view->SetBorder( | |
337 views::CreateRoundedRectBorder(1, 3, SK_ColorLTGRAY)); | |
338 | |
339 constexpr gfx::Size kCardIconSize = gfx::Size(32, 20); | |
340 card_icon_view->SetImageSize(kCardIconSize); | |
341 } | 327 } |
342 | 328 |
343 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 329 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( |
344 this, | 330 this, |
345 l10n_util::GetStringUTF16( | 331 l10n_util::GetStringUTF16( |
346 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), | 332 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), |
347 std::move(content_view), | 333 std::move(content_view), |
348 std::move(card_icon_view), | 334 std::move(card_icon_view), |
349 widest_name_column_view_width_); | 335 widest_name_column_view_width_); |
350 section->set_tag(static_cast<int>( | 336 section->set_tag(static_cast<int>( |
(...skipping 28 matching lines...) Expand all Loading... |
379 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), | 365 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), |
380 widest_name_column_view_width_); | 366 widest_name_column_view_width_); |
381 section->set_tag(static_cast<int>( | 367 section->set_tag(static_cast<int>( |
382 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); | 368 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); |
383 section->set_id( | 369 section->set_id( |
384 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); | 370 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); |
385 return section; | 371 return section; |
386 } | 372 } |
387 | 373 |
388 } // namespace payments | 374 } // namespace payments |
OLD | NEW |