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

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: Change the ViewStack interface to take std::unique_ptr<views::View> directly. 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/browser/ui/views/payments/view_stack.h"
10 #include "chrome/grit/generated_resources.h"
8 #include "components/constrained_window/constrained_window_views.h" 11 #include "components/constrained_window/constrained_window_views.h"
9 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/views/controls/button/md_text_button.h"
15 #include "ui/views/controls/label.h"
10 #include "ui/views/layout/fill_layout.h" 16 #include "ui/views/layout/fill_layout.h"
17 #include "ui/views/layout/grid_layout.h"
18
19 namespace {
20
21 // The tag for the button that navigates back to the payment sheet.
22 constexpr int kBackButtonTag = 0;
23
24 // The tag for the button that navigates to the Order Summary sheet.
25 constexpr int kOrderSummaryTag = 1;
26
27 std::unique_ptr<views::View> CreateOrderSummaryView(
28 views::ButtonListener* button_listener) {
29 std::unique_ptr<views::View> view = base::MakeUnique<views::View>();
30
31 views::GridLayout* layout = new views::GridLayout(view.get());
32 view->SetLayoutManager(layout);
33 views::ColumnSet* columns = layout->AddColumnSet(0);
34 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
35 0, views::GridLayout::USE_PREF, 0, 0);
36
37 layout->StartRow(0, 0);
38 layout->AddView(new views::Label(
39 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_TITLE)));
40
41 layout->StartRow(0, 0);
42 views::LabelButton* back_button =
43 views::MdTextButton::CreateSecondaryUiBlueButton(
44 button_listener, base::ASCIIToUTF16("Back"));
45 back_button->set_tag(kBackButtonTag);
46 layout->AddView(back_button);
47
48 return view;
49 }
50
51 std::unique_ptr<views::View> CreatePaymentSheetView(
52 views::ButtonListener* button_listener) {
53 std::unique_ptr<views::View> view = base::MakeUnique<views::View>();
54
55 views::GridLayout* layout = new views::GridLayout(view.get());
56 view->SetLayoutManager(layout);
57 views::ColumnSet* columns = layout->AddColumnSet(0);
58 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
59 0, views::GridLayout::USE_PREF, 0, 0);
60
61 layout->StartRow(0, 0);
62 layout->AddView(new views::Label(
63 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE)));
64
65 layout->StartRow(0, 0);
66 views::LabelButton* order_summary_button =
67 views::MdTextButton::CreateSecondaryUiBlueButton(
68 button_listener, base::ASCIIToUTF16("Order Summary"));
69 order_summary_button->set_tag(kOrderSummaryTag);
70 layout->AddView(order_summary_button);
71
72 return view;
73 }
74
75 } // namespace
11 76
12 namespace chrome { 77 namespace chrome {
13 78
14 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) { 79 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) {
15 constrained_window::ShowWebModalDialogViews( 80 constrained_window::ShowWebModalDialogViews(
16 new payments::PaymentRequestDialog(impl), impl->web_contents()); 81 new payments::PaymentRequestDialog(impl), impl->web_contents());
17 } 82 }
18 83
19 } 84 } // namespace chrome
20 85
21 namespace payments { 86 namespace payments {
22 87
23 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl) 88 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl)
24 : impl_(impl), 89 : impl_(impl) {
25 label_(new views::Label(base::ASCIIToUTF16("Payments dialog"))) {
26 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 90 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
27 SetLayoutManager(new views::FillLayout()); 91 SetLayoutManager(new views::FillLayout());
28 AddChildView(label_.get()); 92
93 view_stack_.reset(new ViewStack(CreatePaymentSheetView(this)));
94 view_stack_->set_owned_by_client();
95 AddChildView(view_stack_.get());
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::ButtonPressed(
115 views::Button* sender, const ui::Event& event) {
116 if (sender->tag() == kBackButtonTag) {
117 GoBack();
118 } else if (sender->tag() == kOrderSummaryTag) {
119 ShowOrderSummary();
120 }
121 }
122
123 void PaymentRequestDialog::ShowOrderSummary() {
124 view_stack_->Push(CreateOrderSummaryView(this));
125 }
126
127 void PaymentRequestDialog::GoBack() {
128 view_stack_->Pop();
129 }
130
49 } // namespace payments 131 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698