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

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: Initial 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_(observer),
58 widget_(nullptr),
59 propagate_closure_to_renderer_(true) {
56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
57 SetLayoutManager(new views::FillLayout()); 61 SetLayoutManager(new views::FillLayout());
58 62
59 view_stack_.set_owned_by_client(); 63 view_stack_.set_owned_by_client();
60 AddChildView(&view_stack_); 64 AddChildView(&view_stack_);
61 65
62 ShowInitialPaymentSheet(); 66 ShowInitialPaymentSheet();
63 } 67 }
64 68
65 PaymentRequestDialog::~PaymentRequestDialog() {} 69 PaymentRequestDialogView::~PaymentRequestDialogView() {}
66 70
67 ui::ModalType PaymentRequestDialog::GetModalType() const { 71 ui::ModalType PaymentRequestDialogView::GetModalType() const {
68 return ui::MODAL_TYPE_CHILD; 72 return ui::MODAL_TYPE_CHILD;
69 } 73 }
70 74
71 bool PaymentRequestDialog::Cancel() { 75 bool PaymentRequestDialogView::Cancel() {
76 // Called when the widget is about to close. By default, we propagate the
77 // closure to the renderer through a "user cancelled" event. However, if
78 // the renderer is already aware of the closure (possibly because it initiated
79 // it), we do not send such a signal.
72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
73 request_->Cancel(); 81 if (propagate_closure_to_renderer_)
82 request_->UserCancelled();
74 return true; 83 return true;
75 } 84 }
76 85
77 bool PaymentRequestDialog::ShouldShowCloseButton() const { 86 bool PaymentRequestDialogView::ShouldShowCloseButton() const {
78 // Don't show the normal close button on the dialog. This is because the 87 // 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 88 // typical dialog header doesn't allow displaying anything other that the
80 // title and the close button. This is insufficient for the PaymentRequest 89 // title and the close button. This is insufficient for the PaymentRequest
81 // dialog, which must sometimes show the back arrow next to the title. 90 // 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 91 // Moreover, the title (and back arrow) should animate with the view they're
83 // attached to. 92 // attached to.
84 return false; 93 return false;
85 } 94 }
86 95
87 int PaymentRequestDialog::GetDialogButtons() const { 96 int PaymentRequestDialogView::GetDialogButtons() const {
88 // The buttons should animate along with the different dialog sheets since 97 // 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 98 // each sheet presents a different set of buttons. Because of this, hide the
90 // usual dialog buttons. 99 // usual dialog buttons.
91 return ui::DIALOG_BUTTON_NONE; 100 return ui::DIALOG_BUTTON_NONE;
92 } 101 }
93 102
94 void PaymentRequestDialog::GoBack() { 103 void PaymentRequestDialogView::GoBack() {
95 view_stack_.Pop(); 104 view_stack_.Pop();
96 } 105 }
97 106
98 void PaymentRequestDialog::ShowOrderSummary() { 107 void PaymentRequestDialogView::ShowOrderSummary() {
99 view_stack_.Push(CreateViewAndInstallController<OrderSummaryViewController>( 108 view_stack_.Push(CreateViewAndInstallController<OrderSummaryViewController>(
100 &controller_map_, request_, this), 109 &controller_map_, request_, this),
101 true); 110 true);
102 } 111 }
103 112
104 void PaymentRequestDialog::ShowPaymentMethodSheet() { 113 void PaymentRequestDialogView::ShowPaymentMethodSheet() {
105 view_stack_.Push( 114 view_stack_.Push(CreateViewAndInstallController<PaymentMethodViewController>(
106 CreateViewAndInstallController<PaymentMethodViewController>( 115 &controller_map_, request_, this),
107 &controller_map_, request_, this), 116 true);
108 true);
109 } 117 }
110 118
111 void PaymentRequestDialog::CloseDialog() { 119 void PaymentRequestDialogView::ShowDialog() {
120 widget_ = constrained_window::ShowWebModalDialogViews(
121 this, request_->web_contents());
122 }
123
124 void PaymentRequestDialogView::CloseDialog(bool propagate_to_renderer) {
125 // This calls PaymentRequestDialogView::Cancel() before closing.
126 propagate_closure_to_renderer_ = propagate_to_renderer;
112 GetWidget()->Close(); 127 GetWidget()->Close();
113 } 128 }
114 129
115 // static 130 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>( 131 view_stack_.Push(CreateViewAndInstallController<PaymentSheetViewController>(
124 &controller_map_, request_, this), 132 &controller_map_, request_, this),
125 false); 133 false);
126 if (observer_) 134 if (observer_)
127 observer_->OnDialogOpened(); 135 observer_->OnDialogOpened();
128 } 136 }
129 137
130 gfx::Size PaymentRequestDialog::GetPreferredSize() const { 138 gfx::Size PaymentRequestDialogView::GetPreferredSize() const {
131 return gfx::Size(450, 450); 139 return gfx::Size(450, 450);
132 } 140 }
133 141
134 void PaymentRequestDialog::ViewHierarchyChanged( 142 void PaymentRequestDialogView::ViewHierarchyChanged(
135 const ViewHierarchyChangedDetails& details) { 143 const ViewHierarchyChangedDetails& details) {
136 // When a view that is associated with a controller is removed from this 144 // When a view that is associated with a controller is removed from this
137 // view's descendants, dispose of the controller. 145 // view's descendants, dispose of the controller.
138 if (!details.is_add && 146 if (!details.is_add &&
139 controller_map_.find(details.child) != controller_map_.end()) { 147 controller_map_.find(details.child) != controller_map_.end()) {
140 DCHECK(!details.move_view); 148 DCHECK(!details.move_view);
141 controller_map_.erase(details.child); 149 controller_map_.erase(details.child);
142 } 150 }
143 } 151 }
144 152
145 } // namespace payments 153 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698