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

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

Issue 2649683002: [Payments] Improve the closing of the PR dialog. (Closed)
Patch Set: nits Created 3 years, 11 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_request_dialog.h" 5 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" 11 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h"
12 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h" 12 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h"
13 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" 13 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h"
14 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
15 #include "components/constrained_window/constrained_window_views.h" 15 #include "components/constrained_window/constrained_window_views.h"
16 #include "components/payments/payment_request.h" 16 #include "components/payments/payment_request.h"
17 #include "components/payments/payment_request_dialog.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/views/layout/fill_layout.h" 20 #include "ui/views/layout/fill_layout.h"
20 21
21 namespace chrome { 22 namespace chrome {
22 23
23 void ShowPaymentRequestDialog(payments::PaymentRequest* request) { 24 payments::PaymentRequestDialog* CreatePaymentRequestDialog(
24 payments::PaymentRequestDialog::ShowWebModalPaymentDialog( 25 payments::PaymentRequest* request) {
25 new payments::PaymentRequestDialog(request, /* no observer */ nullptr), 26 return new payments::PaymentRequestDialogView(request,
26 request); 27 /* no observer */ nullptr);
27 } 28 }
28 29
29 } // namespace chrome 30 } // namespace chrome
30 31
31 namespace payments { 32 namespace payments {
32 namespace { 33 namespace {
33 34
34 // This function creates an instance of a PaymentRequestSheetController 35 // This function creates an instance of a PaymentRequestSheetController
35 // subclass of concrete type |Controller|, passing it non-owned pointers to 36 // subclass of concrete type |Controller|, passing it non-owned pointers to
36 // |dialog| and the |request| that initiated that dialog. |map| should be owned 37 // |dialog| and the |request| that initiated that dialog. |map| should be owned
37 // by |dialog|. 38 // by |dialog|.
38 template <typename Controller> 39 template <typename Controller>
39 std::unique_ptr<views::View> CreateViewAndInstallController( 40 std::unique_ptr<views::View> CreateViewAndInstallController(
40 payments::ControllerMap* map, 41 payments::ControllerMap* map,
41 payments::PaymentRequest* request, 42 payments::PaymentRequest* request,
42 payments::PaymentRequestDialog* dialog) { 43 payments::PaymentRequestDialogView* dialog) {
43 std::unique_ptr<Controller> controller = 44 std::unique_ptr<Controller> controller =
44 base::MakeUnique<Controller>(request, dialog); 45 base::MakeUnique<Controller>(request, dialog);
45 std::unique_ptr<views::View> view = controller->CreateView(); 46 std::unique_ptr<views::View> view = controller->CreateView();
46 (*map)[view.get()] = std::move(controller); 47 (*map)[view.get()] = std::move(controller);
47 return view; 48 return view;
48 } 49 }
49 50
50 } // namespace 51 } // namespace
51 52
52 PaymentRequestDialog::PaymentRequestDialog( 53 PaymentRequestDialogView::PaymentRequestDialogView(
53 PaymentRequest* request, 54 PaymentRequest* request,
54 PaymentRequestDialog::ObserverForTest* observer) 55 PaymentRequestDialogView::ObserverForTest* observer)
55 : request_(request), observer_(observer) { 56 : request_(request),
57 observer_for_testing_(observer),
58 widget_for_testing_(nullptr) {
56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 59 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
57 SetLayoutManager(new views::FillLayout()); 60 SetLayoutManager(new views::FillLayout());
58 61
59 view_stack_.set_owned_by_client(); 62 view_stack_.set_owned_by_client();
60 AddChildView(&view_stack_); 63 AddChildView(&view_stack_);
61 64
62 ShowInitialPaymentSheet(); 65 ShowInitialPaymentSheet();
63 } 66 }
64 67
65 PaymentRequestDialog::~PaymentRequestDialog() {} 68 PaymentRequestDialogView::~PaymentRequestDialogView() {}
66 69
67 ui::ModalType PaymentRequestDialog::GetModalType() const { 70 ui::ModalType PaymentRequestDialogView::GetModalType() const {
68 return ui::MODAL_TYPE_CHILD; 71 return ui::MODAL_TYPE_CHILD;
69 } 72 }
70 73
71 bool PaymentRequestDialog::Cancel() { 74 bool PaymentRequestDialogView::Cancel() {
75 // Called when the widget is about to close. We send a message to the
76 // PaymentRequest object to signal user cancellation.
72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
73 request_->Cancel(); 78 request_->UserCancelled();
74 return true; 79 return true;
75 } 80 }
76 81
77 bool PaymentRequestDialog::ShouldShowCloseButton() const { 82 bool PaymentRequestDialogView::ShouldShowCloseButton() const {
78 // Don't show the normal close button on the dialog. This is because the 83 // Don't show the normal close button on the dialog. This is because the
79 // typical dialog header doesn't allow displaying anything other that the 84 // typical dialog header doesn't allow displaying anything other that the
80 // title and the close button. This is insufficient for the PaymentRequest 85 // title and the close button. This is insufficient for the PaymentRequest
81 // dialog, which must sometimes show the back arrow next to the title. 86 // dialog, which must sometimes show the back arrow next to the title.
82 // Moreover, the title (and back arrow) should animate with the view they're 87 // Moreover, the title (and back arrow) should animate with the view they're
83 // attached to. 88 // attached to.
84 return false; 89 return false;
85 } 90 }
86 91
87 int PaymentRequestDialog::GetDialogButtons() const { 92 int PaymentRequestDialogView::GetDialogButtons() const {
88 // The buttons should animate along with the different dialog sheets since 93 // The buttons should animate along with the different dialog sheets since
89 // each sheet presents a different set of buttons. Because of this, hide the 94 // each sheet presents a different set of buttons. Because of this, hide the
90 // usual dialog buttons. 95 // usual dialog buttons.
91 return ui::DIALOG_BUTTON_NONE; 96 return ui::DIALOG_BUTTON_NONE;
92 } 97 }
93 98
94 void PaymentRequestDialog::GoBack() { 99 void PaymentRequestDialogView::GoBack() {
95 view_stack_.Pop(); 100 view_stack_.Pop();
96 } 101 }
97 102
98 void PaymentRequestDialog::ShowOrderSummary() { 103 void PaymentRequestDialogView::ShowOrderSummary() {
99 view_stack_.Push(CreateViewAndInstallController<OrderSummaryViewController>( 104 view_stack_.Push(CreateViewAndInstallController<OrderSummaryViewController>(
100 &controller_map_, request_, this), 105 &controller_map_, request_, this),
101 true); 106 true);
102 } 107 }
103 108
104 void PaymentRequestDialog::ShowPaymentMethodSheet() { 109 void PaymentRequestDialogView::ShowPaymentMethodSheet() {
105 view_stack_.Push( 110 view_stack_.Push(CreateViewAndInstallController<PaymentMethodViewController>(
106 CreateViewAndInstallController<PaymentMethodViewController>( 111 &controller_map_, request_, this),
107 &controller_map_, request_, this), 112 true);
108 true);
109 } 113 }
110 114
111 void PaymentRequestDialog::CloseDialog() { 115 void PaymentRequestDialogView::ShowDialog() {
116 widget_for_testing_ = constrained_window::ShowWebModalDialogViews(
117 this, request_->web_contents());
118 }
119
120 void PaymentRequestDialogView::CloseDialog() {
121 // This calls PaymentRequestDialogView::Cancel() before closing.
112 GetWidget()->Close(); 122 GetWidget()->Close();
113 } 123 }
114 124
115 // static 125 void PaymentRequestDialogView::ShowInitialPaymentSheet() {
116 void PaymentRequestDialog::ShowWebModalPaymentDialog(
117 PaymentRequestDialog* dialog,
118 PaymentRequest* request) {
119 constrained_window::ShowWebModalDialogViews(dialog, request->web_contents());
120 }
121
122 void PaymentRequestDialog::ShowInitialPaymentSheet() {
123 view_stack_.Push(CreateViewAndInstallController<PaymentSheetViewController>( 126 view_stack_.Push(CreateViewAndInstallController<PaymentSheetViewController>(
124 &controller_map_, request_, this), 127 &controller_map_, request_, this),
125 false); 128 false);
126 if (observer_) 129 if (observer_for_testing_)
127 observer_->OnDialogOpened(); 130 observer_for_testing_->OnDialogOpened();
128 } 131 }
129 132
130 gfx::Size PaymentRequestDialog::GetPreferredSize() const { 133 gfx::Size PaymentRequestDialogView::GetPreferredSize() const {
131 return gfx::Size(450, 450); 134 return gfx::Size(450, 450);
132 } 135 }
133 136
134 void PaymentRequestDialog::ViewHierarchyChanged( 137 void PaymentRequestDialogView::ViewHierarchyChanged(
135 const ViewHierarchyChangedDetails& details) { 138 const ViewHierarchyChangedDetails& details) {
136 // When a view that is associated with a controller is removed from this 139 // When a view that is associated with a controller is removed from this
137 // view's descendants, dispose of the controller. 140 // view's descendants, dispose of the controller.
138 if (!details.is_add && 141 if (!details.is_add &&
139 controller_map_.find(details.child) != controller_map_.end()) { 142 controller_map_.find(details.child) != controller_map_.end()) {
140 DCHECK(!details.move_view); 143 DCHECK(!details.move_view);
141 controller_map_.erase(details.child); 144 controller_map_.erase(details.child);
142 } 145 }
143 } 146 }
144 147
145 } // namespace payments 148 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698