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