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

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

Issue 2715213005: [Payments] Add the pay button, and control its enabled state (Closed)
Patch Set: tweak Created 3 years, 9 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_view.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"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 void PaymentRequestDialogView::ShowDialog() { 137 void PaymentRequestDialogView::ShowDialog() {
138 constrained_window::ShowWebModalDialogViews(this, request_->web_contents()); 138 constrained_window::ShowWebModalDialogViews(this, request_->web_contents());
139 } 139 }
140 140
141 void PaymentRequestDialogView::CloseDialog() { 141 void PaymentRequestDialogView::CloseDialog() {
142 // This calls PaymentRequestDialogView::Cancel() before closing. 142 // This calls PaymentRequestDialogView::Cancel() before closing.
143 GetWidget()->Close(); 143 GetWidget()->Close();
144 } 144 }
145 145
146 void PaymentRequestDialogView::UpdatePayButtonState(bool enabled) {
anthonyvd 2017/02/28 17:16:32 I don't think this pattern is the way to go: 1. T
Mathieu 2017/02/28 19:42:39 OMG yes, it's much better with observers. Good cat
147 // It's theoretically possible that the dialog is closed and PaymentRequest
148 // still calls this.
149 if (payment_sheet_view_)
150 return;
151
152 const auto it = controller_map_.find(payment_sheet_view_);
153 DCHECK(it != controller_map_.end());
154 PaymentSheetViewController* sheet_controller =
155 static_cast<PaymentSheetViewController*>(it->second.get());
156 sheet_controller->UpdatePayButtonState(enabled);
157 }
158
146 void PaymentRequestDialogView::ShowInitialPaymentSheet() { 159 void PaymentRequestDialogView::ShowInitialPaymentSheet() {
147 view_stack_.Push( 160 std::unique_ptr<views::View> sheet_view = CreateViewAndInstallController(
148 CreateViewAndInstallController( 161 base::MakeUnique<PaymentSheetViewController>(request_, this),
149 base::MakeUnique<PaymentSheetViewController>(request_, this), 162 &controller_map_);
150 &controller_map_), 163 payment_sheet_view_ = sheet_view.get();
151 /* animate = */ false); 164 view_stack_.Push(std::move(sheet_view), /* animate = */ false);
152 if (observer_for_testing_) 165 if (observer_for_testing_)
153 observer_for_testing_->OnDialogOpened(); 166 observer_for_testing_->OnDialogOpened();
154 } 167 }
155 168
156 gfx::Size PaymentRequestDialogView::GetPreferredSize() const { 169 gfx::Size PaymentRequestDialogView::GetPreferredSize() const {
157 return gfx::Size(450, 450); 170 return gfx::Size(450, 450);
158 } 171 }
159 172
160 void PaymentRequestDialogView::ViewHierarchyChanged( 173 void PaymentRequestDialogView::ViewHierarchyChanged(
161 const ViewHierarchyChangedDetails& details) { 174 const ViewHierarchyChangedDetails& details) {
162 // When a view that is associated with a controller is removed from this 175 // When a view that is associated with a controller is removed from this
163 // view's descendants, dispose of the controller. 176 // view's descendants, dispose of the controller.
164 if (!details.is_add && 177 if (!details.is_add &&
165 controller_map_.find(details.child) != controller_map_.end()) { 178 controller_map_.find(details.child) != controller_map_.end()) {
166 DCHECK(!details.move_view); 179 DCHECK(!details.move_view);
180 if (details.child == payment_sheet_view_)
181 payment_sheet_view_ = nullptr;
182
167 controller_map_.erase(details.child); 183 controller_map_.erase(details.child);
168 } 184 }
169 } 185 }
170 186
171 } // namespace payments 187 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698