Chromium Code Reviews| 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 }; | |
|
please use gerrit instead
2017/03/10 20:23:12
DISALLOW_COPY_AND_ASSIGN
tmartino
2017/03/10 23:46:23
Done
| |
| 80 | |
| 81 // The ProfileListViewController subtype for the Shipping address list | |
| 82 // screen of the Payment Request flow. | |
| 83 class ShippingProfileViewController : public ProfileListViewController { | |
| 84 public: | |
| 85 ShippingProfileViewController(PaymentRequest* request, | |
| 86 PaymentRequestDialogView* dialog) | |
| 87 : ProfileListViewController(request, dialog) {} | |
| 88 ~ShippingProfileViewController() override {} | |
| 89 | |
| 90 protected: | |
| 91 // ProfileListViewController: | |
| 92 std::unique_ptr<views::View> GetLabel( | |
| 93 autofill::AutofillProfile* profile) override { | |
| 94 return GetShippingAddressLabel(AddressStyleType::DETAILED, | |
| 95 request_->locale(), *profile); | |
| 96 } | |
| 97 | |
| 98 std::vector<autofill::AutofillProfile*> GetProfiles() override { | |
| 99 return request_->shipping_profiles(); | |
| 100 } | |
| 101 | |
| 102 base::string16 GetHeaderString() override { | |
| 103 return l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_SHIPPING_SECTION_NAME); | |
| 104 } | |
| 105 | |
| 106 private: | |
| 107 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); | |
| 108 }; | |
| 109 | |
| 110 class ContactProfileViewController : public ProfileListViewController { | |
| 111 public: | |
| 112 ContactProfileViewController(PaymentRequest* request, | |
| 113 PaymentRequestDialogView* dialog) | |
| 114 : ProfileListViewController(request, dialog) {} | |
| 115 ~ContactProfileViewController() override {} | |
| 116 | |
| 117 protected: | |
| 118 // ProfileListViewController: | |
| 119 std::unique_ptr<views::View> GetLabel( | |
| 120 autofill::AutofillProfile* profile) override { | |
| 121 return GetContactInfoLabel(AddressStyleType::DETAILED, request_->locale(), | |
| 122 *profile, request_->request_payer_name(), | |
| 123 request_->request_payer_email(), | |
| 124 request_->request_payer_phone()); | |
| 125 } | |
| 126 | |
| 127 std::vector<autofill::AutofillProfile*> GetProfiles() override { | |
| 128 return request_->contact_profiles(); | |
| 129 } | |
| 130 | |
| 131 base::string16 GetHeaderString() override { | |
| 132 return l10n_util::GetStringUTF16( | |
| 133 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME); | |
| 134 } | |
| 135 | |
| 136 private: | |
| 137 DISALLOW_COPY_AND_ASSIGN(ContactProfileViewController); | |
| 138 }; | |
| 139 | |
| 140 } // namespace | |
| 141 | |
| 142 // static | |
| 143 std::unique_ptr<ProfileListViewController> | |
| 144 ProfileListViewController::GetShippingProfileViewController( | |
| 145 PaymentRequest* request, | |
| 146 PaymentRequestDialogView* dialog) { | |
| 147 return base::MakeUnique<ShippingProfileViewController>(request, dialog); | |
| 148 } | |
| 149 | |
| 150 // static | |
| 151 std::unique_ptr<ProfileListViewController> | |
| 152 ProfileListViewController::GetContactProfileViewController( | |
| 153 PaymentRequest* request, | |
| 154 PaymentRequestDialogView* dialog) { | |
| 155 return base::MakeUnique<ContactProfileViewController>(request, dialog); | |
| 156 } | |
| 157 | |
| 158 ProfileListViewController::ProfileListViewController( | |
| 159 PaymentRequest* request, | |
| 160 PaymentRequestDialogView* dialog) | |
| 161 : PaymentRequestSheetController(request, dialog), request_(request) {} | |
| 162 | |
| 163 ProfileListViewController::~ProfileListViewController() {} | |
| 164 | |
| 165 std::unique_ptr<views::View> ProfileListViewController::CreateView() { | |
| 166 autofill::AutofillProfile* selected_profile = | |
| 167 request()->selected_shipping_profile(); | |
| 168 | |
| 169 // This must be done at Create-time, rather than construct-time, because | |
| 170 // the subclass method GetProfiles can't be called in the ctor. | |
| 171 for (auto* profile : GetProfiles()) { | |
| 172 list_.AddItem(base::MakeUnique<ProfileItem>( | |
| 173 profile, request(), &list_, this, profile == selected_profile)); | |
| 174 } | |
| 175 | |
| 176 return CreatePaymentView( | |
| 177 CreateSheetHeaderView( | |
| 178 /* show_back_arrow = */ true, GetHeaderString(), this), | |
| 179 list_.CreateListView()); | |
| 180 } | |
| 181 | |
| 182 } // namespace payments | |
| OLD | NEW |