Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: chrome/browser/ui/views/payments/payment_sheet_view_controller.cc

Issue 2715213005: [Payments] Add the pay button, and control its enabled state (Closed)
Patch Set: tweak Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_sheet_view_controller.h" 5 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 14 matching lines...) Expand all
25 #include "components/autofill/core/browser/personal_data_manager.h" 25 #include "components/autofill/core/browser/personal_data_manager.h"
26 #include "components/payments/content/payment_request.h" 26 #include "components/payments/content/payment_request.h"
27 #include "components/payments/core/currency_formatter.h" 27 #include "components/payments/core/currency_formatter.h"
28 #include "components/strings/grit/components_strings.h" 28 #include "components/strings/grit/components_strings.h"
29 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
30 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/gfx/color_utils.h" 31 #include "ui/gfx/color_utils.h"
32 #include "ui/gfx/font.h" 32 #include "ui/gfx/font.h"
33 #include "ui/gfx/paint_vector_icon.h" 33 #include "ui/gfx/paint_vector_icon.h"
34 #include "ui/gfx/range/range.h" 34 #include "ui/gfx/range/range.h"
35 #include "ui/views/controls/button/label_button.h"
36 #include "ui/views/controls/button/md_text_button.h" 35 #include "ui/views/controls/button/md_text_button.h"
37 #include "ui/views/controls/image_view.h" 36 #include "ui/views/controls/image_view.h"
38 #include "ui/views/controls/label.h" 37 #include "ui/views/controls/label.h"
39 #include "ui/views/controls/styled_label.h" 38 #include "ui/views/controls/styled_label.h"
40 #include "ui/views/layout/fill_layout.h" 39 #include "ui/views/layout/fill_layout.h"
41 #include "ui/views/layout/grid_layout.h" 40 #include "ui/views/layout/grid_layout.h"
42 #include "ui/views/vector_icons.h" 41 #include "ui/views/vector_icons.h"
43 #include "ui/views/view.h" 42 #include "ui/views/view.h"
44 43
45 namespace payments { 44 namespace payments {
46 namespace { 45 namespace {
47 46
48 constexpr int kFirstTagValue = static_cast<int>( 47 constexpr int kFirstTagValue = static_cast<int>(
49 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX); 48 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX);
50 49
51 enum class PaymentSheetViewControllerTags { 50 enum class PaymentSheetViewControllerTags {
52 // The tag for the button that navigates to the Order Summary sheet. 51 // The tag for the button that navigates to the Order Summary sheet.
53 SHOW_ORDER_SUMMARY_BUTTON = kFirstTagValue, 52 SHOW_ORDER_SUMMARY_BUTTON = kFirstTagValue,
54 SHOW_SHIPPING_BUTTON, 53 SHOW_SHIPPING_BUTTON,
55 SHOW_PAYMENT_METHOD_BUTTON, 54 SHOW_PAYMENT_METHOD_BUTTON,
56 SHOW_CONTACT_INFO_BUTTON, 55 SHOW_CONTACT_INFO_BUTTON,
56 PAY_BUTTON
57 }; 57 };
58 58
59 int ComputeWidestNameColumnViewWidth() { 59 int ComputeWidestNameColumnViewWidth() {
60 // The name colums in each row should all have the same width, large enough to 60 // The name colums in each row should all have the same width, large enough to
61 // accomodate the longest piece of text they contain. Because of this, each 61 // accomodate the longest piece of text they contain. Because of this, each
62 // row's GridLayout requires its first column to have a fixed width of the 62 // row's GridLayout requires its first column to have a fixed width of the
63 // correct size. To measure the required size, layout a label with each 63 // correct size. To measure the required size, layout a label with each
64 // section name, measure its width, then initialize |widest_column_width| 64 // section name, measure its width, then initialize |widest_column_width|
65 // with the largest value. 65 // with the largest value.
66 std::vector<int> section_names{ 66 std::vector<int> section_names{
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 return std::move(row); 161 return std::move(row);
162 } 162 }
163 163
164 } // namespace 164 } // namespace
165 165
166 PaymentSheetViewController::PaymentSheetViewController( 166 PaymentSheetViewController::PaymentSheetViewController(
167 PaymentRequest* request, 167 PaymentRequest* request,
168 PaymentRequestDialogView* dialog) 168 PaymentRequestDialogView* dialog)
169 : PaymentRequestSheetController(request, dialog), 169 : PaymentRequestSheetController(request, dialog),
170 pay_button_(nullptr),
170 widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) {} 171 widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) {}
171 172
172 PaymentSheetViewController::~PaymentSheetViewController() {} 173 PaymentSheetViewController::~PaymentSheetViewController() {}
173 174
174 std::unique_ptr<views::View> PaymentSheetViewController::CreateView() { 175 std::unique_ptr<views::View> PaymentSheetViewController::CreateView() {
175 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); 176 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>();
176 177
177 views::GridLayout* layout = new views::GridLayout(content_view.get()); 178 views::GridLayout* layout = new views::GridLayout(content_view.get());
178 content_view->SetLayoutManager(layout); 179 content_view->SetLayoutManager(layout);
179 views::ColumnSet* columns = layout->AddColumnSet(0); 180 views::ColumnSet* columns = layout->AddColumnSet(0);
(...skipping 10 matching lines...) Expand all
190 layout->AddView(CreateContactInfoRow().release()); 191 layout->AddView(CreateContactInfoRow().release());
191 192
192 return CreatePaymentView( 193 return CreatePaymentView(
193 CreateSheetHeaderView( 194 CreateSheetHeaderView(
194 false, 195 false,
195 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE), 196 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE),
196 this), 197 this),
197 std::move(content_view)); 198 std::move(content_view));
198 } 199 }
199 200
201 std::unique_ptr<views::Button>
202 PaymentSheetViewController::CreatePrimaryButton() {
203 std::unique_ptr<views::Button> button(
204 views::MdTextButton::CreateSecondaryUiBlueButton(
205 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON)));
206 button->set_tag(static_cast<int>(PaymentSheetViewControllerTags::PAY_BUTTON));
207 button->set_id(static_cast<int>(DialogViewID::PAYMENT_SHEET_PAY_BUTTON));
208 pay_button_ = button.get();
209 UpdatePayButtonState(request()->is_ready_to_pay());
210 return button;
211 }
212
200 void PaymentSheetViewController::ButtonPressed( 213 void PaymentSheetViewController::ButtonPressed(
201 views::Button* sender, const ui::Event& event) { 214 views::Button* sender, const ui::Event& event) {
202 switch (sender->tag()) { 215 switch (sender->tag()) {
203 case static_cast<int>( 216 case static_cast<int>(
204 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON): 217 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON):
205 dialog()->ShowOrderSummary(); 218 dialog()->ShowOrderSummary();
206 break; 219 break;
207 220
208 case static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON): 221 case static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON):
209 dialog()->ShowShippingListSheet(); 222 dialog()->ShowShippingListSheet();
210 break; 223 break;
211 224
212 case static_cast<int>( 225 case static_cast<int>(
213 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON): 226 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON):
214 dialog()->ShowPaymentMethodSheet(); 227 dialog()->ShowPaymentMethodSheet();
215 break; 228 break;
216 229
217 case static_cast<int>( 230 case static_cast<int>(
218 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON): 231 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON):
219 // TODO(tmartino): Transition to contact info page once it exists. 232 // TODO(tmartino): Transition to contact info page once it exists.
220 break; 233 break;
221 234
235 case static_cast<int>(PaymentSheetViewControllerTags::PAY_BUTTON):
236 request()->Pay();
237 break;
238
222 default: 239 default:
223 PaymentRequestSheetController::ButtonPressed(sender, event); 240 PaymentRequestSheetController::ButtonPressed(sender, event);
224 break; 241 break;
225 } 242 }
226 } 243 }
227 244
245 void PaymentSheetViewController::UpdatePayButtonState(bool enabled) {
246 pay_button_->SetEnabled(enabled);
247 }
248
228 std::unique_ptr<views::View> 249 std::unique_ptr<views::View>
229 PaymentSheetViewController::CreateOrderSummarySectionContent() { 250 PaymentSheetViewController::CreateOrderSummarySectionContent() {
230 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter( 251 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter(
231 request()->details()->total->amount->currency, 252 request()->details()->total->amount->currency,
232 request()->details()->total->amount->currency_system, 253 request()->details()->total->amount->currency_system,
233 g_browser_process->GetApplicationLocale()); 254 g_browser_process->GetApplicationLocale());
234 base::string16 label_value = l10n_util::GetStringFUTF16( 255 base::string16 label_value = l10n_util::GetStringFUTF16(
235 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT, 256 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT,
236 base::UTF8ToUTF16(request()->details()->total->label), 257 base::UTF8ToUTF16(request()->details()->total->label),
237 base::UTF8ToUTF16(formatter->formatted_currency_code()), 258 base::UTF8ToUTF16(formatter->formatted_currency_code()),
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), 385 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr),
365 widest_name_column_view_width_); 386 widest_name_column_view_width_);
366 section->set_tag(static_cast<int>( 387 section->set_tag(static_cast<int>(
367 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); 388 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON));
368 section->set_id( 389 section->set_id(
369 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); 390 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION));
370 return section; 391 return section;
371 } 392 }
372 393
373 } // namespace payments 394 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698