| 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/order_summary_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/ui/views/payments/payment_request_dialog.h" | 14 #include "chrome/browser/ui/views/payments/payment_request_dialog.h" |
| 14 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 15 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 15 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 17 #include "components/payments/currency_formatter.h" |
| 16 #include "components/payments/payment_request.h" | 18 #include "components/payments/payment_request.h" |
| 17 #include "components/strings/grit/components_strings.h" | 19 #include "components/strings/grit/components_strings.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
| 20 #include "ui/views/layout/grid_layout.h" | 22 #include "ui/views/layout/grid_layout.h" |
| 21 #include "ui/views/view.h" | 23 #include "ui/views/view.h" |
| 22 | 24 |
| 23 namespace payments { | 25 namespace payments { |
| 24 | 26 |
| 25 OrderSummaryViewController::OrderSummaryViewController( | 27 OrderSummaryViewController::OrderSummaryViewController( |
| 26 PaymentRequest* request, | 28 PaymentRequest* request, |
| 27 PaymentRequestDialog* dialog) | 29 PaymentRequestDialog* dialog) |
| 28 : PaymentRequestSheetController(request, dialog) {} | 30 : PaymentRequestSheetController(request, dialog) {} |
| 29 | 31 |
| 30 OrderSummaryViewController::~OrderSummaryViewController() {} | 32 OrderSummaryViewController::~OrderSummaryViewController() {} |
| 31 | 33 |
| 32 std::unique_ptr<views::View> OrderSummaryViewController::CreateView() { | 34 std::unique_ptr<views::View> OrderSummaryViewController::CreateView() { |
| 33 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); | 35 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); |
| 34 | 36 |
| 35 views::GridLayout* layout = new views::GridLayout(content_view.get()); | 37 views::GridLayout* layout = new views::GridLayout(content_view.get()); |
| 36 content_view->SetLayoutManager(layout); | 38 content_view->SetLayoutManager(layout); |
| 37 views::ColumnSet* columns = layout->AddColumnSet(0); | 39 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 38 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 40 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
| 39 0, views::GridLayout::USE_PREF, 0, 0); | 41 0, views::GridLayout::USE_PREF, 0, 0); |
| 40 | 42 |
| 43 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter( |
| 44 request()->details()->total->amount->currency, |
| 45 request()->details()->total->amount->currencySystem, |
| 46 g_browser_process->GetApplicationLocale()); |
| 41 layout->StartRow(0, 0); | 47 layout->StartRow(0, 0); |
| 42 layout->AddView(new views::Label(l10n_util::GetStringFUTF16( | 48 layout->AddView(new views::Label(l10n_util::GetStringFUTF16( |
| 43 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT, | 49 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT, |
| 44 base::ASCIIToUTF16(request()->details()->total->label), | 50 base::UTF8ToUTF16(request()->details()->total->label), |
| 45 base::ASCIIToUTF16(request()->details()->total->amount->value), | 51 base::UTF8ToUTF16(request()->details()->total->amount->currency), |
| 46 base::ASCIIToUTF16(request()->details()->total->amount->currency)))); | 52 formatter->Format(request()->details()->total->amount->value)))); |
| 47 | 53 |
| 48 return payments::CreatePaymentView( | 54 return payments::CreatePaymentView( |
| 49 CreateSheetHeaderView( | 55 CreateSheetHeaderView( |
| 50 true, | 56 true, |
| 51 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE), | 57 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE), |
| 52 this), | 58 this), |
| 53 std::move(content_view)); | 59 std::move(content_view)); |
| 54 } | 60 } |
| 55 | 61 |
| 56 void OrderSummaryViewController::ButtonPressed( | 62 void OrderSummaryViewController::ButtonPressed( |
| 57 views::Button* sender, const ui::Event& event) { | 63 views::Button* sender, const ui::Event& event) { |
| 58 switch (sender->tag()) { | 64 switch (sender->tag()) { |
| 59 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG): | 65 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG): |
| 60 dialog()->CloseDialog(); | 66 dialog()->CloseDialog(); |
| 61 break; | 67 break; |
| 62 case static_cast<int>(PaymentRequestCommonTags::BACK_BUTTON_TAG): | 68 case static_cast<int>(PaymentRequestCommonTags::BACK_BUTTON_TAG): |
| 63 dialog()->GoBack(); | 69 dialog()->GoBack(); |
| 64 break; | 70 break; |
| 65 default: | 71 default: |
| 66 NOTREACHED(); | 72 NOTREACHED(); |
| 67 } | 73 } |
| 68 } | 74 } |
| 69 | 75 |
| 70 } // namespace payments | 76 } // namespace payments |
| OLD | NEW |