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

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: Add missing include and semicolon. 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 <utility>
8
9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h"
8 #include "chrome/browser/payments/payment_request_impl.h" 11 #include "chrome/browser/payments/payment_request_impl.h"
12 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h"
13 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h"
9 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
10 #include "components/constrained_window/constrained_window_views.h" 15 #include "components/constrained_window/constrained_window_views.h"
11 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
12 #include "ui/base/l10n/l10n_util.h" 17 #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" 18 #include "ui/views/layout/fill_layout.h"
16 #include "ui/views/layout/grid_layout.h"
17 19
18 namespace { 20 namespace {
19 21
20 // The tag for the button that navigates back to the payment sheet. 22 // This function creates an instance of a PaymentRequestSheetController
21 constexpr int kBackButtonTag = 0; 23 // subclass of concrete type |Controller|, passing it non-owned pointers to
22 24 // |dialog| and the |impl| that initiated that dialog. |map| should be owned by
23 // The tag for the button that navigates to the Order Summary sheet. 25 // |dialog|.
24 constexpr int kOrderSummaryTag = 1; 26 template<typename Controller>
25 27 std::unique_ptr<views::View> CreateViewAndInstallController(
26 std::unique_ptr<views::View> CreateOrderSummaryView( 28 payments::ControllerMap* map,
27 views::ButtonListener* button_listener) { 29 payments::PaymentRequestImpl* impl,
28 std::unique_ptr<views::View> view = base::MakeUnique<views::View>(); 30 payments::PaymentRequestDialog* dialog) {
29 31 std::unique_ptr<Controller> controller =
30 views::GridLayout* layout = new views::GridLayout(view.get()); 32 base::MakeUnique<Controller>(impl, dialog);
31 view->SetLayoutManager(layout); 33 std::unique_ptr<views::View> view = controller->CreateView();
32 views::ColumnSet* columns = layout->AddColumnSet(0); 34 (*map)[view.get()] = std::move(controller);
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; 35 return view;
48 } 36 }
49 37
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 38 } // namespace
75 39
76 namespace chrome { 40 namespace chrome {
77 41
78 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) { 42 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) {
79 constrained_window::ShowWebModalDialogViews( 43 constrained_window::ShowWebModalDialogViews(
80 new payments::PaymentRequestDialog(impl), impl->web_contents()); 44 new payments::PaymentRequestDialog(impl), impl->web_contents());
81 } 45 }
82 46
83 } // namespace chrome 47 } // namespace chrome
(...skipping 10 matching lines...) Expand all
94 58
95 ShowInitialPaymentSheet(); 59 ShowInitialPaymentSheet();
96 } 60 }
97 61
98 PaymentRequestDialog::~PaymentRequestDialog() {} 62 PaymentRequestDialog::~PaymentRequestDialog() {}
99 63
100 ui::ModalType PaymentRequestDialog::GetModalType() const { 64 ui::ModalType PaymentRequestDialog::GetModalType() const {
101 return ui::MODAL_TYPE_CHILD; 65 return ui::MODAL_TYPE_CHILD;
102 } 66 }
103 67
104 gfx::Size PaymentRequestDialog::GetPreferredSize() const {
105 return gfx::Size(300, 300);
106 }
107
108 bool PaymentRequestDialog::Cancel() { 68 bool PaymentRequestDialog::Cancel() {
109 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 69 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
110 impl_->Cancel(); 70 impl_->Cancel();
111 return true; 71 return true;
112 } 72 }
113 73
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() { 74 void PaymentRequestDialog::GoBack() {
123 view_stack_.Pop(); 75 view_stack_.Pop();
124 } 76 }
125 77
126 void PaymentRequestDialog::ButtonPressed( 78 void PaymentRequestDialog::ShowOrderSummary() {
127 views::Button* sender, const ui::Event& event) { 79 view_stack_.Push(
128 if (sender->tag() == kBackButtonTag) { 80 CreateViewAndInstallController<OrderSummaryViewController>(
129 GoBack(); 81 &controller_map_, impl_, this),
130 } else if (sender->tag() == kOrderSummaryTag) { 82 true);
131 ShowOrderSummary(); 83 }
84
85 void PaymentRequestDialog::ShowInitialPaymentSheet() {
86 view_stack_.Push(
87 CreateViewAndInstallController<PaymentSheetViewController>(
88 &controller_map_, impl_, this),
89 false);
90 }
91
92 gfx::Size PaymentRequestDialog::GetPreferredSize() const {
93 return gfx::Size(450, 450);
94 }
95
96 void PaymentRequestDialog::ViewHierarchyChanged(
97 const ViewHierarchyChangedDetails& details) {
98 // When a view that is associated with a controller is removed from this
99 // view's descendants, dispose of the controller.
100 if (!details.is_add &&
101 controller_map_.find(details.child) != controller_map_.end()) {
102 DCHECK(!details.move_view);
103 controller_map_.erase(details.child);
132 } 104 }
133 } 105 }
134 106
135 } // namespace payments 107 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698