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_dialog_view_ids.h" | 8 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
9 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | 9 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
10 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 10 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
12 #include "components/payments/content/payment_request_spec.h" | 12 #include "components/payments/content/payment_request_spec.h" |
13 #include "components/payments/content/payment_request_state.h" | 13 #include "components/payments/content/payment_request_state.h" |
14 #include "components/strings/grit/components_strings.h" | 14 #include "components/strings/grit/components_strings.h" |
15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/views/controls/button/label_button.h" | 16 #include "ui/views/controls/button/label_button.h" |
17 #include "ui/views/controls/button/md_text_button.h" | 17 #include "ui/views/controls/button/md_text_button.h" |
18 #include "ui/views/controls/image_view.h" | 18 #include "ui/views/controls/image_view.h" |
19 #include "ui/views/layout/box_layout.h" | 19 #include "ui/views/layout/box_layout.h" |
| 20 #include "ui/views/layout/fill_layout.h" |
20 #include "ui/views/layout/grid_layout.h" | 21 #include "ui/views/layout/grid_layout.h" |
21 | 22 |
22 namespace payments { | 23 namespace payments { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 constexpr int kFirstTagValue = static_cast<int>( | 27 constexpr int kFirstTagValue = static_cast<int>( |
27 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX); | 28 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX); |
28 | 29 |
29 enum class PaymentMethodViewControllerTags : int { | 30 enum class PaymentMethodViewControllerTags : int { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 DISALLOW_COPY_AND_ASSIGN(ProfileItem); | 89 DISALLOW_COPY_AND_ASSIGN(ProfileItem); |
89 }; | 90 }; |
90 | 91 |
91 // The ProfileListViewController subtype for the Shipping address list | 92 // The ProfileListViewController subtype for the Shipping address list |
92 // screen of the Payment Request flow. | 93 // screen of the Payment Request flow. |
93 class ShippingProfileViewController : public ProfileListViewController { | 94 class ShippingProfileViewController : public ProfileListViewController { |
94 public: | 95 public: |
95 ShippingProfileViewController(PaymentRequestSpec* spec, | 96 ShippingProfileViewController(PaymentRequestSpec* spec, |
96 PaymentRequestState* state, | 97 PaymentRequestState* state, |
97 PaymentRequestDialogView* dialog) | 98 PaymentRequestDialogView* dialog) |
98 : ProfileListViewController(spec, state, dialog) {} | 99 : ProfileListViewController(spec, state, dialog) { |
| 100 PopulateList(); |
| 101 } |
99 ~ShippingProfileViewController() override {} | 102 ~ShippingProfileViewController() override {} |
100 | 103 |
101 protected: | 104 protected: |
102 // ProfileListViewController: | 105 // ProfileListViewController: |
103 std::unique_ptr<views::View> GetLabel( | 106 std::unique_ptr<views::View> GetLabel( |
104 autofill::AutofillProfile* profile) override { | 107 autofill::AutofillProfile* profile) override { |
105 return GetShippingAddressLabel(AddressStyleType::DETAILED, | 108 return GetShippingAddressLabel(AddressStyleType::DETAILED, |
106 state()->GetApplicationLocale(), *profile); | 109 state()->GetApplicationLocale(), *profile); |
107 } | 110 } |
108 | 111 |
109 void SelectProfile(autofill::AutofillProfile* profile) override { | 112 void SelectProfile(autofill::AutofillProfile* profile) override { |
110 state()->SetSelectedShippingProfile(profile); | 113 state()->SetSelectedShippingProfile(profile); |
111 } | 114 } |
112 | 115 |
113 autofill::AutofillProfile* GetSelectedProfile() override { | 116 autofill::AutofillProfile* GetSelectedProfile() override { |
114 return state()->selected_shipping_profile(); | 117 return state()->selected_shipping_profile(); |
115 } | 118 } |
116 | 119 |
117 std::vector<autofill::AutofillProfile*> GetProfiles() override { | 120 std::vector<autofill::AutofillProfile*> GetProfiles() override { |
118 return state()->shipping_profiles(); | 121 return state()->shipping_profiles(); |
119 } | 122 } |
120 | 123 |
121 base::string16 GetHeaderString() override { | 124 base::string16 GetSheetTitle() override { |
122 return GetShippingAddressSectionString(spec()->options().shipping_type); | 125 return GetShippingAddressSectionString(spec()->options().shipping_type); |
123 } | 126 } |
124 | 127 |
125 int GetSecondaryButtonTextId() override { | 128 int GetSecondaryButtonTextId() override { |
126 return IDS_AUTOFILL_ADD_ADDRESS_CAPTION; | 129 return IDS_AUTOFILL_ADD_ADDRESS_CAPTION; |
127 } | 130 } |
128 | 131 |
129 int GetSecondaryButtonTag() override { | 132 int GetSecondaryButtonTag() override { |
130 return static_cast<int>( | 133 return static_cast<int>( |
131 PaymentMethodViewControllerTags::ADD_SHIPPING_ADDRESS_BUTTON); | 134 PaymentMethodViewControllerTags::ADD_SHIPPING_ADDRESS_BUTTON); |
132 } | 135 } |
133 | 136 |
134 int GetSecondaryButtonViewId() override { | 137 int GetSecondaryButtonViewId() override { |
135 return static_cast<int>(DialogViewID::PAYMENT_METHOD_ADD_SHIPPING_BUTTON); | 138 return static_cast<int>(DialogViewID::PAYMENT_METHOD_ADD_SHIPPING_BUTTON); |
136 } | 139 } |
137 | 140 |
138 void OnSecondaryButtonPressed() override { | 141 void OnSecondaryButtonPressed() override { |
139 dialog()->ShowShippingAddressEditor(); | 142 dialog()->ShowShippingAddressEditor(); |
140 } | 143 } |
141 | 144 |
142 private: | 145 private: |
143 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); | 146 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); |
144 }; | 147 }; |
145 | 148 |
146 class ContactProfileViewController : public ProfileListViewController { | 149 class ContactProfileViewController : public ProfileListViewController { |
147 public: | 150 public: |
148 ContactProfileViewController(PaymentRequestSpec* spec, | 151 ContactProfileViewController(PaymentRequestSpec* spec, |
149 PaymentRequestState* state, | 152 PaymentRequestState* state, |
150 PaymentRequestDialogView* dialog) | 153 PaymentRequestDialogView* dialog) |
151 : ProfileListViewController(spec, state, dialog) {} | 154 : ProfileListViewController(spec, state, dialog) { |
| 155 PopulateList(); |
| 156 } |
152 ~ContactProfileViewController() override {} | 157 ~ContactProfileViewController() override {} |
153 | 158 |
154 protected: | 159 protected: |
155 // ProfileListViewController: | 160 // ProfileListViewController: |
156 std::unique_ptr<views::View> GetLabel( | 161 std::unique_ptr<views::View> GetLabel( |
157 autofill::AutofillProfile* profile) override { | 162 autofill::AutofillProfile* profile) override { |
158 return GetContactInfoLabel( | 163 return GetContactInfoLabel( |
159 AddressStyleType::DETAILED, state()->GetApplicationLocale(), *profile, | 164 AddressStyleType::DETAILED, state()->GetApplicationLocale(), *profile, |
160 spec()->request_payer_name(), spec()->request_payer_phone(), | 165 spec()->request_payer_name(), spec()->request_payer_phone(), |
161 spec()->request_payer_email()); | 166 spec()->request_payer_email()); |
162 } | 167 } |
163 | 168 |
164 void SelectProfile(autofill::AutofillProfile* profile) override { | 169 void SelectProfile(autofill::AutofillProfile* profile) override { |
165 state()->SetSelectedContactProfile(profile); | 170 state()->SetSelectedContactProfile(profile); |
166 } | 171 } |
167 | 172 |
168 autofill::AutofillProfile* GetSelectedProfile() override { | 173 autofill::AutofillProfile* GetSelectedProfile() override { |
169 return state()->selected_contact_profile(); | 174 return state()->selected_contact_profile(); |
170 } | 175 } |
171 | 176 |
172 std::vector<autofill::AutofillProfile*> GetProfiles() override { | 177 std::vector<autofill::AutofillProfile*> GetProfiles() override { |
173 return state()->contact_profiles(); | 178 return state()->contact_profiles(); |
174 } | 179 } |
175 | 180 |
176 base::string16 GetHeaderString() override { | 181 base::string16 GetSheetTitle() override { |
177 return l10n_util::GetStringUTF16( | 182 return l10n_util::GetStringUTF16( |
178 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME); | 183 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME); |
179 } | 184 } |
180 | 185 |
181 int GetSecondaryButtonTextId() override { | 186 int GetSecondaryButtonTextId() override { |
182 return IDS_AUTOFILL_ADD_CONTACT_CAPTION; | 187 return IDS_AUTOFILL_ADD_CONTACT_CAPTION; |
183 } | 188 } |
184 | 189 |
185 int GetSecondaryButtonTag() override { | 190 int GetSecondaryButtonTag() override { |
186 return static_cast<int>( | 191 return static_cast<int>( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 225 } |
221 | 226 |
222 ProfileListViewController::ProfileListViewController( | 227 ProfileListViewController::ProfileListViewController( |
223 PaymentRequestSpec* spec, | 228 PaymentRequestSpec* spec, |
224 PaymentRequestState* state, | 229 PaymentRequestState* state, |
225 PaymentRequestDialogView* dialog) | 230 PaymentRequestDialogView* dialog) |
226 : PaymentRequestSheetController(spec, state, dialog) {} | 231 : PaymentRequestSheetController(spec, state, dialog) {} |
227 | 232 |
228 ProfileListViewController::~ProfileListViewController() {} | 233 ProfileListViewController::~ProfileListViewController() {} |
229 | 234 |
230 std::unique_ptr<views::View> ProfileListViewController::CreateView() { | 235 void ProfileListViewController::PopulateList() { |
231 autofill::AutofillProfile* selected_profile = GetSelectedProfile(); | 236 autofill::AutofillProfile* selected_profile = GetSelectedProfile(); |
232 | 237 |
233 // This must be done at Create-time, rather than construct-time, because | 238 // This must be done at Create-time, rather than construct-time, because |
234 // the subclass method GetProfiles can't be called in the ctor. | 239 // the subclass method GetProfiles can't be called in the ctor. |
235 for (auto* profile : GetProfiles()) { | 240 for (auto* profile : GetProfiles()) { |
236 list_.AddItem(base::MakeUnique<ProfileItem>(profile, spec(), state(), | 241 list_.AddItem(base::MakeUnique<ProfileItem>(profile, spec(), state(), |
237 &list_, this, dialog(), | 242 &list_, this, dialog(), |
238 profile == selected_profile)); | 243 profile == selected_profile)); |
239 } | 244 } |
| 245 } |
240 | 246 |
241 return CreatePaymentView( | 247 void ProfileListViewController::FillContentView(views::View* content_view) { |
242 CreateSheetHeaderView( | 248 content_view->SetLayoutManager(new views::FillLayout); |
243 /* show_back_arrow = */ true, GetHeaderString(), this), | 249 content_view->AddChildView(list_.CreateListView().release()); |
244 list_.CreateListView()); | |
245 } | 250 } |
246 | 251 |
247 std::unique_ptr<views::View> | 252 std::unique_ptr<views::View> |
248 ProfileListViewController::CreateExtraFooterView() { | 253 ProfileListViewController::CreateExtraFooterView() { |
249 std::unique_ptr<views::View> extra_view = base::MakeUnique<views::View>(); | 254 std::unique_ptr<views::View> extra_view = base::MakeUnique<views::View>(); |
250 | 255 |
251 extra_view->SetLayoutManager(new views::BoxLayout( | 256 extra_view->SetLayoutManager(new views::BoxLayout( |
252 views::BoxLayout::kHorizontal, 0, 0, kPaymentRequestButtonSpacing)); | 257 views::BoxLayout::kHorizontal, 0, 0, kPaymentRequestButtonSpacing)); |
253 | 258 |
254 views::LabelButton* button = views::MdTextButton::CreateSecondaryUiButton( | 259 views::LabelButton* button = views::MdTextButton::CreateSecondaryUiButton( |
255 this, l10n_util::GetStringUTF16(GetSecondaryButtonTextId())); | 260 this, l10n_util::GetStringUTF16(GetSecondaryButtonTextId())); |
256 button->set_tag(GetSecondaryButtonTag()); | 261 button->set_tag(GetSecondaryButtonTag()); |
257 button->set_id(GetSecondaryButtonViewId()); | 262 button->set_id(GetSecondaryButtonViewId()); |
258 extra_view->AddChildView(button); | 263 extra_view->AddChildView(button); |
259 | 264 |
260 return extra_view; | 265 return extra_view; |
261 } | 266 } |
262 | 267 |
263 void ProfileListViewController::ButtonPressed(views::Button* sender, | 268 void ProfileListViewController::ButtonPressed(views::Button* sender, |
264 const ui::Event& event) { | 269 const ui::Event& event) { |
265 if (sender->tag() == GetSecondaryButtonTag()) | 270 if (sender->tag() == GetSecondaryButtonTag()) |
266 OnSecondaryButtonPressed(); | 271 OnSecondaryButtonPressed(); |
267 else | 272 else |
268 PaymentRequestSheetController::ButtonPressed(sender, event); | 273 PaymentRequestSheetController::ButtonPressed(sender, event); |
269 } | 274 } |
270 | 275 |
271 } // namespace payments | 276 } // namespace payments |
OLD | NEW |