OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/views/payments/profile_list_view_controller.h" |
| 6 |
| 7 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
| 8 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 9 #include "components/payments/content/payment_request.h" |
| 10 #include "components/strings/grit/components_strings.h" |
| 11 #include "ui/base/l10n/l10n_util.h" |
| 12 #include "ui/views/controls/image_view.h" |
| 13 #include "ui/views/layout/grid_layout.h" |
| 14 |
| 15 namespace payments { |
| 16 |
| 17 namespace { |
| 18 |
| 19 class ProfileItem : public PaymentRequestItemList::Item { |
| 20 public: |
| 21 // Constructs an object owned by |parent_list|, representing one element in |
| 22 // the list. |request| is the PaymentRequest object that is represented by the |
| 23 // current instance of the dialog. |parent_view| points to the controller |
| 24 // which owns |parent_list|. |profile| is the AutofillProfile that this |
| 25 // specific list item represents. It's a cached profile owned by |request|. |
| 26 ProfileItem(autofill::AutofillProfile* profile, |
| 27 PaymentRequest* request, |
| 28 PaymentRequestItemList* parent_list, |
| 29 ProfileListViewController* parent_view, |
| 30 bool selected) |
| 31 : payments::PaymentRequestItemList::Item(request, parent_list, selected), |
| 32 parent_view_(parent_view), |
| 33 profile_(profile) {} |
| 34 ~ProfileItem() override {} |
| 35 |
| 36 private: |
| 37 // payments::PaymentRequestItemList::Item: |
| 38 std::unique_ptr<views::View> CreateItemView() override { |
| 39 DCHECK(profile_); |
| 40 |
| 41 std::unique_ptr<views::View> content = parent_view_->GetLabel(profile_); |
| 42 |
| 43 std::unique_ptr<PaymentRequestRowView> row = |
| 44 base::MakeUnique<PaymentRequestRowView>(this); |
| 45 views::GridLayout* layout = new views::GridLayout(row.get()); |
| 46 row->SetLayoutManager(layout); |
| 47 |
| 48 layout->SetInsets( |
| 49 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets, |
| 50 kPaymentRequestRowVerticalInsets, |
| 51 kPaymentRequestRowHorizontalInsets + kPaymentRequestRowExtraRightInset); |
| 52 |
| 53 // Add a column listing the profile information. |
| 54 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 55 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, 1, |
| 56 views::GridLayout::USE_PREF, 0, 0); |
| 57 |
| 58 columns->AddPaddingColumn(1, 0); |
| 59 |
| 60 // Add a column for the checkmark shown next to the selected profile. |
| 61 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
| 62 0, views::GridLayout::USE_PREF, 0, 0); |
| 63 |
| 64 layout->StartRow(0, 0); |
| 65 content->set_can_process_events_within_subtree(false); |
| 66 layout->AddView(content.release()); |
| 67 |
| 68 checkmark_ = CreateCheckmark(selected()); |
| 69 layout->AddView(checkmark_.get()); |
| 70 |
| 71 return std::move(row); |
| 72 } |
| 73 |
| 74 void SelectedStateChanged() override {} |
| 75 |
| 76 ProfileListViewController* parent_view_; |
| 77 autofill::AutofillProfile* profile_; |
| 78 std::unique_ptr<views::ImageView> checkmark_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(ProfileItem); |
| 81 }; |
| 82 |
| 83 // The ProfileListViewController subtype for the Shipping address list |
| 84 // screen of the Payment Request flow. |
| 85 class ShippingProfileViewController : public ProfileListViewController { |
| 86 public: |
| 87 ShippingProfileViewController(PaymentRequest* request, |
| 88 PaymentRequestDialogView* dialog) |
| 89 : ProfileListViewController(request, dialog) {} |
| 90 ~ShippingProfileViewController() override {} |
| 91 |
| 92 protected: |
| 93 // ProfileListViewController: |
| 94 std::unique_ptr<views::View> GetLabel( |
| 95 autofill::AutofillProfile* profile) override { |
| 96 return GetShippingAddressLabel(AddressStyleType::DETAILED, |
| 97 request_->locale(), *profile); |
| 98 } |
| 99 |
| 100 std::vector<autofill::AutofillProfile*> GetProfiles() override { |
| 101 return request_->shipping_profiles(); |
| 102 } |
| 103 |
| 104 base::string16 GetHeaderString() override { |
| 105 return l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_SHIPPING_SECTION_NAME); |
| 106 } |
| 107 |
| 108 private: |
| 109 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); |
| 110 }; |
| 111 |
| 112 class ContactProfileViewController : public ProfileListViewController { |
| 113 public: |
| 114 ContactProfileViewController(PaymentRequest* request, |
| 115 PaymentRequestDialogView* dialog) |
| 116 : ProfileListViewController(request, dialog) {} |
| 117 ~ContactProfileViewController() override {} |
| 118 |
| 119 protected: |
| 120 // ProfileListViewController: |
| 121 std::unique_ptr<views::View> GetLabel( |
| 122 autofill::AutofillProfile* profile) override { |
| 123 return GetContactInfoLabel(AddressStyleType::DETAILED, request_->locale(), |
| 124 *profile, request_->request_payer_name(), |
| 125 request_->request_payer_phone(), |
| 126 request_->request_payer_email()); |
| 127 } |
| 128 |
| 129 std::vector<autofill::AutofillProfile*> GetProfiles() override { |
| 130 return request_->contact_profiles(); |
| 131 } |
| 132 |
| 133 base::string16 GetHeaderString() override { |
| 134 return l10n_util::GetStringUTF16( |
| 135 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME); |
| 136 } |
| 137 |
| 138 private: |
| 139 DISALLOW_COPY_AND_ASSIGN(ContactProfileViewController); |
| 140 }; |
| 141 |
| 142 } // namespace |
| 143 |
| 144 // static |
| 145 std::unique_ptr<ProfileListViewController> |
| 146 ProfileListViewController::GetShippingProfileViewController( |
| 147 PaymentRequest* request, |
| 148 PaymentRequestDialogView* dialog) { |
| 149 return base::MakeUnique<ShippingProfileViewController>(request, dialog); |
| 150 } |
| 151 |
| 152 // static |
| 153 std::unique_ptr<ProfileListViewController> |
| 154 ProfileListViewController::GetContactProfileViewController( |
| 155 PaymentRequest* request, |
| 156 PaymentRequestDialogView* dialog) { |
| 157 return base::MakeUnique<ContactProfileViewController>(request, dialog); |
| 158 } |
| 159 |
| 160 ProfileListViewController::ProfileListViewController( |
| 161 PaymentRequest* request, |
| 162 PaymentRequestDialogView* dialog) |
| 163 : PaymentRequestSheetController(request, dialog), request_(request) {} |
| 164 |
| 165 ProfileListViewController::~ProfileListViewController() {} |
| 166 |
| 167 std::unique_ptr<views::View> ProfileListViewController::CreateView() { |
| 168 autofill::AutofillProfile* selected_profile = |
| 169 request()->selected_shipping_profile(); |
| 170 |
| 171 // This must be done at Create-time, rather than construct-time, because |
| 172 // the subclass method GetProfiles can't be called in the ctor. |
| 173 for (auto* profile : GetProfiles()) { |
| 174 list_.AddItem(base::MakeUnique<ProfileItem>( |
| 175 profile, request(), &list_, this, profile == selected_profile)); |
| 176 } |
| 177 |
| 178 return CreatePaymentView( |
| 179 CreateSheetHeaderView( |
| 180 /* show_back_arrow = */ true, GetHeaderString(), this), |
| 181 list_.CreateListView()); |
| 182 } |
| 183 |
| 184 } // namespace payments |
OLD | NEW |