| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 constexpr int kFirstTagValue = static_cast<int>( | 51 constexpr int kFirstTagValue = static_cast<int>( |
| 52 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX); | 52 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX); |
| 53 | 53 |
| 54 enum class PaymentSheetViewControllerTags { | 54 enum class PaymentSheetViewControllerTags { |
| 55 // The tag for the button that navigates to the Order Summary sheet. | 55 // The tag for the button that navigates to the Order Summary sheet. |
| 56 SHOW_ORDER_SUMMARY_BUTTON = kFirstTagValue, | 56 SHOW_ORDER_SUMMARY_BUTTON = kFirstTagValue, |
| 57 SHOW_SHIPPING_BUTTON, | 57 SHOW_SHIPPING_BUTTON, |
| 58 SHOW_PAYMENT_METHOD_BUTTON, | 58 SHOW_PAYMENT_METHOD_BUTTON, |
| 59 SHOW_CONTACT_INFO_BUTTON, | 59 SHOW_CONTACT_INFO_BUTTON, |
| 60 SHOW_SHIPPING_OPTION_BUTTON, |
| 60 PAY_BUTTON | 61 PAY_BUTTON |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 int ComputeWidestNameColumnViewWidth() { | 64 int ComputeWidestNameColumnViewWidth() { |
| 64 // The name colums in each row should all have the same width, large enough to | 65 // The name colums in each row should all have the same width, large enough to |
| 65 // accomodate the longest piece of text they contain. Because of this, each | 66 // accomodate the longest piece of text they contain. Because of this, each |
| 66 // row's GridLayout requires its first column to have a fixed width of the | 67 // row's GridLayout requires its first column to have a fixed width of the |
| 67 // correct size. To measure the required size, layout a label with each | 68 // correct size. To measure the required size, layout a label with each |
| 68 // section name, measure its width, then initialize |widest_column_width| | 69 // section name, measure its width, then initialize |widest_column_width| |
| 69 // with the largest value. | 70 // with the largest value. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 209 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
| 209 1, views::GridLayout::USE_PREF, 0, 0); | 210 1, views::GridLayout::USE_PREF, 0, 0); |
| 210 | 211 |
| 211 // The shipping address and contact info rows are optional. | 212 // The shipping address and contact info rows are optional. |
| 212 layout->StartRow(0, 0); | 213 layout->StartRow(0, 0); |
| 213 layout->AddView(CreatePaymentSheetSummaryRow().release()); | 214 layout->AddView(CreatePaymentSheetSummaryRow().release()); |
| 214 | 215 |
| 215 if (request()->request_shipping()) { | 216 if (request()->request_shipping()) { |
| 216 layout->StartRow(0, 0); | 217 layout->StartRow(0, 0); |
| 217 layout->AddView(CreateShippingRow().release()); | 218 layout->AddView(CreateShippingRow().release()); |
| 219 layout->StartRow(0, 0); |
| 220 layout->AddView(CreateShippingOptionRow().release()); |
| 218 } | 221 } |
| 219 layout->StartRow(0, 0); | 222 layout->StartRow(0, 0); |
| 220 layout->AddView(CreatePaymentMethodRow().release()); | 223 layout->AddView(CreatePaymentMethodRow().release()); |
| 221 if (request()->request_payer_name() || request()->request_payer_email() || | 224 if (request()->request_payer_name() || request()->request_payer_email() || |
| 222 request()->request_payer_phone()) { | 225 request()->request_payer_phone()) { |
| 223 layout->StartRow(0, 0); | 226 layout->StartRow(0, 0); |
| 224 layout->AddView(CreateContactInfoRow().release()); | 227 layout->AddView(CreateContactInfoRow().release()); |
| 225 } | 228 } |
| 226 | 229 |
| 227 return CreatePaymentView( | 230 return CreatePaymentView( |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), | 496 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), |
| 494 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), | 497 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), |
| 495 widest_name_column_view_width_); | 498 widest_name_column_view_width_); |
| 496 section->set_tag(static_cast<int>( | 499 section->set_tag(static_cast<int>( |
| 497 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); | 500 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); |
| 498 section->set_id( | 501 section->set_id( |
| 499 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); | 502 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); |
| 500 return section; | 503 return section; |
| 501 } | 504 } |
| 502 | 505 |
| 506 std::unique_ptr<views::View> |
| 507 PaymentSheetViewController::CreateShippingOptionContent() { |
| 508 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); |
| 509 |
| 510 std::unique_ptr<views::BoxLayout> layout = |
| 511 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); |
| 512 layout->set_cross_axis_alignment( |
| 513 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); |
| 514 container->SetLayoutManager(layout.release()); |
| 515 |
| 516 payments::mojom::PaymentShippingOption* selected_shipping_option = |
| 517 request()->selected_shipping_option(); |
| 518 if (selected_shipping_option) { |
| 519 container->AddChildView( |
| 520 new views::Label(base::ASCIIToUTF16(selected_shipping_option->label))); |
| 521 container->AddChildView( |
| 522 new views::Label(request()->GetFormattedCurrencyAmount( |
| 523 selected_shipping_option->amount->value))); |
| 524 } |
| 525 |
| 526 return container; |
| 527 } |
| 528 |
| 529 std::unique_ptr<views::Button> |
| 530 PaymentSheetViewController::CreateShippingOptionRow() { |
| 531 // TODO(anthonyvd): Use the correct IDS_PAYMENTS_*_OPTION_LABEL string based |
| 532 // on the data passed by the website. |
| 533 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( |
| 534 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL), |
| 535 CreateShippingOptionContent(), std::unique_ptr<views::View>(nullptr), |
| 536 widest_name_column_view_width_); |
| 537 section->set_tag(static_cast<int>( |
| 538 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); |
| 539 section->set_id( |
| 540 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); |
| 541 return section; |
| 542 } |
| 543 |
| 503 } // namespace payments | 544 } // namespace payments |
| OLD | NEW |