Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(736)

Side by Side Diff: chrome/browser/ui/views/payments/profile_list_view_controller.cc

Issue 2759253002: [Web Payments] Implement item selection in lists. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_spec.h" 9 #include "components/payments/content/payment_request_spec.h"
10 #include "components/payments/content/payment_request_state.h" 10 #include "components/payments/content/payment_request_state.h"
(...skipping 27 matching lines...) Expand all
38 ~ProfileItem() override {} 38 ~ProfileItem() override {}
39 39
40 private: 40 private:
41 // payments::PaymentRequestItemList::Item: 41 // payments::PaymentRequestItemList::Item:
42 std::unique_ptr<views::View> CreateContentView() override { 42 std::unique_ptr<views::View> CreateContentView() override {
43 DCHECK(profile_); 43 DCHECK(profile_);
44 44
45 return parent_view_->GetLabel(profile_); 45 return parent_view_->GetLabel(profile_);
46 } 46 }
47 47
48 void SelectedStateChanged() override {} 48 void SelectedStateChanged() override {
49 if (selected())
50 parent_view_->SelectProfile(profile_);
51 }
49 52
50 bool CanBeSelected() const override { 53 bool CanBeSelected() const override {
51 // TODO(anthonyvd): Check for profile completedness. 54 // TODO(anthonyvd): Check for profile completedness.
52 return true; 55 return true;
53 } 56 }
54 57
55 void PerformSelectionFallback() override { 58 void PerformSelectionFallback() override {
56 // TODO(anthonyvd): Open the editor pre-populated with this profile's data. 59 // TODO(anthonyvd): Open the editor pre-populated with this profile's data.
57 } 60 }
58 61
(...skipping 14 matching lines...) Expand all
73 ~ShippingProfileViewController() override {} 76 ~ShippingProfileViewController() override {}
74 77
75 protected: 78 protected:
76 // ProfileListViewController: 79 // ProfileListViewController:
77 std::unique_ptr<views::View> GetLabel( 80 std::unique_ptr<views::View> GetLabel(
78 autofill::AutofillProfile* profile) override { 81 autofill::AutofillProfile* profile) override {
79 return GetShippingAddressLabel(AddressStyleType::DETAILED, 82 return GetShippingAddressLabel(AddressStyleType::DETAILED,
80 state()->GetApplicationLocale(), *profile); 83 state()->GetApplicationLocale(), *profile);
81 } 84 }
82 85
86 void SelectProfile(autofill::AutofillProfile* profile) override {
87 state()->SetSelectedShippingProfile(profile);
88 }
89
90 autofill::AutofillProfile* GetSelectedProfile() override {
91 return state()->selected_shipping_profile();
92 }
93
83 std::vector<autofill::AutofillProfile*> GetProfiles() override { 94 std::vector<autofill::AutofillProfile*> GetProfiles() override {
84 return state()->shipping_profiles(); 95 return state()->shipping_profiles();
85 } 96 }
86 97
87 base::string16 GetHeaderString() override { 98 base::string16 GetHeaderString() override {
88 return GetShippingAddressSectionString(spec()->options().shipping_type); 99 return GetShippingAddressSectionString(spec()->options().shipping_type);
89 } 100 }
90 101
91 private: 102 private:
92 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); 103 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController);
(...skipping 10 matching lines...) Expand all
103 protected: 114 protected:
104 // ProfileListViewController: 115 // ProfileListViewController:
105 std::unique_ptr<views::View> GetLabel( 116 std::unique_ptr<views::View> GetLabel(
106 autofill::AutofillProfile* profile) override { 117 autofill::AutofillProfile* profile) override {
107 return GetContactInfoLabel( 118 return GetContactInfoLabel(
108 AddressStyleType::DETAILED, state()->GetApplicationLocale(), *profile, 119 AddressStyleType::DETAILED, state()->GetApplicationLocale(), *profile,
109 spec()->request_payer_name(), spec()->request_payer_phone(), 120 spec()->request_payer_name(), spec()->request_payer_phone(),
110 spec()->request_payer_email()); 121 spec()->request_payer_email());
111 } 122 }
112 123
124 void SelectProfile(autofill::AutofillProfile* profile) override {
125 state()->SetSelectedContactProfile(profile);
126 }
127
128 autofill::AutofillProfile* GetSelectedProfile() override {
129 return state()->selected_contact_profile();
130 }
131
113 std::vector<autofill::AutofillProfile*> GetProfiles() override { 132 std::vector<autofill::AutofillProfile*> GetProfiles() override {
114 return state()->contact_profiles(); 133 return state()->contact_profiles();
115 } 134 }
116 135
117 base::string16 GetHeaderString() override { 136 base::string16 GetHeaderString() override {
118 return l10n_util::GetStringUTF16( 137 return l10n_util::GetStringUTF16(
119 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME); 138 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME);
120 } 139 }
121 140
122 private: 141 private:
(...skipping 17 matching lines...) Expand all
140 PaymentRequestSpec* spec, 159 PaymentRequestSpec* spec,
141 PaymentRequestState* state, 160 PaymentRequestState* state,
142 PaymentRequestDialogView* dialog) { 161 PaymentRequestDialogView* dialog) {
143 return base::MakeUnique<ContactProfileViewController>(spec, state, dialog); 162 return base::MakeUnique<ContactProfileViewController>(spec, state, dialog);
144 } 163 }
145 164
146 ProfileListViewController::ProfileListViewController( 165 ProfileListViewController::ProfileListViewController(
147 PaymentRequestSpec* spec, 166 PaymentRequestSpec* spec,
148 PaymentRequestState* state, 167 PaymentRequestState* state,
149 PaymentRequestDialogView* dialog) 168 PaymentRequestDialogView* dialog)
150 : PaymentRequestSheetController(spec, state, dialog) {} 169 : PaymentRequestSheetController(spec, state, dialog), list_(dialog) {}
151 170
152 ProfileListViewController::~ProfileListViewController() {} 171 ProfileListViewController::~ProfileListViewController() {}
153 172
154 std::unique_ptr<views::View> ProfileListViewController::CreateView() { 173 std::unique_ptr<views::View> ProfileListViewController::CreateView() {
155 autofill::AutofillProfile* selected_profile = 174 autofill::AutofillProfile* selected_profile = GetSelectedProfile();
156 state()->selected_shipping_profile();
157 175
158 // This must be done at Create-time, rather than construct-time, because 176 // This must be done at Create-time, rather than construct-time, because
159 // the subclass method GetProfiles can't be called in the ctor. 177 // the subclass method GetProfiles can't be called in the ctor.
160 for (auto* profile : GetProfiles()) { 178 for (auto* profile : GetProfiles()) {
161 list_.AddItem(base::MakeUnique<ProfileItem>( 179 list_.AddItem(base::MakeUnique<ProfileItem>(
162 profile, spec(), state(), &list_, this, profile == selected_profile)); 180 profile, spec(), state(), &list_, this, profile == selected_profile));
163 } 181 }
164 182
165 return CreatePaymentView( 183 return CreatePaymentView(
166 CreateSheetHeaderView( 184 CreateSheetHeaderView(
167 /* show_back_arrow = */ true, GetHeaderString(), this), 185 /* show_back_arrow = */ true, GetHeaderString(), this),
168 list_.CreateListView()); 186 list_.CreateListView());
169 } 187 }
170 188
171 } // namespace payments 189 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698