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

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

Issue 2592833002: [WebPayments] Start populating the Payment Sheet. (Closed)
Patch Set: Fix failing implicit move on ChromeOS builds. 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.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/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" 12 #include "chrome/browser/ui/views/payments/order_summary_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 "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/views/layout/fill_layout.h" 18 #include "ui/views/layout/fill_layout.h"
19 19
20 namespace chrome {
21
22 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) {
23 constrained_window::ShowWebModalDialogViews(
24 new payments::PaymentRequestDialog(impl), impl->web_contents());
25 }
26
27 } // namespace chrome
28
29 namespace payments {
20 namespace { 30 namespace {
21 31
22 // This function creates an instance of a PaymentRequestSheetController 32 // This function creates an instance of a PaymentRequestSheetController
23 // subclass of concrete type |Controller|, passing it non-owned pointers to 33 // subclass of concrete type |Controller|, passing it non-owned pointers to
24 // |dialog| and the |impl| that initiated that dialog. |map| should be owned by 34 // |dialog| and the |impl| that initiated that dialog. |map| should be owned by
25 // |dialog|. 35 // |dialog|.
26 template<typename Controller> 36 template<typename Controller>
27 std::unique_ptr<views::View> CreateViewAndInstallController( 37 std::unique_ptr<views::View> CreateViewAndInstallController(
28 payments::ControllerMap* map, 38 payments::ControllerMap* map,
29 payments::PaymentRequestImpl* impl, 39 payments::PaymentRequestImpl* impl,
30 payments::PaymentRequestDialog* dialog) { 40 payments::PaymentRequestDialog* dialog) {
31 std::unique_ptr<Controller> controller = 41 std::unique_ptr<Controller> controller =
32 base::MakeUnique<Controller>(impl, dialog); 42 base::MakeUnique<Controller>(impl, dialog);
33 std::unique_ptr<views::View> view = controller->CreateView(); 43 std::unique_ptr<views::View> view = controller->CreateView();
34 (*map)[view.get()] = std::move(controller); 44 (*map)[view.get()] = std::move(controller);
35 return view; 45 return view;
36 } 46 }
37 47
38 } // namespace 48 } // namespace
39 49
40 namespace chrome {
41
42 void ShowPaymentRequestDialog(payments::PaymentRequestImpl* impl) {
43 constrained_window::ShowWebModalDialogViews(
44 new payments::PaymentRequestDialog(impl), impl->web_contents());
45 }
46
47 } // namespace chrome
48
49 namespace payments {
50
51 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl) 50 PaymentRequestDialog::PaymentRequestDialog(PaymentRequestImpl* impl)
52 : impl_(impl) { 51 : impl_(impl) {
53 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 52 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
54 SetLayoutManager(new views::FillLayout()); 53 SetLayoutManager(new views::FillLayout());
55 54
56 view_stack_.set_owned_by_client(); 55 view_stack_.set_owned_by_client();
57 AddChildView(&view_stack_); 56 AddChildView(&view_stack_);
58 57
59 ShowInitialPaymentSheet(); 58 ShowInitialPaymentSheet();
60 } 59 }
61 60
62 PaymentRequestDialog::~PaymentRequestDialog() {} 61 PaymentRequestDialog::~PaymentRequestDialog() {}
63 62
64 ui::ModalType PaymentRequestDialog::GetModalType() const { 63 ui::ModalType PaymentRequestDialog::GetModalType() const {
65 return ui::MODAL_TYPE_CHILD; 64 return ui::MODAL_TYPE_CHILD;
66 } 65 }
67 66
68 bool PaymentRequestDialog::Cancel() { 67 bool PaymentRequestDialog::Cancel() {
69 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 68 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
70 impl_->Cancel(); 69 impl_->Cancel();
71 return true; 70 return true;
72 } 71 }
73 72
73 bool PaymentRequestDialog::ShouldShowCloseButton() const {
74 // Don't show the normal close button on the dialog. This is because the
75 // typical dialog header doesn't allow displaying anything other that the
76 // title and the close button. This is insufficient for the PaymentRequest
77 // dialog, which must sometimes show the back arrow next to the title.
78 // Moreover, the title (and back arrow) should animate with the view they're
79 // attached to.
80 return false;
81 }
82
83 int PaymentRequestDialog::GetDialogButtons() const {
84 // The buttons should animate along with the different dialog sheets since
85 // each sheet presents a different set of buttons. Because of this, hide the
86 // usual dialog buttons.
87 return ui::DIALOG_BUTTON_NONE;
88 }
89
74 void PaymentRequestDialog::GoBack() { 90 void PaymentRequestDialog::GoBack() {
75 view_stack_.Pop(); 91 view_stack_.Pop();
76 } 92 }
77 93
78 void PaymentRequestDialog::ShowOrderSummary() { 94 void PaymentRequestDialog::ShowOrderSummary() {
79 view_stack_.Push( 95 view_stack_.Push(
80 CreateViewAndInstallController<OrderSummaryViewController>( 96 CreateViewAndInstallController<OrderSummaryViewController>(
81 &controller_map_, impl_, this), 97 &controller_map_, impl_, this),
82 true); 98 true);
83 } 99 }
84 100
101 void PaymentRequestDialog::CloseDialog() {
102 GetWidget()->Close();
103 }
104
85 void PaymentRequestDialog::ShowInitialPaymentSheet() { 105 void PaymentRequestDialog::ShowInitialPaymentSheet() {
86 view_stack_.Push( 106 view_stack_.Push(
87 CreateViewAndInstallController<PaymentSheetViewController>( 107 CreateViewAndInstallController<PaymentSheetViewController>(
88 &controller_map_, impl_, this), 108 &controller_map_, impl_, this),
89 false); 109 false);
90 } 110 }
91 111
92 gfx::Size PaymentRequestDialog::GetPreferredSize() const { 112 gfx::Size PaymentRequestDialog::GetPreferredSize() const {
93 return gfx::Size(450, 450); 113 return gfx::Size(450, 450);
94 } 114 }
95 115
96 void PaymentRequestDialog::ViewHierarchyChanged( 116 void PaymentRequestDialog::ViewHierarchyChanged(
97 const ViewHierarchyChangedDetails& details) { 117 const ViewHierarchyChangedDetails& details) {
98 // When a view that is associated with a controller is removed from this 118 // When a view that is associated with a controller is removed from this
99 // view's descendants, dispose of the controller. 119 // view's descendants, dispose of the controller.
100 if (!details.is_add && 120 if (!details.is_add &&
101 controller_map_.find(details.child) != controller_map_.end()) { 121 controller_map_.find(details.child) != controller_map_.end()) {
102 DCHECK(!details.move_view); 122 DCHECK(!details.move_view);
103 controller_map_.erase(details.child); 123 controller_map_.erase(details.child);
104 } 124 }
105 } 125 }
106 126
107 } // namespace payments 127 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698