Chromium Code Reviews| 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_METHOD_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(CreateShippingMethodRow().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::CreateShippingMethodContent() { | |
| 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 if (request()->selected_shipping_option()) { | |
|
Mathieu
2017/03/09 19:07:03
pull this out first since it's being reused 3 time
anthonyvd
2017/03/09 19:43:55
Done.
| |
| 517 container->AddChildView(new views::Label( | |
| 518 base::ASCIIToUTF16(request()->selected_shipping_option()->label))); | |
| 519 container->AddChildView( | |
| 520 new views::Label(request()->GetFormattedCurrencyAmount( | |
| 521 request()->selected_shipping_option()->amount->value))); | |
| 522 } | |
| 523 | |
| 524 return container; | |
| 525 } | |
| 526 | |
| 527 std::unique_ptr<views::Button> | |
| 528 PaymentSheetViewController::CreateShippingMethodRow() { | |
| 529 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | |
| 530 this, | |
| 531 l10n_util::GetStringUTF16( | |
| 532 IDS_PAYMENT_REQUEST_SHIPPING_METHOD_SECTION_NAME), | |
| 533 CreateShippingMethodContent(), std::unique_ptr<views::View>(nullptr), | |
| 534 widest_name_column_view_width_); | |
| 535 section->set_tag(static_cast<int>( | |
| 536 PaymentSheetViewControllerTags::SHOW_SHIPPING_METHOD_BUTTON)); | |
| 537 section->set_id( | |
| 538 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_METHOD_SECTION)); | |
| 539 return section; | |
| 540 } | |
| 541 | |
| 503 } // namespace payments | 542 } // namespace payments |
| OLD | NEW |