| OLD | NEW |
| 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 "chrome/grit/chromium_strings.h" | 13 #include "chrome/grit/chromium_strings.h" |
| 14 #include "chrome/grit/theme_resources.h" | 14 #include "chrome/grit/theme_resources.h" |
| 15 #include "components/autofill/core/browser/autofill_data_util.h" | 15 #include "components/autofill/core/browser/autofill_data_util.h" |
| 16 #include "components/autofill/core/browser/autofill_profile.h" | 16 #include "components/autofill/core/browser/autofill_profile.h" |
| 17 #include "components/autofill/core/browser/autofill_type.h" | 17 #include "components/autofill/core/browser/autofill_type.h" |
| 18 #include "components/autofill/core/browser/credit_card.h" | 18 #include "components/autofill/core/browser/credit_card.h" |
| 19 #include "components/autofill/core/browser/field_types.h" | 19 #include "components/autofill/core/browser/field_types.h" |
| 20 #include "components/payments/core/payment_options_provider.h" | 20 #include "components/payments/core/payment_options_provider.h" |
| 21 #include "components/strings/grit/components_strings.h" | |
| 22 #include "third_party/skia/include/core/SkColor.h" | 21 #include "third_party/skia/include/core/SkColor.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
| 26 #include "ui/gfx/font_list.h" | 25 #include "ui/gfx/font_list.h" |
| 27 #include "ui/gfx/geometry/insets.h" | 26 #include "ui/gfx/geometry/insets.h" |
| 28 #include "ui/gfx/geometry/point_f.h" | 27 #include "ui/gfx/geometry/point_f.h" |
| 29 #include "ui/gfx/paint_vector_icon.h" | 28 #include "ui/gfx/paint_vector_icon.h" |
| 30 #include "ui/vector_icons/vector_icons.h" | 29 #include "ui/vector_icons/vector_icons.h" |
| 31 #include "ui/views/border.h" | 30 #include "ui/views/border.h" |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 262 |
| 264 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) { | 263 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) { |
| 265 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text); | 264 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text); |
| 266 | 265 |
| 267 label->SetFontList( | 266 label->SetFontList( |
| 268 label->font_list().DeriveWithWeight(gfx::Font::Weight::BOLD)); | 267 label->font_list().DeriveWithWeight(gfx::Font::Weight::BOLD)); |
| 269 | 268 |
| 270 return label; | 269 return label; |
| 271 } | 270 } |
| 272 | 271 |
| 273 base::string16 GetShippingAddressSectionString( | |
| 274 PaymentShippingType shipping_type) { | |
| 275 switch (shipping_type) { | |
| 276 case PaymentShippingType::DELIVERY: | |
| 277 return l10n_util::GetStringUTF16(IDS_PAYMENTS_DELIVERY_ADDRESS_LABEL); | |
| 278 case PaymentShippingType::PICKUP: | |
| 279 return l10n_util::GetStringUTF16(IDS_PAYMENTS_PICKUP_ADDRESS_LABEL); | |
| 280 case PaymentShippingType::SHIPPING: | |
| 281 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_ADDRESS_LABEL); | |
| 282 } | |
| 283 // MSVC doesn't compile with only the above switch statement because it can't | |
| 284 // see that all control paths return a value. | |
| 285 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_ADDRESS_LABEL); | |
| 286 } | |
| 287 | |
| 288 base::string16 GetShippingOptionSectionString( | |
| 289 PaymentShippingType shipping_type) { | |
| 290 switch (shipping_type) { | |
| 291 case PaymentShippingType::DELIVERY: | |
| 292 return l10n_util::GetStringUTF16(IDS_PAYMENTS_DELIVERY_OPTION_LABEL); | |
| 293 case PaymentShippingType::PICKUP: | |
| 294 return l10n_util::GetStringUTF16(IDS_PAYMENTS_PICKUP_OPTION_LABEL); | |
| 295 case PaymentShippingType::SHIPPING: | |
| 296 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL); | |
| 297 } | |
| 298 // MSVC doesn't compile with only the above switch statement because it can't | |
| 299 // see that all control paths return a value. | |
| 300 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL); | |
| 301 } | |
| 302 | |
| 303 std::unique_ptr<views::View> CreateShippingOptionLabel( | 272 std::unique_ptr<views::View> CreateShippingOptionLabel( |
| 304 payments::mojom::PaymentShippingOption* shipping_option, | 273 payments::mojom::PaymentShippingOption* shipping_option, |
| 305 const base::string16& formatted_amount) { | 274 const base::string16& formatted_amount) { |
| 306 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); | 275 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); |
| 307 | 276 |
| 308 std::unique_ptr<views::BoxLayout> layout = | 277 std::unique_ptr<views::BoxLayout> layout = |
| 309 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); | 278 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); |
| 310 layout->set_cross_axis_alignment( | 279 layout->set_cross_axis_alignment( |
| 311 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | 280 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); |
| 312 container->SetLayoutManager(layout.release()); | 281 container->SetLayoutManager(layout.release()); |
| 313 | 282 |
| 314 if (shipping_option) { | 283 if (shipping_option) { |
| 315 container->AddChildView( | 284 container->AddChildView( |
| 316 new views::Label(base::ASCIIToUTF16(shipping_option->label))); | 285 new views::Label(base::ASCIIToUTF16(shipping_option->label))); |
| 317 container->AddChildView(new views::Label(formatted_amount)); | 286 container->AddChildView(new views::Label(formatted_amount)); |
| 318 } | 287 } |
| 319 | 288 |
| 320 return container; | 289 return container; |
| 321 } | 290 } |
| 322 | 291 |
| 323 } // namespace payments | 292 } // namespace payments |
| OLD | NEW |