| 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/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 16 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 17 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| 17 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 18 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 18 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
| 19 #include "components/autofill/core/browser/autofill_data_util.h" | 20 #include "components/autofill/core/browser/autofill_data_util.h" |
| 20 #include "components/autofill/core/browser/autofill_type.h" | 21 #include "components/autofill/core/browser/autofill_type.h" |
| 21 #include "components/autofill/core/browser/credit_card.h" | 22 #include "components/autofill/core/browser/credit_card.h" |
| 22 #include "components/autofill/core/browser/field_types.h" | 23 #include "components/autofill/core/browser/field_types.h" |
| 23 #include "components/autofill/core/browser/personal_data_manager.h" | 24 #include "components/autofill/core/browser/personal_data_manager.h" |
| 24 #include "components/payments/currency_formatter.h" | 25 #include "components/payments/currency_formatter.h" |
| 25 #include "components/payments/payment_request.h" | 26 #include "components/payments/payment_request.h" |
| 26 #include "components/strings/grit/components_strings.h" | 27 #include "components/strings/grit/components_strings.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 std::unique_ptr<views::Button> | 255 std::unique_ptr<views::Button> |
| 255 PaymentSheetViewController::CreatePaymentSheetSummaryRow() { | 256 PaymentSheetViewController::CreatePaymentSheetSummaryRow() { |
| 256 std::unique_ptr<views::Button> section = base::MakeUnique<PaymentSheetRow>( | 257 std::unique_ptr<views::Button> section = base::MakeUnique<PaymentSheetRow>( |
| 257 this, | 258 this, |
| 258 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), | 259 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), |
| 259 std::unique_ptr<views::View>(nullptr), | 260 std::unique_ptr<views::View>(nullptr), |
| 260 CreateOrderSummarySectionContent(), | 261 CreateOrderSummarySectionContent(), |
| 261 widest_name_column_view_width_); | 262 widest_name_column_view_width_); |
| 262 section->set_tag(static_cast<int>( | 263 section->set_tag(static_cast<int>( |
| 263 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); | 264 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); |
| 265 section->set_id( |
| 266 static_cast<int>(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION)); |
| 264 return section; | 267 return section; |
| 265 } | 268 } |
| 266 | 269 |
| 267 std::unique_ptr<views::View> | 270 std::unique_ptr<views::View> |
| 268 PaymentSheetViewController::CreateShippingSectionContent() { | 271 PaymentSheetViewController::CreateShippingSectionContent() { |
| 269 auto profile = request()->selected_shipping_profile(); | 272 auto profile = request()->selected_shipping_profile(); |
| 270 | 273 |
| 271 // TODO(tmartino): Empty string param is app locale; this should be passed | 274 // TODO(tmartino): Empty string param is app locale; this should be passed |
| 272 // at construct-time and stored as a member in a future CL. | 275 // at construct-time and stored as a member in a future CL. |
| 273 return profile ? payments::GetShippingAddressLabel(AddressStyleType::SUMMARY, | 276 return profile ? payments::GetShippingAddressLabel(AddressStyleType::SUMMARY, |
| 274 std::string(), *profile) | 277 std::string(), *profile) |
| 275 : base::MakeUnique<views::Label>(base::string16()); | 278 : base::MakeUnique<views::Label>(base::string16()); |
| 276 } | 279 } |
| 277 | 280 |
| 278 // Creates the Shipping row, which contains a "Shipping address" label, the | 281 // Creates the Shipping row, which contains a "Shipping address" label, the |
| 279 // user's selected shipping address, and a chevron. | 282 // user's selected shipping address, and a chevron. |
| 280 // +----------------------------------------------+ | 283 // +----------------------------------------------+ |
| 281 // | Shipping Address Barack Obama | | 284 // | Shipping Address Barack Obama | |
| 282 // | 1600 Pennsylvania Ave. > | | 285 // | 1600 Pennsylvania Ave. > | |
| 283 // | 1800MYPOTUS | | 286 // | 1800MYPOTUS | |
| 284 // +----------------------------------------------+ | 287 // +----------------------------------------------+ |
| 285 std::unique_ptr<views::Button> PaymentSheetViewController::CreateShippingRow() { | 288 std::unique_ptr<views::Button> PaymentSheetViewController::CreateShippingRow() { |
| 286 std::unique_ptr<views::Button> section = base::MakeUnique<PaymentSheetRow>( | 289 std::unique_ptr<views::Button> section = base::MakeUnique<PaymentSheetRow>( |
| 287 this, | 290 this, |
| 288 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_SHIPPING_SECTION_NAME), | 291 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_SHIPPING_SECTION_NAME), |
| 289 CreateShippingSectionContent(), std::unique_ptr<views::View>(nullptr), | 292 CreateShippingSectionContent(), std::unique_ptr<views::View>(nullptr), |
| 290 widest_name_column_view_width_); | 293 widest_name_column_view_width_); |
| 291 section->set_tag( | 294 section->set_tag( |
| 292 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON)); | 295 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON)); |
| 296 section->set_id( |
| 297 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_SECTION)); |
| 293 return section; | 298 return section; |
| 294 } | 299 } |
| 295 | 300 |
| 296 // Creates the Payment Method row, which contains a "Payment" label, the user's | 301 // Creates the Payment Method row, which contains a "Payment" label, the user's |
| 297 // masked Credit Card details, the icon for the selected card, and a chevron. | 302 // masked Credit Card details, the icon for the selected card, and a chevron. |
| 298 // +----------------------------------------------+ | 303 // +----------------------------------------------+ |
| 299 // | Payment Visa ****0000 | | 304 // | Payment Visa ****0000 | |
| 300 // | John Smith | VISA | > | | 305 // | John Smith | VISA | > | |
| 301 // | | | 306 // | | |
| 302 // +----------------------------------------------+ | 307 // +----------------------------------------------+ |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 344 |
| 340 std::unique_ptr<views::Button> section = base::MakeUnique<PaymentSheetRow>( | 345 std::unique_ptr<views::Button> section = base::MakeUnique<PaymentSheetRow>( |
| 341 this, | 346 this, |
| 342 l10n_util::GetStringUTF16( | 347 l10n_util::GetStringUTF16( |
| 343 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), | 348 IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), |
| 344 std::move(content_view), | 349 std::move(content_view), |
| 345 std::move(card_icon_view), | 350 std::move(card_icon_view), |
| 346 widest_name_column_view_width_); | 351 widest_name_column_view_width_); |
| 347 section->set_tag(static_cast<int>( | 352 section->set_tag(static_cast<int>( |
| 348 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON)); | 353 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON)); |
| 354 section->set_id( |
| 355 static_cast<int>(DialogViewID::PAYMENT_SHEET_PAYMENT_METHOD_SECTION)); |
| 349 return section; | 356 return section; |
| 350 } | 357 } |
| 351 | 358 |
| 352 std::unique_ptr<views::View> | 359 std::unique_ptr<views::View> |
| 353 PaymentSheetViewController::CreateContactInfoSectionContent() { | 360 PaymentSheetViewController::CreateContactInfoSectionContent() { |
| 354 auto profile = request()->selected_contact_profile(); | 361 auto profile = request()->selected_contact_profile(); |
| 355 // TODO(tmartino): Replace empty string with app locale. | 362 // TODO(tmartino): Replace empty string with app locale. |
| 356 return profile ? payments::GetContactInfoLabel(AddressStyleType::SUMMARY, | 363 return profile ? payments::GetContactInfoLabel(AddressStyleType::SUMMARY, |
| 357 std::string(), *profile, true, | 364 std::string(), *profile, true, |
| 358 true, true) | 365 true, true) |
| 359 : base::MakeUnique<views::Label>(base::string16()); | 366 : base::MakeUnique<views::Label>(base::string16()); |
| 360 } | 367 } |
| 361 | 368 |
| 362 // Creates the Contact Info row, which contains a "Contact info" label; the | 369 // Creates the Contact Info row, which contains a "Contact info" label; the |
| 363 // name, email address, and/or phone number; and a chevron. | 370 // name, email address, and/or phone number; and a chevron. |
| 364 // +----------------------------------------------+ | 371 // +----------------------------------------------+ |
| 365 // | Contact info Barack Obama | | 372 // | Contact info Barack Obama | |
| 366 // | 1800MYPOTUS > | | 373 // | 1800MYPOTUS > | |
| 367 // | potus@whitehouse.gov | | 374 // | potus@whitehouse.gov | |
| 368 // +----------------------------------------------+ | 375 // +----------------------------------------------+ |
| 369 std::unique_ptr<views::Button> | 376 std::unique_ptr<views::Button> |
| 370 PaymentSheetViewController::CreateContactInfoRow() { | 377 PaymentSheetViewController::CreateContactInfoRow() { |
| 371 std::unique_ptr<views::Button> section = base::MakeUnique<PaymentSheetRow>( | 378 std::unique_ptr<views::Button> section = base::MakeUnique<PaymentSheetRow>( |
| 372 this, | 379 this, |
| 373 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), | 380 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), |
| 374 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), | 381 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), |
| 375 widest_name_column_view_width_); | 382 widest_name_column_view_width_); |
| 376 section->set_tag(static_cast<int>( | 383 section->set_tag(static_cast<int>( |
| 377 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); | 384 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); |
| 385 section->set_id( |
| 386 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); |
| 378 return section; | 387 return section; |
| 379 } | 388 } |
| 380 | 389 |
| 381 } // namespace payments | 390 } // namespace payments |
| OLD | NEW |