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

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

Issue 2528503002: [WebPayments] Implement state transitions in desktop WebPayments dialog. (Closed)
Patch Set: Handle Layout while animating Created 4 years 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_request_dialog.h"
6
5 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/browser/payments/payment_request_impl.h" 8 #include "chrome/browser/payments/payment_request_impl.h"
7 #include "chrome/browser/ui/views/payments/payment_request_dialog.h" 9 #include "chrome/grit/generated_resources.h"
8 #include "components/constrained_window/constrained_window_views.h" 10 #include "components/constrained_window/constrained_window_views.h"
9 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/views/controls/button/md_text_button.h"
14 #include "ui/views/controls/label.h"
10 #include "ui/views/layout/fill_layout.h" 15 #include "ui/views/layout/fill_layout.h"
16 #include "ui/views/layout/grid_layout.h"
17
18 namespace {
19
20 // The tag for the button that navigates back to the payment sheet.
21 constexpr int kBackButtonTag = 0;
22
23 // The tag for the button that navigates to the Order Summary sheet.
24 constexpr int kOrderSummaryTag = 1;
25
26 std::unique_ptr<views::View> CreateOrderSummaryView(
27 views::ButtonListener* button_listener) {
28 std::unique_ptr<views::View> view = base::MakeUnique<views::View>();
29
30 views::GridLayout* layout = new views::GridLayout(view.get());
31 view->SetLayoutManager(layout);
32 views::ColumnSet* columns = layout->AddColumnSet(0);
33 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
34 0, views::GridLayout::USE_PREF, 0, 0);
35
36 layout->StartRow(0, 0);
37 layout->AddView(new views::Label(
38 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE)));
39
40 layout->StartRow(0, 0);
41 views::LabelButton* back_button =
42 views::MdTextButton::CreateSecondaryUiBlueButton(
43 button_listener, base::ASCIIToUTF16("Back"));
44 back_button->set_tag(kBackButtonTag);
45 layout->AddView(back_button);
46
47 return view;
48 }
49
50 std::unique_ptr<views::View> CreatePaymentSheetView(
51 views::ButtonListener* button_listener) {
52 std::unique_ptr<views::View> view = base::MakeUnique<views::View>();
53
54 views::GridLayout* layout = new views::GridLayout(view.get());
55 view->SetLayoutManager(layout);
56 views::ColumnSet* columns = layout->AddColumnSet(0);
57 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
58 0, views::GridLayout::USE_PREF, 0, 0);
59
60 layout->StartRow(0, 0);
61 layout->AddView(new views::Label(
62 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE)));
63
64 layout->StartRow(0, 0);
65 views::LabelButton* order_summary_button =
66 views::MdTextButton::CreateSecondaryUiBlueButton(
67 button_listener, base::ASCIIToUTF16("Order Summary"));
68 order_summary_button->set_tag(kOrderSummaryTag);
69 layout->AddView(order_summary_button);
70
71 return view;
72 }
73
74 } // namespace
11 75
12 namespace chrome { 76 namespace chrome {
13 77
14 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) { 78 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) {
15 constrained_window::ShowWebModalDialogViews( 79 constrained_window::ShowWebModalDialogViews(
16 new payments::PaymentRequestDialog(impl), impl->web_contents()); 80 new payments::PaymentRequestDialog(impl), impl->web_contents());
17 } 81 }
18 82
19 } 83 } // namespace chrome
20 84
21 namespace payments { 85 namespace payments {
22 86
23 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl) 87 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl)
24 : impl_(impl), 88 : impl_(impl) {
25 label_(new views::Label(base::ASCIIToUTF16("Payments dialog"))) {
26 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
27 SetLayoutManager(new views::FillLayout()); 90 SetLayoutManager(new views::FillLayout());
28 AddChildView(label_.get()); 91
92 view_stack_.set_owned_by_client();
93 AddChildView(&view_stack_);
94
95 ShowInitialPaymentSheet();
29 } 96 }
30 97
31 PaymentRequestDialog::~PaymentRequestDialog() {} 98 PaymentRequestDialog::~PaymentRequestDialog() {}
32 99
33 ui::ModalType PaymentRequestDialog::GetModalType() const { 100 ui::ModalType PaymentRequestDialog::GetModalType() const {
34 return ui::MODAL_TYPE_CHILD; 101 return ui::MODAL_TYPE_CHILD;
35 } 102 }
36 103
37 gfx::Size PaymentRequestDialog::GetPreferredSize() const { 104 gfx::Size PaymentRequestDialog::GetPreferredSize() const {
38 gfx::Size ps = label_->GetPreferredSize(); 105 return gfx::Size(300, 300);
39 ps.Enlarge(200, 200);
40 return ps;
41 } 106 }
42 107
43 bool PaymentRequestDialog::Cancel() { 108 bool PaymentRequestDialog::Cancel() {
44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 109 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
45 impl_->Cancel(); 110 impl_->Cancel();
46 return true; 111 return true;
47 } 112 }
48 113
114 void PaymentRequestDialog::ShowInitialPaymentSheet() {
115 view_stack_.Push(CreatePaymentSheetView(this), false);
116 }
117
118 void PaymentRequestDialog::ShowOrderSummary() {
119 view_stack_.Push(CreateOrderSummaryView(this), true);
120 }
121
122 void PaymentRequestDialog::GoBack() {
123 view_stack_.Pop();
124 }
125
126 void PaymentRequestDialog::ButtonPressed(
127 views::Button* sender, const ui::Event& event) {
128 if (sender->tag() == kBackButtonTag) {
129 GoBack();
130 } else if (sender->tag() == kOrderSummaryTag) {
131 ShowOrderSummary();
132 }
133 }
134
49 } // namespace payments 135 } // namespace payments
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/payments/payment_request_dialog.h ('k') | chrome/browser/ui/views/payments/view_stack.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698