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

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

Issue 2774233005: Creating PaymentOptionsProvider interface (Closed)
Patch Set: rouslan comments 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"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" 12 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h"
13 #include "components/autofill/core/browser/autofill_data_util.h" 13 #include "components/autofill/core/browser/autofill_data_util.h"
14 #include "components/autofill/core/browser/autofill_profile.h" 14 #include "components/autofill/core/browser/autofill_profile.h"
15 #include "components/autofill/core/browser/autofill_type.h" 15 #include "components/autofill/core/browser/autofill_type.h"
16 #include "components/autofill/core/browser/credit_card.h" 16 #include "components/autofill/core/browser/credit_card.h"
17 #include "components/autofill/core/browser/field_types.h" 17 #include "components/autofill/core/browser/field_types.h"
18 #include "components/payments/core/payment_options_provider.h"
18 #include "components/strings/grit/components_strings.h" 19 #include "components/strings/grit/components_strings.h"
19 #include "third_party/skia/include/core/SkColor.h" 20 #include "third_party/skia/include/core/SkColor.h"
20 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/gfx/canvas.h" 23 #include "ui/gfx/canvas.h"
23 #include "ui/gfx/font_list.h" 24 #include "ui/gfx/font_list.h"
24 #include "ui/gfx/geometry/insets.h" 25 #include "ui/gfx/geometry/insets.h"
25 #include "ui/gfx/geometry/point_f.h" 26 #include "ui/gfx/geometry/point_f.h"
26 #include "ui/gfx/paint_vector_icon.h" 27 #include "ui/gfx/paint_vector_icon.h"
27 #include "ui/vector_icons/vector_icons.h" 28 #include "ui/vector_icons/vector_icons.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); 201 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale);
201 202
202 return GetThreeLineLabel(type, name, address, phone); 203 return GetThreeLineLabel(type, name, address, phone);
203 } 204 }
204 205
205 // TODO(anthonyvd): unit test the label layout. 206 // TODO(anthonyvd): unit test the label layout.
206 std::unique_ptr<views::View> GetContactInfoLabel( 207 std::unique_ptr<views::View> GetContactInfoLabel(
207 AddressStyleType type, 208 AddressStyleType type,
208 const std::string& locale, 209 const std::string& locale,
209 const autofill::AutofillProfile& profile, 210 const autofill::AutofillProfile& profile,
210 bool show_payer_name, 211 const PaymentOptionsProvider& options) {
211 bool show_payer_phone,
212 bool show_payer_email) {
213 base::string16 name = 212 base::string16 name =
214 show_payer_name 213 options.request_payer_name()
215 ? profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale) 214 ? profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale)
216 : base::string16(); 215 : base::string16();
217 216
218 base::string16 phone = 217 base::string16 phone =
219 show_payer_phone 218 options.request_payer_phone()
220 ? profile.GetInfo( 219 ? profile.GetInfo(
221 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), 220 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
222 locale) 221 locale)
223 : base::string16(); 222 : base::string16();
224 223
225 base::string16 email = 224 base::string16 email =
226 show_payer_email 225 options.request_payer_email()
227 ? profile.GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS), 226 ? profile.GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS),
228 locale) 227 locale)
229 : base::string16(); 228 : base::string16();
230 229
231 return GetThreeLineLabel(type, name, phone, email); 230 return GetThreeLineLabel(type, name, phone, email);
232 } 231 }
233 232
234 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() { 233 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() {
235 return views::CreateBorderPainter( 234 return views::CreateBorderPainter(
236 base::MakeUnique<PaymentRequestRowBorderPainter>(), 235 base::MakeUnique<PaymentRequestRowBorderPainter>(),
237 gfx::Insets()); 236 gfx::Insets());
238 } 237 }
239 238
240 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) { 239 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) {
241 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text); 240 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text);
242 241
243 label->SetFontList( 242 label->SetFontList(
244 label->font_list().DeriveWithWeight(gfx::Font::Weight::BOLD)); 243 label->font_list().DeriveWithWeight(gfx::Font::Weight::BOLD));
245 244
246 return label; 245 return label;
247 } 246 }
248 247
249 base::string16 GetShippingAddressSectionString( 248 base::string16 GetShippingAddressSectionString(
250 payments::mojom::PaymentShippingType shipping_type) { 249 PaymentShippingType shipping_type) {
251 switch (shipping_type) { 250 switch (shipping_type) {
252 case payments::mojom::PaymentShippingType::DELIVERY: 251 case PaymentShippingType::DELIVERY:
253 return l10n_util::GetStringUTF16(IDS_PAYMENTS_DELIVERY_ADDRESS_LABEL); 252 return l10n_util::GetStringUTF16(IDS_PAYMENTS_DELIVERY_ADDRESS_LABEL);
254 case payments::mojom::PaymentShippingType::PICKUP: 253 case PaymentShippingType::PICKUP:
255 return l10n_util::GetStringUTF16(IDS_PAYMENTS_PICKUP_ADDRESS_LABEL); 254 return l10n_util::GetStringUTF16(IDS_PAYMENTS_PICKUP_ADDRESS_LABEL);
256 case payments::mojom::PaymentShippingType::SHIPPING: 255 case PaymentShippingType::SHIPPING:
257 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_ADDRESS_LABEL); 256 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_ADDRESS_LABEL);
258 } 257 }
259 // MSVC doesn't compile with only the above switch statement because it can't 258 // MSVC doesn't compile with only the above switch statement because it can't
260 // see that all control paths return a value. 259 // see that all control paths return a value.
261 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_ADDRESS_LABEL); 260 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_ADDRESS_LABEL);
262 } 261 }
263 262
264 base::string16 GetShippingOptionSectionString( 263 base::string16 GetShippingOptionSectionString(
265 payments::mojom::PaymentShippingType shipping_type) { 264 PaymentShippingType shipping_type) {
266 switch (shipping_type) { 265 switch (shipping_type) {
267 case payments::mojom::PaymentShippingType::DELIVERY: 266 case PaymentShippingType::DELIVERY:
268 return l10n_util::GetStringUTF16(IDS_PAYMENTS_DELIVERY_OPTION_LABEL); 267 return l10n_util::GetStringUTF16(IDS_PAYMENTS_DELIVERY_OPTION_LABEL);
269 case payments::mojom::PaymentShippingType::PICKUP: 268 case PaymentShippingType::PICKUP:
270 return l10n_util::GetStringUTF16(IDS_PAYMENTS_PICKUP_OPTION_LABEL); 269 return l10n_util::GetStringUTF16(IDS_PAYMENTS_PICKUP_OPTION_LABEL);
271 case payments::mojom::PaymentShippingType::SHIPPING: 270 case PaymentShippingType::SHIPPING:
272 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL); 271 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL);
273 } 272 }
274 // MSVC doesn't compile with only the above switch statement because it can't 273 // MSVC doesn't compile with only the above switch statement because it can't
275 // see that all control paths return a value. 274 // see that all control paths return a value.
276 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL); 275 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL);
277 } 276 }
278 277
279 std::unique_ptr<views::View> CreateShippingOptionLabel( 278 std::unique_ptr<views::View> CreateShippingOptionLabel(
280 payments::mojom::PaymentShippingOption* shipping_option, 279 payments::mojom::PaymentShippingOption* shipping_option,
281 const base::string16& formatted_amount) { 280 const base::string16& formatted_amount) {
282 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); 281 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
283 282
284 std::unique_ptr<views::BoxLayout> layout = 283 std::unique_ptr<views::BoxLayout> layout =
285 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); 284 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0);
286 layout->set_cross_axis_alignment( 285 layout->set_cross_axis_alignment(
287 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); 286 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
288 container->SetLayoutManager(layout.release()); 287 container->SetLayoutManager(layout.release());
289 288
290 if (shipping_option) { 289 if (shipping_option) {
291 container->AddChildView( 290 container->AddChildView(
292 new views::Label(base::ASCIIToUTF16(shipping_option->label))); 291 new views::Label(base::ASCIIToUTF16(shipping_option->label)));
293 container->AddChildView(new views::Label(formatted_amount)); 292 container->AddChildView(new views::Label(formatted_amount));
294 } 293 }
295 294
296 return container; 295 return container;
297 } 296 }
298 297
299 } // namespace payments 298 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698