| 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_row_view.h" | 7 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
| 8 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 8 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 9 #include "components/payments/content/payment_request.h" | 9 #include "components/payments/content/payment_request_spec.h" |
| 10 #include "components/payments/content/payment_request_state.h" |
| 10 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
| 11 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 12 #include "ui/views/controls/image_view.h" | 13 #include "ui/views/controls/image_view.h" |
| 13 #include "ui/views/layout/grid_layout.h" | 14 #include "ui/views/layout/grid_layout.h" |
| 14 | 15 |
| 15 namespace payments { | 16 namespace payments { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 class ProfileItem : public PaymentRequestItemList::Item { | 20 class ProfileItem : public PaymentRequestItemList::Item { |
| 20 public: | 21 public: |
| 21 // Constructs an object owned by |parent_list|, representing one element in | 22 // 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 // the list. |spec| and |state| are the PaymentRequestSpec/State objects that |
| 23 // current instance of the dialog. |parent_view| points to the controller | 24 // are represented by the current instance of the dialog. |parent_view| points |
| 24 // which owns |parent_list|. |profile| is the AutofillProfile that this | 25 // to the controller which owns |parent_list|. |profile| is the |
| 25 // specific list item represents. It's a cached profile owned by |request|. | 26 // AutofillProfile that this specific list item represents. It's a cached |
| 27 // profile owned by |state|. |
| 26 ProfileItem(autofill::AutofillProfile* profile, | 28 ProfileItem(autofill::AutofillProfile* profile, |
| 27 PaymentRequest* request, | 29 PaymentRequestSpec* spec, |
| 30 PaymentRequestState* state, |
| 28 PaymentRequestItemList* parent_list, | 31 PaymentRequestItemList* parent_list, |
| 29 ProfileListViewController* parent_view, | 32 ProfileListViewController* parent_view, |
| 30 bool selected) | 33 bool selected) |
| 31 : payments::PaymentRequestItemList::Item(request, parent_list, selected), | 34 : payments::PaymentRequestItemList::Item(spec, |
| 35 state, |
| 36 parent_list, |
| 37 selected), |
| 32 parent_view_(parent_view), | 38 parent_view_(parent_view), |
| 33 profile_(profile) {} | 39 profile_(profile) {} |
| 34 ~ProfileItem() override {} | 40 ~ProfileItem() override {} |
| 35 | 41 |
| 36 private: | 42 private: |
| 37 // payments::PaymentRequestItemList::Item: | 43 // payments::PaymentRequestItemList::Item: |
| 38 std::unique_ptr<views::View> CreateItemView() override { | 44 std::unique_ptr<views::View> CreateItemView() override { |
| 39 DCHECK(profile_); | 45 DCHECK(profile_); |
| 40 | 46 |
| 41 std::unique_ptr<views::View> content = parent_view_->GetLabel(profile_); | 47 std::unique_ptr<views::View> content = parent_view_->GetLabel(profile_); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 autofill::AutofillProfile* profile_; | 83 autofill::AutofillProfile* profile_; |
| 78 std::unique_ptr<views::ImageView> checkmark_; | 84 std::unique_ptr<views::ImageView> checkmark_; |
| 79 | 85 |
| 80 DISALLOW_COPY_AND_ASSIGN(ProfileItem); | 86 DISALLOW_COPY_AND_ASSIGN(ProfileItem); |
| 81 }; | 87 }; |
| 82 | 88 |
| 83 // The ProfileListViewController subtype for the Shipping address list | 89 // The ProfileListViewController subtype for the Shipping address list |
| 84 // screen of the Payment Request flow. | 90 // screen of the Payment Request flow. |
| 85 class ShippingProfileViewController : public ProfileListViewController { | 91 class ShippingProfileViewController : public ProfileListViewController { |
| 86 public: | 92 public: |
| 87 ShippingProfileViewController(PaymentRequest* request, | 93 ShippingProfileViewController(PaymentRequestSpec* spec, |
| 94 PaymentRequestState* state, |
| 88 PaymentRequestDialogView* dialog) | 95 PaymentRequestDialogView* dialog) |
| 89 : ProfileListViewController(request, dialog) {} | 96 : ProfileListViewController(spec, state, dialog) {} |
| 90 ~ShippingProfileViewController() override {} | 97 ~ShippingProfileViewController() override {} |
| 91 | 98 |
| 92 protected: | 99 protected: |
| 93 // ProfileListViewController: | 100 // ProfileListViewController: |
| 94 std::unique_ptr<views::View> GetLabel( | 101 std::unique_ptr<views::View> GetLabel( |
| 95 autofill::AutofillProfile* profile) override { | 102 autofill::AutofillProfile* profile) override { |
| 96 return GetShippingAddressLabel(AddressStyleType::DETAILED, | 103 return GetShippingAddressLabel(AddressStyleType::DETAILED, |
| 97 request()->state()->GetApplicationLocale(), | 104 state()->GetApplicationLocale(), *profile); |
| 98 *profile); | |
| 99 } | 105 } |
| 100 | 106 |
| 101 std::vector<autofill::AutofillProfile*> GetProfiles() override { | 107 std::vector<autofill::AutofillProfile*> GetProfiles() override { |
| 102 return request()->state()->shipping_profiles(); | 108 return state()->shipping_profiles(); |
| 103 } | 109 } |
| 104 | 110 |
| 105 base::string16 GetHeaderString() override { | 111 base::string16 GetHeaderString() override { |
| 106 return GetShippingAddressSectionString( | 112 return GetShippingAddressSectionString(spec()->options().shipping_type); |
| 107 request()->spec()->options().shipping_type); | |
| 108 } | 113 } |
| 109 | 114 |
| 110 private: | 115 private: |
| 111 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); | 116 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); |
| 112 }; | 117 }; |
| 113 | 118 |
| 114 class ContactProfileViewController : public ProfileListViewController { | 119 class ContactProfileViewController : public ProfileListViewController { |
| 115 public: | 120 public: |
| 116 ContactProfileViewController(PaymentRequest* request, | 121 ContactProfileViewController(PaymentRequestSpec* spec, |
| 122 PaymentRequestState* state, |
| 117 PaymentRequestDialogView* dialog) | 123 PaymentRequestDialogView* dialog) |
| 118 : ProfileListViewController(request, dialog) {} | 124 : ProfileListViewController(spec, state, dialog) {} |
| 119 ~ContactProfileViewController() override {} | 125 ~ContactProfileViewController() override {} |
| 120 | 126 |
| 121 protected: | 127 protected: |
| 122 // ProfileListViewController: | 128 // ProfileListViewController: |
| 123 std::unique_ptr<views::View> GetLabel( | 129 std::unique_ptr<views::View> GetLabel( |
| 124 autofill::AutofillProfile* profile) override { | 130 autofill::AutofillProfile* profile) override { |
| 125 return GetContactInfoLabel( | 131 return GetContactInfoLabel( |
| 126 AddressStyleType::DETAILED, request()->state()->GetApplicationLocale(), | 132 AddressStyleType::DETAILED, state()->GetApplicationLocale(), *profile, |
| 127 *profile, request()->spec()->request_payer_name(), | 133 spec()->request_payer_name(), spec()->request_payer_phone(), |
| 128 request()->spec()->request_payer_phone(), | 134 spec()->request_payer_email()); |
| 129 request()->spec()->request_payer_email()); | |
| 130 } | 135 } |
| 131 | 136 |
| 132 std::vector<autofill::AutofillProfile*> GetProfiles() override { | 137 std::vector<autofill::AutofillProfile*> GetProfiles() override { |
| 133 return request()->state()->contact_profiles(); | 138 return state()->contact_profiles(); |
| 134 } | 139 } |
| 135 | 140 |
| 136 base::string16 GetHeaderString() override { | 141 base::string16 GetHeaderString() override { |
| 137 return l10n_util::GetStringUTF16( | 142 return l10n_util::GetStringUTF16( |
| 138 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME); | 143 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME); |
| 139 } | 144 } |
| 140 | 145 |
| 141 private: | 146 private: |
| 142 DISALLOW_COPY_AND_ASSIGN(ContactProfileViewController); | 147 DISALLOW_COPY_AND_ASSIGN(ContactProfileViewController); |
| 143 }; | 148 }; |
| 144 | 149 |
| 145 } // namespace | 150 } // namespace |
| 146 | 151 |
| 147 // static | 152 // static |
| 148 std::unique_ptr<ProfileListViewController> | 153 std::unique_ptr<ProfileListViewController> |
| 149 ProfileListViewController::GetShippingProfileViewController( | 154 ProfileListViewController::GetShippingProfileViewController( |
| 150 PaymentRequest* request, | 155 PaymentRequestSpec* spec, |
| 156 PaymentRequestState* state, |
| 151 PaymentRequestDialogView* dialog) { | 157 PaymentRequestDialogView* dialog) { |
| 152 return base::MakeUnique<ShippingProfileViewController>(request, dialog); | 158 return base::MakeUnique<ShippingProfileViewController>(spec, state, dialog); |
| 153 } | 159 } |
| 154 | 160 |
| 155 // static | 161 // static |
| 156 std::unique_ptr<ProfileListViewController> | 162 std::unique_ptr<ProfileListViewController> |
| 157 ProfileListViewController::GetContactProfileViewController( | 163 ProfileListViewController::GetContactProfileViewController( |
| 158 PaymentRequest* request, | 164 PaymentRequestSpec* spec, |
| 165 PaymentRequestState* state, |
| 159 PaymentRequestDialogView* dialog) { | 166 PaymentRequestDialogView* dialog) { |
| 160 return base::MakeUnique<ContactProfileViewController>(request, dialog); | 167 return base::MakeUnique<ContactProfileViewController>(spec, state, dialog); |
| 161 } | 168 } |
| 162 | 169 |
| 163 ProfileListViewController::ProfileListViewController( | 170 ProfileListViewController::ProfileListViewController( |
| 164 PaymentRequest* request, | 171 PaymentRequestSpec* spec, |
| 172 PaymentRequestState* state, |
| 165 PaymentRequestDialogView* dialog) | 173 PaymentRequestDialogView* dialog) |
| 166 : PaymentRequestSheetController(request, dialog) {} | 174 : PaymentRequestSheetController(spec, state, dialog) {} |
| 167 | 175 |
| 168 ProfileListViewController::~ProfileListViewController() {} | 176 ProfileListViewController::~ProfileListViewController() {} |
| 169 | 177 |
| 170 std::unique_ptr<views::View> ProfileListViewController::CreateView() { | 178 std::unique_ptr<views::View> ProfileListViewController::CreateView() { |
| 171 autofill::AutofillProfile* selected_profile = | 179 autofill::AutofillProfile* selected_profile = |
| 172 request()->state()->selected_shipping_profile(); | 180 state()->selected_shipping_profile(); |
| 173 | 181 |
| 174 // This must be done at Create-time, rather than construct-time, because | 182 // This must be done at Create-time, rather than construct-time, because |
| 175 // the subclass method GetProfiles can't be called in the ctor. | 183 // the subclass method GetProfiles can't be called in the ctor. |
| 176 for (auto* profile : GetProfiles()) { | 184 for (auto* profile : GetProfiles()) { |
| 177 list_.AddItem(base::MakeUnique<ProfileItem>( | 185 list_.AddItem(base::MakeUnique<ProfileItem>( |
| 178 profile, request(), &list_, this, profile == selected_profile)); | 186 profile, spec(), state(), &list_, this, profile == selected_profile)); |
| 179 } | 187 } |
| 180 | 188 |
| 181 return CreatePaymentView( | 189 return CreatePaymentView( |
| 182 CreateSheetHeaderView( | 190 CreateSheetHeaderView( |
| 183 /* show_back_arrow = */ true, GetHeaderString(), this), | 191 /* show_back_arrow = */ true, GetHeaderString(), this), |
| 184 list_.CreateListView()); | 192 list_.CreateListView()); |
| 185 } | 193 } |
| 186 | 194 |
| 187 } // namespace payments | 195 } // namespace payments |
| OLD | NEW |