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 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 PaymentRequestState* state, | 88 PaymentRequestState* state, |
89 PaymentRequestDialogView* dialog) | 89 PaymentRequestDialogView* dialog) |
90 : PaymentRequestSheetController(spec, state, dialog), pay_button_(nullptr) { | 90 : PaymentRequestSheetController(spec, state, dialog), pay_button_(nullptr) { |
91 state->AddObserver(this); | 91 state->AddObserver(this); |
92 } | 92 } |
93 | 93 |
94 OrderSummaryViewController::~OrderSummaryViewController() { | 94 OrderSummaryViewController::~OrderSummaryViewController() { |
95 state()->RemoveObserver(this); | 95 state()->RemoveObserver(this); |
96 } | 96 } |
97 | 97 |
98 std::unique_ptr<views::View> OrderSummaryViewController::CreateView() { | 98 std::unique_ptr<views::Button> |
99 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); | 99 OrderSummaryViewController::CreatePrimaryButton() { |
| 100 std::unique_ptr<views::Button> button( |
| 101 views::MdTextButton::CreateSecondaryUiBlueButton( |
| 102 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); |
| 103 button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG)); |
| 104 button->set_id(static_cast<int>(DialogViewID::PAY_BUTTON)); |
| 105 pay_button_ = button.get(); |
| 106 UpdatePayButtonState(state()->is_ready_to_pay()); |
| 107 return button; |
| 108 } |
100 | 109 |
| 110 base::string16 OrderSummaryViewController::GetSheetTitle() { |
| 111 return l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE); |
| 112 } |
| 113 |
| 114 void OrderSummaryViewController::FillContentView(views::View* content_view) { |
101 views::BoxLayout* layout = new views::BoxLayout( | 115 views::BoxLayout* layout = new views::BoxLayout( |
102 views::BoxLayout::kVertical, 0, 0, 0); | 116 views::BoxLayout::kVertical, 0, 0, 0); |
103 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | 117 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); |
104 layout->set_cross_axis_alignment( | 118 layout->set_cross_axis_alignment( |
105 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); | 119 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); |
106 content_view->SetLayoutManager(layout); | 120 content_view->SetLayoutManager(layout); |
107 | 121 |
108 // Set the ID for the first few line items labels, for testing. | 122 // Set the ID for the first few line items labels, for testing. |
109 const std::vector<DialogViewID> line_items{ | 123 const std::vector<DialogViewID> line_items{ |
110 DialogViewID::ORDER_SUMMARY_LINE_ITEM_1, | 124 DialogViewID::ORDER_SUMMARY_LINE_ITEM_1, |
(...skipping 15 matching lines...) Expand all Loading... |
126 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, | 140 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, |
127 base::UTF8ToUTF16(spec()->details().total->amount->currency), | 141 base::UTF8ToUTF16(spec()->details().total->amount->currency), |
128 spec()->GetFormattedCurrencyAmount( | 142 spec()->GetFormattedCurrencyAmount( |
129 spec()->details().total->amount->value)); | 143 spec()->details().total->amount->value)); |
130 | 144 |
131 content_view->AddChildView( | 145 content_view->AddChildView( |
132 CreateLineItemView(base::UTF8ToUTF16(spec()->details().total->label), | 146 CreateLineItemView(base::UTF8ToUTF16(spec()->details().total->label), |
133 total_label_value, true, | 147 total_label_value, true, |
134 DialogViewID::ORDER_SUMMARY_TOTAL_AMOUNT_LABEL) | 148 DialogViewID::ORDER_SUMMARY_TOTAL_AMOUNT_LABEL) |
135 .release()); | 149 .release()); |
136 | |
137 return CreatePaymentView( | |
138 CreateSheetHeaderView( | |
139 true, | |
140 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE), | |
141 this), | |
142 std::move(content_view)); | |
143 } | |
144 | |
145 std::unique_ptr<views::Button> | |
146 OrderSummaryViewController::CreatePrimaryButton() { | |
147 std::unique_ptr<views::Button> button( | |
148 views::MdTextButton::CreateSecondaryUiBlueButton( | |
149 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); | |
150 button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG)); | |
151 button->set_id(static_cast<int>(DialogViewID::PAY_BUTTON)); | |
152 pay_button_ = button.get(); | |
153 UpdatePayButtonState(state()->is_ready_to_pay()); | |
154 return button; | |
155 } | 150 } |
156 | 151 |
157 void OrderSummaryViewController::OnSelectedInformationChanged() { | 152 void OrderSummaryViewController::OnSelectedInformationChanged() { |
158 UpdatePayButtonState(state()->is_ready_to_pay()); | 153 UpdatePayButtonState(state()->is_ready_to_pay()); |
159 } | 154 } |
160 | 155 |
161 void OrderSummaryViewController::UpdatePayButtonState(bool enabled) { | 156 void OrderSummaryViewController::UpdatePayButtonState(bool enabled) { |
162 pay_button_->SetEnabled(enabled); | 157 pay_button_->SetEnabled(enabled); |
163 } | 158 } |
164 | 159 |
165 } // namespace payments | 160 } // namespace payments |
OLD | NEW |