| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/shipping_list_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/shipping_list_view_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 10 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 11 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | 11 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
| 12 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 12 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 13 #include "components/payments/content/payment_request.h" | 13 #include "components/payments/content/payment_request.h" |
| 14 #include "components/strings/grit/components_strings.h" | 14 #include "components/strings/grit/components_strings.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/views/controls/image_view.h" |
| 16 #include "ui/views/layout/box_layout.h" | 17 #include "ui/views/layout/box_layout.h" |
| 17 #include "ui/views/layout/grid_layout.h" | 18 #include "ui/views/layout/grid_layout.h" |
| 18 | 19 |
| 19 namespace payments { | 20 namespace payments { |
| 20 | 21 |
| 22 class ShippingListItem : public payments::PaymentRequestItemList::Item, |
| 23 public views::ButtonListener { |
| 24 public: |
| 25 ShippingListItem(autofill::AutofillProfile* profile, |
| 26 PaymentRequest* request, |
| 27 PaymentRequestItemList* list, |
| 28 bool selected) |
| 29 : payments::PaymentRequestItemList::Item(request, list, selected), |
| 30 profile_(profile) {} |
| 31 ~ShippingListItem() override {} |
| 32 |
| 33 private: |
| 34 // payments::PaymentRequestItemList::Item: |
| 35 std::unique_ptr<views::View> CreateItemView() override { |
| 36 DCHECK(profile_); |
| 37 |
| 38 // TODO(tmartino): Pass an actual locale in place of empty string. |
| 39 std::unique_ptr<views::View> content = GetShippingAddressLabel( |
| 40 AddressStyleType::DETAILED, std::string(), *profile_); |
| 41 |
| 42 std::unique_ptr<PaymentRequestRowView> row = |
| 43 base::MakeUnique<PaymentRequestRowView>(this); |
| 44 views::GridLayout* layout = new views::GridLayout(row.get()); |
| 45 row->SetLayoutManager(layout); |
| 46 |
| 47 layout->SetInsets( |
| 48 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets, |
| 49 kPaymentRequestRowVerticalInsets, |
| 50 kPaymentRequestRowHorizontalInsets + kPaymentRequestRowExtraRightInset); |
| 51 |
| 52 // Add a column listing the address. |
| 53 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 54 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| 55 views::GridLayout::USE_PREF, 0, 0); |
| 56 |
| 57 columns->AddPaddingColumn(1, 0); |
| 58 |
| 59 // Add a column for the checkmark shown next to the selected address. |
| 60 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
| 61 0, views::GridLayout::USE_PREF, 0, 0); |
| 62 |
| 63 layout->StartRow(0, 0); |
| 64 content->set_can_process_events_within_subtree(false); |
| 65 layout->AddView(content.release()); |
| 66 |
| 67 checkmark_ = CreateCheckmark(selected()); |
| 68 layout->AddView(checkmark_.get()); |
| 69 |
| 70 return std::move(row); |
| 71 } |
| 72 |
| 73 void SelectedStateChanged() override {} |
| 74 |
| 75 // views::ButtonListener: |
| 76 void ButtonPressed(views::Button* sender, const ui::Event& event) override {} |
| 77 |
| 78 autofill::AutofillProfile* profile_; |
| 79 std::unique_ptr<views::ImageView> checkmark_; |
| 80 }; |
| 81 |
| 21 ShippingListViewController::ShippingListViewController( | 82 ShippingListViewController::ShippingListViewController( |
| 22 PaymentRequest* request, | 83 PaymentRequest* request, |
| 23 PaymentRequestDialogView* dialog) | 84 PaymentRequestDialogView* dialog) |
| 24 : PaymentRequestSheetController(request, dialog) {} | 85 : PaymentRequestSheetController(request, dialog) { |
| 86 auto* selected_profile = request->selected_shipping_profile(); |
| 87 |
| 88 for (auto* profile : request->shipping_profiles()) { |
| 89 list_.AddItem(base::MakeUnique<ShippingListItem>( |
| 90 profile, request, &list_, profile == selected_profile)); |
| 91 } |
| 92 } |
| 25 | 93 |
| 26 ShippingListViewController::~ShippingListViewController() {} | 94 ShippingListViewController::~ShippingListViewController() {} |
| 27 | 95 |
| 28 std::unique_ptr<views::View> ShippingListViewController::CreateView() { | 96 std::unique_ptr<views::View> ShippingListViewController::CreateView() { |
| 29 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); | |
| 30 | |
| 31 views::BoxLayout* layout = | |
| 32 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | |
| 33 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | |
| 34 layout->set_cross_axis_alignment( | |
| 35 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); | |
| 36 content_view->SetLayoutManager(layout); | |
| 37 | |
| 38 for (auto* profile : request()->shipping_profiles()) { | |
| 39 // TODO(tmartino): Pass an actual locale in place of empty string. | |
| 40 content_view->AddChildView( | |
| 41 CreateAddressRow(GetShippingAddressLabel(AddressStyleType::DETAILED, | |
| 42 std::string(), *profile)) | |
| 43 .release()); | |
| 44 } | |
| 45 | |
| 46 return CreatePaymentView( | 97 return CreatePaymentView( |
| 47 CreateSheetHeaderView( | 98 CreateSheetHeaderView( |
| 48 /* show_back_arrow = */ true, | 99 /* show_back_arrow = */ true, |
| 49 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_SHIPPING_SECTION_NAME), | 100 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_SHIPPING_SECTION_NAME), |
| 50 this), | 101 this), |
| 51 std::move(content_view)); | 102 list_.CreateListView()); |
| 52 } | |
| 53 | |
| 54 std::unique_ptr<views::Button> ShippingListViewController::CreateAddressRow( | |
| 55 std::unique_ptr<views::View> content) { | |
| 56 std::unique_ptr<PaymentRequestRowView> row = | |
| 57 base::MakeUnique<PaymentRequestRowView>(this); | |
| 58 views::GridLayout* layout = new views::GridLayout(row.get()); | |
| 59 row->SetLayoutManager(layout); | |
| 60 | |
| 61 layout->SetInsets( | |
| 62 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets, | |
| 63 kPaymentRequestRowVerticalInsets, | |
| 64 kPaymentRequestRowHorizontalInsets + kPaymentRequestRowExtraRightInset); | |
| 65 | |
| 66 // Add a column listing the address. | |
| 67 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 68 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | |
| 69 views::GridLayout::USE_PREF, 0, 0); | |
| 70 | |
| 71 layout->StartRow(0, 0); | |
| 72 content->set_can_process_events_within_subtree(false); | |
| 73 layout->AddView(content.release()); | |
| 74 | |
| 75 return std::move(row); | |
| 76 } | 103 } |
| 77 | 104 |
| 78 } // namespace payments | 105 } // namespace payments |
| OLD | NEW |