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

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: Assert back navigation in browser tests. 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_dialog_view.h"
7 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" 8 #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 "chrome/browser/ui/views/payments/payment_request_views_util.h"
9 #include "components/payments/content/payment_request_spec.h" 10 #include "components/payments/content/payment_request_spec.h"
10 #include "components/payments/content/payment_request_state.h" 11 #include "components/payments/content/payment_request_state.h"
11 #include "components/strings/grit/components_strings.h" 12 #include "components/strings/grit/components_strings.h"
12 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
13 14
14 namespace payments { 15 namespace payments {
15 16
16 namespace { 17 namespace {
17 18
18 class ProfileItem : public PaymentRequestItemList::Item { 19 class ProfileItem : public PaymentRequestItemList::Item {
19 public: 20 public:
20 // Constructs an object owned by |parent_list|, representing one element in 21 // Constructs an object owned by |parent_list|, representing one element in
21 // the list. |spec| and |state| are the PaymentRequestSpec/State objects that 22 // the list. |spec| and |state| are the PaymentRequestSpec/State objects that
22 // are represented by the current instance of the dialog. |parent_view| points 23 // are represented by the current instance of the dialog. |parent_view| points
23 // to the controller which owns |parent_list|. |profile| is the 24 // to the controller which owns |parent_list|. |profile| is the
24 // AutofillProfile that this specific list item represents. It's a cached 25 // AutofillProfile that this specific list item represents. It's a cached
25 // profile owned by |state|. 26 // profile owned by |state|.
26 ProfileItem(autofill::AutofillProfile* profile, 27 ProfileItem(autofill::AutofillProfile* profile,
27 PaymentRequestSpec* spec, 28 PaymentRequestSpec* spec,
28 PaymentRequestState* state, 29 PaymentRequestState* state,
29 PaymentRequestItemList* parent_list, 30 PaymentRequestItemList* parent_list,
30 ProfileListViewController* parent_view, 31 ProfileListViewController* parent_view,
32 PaymentRequestDialogView* dialog,
31 bool selected) 33 bool selected)
32 : payments::PaymentRequestItemList::Item(spec, 34 : payments::PaymentRequestItemList::Item(spec,
33 state, 35 state,
34 parent_list, 36 parent_list,
35 selected), 37 selected),
36 parent_view_(parent_view), 38 parent_view_(parent_view),
37 profile_(profile) {} 39 profile_(profile),
40 dialog_(dialog) {}
38 ~ProfileItem() override {} 41 ~ProfileItem() override {}
39 42
40 private: 43 private:
41 // payments::PaymentRequestItemList::Item: 44 // payments::PaymentRequestItemList::Item:
42 std::unique_ptr<views::View> CreateContentView() override { 45 std::unique_ptr<views::View> CreateContentView() override {
43 DCHECK(profile_); 46 DCHECK(profile_);
44 47
45 return parent_view_->GetLabel(profile_); 48 return parent_view_->GetLabel(profile_);
46 } 49 }
47 50
48 void SelectedStateChanged() override {} 51 void SelectedStateChanged() override {
52 if (selected()) {
53 parent_view_->SelectProfile(profile_);
54 dialog_->GoBack();
55 }
56 }
49 57
50 bool CanBeSelected() const override { 58 bool CanBeSelected() const override {
51 // TODO(anthonyvd): Check for profile completedness. 59 // TODO(anthonyvd): Check for profile completedness.
52 return true; 60 return true;
53 } 61 }
54 62
55 void PerformSelectionFallback() override { 63 void PerformSelectionFallback() override {
56 // TODO(anthonyvd): Open the editor pre-populated with this profile's data. 64 // TODO(anthonyvd): Open the editor pre-populated with this profile's data.
57 } 65 }
58 66
59 ProfileListViewController* parent_view_; 67 ProfileListViewController* parent_view_;
60 autofill::AutofillProfile* profile_; 68 autofill::AutofillProfile* profile_;
69 PaymentRequestDialogView* dialog_;
61 70
62 DISALLOW_COPY_AND_ASSIGN(ProfileItem); 71 DISALLOW_COPY_AND_ASSIGN(ProfileItem);
63 }; 72 };
64 73
65 // The ProfileListViewController subtype for the Shipping address list 74 // The ProfileListViewController subtype for the Shipping address list
66 // screen of the Payment Request flow. 75 // screen of the Payment Request flow.
67 class ShippingProfileViewController : public ProfileListViewController { 76 class ShippingProfileViewController : public ProfileListViewController {
68 public: 77 public:
69 ShippingProfileViewController(PaymentRequestSpec* spec, 78 ShippingProfileViewController(PaymentRequestSpec* spec,
70 PaymentRequestState* state, 79 PaymentRequestState* state,
71 PaymentRequestDialogView* dialog) 80 PaymentRequestDialogView* dialog)
72 : ProfileListViewController(spec, state, dialog) {} 81 : ProfileListViewController(spec, state, dialog) {}
73 ~ShippingProfileViewController() override {} 82 ~ShippingProfileViewController() override {}
74 83
75 protected: 84 protected:
76 // ProfileListViewController: 85 // ProfileListViewController:
77 std::unique_ptr<views::View> GetLabel( 86 std::unique_ptr<views::View> GetLabel(
78 autofill::AutofillProfile* profile) override { 87 autofill::AutofillProfile* profile) override {
79 return GetShippingAddressLabel(AddressStyleType::DETAILED, 88 return GetShippingAddressLabel(AddressStyleType::DETAILED,
80 state()->GetApplicationLocale(), *profile); 89 state()->GetApplicationLocale(), *profile);
81 } 90 }
82 91
92 void SelectProfile(autofill::AutofillProfile* profile) override {
93 state()->SetSelectedShippingProfile(profile);
94 }
95
96 autofill::AutofillProfile* GetSelectedProfile() override {
97 return state()->selected_shipping_profile();
98 }
99
83 std::vector<autofill::AutofillProfile*> GetProfiles() override { 100 std::vector<autofill::AutofillProfile*> GetProfiles() override {
84 return state()->shipping_profiles(); 101 return state()->shipping_profiles();
85 } 102 }
86 103
87 base::string16 GetHeaderString() override { 104 base::string16 GetHeaderString() override {
88 return GetShippingAddressSectionString(spec()->options().shipping_type); 105 return GetShippingAddressSectionString(spec()->options().shipping_type);
89 } 106 }
90 107
91 private: 108 private:
92 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); 109 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController);
(...skipping 10 matching lines...) Expand all
103 protected: 120 protected:
104 // ProfileListViewController: 121 // ProfileListViewController:
105 std::unique_ptr<views::View> GetLabel( 122 std::unique_ptr<views::View> GetLabel(
106 autofill::AutofillProfile* profile) override { 123 autofill::AutofillProfile* profile) override {
107 return GetContactInfoLabel( 124 return GetContactInfoLabel(
108 AddressStyleType::DETAILED, state()->GetApplicationLocale(), *profile, 125 AddressStyleType::DETAILED, state()->GetApplicationLocale(), *profile,
109 spec()->request_payer_name(), spec()->request_payer_phone(), 126 spec()->request_payer_name(), spec()->request_payer_phone(),
110 spec()->request_payer_email()); 127 spec()->request_payer_email());
111 } 128 }
112 129
130 void SelectProfile(autofill::AutofillProfile* profile) override {
131 state()->SetSelectedContactProfile(profile);
132 }
133
134 autofill::AutofillProfile* GetSelectedProfile() override {
135 return state()->selected_contact_profile();
136 }
137
113 std::vector<autofill::AutofillProfile*> GetProfiles() override { 138 std::vector<autofill::AutofillProfile*> GetProfiles() override {
114 return state()->contact_profiles(); 139 return state()->contact_profiles();
115 } 140 }
116 141
117 base::string16 GetHeaderString() override { 142 base::string16 GetHeaderString() override {
118 return l10n_util::GetStringUTF16( 143 return l10n_util::GetStringUTF16(
119 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME); 144 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME);
120 } 145 }
121 146
122 private: 147 private:
(...skipping 22 matching lines...) Expand all
145 170
146 ProfileListViewController::ProfileListViewController( 171 ProfileListViewController::ProfileListViewController(
147 PaymentRequestSpec* spec, 172 PaymentRequestSpec* spec,
148 PaymentRequestState* state, 173 PaymentRequestState* state,
149 PaymentRequestDialogView* dialog) 174 PaymentRequestDialogView* dialog)
150 : PaymentRequestSheetController(spec, state, dialog) {} 175 : PaymentRequestSheetController(spec, state, dialog) {}
151 176
152 ProfileListViewController::~ProfileListViewController() {} 177 ProfileListViewController::~ProfileListViewController() {}
153 178
154 std::unique_ptr<views::View> ProfileListViewController::CreateView() { 179 std::unique_ptr<views::View> ProfileListViewController::CreateView() {
155 autofill::AutofillProfile* selected_profile = 180 autofill::AutofillProfile* selected_profile = GetSelectedProfile();
156 state()->selected_shipping_profile();
157 181
158 // 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
159 // the subclass method GetProfiles can't be called in the ctor. 183 // the subclass method GetProfiles can't be called in the ctor.
160 for (auto* profile : GetProfiles()) { 184 for (auto* profile : GetProfiles()) {
161 list_.AddItem(base::MakeUnique<ProfileItem>( 185 list_.AddItem(base::MakeUnique<ProfileItem>(profile, spec(), state(),
162 profile, spec(), state(), &list_, this, profile == selected_profile)); 186 &list_, this, dialog(),
187 profile == selected_profile));
163 } 188 }
164 189
165 return CreatePaymentView( 190 return CreatePaymentView(
166 CreateSheetHeaderView( 191 CreateSheetHeaderView(
167 /* show_back_arrow = */ true, GetHeaderString(), this), 192 /* show_back_arrow = */ true, GetHeaderString(), this),
168 list_.CreateListView()); 193 list_.CreateListView());
169 } 194 }
170 195
171 } // namespace payments 196 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698