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

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

Issue 2774233005: Creating PaymentOptionsProvider interface (Closed)
Patch Set: default case for compile Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/payment_request_views_util.h" 5 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); 200 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale);
201 201
202 return GetThreeLineLabel(type, name, address, phone); 202 return GetThreeLineLabel(type, name, address, phone);
203 } 203 }
204 204
205 // TODO(anthonyvd): unit test the label layout. 205 // TODO(anthonyvd): unit test the label layout.
206 std::unique_ptr<views::View> GetContactInfoLabel( 206 std::unique_ptr<views::View> GetContactInfoLabel(
207 AddressStyleType type, 207 AddressStyleType type,
208 const std::string& locale, 208 const std::string& locale,
209 const autofill::AutofillProfile& profile, 209 const autofill::AutofillProfile& profile,
210 bool show_payer_name, 210 PaymentOptionsProvider* options) {
211 bool show_payer_phone,
212 bool show_payer_email) {
213 base::string16 name = 211 base::string16 name =
214 show_payer_name 212 options->request_payer_name()
215 ? profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale) 213 ? profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale)
216 : base::string16(); 214 : base::string16();
217 215
218 base::string16 phone = 216 base::string16 phone =
219 show_payer_phone 217 options->request_payer_phone()
220 ? profile.GetInfo( 218 ? profile.GetInfo(
221 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), 219 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
222 locale) 220 locale)
223 : base::string16(); 221 : base::string16();
224 222
225 base::string16 email = 223 base::string16 email =
226 show_payer_email 224 options->request_payer_email()
227 ? profile.GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS), 225 ? profile.GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS),
228 locale) 226 locale)
229 : base::string16(); 227 : base::string16();
230 228
231 return GetThreeLineLabel(type, name, phone, email); 229 return GetThreeLineLabel(type, name, phone, email);
232 } 230 }
233 231
234 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() { 232 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() {
235 return views::CreateBorderPainter( 233 return views::CreateBorderPainter(
236 base::MakeUnique<PaymentRequestRowBorderPainter>(), 234 base::MakeUnique<PaymentRequestRowBorderPainter>(),
237 gfx::Insets()); 235 gfx::Insets());
238 } 236 }
239 237
240 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) { 238 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) {
241 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text); 239 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text);
242 240
243 label->SetFontList( 241 label->SetFontList(
244 label->font_list().DeriveWithWeight(gfx::Font::Weight::BOLD)); 242 label->font_list().DeriveWithWeight(gfx::Font::Weight::BOLD));
245 243
246 return label; 244 return label;
247 } 245 }
248 246
249 base::string16 GetShippingAddressSectionString( 247 base::string16 GetShippingAddressSectionString(
250 payments::mojom::PaymentShippingType shipping_type) { 248 PaymentShippingType shipping_type) {
251 switch (shipping_type) { 249 switch (shipping_type) {
252 case payments::mojom::PaymentShippingType::DELIVERY: 250 case PaymentShippingType::DELIVERY:
253 return l10n_util::GetStringUTF16(IDS_PAYMENTS_DELIVERY_ADDRESS_LABEL); 251 return l10n_util::GetStringUTF16(IDS_PAYMENTS_DELIVERY_ADDRESS_LABEL);
254 case payments::mojom::PaymentShippingType::PICKUP: 252 case PaymentShippingType::PICKUP:
255 return l10n_util::GetStringUTF16(IDS_PAYMENTS_PICKUP_ADDRESS_LABEL); 253 return l10n_util::GetStringUTF16(IDS_PAYMENTS_PICKUP_ADDRESS_LABEL);
256 case payments::mojom::PaymentShippingType::SHIPPING: 254 case PaymentShippingType::SHIPPING:
257 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_ADDRESS_LABEL); 255 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_ADDRESS_LABEL);
258 } 256 }
259 // MSVC doesn't compile with only the above switch statement because it can't 257 // MSVC doesn't compile with only the above switch statement because it can't
260 // see that all control paths return a value. 258 // see that all control paths return a value.
261 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_ADDRESS_LABEL); 259 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_ADDRESS_LABEL);
262 } 260 }
263 261
264 base::string16 GetShippingOptionSectionString( 262 base::string16 GetShippingOptionSectionString(
265 payments::mojom::PaymentShippingType shipping_type) { 263 PaymentShippingType shipping_type) {
266 switch (shipping_type) { 264 switch (shipping_type) {
267 case payments::mojom::PaymentShippingType::DELIVERY: 265 case PaymentShippingType::DELIVERY:
268 return l10n_util::GetStringUTF16(IDS_PAYMENTS_DELIVERY_OPTION_LABEL); 266 return l10n_util::GetStringUTF16(IDS_PAYMENTS_DELIVERY_OPTION_LABEL);
269 case payments::mojom::PaymentShippingType::PICKUP: 267 case PaymentShippingType::PICKUP:
270 return l10n_util::GetStringUTF16(IDS_PAYMENTS_PICKUP_OPTION_LABEL); 268 return l10n_util::GetStringUTF16(IDS_PAYMENTS_PICKUP_OPTION_LABEL);
271 case payments::mojom::PaymentShippingType::SHIPPING: 269 case PaymentShippingType::SHIPPING:
272 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL); 270 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL);
273 } 271 }
274 // MSVC doesn't compile with only the above switch statement because it can't 272 // MSVC doesn't compile with only the above switch statement because it can't
275 // see that all control paths return a value. 273 // see that all control paths return a value.
276 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL); 274 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL);
277 } 275 }
278 276
279 std::unique_ptr<views::View> CreateShippingOptionLabel( 277 std::unique_ptr<views::View> CreateShippingOptionLabel(
280 payments::mojom::PaymentShippingOption* shipping_option, 278 payments::mojom::PaymentShippingOption* shipping_option,
281 const base::string16& formatted_amount) { 279 const base::string16& formatted_amount) {
282 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); 280 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
283 281
284 std::unique_ptr<views::BoxLayout> layout = 282 std::unique_ptr<views::BoxLayout> layout =
285 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); 283 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0);
286 layout->set_cross_axis_alignment( 284 layout->set_cross_axis_alignment(
287 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); 285 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
288 container->SetLayoutManager(layout.release()); 286 container->SetLayoutManager(layout.release());
289 287
290 if (shipping_option) { 288 if (shipping_option) {
291 container->AddChildView( 289 container->AddChildView(
292 new views::Label(base::ASCIIToUTF16(shipping_option->label))); 290 new views::Label(base::ASCIIToUTF16(shipping_option->label)));
293 container->AddChildView(new views::Label(formatted_amount)); 291 container->AddChildView(new views::Label(formatted_amount));
294 } 292 }
295 293
296 return container; 294 return container;
297 } 295 }
298 296
299 } // namespace payments 297 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698