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

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

Issue 2579513002: [WebPayments] Factor out sheet-specific logic in Controllers. (Closed)
Patch Set: 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" 5 #include "chrome/browser/ui/views/payments/payment_request_dialog.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/payments/payment_request_impl.h" 8 #include "chrome/browser/payments/payment_request_impl.h"
9 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h"
10 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
11 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h"
9 #include "chrome/grit/generated_resources.h" 12 #include "chrome/grit/generated_resources.h"
10 #include "components/constrained_window/constrained_window_views.h" 13 #include "components/constrained_window/constrained_window_views.h"
11 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
12 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/views/controls/button/md_text_button.h"
14 #include "ui/views/controls/label.h"
15 #include "ui/views/layout/fill_layout.h" 16 #include "ui/views/layout/fill_layout.h"
16 #include "ui/views/layout/grid_layout.h" 17 #include "ui/views/layout/grid_layout.h"
17 18
18 namespace { 19 namespace {
19 20
20 // The tag for the button that navigates back to the payment sheet. 21 template<typename TController>
sky 2016/12/14 23:44:25 optional: I don't think 'T' adds much here, Contro
anthonyvd 2016/12/15 15:02:58 Hold habit, done.
21 constexpr int kBackButtonTag = 0; 22 std::unique_ptr<views::View> CreateViewAndInstallController(
23 payments::ControllerMap* map,
24 payments::PaymentRequestImpl* impl,
25 payments::PaymentRequestDialog* dialog) {
22 26
sky 2016/12/14 23:44:25 Remove newline?
anthonyvd 2016/12/15 15:02:58 Done.
23 // The tag for the button that navigates to the Order Summary sheet. 27 std::unique_ptr<TController> controller =
24 constexpr int kOrderSummaryTag = 1; 28 base::MakeUnique<TController>(impl, dialog);
25 29 std::unique_ptr<views::View> view = TController::CreateView(controller.get());
sky 2016/12/14 23:44:25 See comment in other file, I would change this to
anthonyvd 2016/12/15 15:02:58 Done.
26 std::unique_ptr<views::View> CreateOrderSummaryView( 30 (*map)[view.get()] = std::move(controller);
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; 31 return view;
48 } 32 }
49 33
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 34 } // namespace
75 35
76 namespace chrome { 36 namespace chrome {
77 37
78 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) { 38 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) {
79 constrained_window::ShowWebModalDialogViews( 39 constrained_window::ShowWebModalDialogViews(
80 new payments::PaymentRequestDialog(impl), impl->web_contents()); 40 new payments::PaymentRequestDialog(impl), impl->web_contents());
81 } 41 }
82 42
83 } // namespace chrome 43 } // namespace chrome
84 44
85 namespace payments { 45 namespace payments {
86 46
87 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl) 47 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl)
88 : impl_(impl) { 48 : impl_(impl) {
89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
90 SetLayoutManager(new views::FillLayout()); 50 SetLayoutManager(new views::FillLayout());
91 51
92 view_stack_.set_owned_by_client(); 52 view_stack_.set_owned_by_client();
93 AddChildView(&view_stack_); 53 AddChildView(&view_stack_);
94 54
95 ShowInitialPaymentSheet(); 55 ShowInitialPaymentSheet();
96 } 56 }
97 57
98 PaymentRequestDialog::~PaymentRequestDialog() {} 58 PaymentRequestDialog::~PaymentRequestDialog() {}
sky 2016/12/14 23:44:25 If this is hit and controller_map_ is non-empty th
anthonyvd 2016/12/15 15:02:58 Yep, that's on purpose for a couple reasons: 1-
99 59
100 ui::ModalType PaymentRequestDialog::GetModalType() const { 60 ui::ModalType PaymentRequestDialog::GetModalType() const {
101 return ui::MODAL_TYPE_CHILD; 61 return ui::MODAL_TYPE_CHILD;
102 } 62 }
103 63
104 gfx::Size PaymentRequestDialog::GetPreferredSize() const {
105 return gfx::Size(300, 300);
106 }
107
108 bool PaymentRequestDialog::Cancel() { 64 bool PaymentRequestDialog::Cancel() {
109 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 65 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
110 impl_->Cancel(); 66 impl_->Cancel();
111 return true; 67 return true;
112 } 68 }
113 69
114 void PaymentRequestDialog::ShowInitialPaymentSheet() { 70 void PaymentRequestDialog::ShowInitialPaymentSheet() {
115 view_stack_.Push(CreatePaymentSheetView(this), false); 71 view_stack_.Push(
72 CreateViewAndInstallController<PaymentSheetViewController>(
73 &controller_map_, impl_, this),
74 false);
116 } 75 }
117 76
118 void PaymentRequestDialog::ShowOrderSummary() { 77 void PaymentRequestDialog::ShowOrderSummary() {
119 view_stack_.Push(CreateOrderSummaryView(this), true); 78 view_stack_.Push(
79 CreateViewAndInstallController<OrderSummaryViewController>(
80 &controller_map_, impl_, this),
81 true);
120 } 82 }
121 83
122 void PaymentRequestDialog::GoBack() { 84 void PaymentRequestDialog::GoBack() {
123 view_stack_.Pop(); 85 view_stack_.Pop();
124 } 86 }
125 87
126 void PaymentRequestDialog::ButtonPressed( 88 gfx::Size PaymentRequestDialog::GetPreferredSize() const {
127 views::Button* sender, const ui::Event& event) { 89 return gfx::Size(450, 450);
128 if (sender->tag() == kBackButtonTag) { 90 }
129 GoBack(); 91
130 } else if (sender->tag() == kOrderSummaryTag) { 92 void PaymentRequestDialog::ViewHierarchyChanged(
131 ShowOrderSummary(); 93 const ViewHierarchyChangedDetails& details) {
94 // When a view that is associated with a controller is removed from this
95 // view's descendants, dispose of the controller.
96 if (!details.is_add &&
97 controller_map_.find(details.child) != controller_map_.end()) {
98 DCHECK(!details.move_view);
99 controller_map_.erase(details.child);
132 } 100 }
133 } 101 }
134 102
135 } // namespace payments 103 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698