| 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 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 15 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 16 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 16 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| 17 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 17 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 18 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 19 #include "components/payments/content/payment_request_spec.h" |
| 20 #include "components/payments/content/payment_request_state.h" |
| 19 #include "components/payments/core/currency_formatter.h" | 21 #include "components/payments/core/currency_formatter.h" |
| 20 #include "components/strings/grit/components_strings.h" | 22 #include "components/strings/grit/components_strings.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/gfx/font.h" | 24 #include "ui/gfx/font.h" |
| 23 #include "ui/views/border.h" | 25 #include "ui/views/border.h" |
| 24 #include "ui/views/controls/button/md_text_button.h" | 26 #include "ui/views/controls/button/md_text_button.h" |
| 25 #include "ui/views/controls/label.h" | 27 #include "ui/views/controls/label.h" |
| 26 #include "ui/views/controls/styled_label.h" | 28 #include "ui/views/controls/styled_label.h" |
| 27 #include "ui/views/layout/box_layout.h" | 29 #include "ui/views/layout/box_layout.h" |
| 28 #include "ui/views/layout/grid_layout.h" | 30 #include "ui/views/layout/grid_layout.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 81 |
| 80 return row; | 82 return row; |
| 81 } | 83 } |
| 82 | 84 |
| 83 } // namespace | 85 } // namespace |
| 84 | 86 |
| 85 OrderSummaryViewController::OrderSummaryViewController( | 87 OrderSummaryViewController::OrderSummaryViewController( |
| 86 PaymentRequest* request, | 88 PaymentRequest* request, |
| 87 PaymentRequestDialogView* dialog) | 89 PaymentRequestDialogView* dialog) |
| 88 : PaymentRequestSheetController(request, dialog), pay_button_(nullptr) { | 90 : PaymentRequestSheetController(request, dialog), pay_button_(nullptr) { |
| 89 request->AddObserver(this); | 91 request->state()->AddObserver(this); |
| 90 } | 92 } |
| 91 | 93 |
| 92 OrderSummaryViewController::~OrderSummaryViewController() { | 94 OrderSummaryViewController::~OrderSummaryViewController() { |
| 93 request()->RemoveObserver(this); | 95 request()->state()->RemoveObserver(this); |
| 94 } | 96 } |
| 95 | 97 |
| 96 std::unique_ptr<views::View> OrderSummaryViewController::CreateView() { | 98 std::unique_ptr<views::View> OrderSummaryViewController::CreateView() { |
| 97 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); | 99 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); |
| 98 | 100 |
| 99 views::BoxLayout* layout = new views::BoxLayout( | 101 views::BoxLayout* layout = new views::BoxLayout( |
| 100 views::BoxLayout::kVertical, 0, 0, 0); | 102 views::BoxLayout::kVertical, 0, 0, 0); |
| 101 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | 103 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); |
| 102 layout->set_cross_axis_alignment( | 104 layout->set_cross_axis_alignment( |
| 103 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); | 105 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); |
| 104 content_view->SetLayoutManager(layout); | 106 content_view->SetLayoutManager(layout); |
| 105 | 107 |
| 106 // Set the ID for the first few line items labels, for testing. | 108 // Set the ID for the first few line items labels, for testing. |
| 107 const std::vector<DialogViewID> line_items{ | 109 const std::vector<DialogViewID> line_items{ |
| 108 DialogViewID::ORDER_SUMMARY_LINE_ITEM_1, | 110 DialogViewID::ORDER_SUMMARY_LINE_ITEM_1, |
| 109 DialogViewID::ORDER_SUMMARY_LINE_ITEM_2, | 111 DialogViewID::ORDER_SUMMARY_LINE_ITEM_2, |
| 110 DialogViewID::ORDER_SUMMARY_LINE_ITEM_3}; | 112 DialogViewID::ORDER_SUMMARY_LINE_ITEM_3}; |
| 111 for (size_t i = 0; i < request()->details()->display_items.size(); i++) { | 113 for (size_t i = 0; i < request()->spec()->details().display_items.size(); |
| 114 i++) { |
| 112 DialogViewID view_id = | 115 DialogViewID view_id = |
| 113 i < line_items.size() ? line_items[i] : DialogViewID::VIEW_ID_NONE; | 116 i < line_items.size() ? line_items[i] : DialogViewID::VIEW_ID_NONE; |
| 114 content_view->AddChildView( | 117 content_view->AddChildView( |
| 115 CreateLineItemView( | 118 CreateLineItemView( |
| 116 base::UTF8ToUTF16(request()->details()->display_items[i]->label), | 119 base::UTF8ToUTF16( |
| 120 request()->spec()->details().display_items[i]->label), |
| 117 request()->GetFormattedCurrencyAmount( | 121 request()->GetFormattedCurrencyAmount( |
| 118 request()->details()->display_items[i]->amount->value), | 122 request()->spec()->details().display_items[i]->amount->value), |
| 119 false, view_id) | 123 false, view_id) |
| 120 .release()); | 124 .release()); |
| 121 } | 125 } |
| 122 | 126 |
| 123 base::string16 total_label_value = l10n_util::GetStringFUTF16( | 127 base::string16 total_label_value = l10n_util::GetStringFUTF16( |
| 124 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, | 128 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, |
| 125 base::UTF8ToUTF16(request()->details()->total->amount->currency), | 129 base::UTF8ToUTF16(request()->spec()->details().total->amount->currency), |
| 126 request()->GetFormattedCurrencyAmount( | 130 request()->GetFormattedCurrencyAmount( |
| 127 request()->details()->total->amount->value)); | 131 request()->spec()->details().total->amount->value)); |
| 128 | 132 |
| 129 content_view->AddChildView( | 133 content_view->AddChildView( |
| 130 CreateLineItemView(base::UTF8ToUTF16(request()->details()->total->label), | 134 CreateLineItemView( |
| 131 total_label_value, true, | 135 base::UTF8ToUTF16(request()->spec()->details().total->label), |
| 132 DialogViewID::ORDER_SUMMARY_TOTAL_AMOUNT_LABEL) | 136 total_label_value, true, |
| 137 DialogViewID::ORDER_SUMMARY_TOTAL_AMOUNT_LABEL) |
| 133 .release()); | 138 .release()); |
| 134 | 139 |
| 135 return CreatePaymentView( | 140 return CreatePaymentView( |
| 136 CreateSheetHeaderView( | 141 CreateSheetHeaderView( |
| 137 true, | 142 true, |
| 138 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE), | 143 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE), |
| 139 this), | 144 this), |
| 140 std::move(content_view)); | 145 std::move(content_view)); |
| 141 } | 146 } |
| 142 | 147 |
| 143 std::unique_ptr<views::Button> | 148 std::unique_ptr<views::Button> |
| 144 OrderSummaryViewController::CreatePrimaryButton() { | 149 OrderSummaryViewController::CreatePrimaryButton() { |
| 145 std::unique_ptr<views::Button> button( | 150 std::unique_ptr<views::Button> button( |
| 146 views::MdTextButton::CreateSecondaryUiBlueButton( | 151 views::MdTextButton::CreateSecondaryUiBlueButton( |
| 147 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); | 152 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); |
| 148 button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG)); | 153 button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG)); |
| 149 button->set_id(static_cast<int>(DialogViewID::PAY_BUTTON)); | 154 button->set_id(static_cast<int>(DialogViewID::PAY_BUTTON)); |
| 150 pay_button_ = button.get(); | 155 pay_button_ = button.get(); |
| 151 UpdatePayButtonState(request()->is_ready_to_pay()); | 156 UpdatePayButtonState(request()->state()->is_ready_to_pay()); |
| 152 return button; | 157 return button; |
| 153 } | 158 } |
| 154 | 159 |
| 155 void OrderSummaryViewController::OnSelectedInformationChanged() { | 160 void OrderSummaryViewController::OnSelectedInformationChanged() { |
| 156 UpdatePayButtonState(request()->is_ready_to_pay()); | 161 UpdatePayButtonState(request()->state()->is_ready_to_pay()); |
| 157 } | 162 } |
| 158 | 163 |
| 159 void OrderSummaryViewController::UpdatePayButtonState(bool enabled) { | 164 void OrderSummaryViewController::UpdatePayButtonState(bool enabled) { |
| 160 pay_button_->SetEnabled(enabled); | 165 pay_button_->SetEnabled(enabled); |
| 161 } | 166 } |
| 162 | 167 |
| 163 } // namespace payments | 168 } // namespace payments |
| OLD | NEW |