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/i18n/message_formatter.h" | 13 #include "base/i18n/message_formatter.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/profiles/profile.h" | |
22 #include "chrome/browser/ui/chrome_pages.h" | |
20 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 23 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
21 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 24 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
22 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | 25 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
23 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 26 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
24 #include "chrome/grit/generated_resources.h" | 27 #include "chrome/grit/generated_resources.h" |
25 #include "components/autofill/core/browser/field_types.h" | 28 #include "components/autofill/core/browser/field_types.h" |
26 #include "components/autofill/core/browser/personal_data_manager.h" | 29 #include "components/autofill/core/browser/personal_data_manager.h" |
30 #include "components/payments/content/payment_prefs.h" | |
27 #include "components/payments/content/payment_request_spec.h" | 31 #include "components/payments/content/payment_request_spec.h" |
28 #include "components/payments/content/payment_request_state.h" | 32 #include "components/payments/content/payment_request_state.h" |
29 #include "components/payments/core/currency_formatter.h" | 33 #include "components/payments/core/currency_formatter.h" |
30 #include "components/payments/core/payment_instrument.h" | 34 #include "components/payments/core/payment_instrument.h" |
31 #include "components/payments/core/strings_util.h" | 35 #include "components/payments/core/strings_util.h" |
36 #include "components/prefs/pref_service.h" | |
32 #include "components/strings/grit/components_strings.h" | 37 #include "components/strings/grit/components_strings.h" |
33 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
34 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
35 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
36 #include "ui/gfx/color_utils.h" | 41 #include "ui/gfx/color_utils.h" |
37 #include "ui/gfx/font.h" | 42 #include "ui/gfx/font.h" |
38 #include "ui/gfx/paint_vector_icon.h" | 43 #include "ui/gfx/paint_vector_icon.h" |
39 #include "ui/gfx/range/range.h" | 44 #include "ui/gfx/range/range.h" |
40 #include "ui/gfx/text_elider.h" | 45 #include "ui/gfx/text_elider.h" |
41 #include "ui/gfx/text_utils.h" | 46 #include "ui/gfx/text_utils.h" |
47 #include "ui/views/border.h" | |
42 #include "ui/views/controls/button/md_text_button.h" | 48 #include "ui/views/controls/button/md_text_button.h" |
43 #include "ui/views/controls/image_view.h" | 49 #include "ui/views/controls/image_view.h" |
44 #include "ui/views/controls/label.h" | 50 #include "ui/views/controls/label.h" |
45 #include "ui/views/controls/styled_label.h" | 51 #include "ui/views/controls/styled_label.h" |
46 #include "ui/views/layout/box_layout.h" | 52 #include "ui/views/layout/box_layout.h" |
47 #include "ui/views/layout/fill_layout.h" | 53 #include "ui/views/layout/fill_layout.h" |
48 #include "ui/views/layout/grid_layout.h" | 54 #include "ui/views/layout/grid_layout.h" |
49 #include "ui/views/vector_icons.h" | 55 #include "ui/views/vector_icons.h" |
50 #include "ui/views/view.h" | 56 #include "ui/views/view.h" |
51 | 57 |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 layout->AddView(shipping_row.release()); | 459 layout->AddView(shipping_row.release()); |
454 } | 460 } |
455 } | 461 } |
456 layout->StartRow(0, 0); | 462 layout->StartRow(0, 0); |
457 layout->AddView(CreatePaymentMethodRow().release()); | 463 layout->AddView(CreatePaymentMethodRow().release()); |
458 if (spec()->request_payer_name() || spec()->request_payer_email() || | 464 if (spec()->request_payer_name() || spec()->request_payer_email() || |
459 spec()->request_payer_phone()) { | 465 spec()->request_payer_phone()) { |
460 layout->StartRow(0, 0); | 466 layout->StartRow(0, 0); |
461 layout->AddView(CreateContactInfoRow().release()); | 467 layout->AddView(CreateContactInfoRow().release()); |
462 } | 468 } |
469 layout->StartRow(0, 0); | |
470 layout->AddView(CreateDataSourceRow().release()); | |
463 } | 471 } |
464 | 472 |
465 // Adds the product logo to the footer. | 473 // Adds the product logo to the footer. |
466 // +---------------------------------------------------------+ | 474 // +---------------------------------------------------------+ |
467 // | (•) chrome | PAY | CANCEL | | 475 // | (•) chrome | PAY | CANCEL | |
468 // +---------------------------------------------------------+ | 476 // +---------------------------------------------------------+ |
469 std::unique_ptr<views::View> | 477 std::unique_ptr<views::View> |
470 PaymentSheetViewController::CreateExtraFooterView() { | 478 PaymentSheetViewController::CreateExtraFooterView() { |
471 return CreateProductLogoFooterView(); | 479 return CreateProductLogoFooterView(); |
472 } | 480 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON): | 533 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON): |
526 dialog()->ShowShippingOptionSheet(); | 534 dialog()->ShowShippingOptionSheet(); |
527 break; | 535 break; |
528 | 536 |
529 default: | 537 default: |
530 PaymentRequestSheetController::ButtonPressed(sender, event); | 538 PaymentRequestSheetController::ButtonPressed(sender, event); |
531 break; | 539 break; |
532 } | 540 } |
533 } | 541 } |
534 | 542 |
543 void PaymentSheetViewController::StyledLabelLinkClicked( | |
544 views::StyledLabel* label, | |
545 const gfx::Range& range, | |
546 int event_flags) { | |
547 // The only thing that can trigger this is the user clicking on the "settings" | |
548 // link in the data attribution text. | |
549 chrome::ShowSettingsSubPageForProfile( | |
550 Profile::FromBrowserContext(state()->GetBrowserContext()), ""); | |
Mathieu
2017/05/11 00:28:04
could we expose BrowserContext from the PaymentReq
anthonyvd
2017/05/11 00:56:46
Good point, somehow I missed the fact that the dia
| |
551 } | |
552 | |
535 void PaymentSheetViewController::UpdatePayButtonState(bool enabled) { | 553 void PaymentSheetViewController::UpdatePayButtonState(bool enabled) { |
536 pay_button_->SetEnabled(enabled); | 554 pay_button_->SetEnabled(enabled); |
537 } | 555 } |
538 | 556 |
539 // Creates the Order Summary row, which contains an "Order Summary" label, | 557 // Creates the Order Summary row, which contains an "Order Summary" label, |
540 // an inline list of display items, a Total Amount label, and a Chevron. | 558 // an inline list of display items, a Total Amount label, and a Chevron. |
541 // +----------------------------------------------+ | 559 // +----------------------------------------------+ |
542 // | Order Summary Item 1 $ 1.34 | | 560 // | Order Summary Item 1 $ 1.34 | |
543 // | Item 2 $ 2.00 > | | 561 // | Item 2 $ 2.00 > | |
544 // | 2 more items... | | 562 // | 2 more items... | |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
890 } | 908 } |
891 } else { | 909 } else { |
892 return builder | 910 return builder |
893 .Id(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION_BUTTON) | 911 .Id(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION_BUTTON) |
894 .CreateWithButton( | 912 .CreateWithButton( |
895 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CHOOSE_AN_ADDRESS), | 913 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CHOOSE_AN_ADDRESS), |
896 l10n_util::GetStringUTF16(IDS_CHOOSE), /*button_enabled=*/false); | 914 l10n_util::GetStringUTF16(IDS_CHOOSE), /*button_enabled=*/false); |
897 } | 915 } |
898 } | 916 } |
899 | 917 |
918 std::unique_ptr<views::View> PaymentSheetViewController::CreateDataSourceRow() { | |
919 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); | |
920 views::BoxLayout* layout = new views::BoxLayout( | |
921 views::BoxLayout::kVertical, kPaymentRequestRowHorizontalInsets, 0, 0); | |
922 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | |
923 layout->set_cross_axis_alignment( | |
924 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | |
925 content_view->SetLayoutManager(layout); | |
926 | |
927 base::string16 data_source; | |
928 bool first_transaction_completed = | |
929 Profile::FromBrowserContext(state()->GetBrowserContext()) | |
930 ->GetPrefs() | |
931 ->GetBoolean(payments::kPaymentsFirstTransactionCompleted); | |
932 if (first_transaction_completed) { | |
Mathieu
2017/05/11 00:28:04
would benefit from a top-level comment to explain
anthonyvd
2017/05/11 00:56:46
Done.
| |
933 data_source = | |
934 l10n_util::GetStringUTF16(IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS); | |
935 } else { | |
936 std::string user_email = state()->GetAuthenticatedEmail(); | |
937 if (!user_email.empty()) { | |
938 // Insert the user's email into the format string. | |
939 data_source = base::UTF8ToUTF16(base::StringPrintf( | |
940 l10n_util::GetStringUTF8( | |
941 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_IN) | |
942 .c_str(), | |
943 user_email.c_str())); | |
944 // Settings link. | |
Mathieu
2017/05/11 00:28:04
remove
anthonyvd
2017/05/11 00:56:46
Done.
| |
945 } else { | |
946 data_source = l10n_util::GetStringUTF16( | |
947 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_OUT); | |
948 } | |
949 } | |
950 | |
951 base::string16 begin_tag = base::UTF8ToUTF16("BEGIN_LINK"); | |
Mathieu
2017/05/11 00:28:04
// Activate the "Settings" link in the data source
anthonyvd
2017/05/11 00:56:46
Done.
| |
952 base::string16 end_tag = base::UTF8ToUTF16("END_LINK"); | |
953 size_t link_begin = data_source.find(begin_tag); | |
954 DCHECK(link_begin != base::string16::npos); | |
955 | |
956 size_t link_end = data_source.find(end_tag); | |
957 DCHECK(link_end != base::string16::npos); | |
958 | |
959 size_t link_length = link_end - link_begin - begin_tag.size(); | |
960 data_source.erase(link_end, end_tag.size()); | |
961 data_source.erase(link_begin, begin_tag.size()); | |
962 | |
963 std::unique_ptr<views::StyledLabel> data_source_label = | |
964 base::MakeUnique<views::StyledLabel>(data_source, this); | |
965 data_source_label->SetBorder(views::CreateEmptyBorder(22, 0, 0, 0)); | |
966 | |
967 views::StyledLabel::RangeStyleInfo default_style; | |
968 default_style.color = data_source_label->GetNativeTheme()->GetSystemColor( | |
969 ui::NativeTheme::kColorId_LabelDisabledColor); | |
970 data_source_label->SetDefaultStyle(default_style); | |
971 data_source_label->AddStyleRange( | |
972 gfx::Range(link_begin, link_begin + link_length), | |
973 views::StyledLabel::RangeStyleInfo::CreateForLink()); | |
974 data_source_label->SizeToFit(0); | |
975 content_view->AddChildView(data_source_label.release()); | |
976 return content_view; | |
977 } | |
978 | |
900 } // namespace payments | 979 } // namespace payments |
OLD | NEW |