| 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/profile_list_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/profile_list_view_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 7 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 8 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | 8 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
| 9 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 9 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 10 #include "components/payments/content/payment_request_spec.h" | 10 #include "components/payments/content/payment_request_spec.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 DISALLOW_COPY_AND_ASSIGN(ProfileItem); | 71 DISALLOW_COPY_AND_ASSIGN(ProfileItem); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // The ProfileListViewController subtype for the Shipping address list | 74 // The ProfileListViewController subtype for the Shipping address list |
| 75 // screen of the Payment Request flow. | 75 // screen of the Payment Request flow. |
| 76 class ShippingProfileViewController : public ProfileListViewController { | 76 class ShippingProfileViewController : public ProfileListViewController { |
| 77 public: | 77 public: |
| 78 ShippingProfileViewController(PaymentRequestSpec* spec, | 78 ShippingProfileViewController(PaymentRequestSpec* spec, |
| 79 PaymentRequestState* state, | 79 PaymentRequestState* state, |
| 80 PaymentRequestDialogView* dialog) | 80 PaymentRequestDialogView* dialog) |
| 81 : ProfileListViewController(spec, state, dialog) {} | 81 : ProfileListViewController(spec, state, dialog) { |
| 82 PopulateList(); |
| 83 } |
| 82 ~ShippingProfileViewController() override {} | 84 ~ShippingProfileViewController() override {} |
| 83 | 85 |
| 84 protected: | 86 protected: |
| 85 // ProfileListViewController: | 87 // ProfileListViewController: |
| 86 std::unique_ptr<views::View> GetLabel( | 88 std::unique_ptr<views::View> GetLabel( |
| 87 autofill::AutofillProfile* profile) override { | 89 autofill::AutofillProfile* profile) override { |
| 88 return GetShippingAddressLabel(AddressStyleType::DETAILED, | 90 return GetShippingAddressLabel(AddressStyleType::DETAILED, |
| 89 state()->GetApplicationLocale(), *profile); | 91 state()->GetApplicationLocale(), *profile); |
| 90 } | 92 } |
| 91 | 93 |
| 92 void SelectProfile(autofill::AutofillProfile* profile) override { | 94 void SelectProfile(autofill::AutofillProfile* profile) override { |
| 93 state()->SetSelectedShippingProfile(profile); | 95 state()->SetSelectedShippingProfile(profile); |
| 94 } | 96 } |
| 95 | 97 |
| 96 autofill::AutofillProfile* GetSelectedProfile() override { | 98 autofill::AutofillProfile* GetSelectedProfile() override { |
| 97 return state()->selected_shipping_profile(); | 99 return state()->selected_shipping_profile(); |
| 98 } | 100 } |
| 99 | 101 |
| 100 std::vector<autofill::AutofillProfile*> GetProfiles() override { | 102 std::vector<autofill::AutofillProfile*> GetProfiles() override { |
| 101 return state()->shipping_profiles(); | 103 return state()->shipping_profiles(); |
| 102 } | 104 } |
| 103 | 105 |
| 104 base::string16 GetHeaderString() override { | 106 base::string16 GetSheetTitle() override { |
| 105 return GetShippingAddressSectionString(spec()->options().shipping_type); | 107 return GetShippingAddressSectionString(spec()->options().shipping_type); |
| 106 } | 108 } |
| 107 | 109 |
| 108 private: | 110 private: |
| 109 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); | 111 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); |
| 110 }; | 112 }; |
| 111 | 113 |
| 112 class ContactProfileViewController : public ProfileListViewController { | 114 class ContactProfileViewController : public ProfileListViewController { |
| 113 public: | 115 public: |
| 114 ContactProfileViewController(PaymentRequestSpec* spec, | 116 ContactProfileViewController(PaymentRequestSpec* spec, |
| 115 PaymentRequestState* state, | 117 PaymentRequestState* state, |
| 116 PaymentRequestDialogView* dialog) | 118 PaymentRequestDialogView* dialog) |
| 117 : ProfileListViewController(spec, state, dialog) {} | 119 : ProfileListViewController(spec, state, dialog) { |
| 120 PopulateList(); |
| 121 } |
| 118 ~ContactProfileViewController() override {} | 122 ~ContactProfileViewController() override {} |
| 119 | 123 |
| 120 protected: | 124 protected: |
| 121 // ProfileListViewController: | 125 // ProfileListViewController: |
| 122 std::unique_ptr<views::View> GetLabel( | 126 std::unique_ptr<views::View> GetLabel( |
| 123 autofill::AutofillProfile* profile) override { | 127 autofill::AutofillProfile* profile) override { |
| 124 return GetContactInfoLabel( | 128 return GetContactInfoLabel( |
| 125 AddressStyleType::DETAILED, state()->GetApplicationLocale(), *profile, | 129 AddressStyleType::DETAILED, state()->GetApplicationLocale(), *profile, |
| 126 spec()->request_payer_name(), spec()->request_payer_phone(), | 130 spec()->request_payer_name(), spec()->request_payer_phone(), |
| 127 spec()->request_payer_email()); | 131 spec()->request_payer_email()); |
| 128 } | 132 } |
| 129 | 133 |
| 130 void SelectProfile(autofill::AutofillProfile* profile) override { | 134 void SelectProfile(autofill::AutofillProfile* profile) override { |
| 131 state()->SetSelectedContactProfile(profile); | 135 state()->SetSelectedContactProfile(profile); |
| 132 } | 136 } |
| 133 | 137 |
| 134 autofill::AutofillProfile* GetSelectedProfile() override { | 138 autofill::AutofillProfile* GetSelectedProfile() override { |
| 135 return state()->selected_contact_profile(); | 139 return state()->selected_contact_profile(); |
| 136 } | 140 } |
| 137 | 141 |
| 138 std::vector<autofill::AutofillProfile*> GetProfiles() override { | 142 std::vector<autofill::AutofillProfile*> GetProfiles() override { |
| 139 return state()->contact_profiles(); | 143 return state()->contact_profiles(); |
| 140 } | 144 } |
| 141 | 145 |
| 142 base::string16 GetHeaderString() override { | 146 base::string16 GetSheetTitle() override { |
| 143 return l10n_util::GetStringUTF16( | 147 return l10n_util::GetStringUTF16( |
| 144 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME); | 148 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME); |
| 145 } | 149 } |
| 146 | 150 |
| 147 private: | 151 private: |
| 148 DISALLOW_COPY_AND_ASSIGN(ContactProfileViewController); | 152 DISALLOW_COPY_AND_ASSIGN(ContactProfileViewController); |
| 149 }; | 153 }; |
| 150 | 154 |
| 151 } // namespace | 155 } // namespace |
| 152 | 156 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 169 } | 173 } |
| 170 | 174 |
| 171 ProfileListViewController::ProfileListViewController( | 175 ProfileListViewController::ProfileListViewController( |
| 172 PaymentRequestSpec* spec, | 176 PaymentRequestSpec* spec, |
| 173 PaymentRequestState* state, | 177 PaymentRequestState* state, |
| 174 PaymentRequestDialogView* dialog) | 178 PaymentRequestDialogView* dialog) |
| 175 : PaymentRequestSheetController(spec, state, dialog) {} | 179 : PaymentRequestSheetController(spec, state, dialog) {} |
| 176 | 180 |
| 177 ProfileListViewController::~ProfileListViewController() {} | 181 ProfileListViewController::~ProfileListViewController() {} |
| 178 | 182 |
| 179 std::unique_ptr<views::View> ProfileListViewController::CreateView() { | 183 void ProfileListViewController::PopulateList() { |
| 180 autofill::AutofillProfile* selected_profile = GetSelectedProfile(); | 184 autofill::AutofillProfile* selected_profile = GetSelectedProfile(); |
| 181 | 185 |
| 182 // This must be done at Create-time, rather than construct-time, because | 186 // This must be done at Create-time, rather than construct-time, because |
| 183 // the subclass method GetProfiles can't be called in the ctor. | 187 // the subclass method GetProfiles can't be called in the ctor. |
| 184 for (auto* profile : GetProfiles()) { | 188 for (auto* profile : GetProfiles()) { |
| 185 list_.AddItem(base::MakeUnique<ProfileItem>(profile, spec(), state(), | 189 list_.AddItem(base::MakeUnique<ProfileItem>(profile, spec(), state(), |
| 186 &list_, this, dialog(), | 190 &list_, this, dialog(), |
| 187 profile == selected_profile)); | 191 profile == selected_profile)); |
| 188 } | 192 } |
| 193 } |
| 189 | 194 |
| 190 return CreatePaymentView( | 195 void ProfileListViewController::FillContentView(views::View* content_view) { |
| 191 CreateSheetHeaderView( | 196 content_view->AddChildView(list_.CreateListView().release()); |
| 192 /* show_back_arrow = */ true, GetHeaderString(), this), | |
| 193 list_.CreateListView()); | |
| 194 } | 197 } |
| 195 | 198 |
| 196 } // namespace payments | 199 } // namespace payments |
| OLD | NEW |