OLD | NEW |
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" |
11 #include "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h" | 11 #include "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h" |
12 #include "chrome/browser/ui/views/payments/cvc_unmask_view_controller.h" | 12 #include "chrome/browser/ui/views/payments/cvc_unmask_view_controller.h" |
13 #include "chrome/browser/ui/views/payments/error_message_view_controller.h" | 13 #include "chrome/browser/ui/views/payments/error_message_view_controller.h" |
14 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" | 14 #include "chrome/browser/ui/views/payments/order_summary_view_controller.h" |
15 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h" | 15 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h" |
16 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 16 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
17 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" | 17 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h" |
18 #include "chrome/browser/ui/views/payments/profile_list_view_controller.h" | 18 #include "chrome/browser/ui/views/payments/profile_list_view_controller.h" |
19 #include "chrome/browser/ui/views/payments/shipping_address_editor_view_controll
er.h" | 19 #include "chrome/browser/ui/views/payments/shipping_address_editor_view_controll
er.h" |
20 #include "chrome/browser/ui/views/payments/shipping_option_view_controller.h" | 20 #include "chrome/browser/ui/views/payments/shipping_option_view_controller.h" |
21 #include "components/constrained_window/constrained_window_views.h" | 21 #include "components/constrained_window/constrained_window_views.h" |
22 #include "components/payments/content/payment_request.h" | 22 #include "components/payments/content/payment_request.h" |
| 23 #include "components/strings/grit/components_strings.h" |
23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/views/background.h" |
| 27 #include "ui/views/controls/label.h" |
24 #include "ui/views/layout/fill_layout.h" | 28 #include "ui/views/layout/fill_layout.h" |
| 29 #include "ui/views/layout/grid_layout.h" |
25 | 30 |
26 namespace chrome { | 31 namespace chrome { |
27 | 32 |
28 payments::PaymentRequestDialog* CreatePaymentRequestDialog( | 33 payments::PaymentRequestDialog* CreatePaymentRequestDialog( |
29 payments::PaymentRequest* request) { | 34 payments::PaymentRequest* request) { |
30 return new payments::PaymentRequestDialogView(request, | 35 return new payments::PaymentRequestDialogView(request, |
31 /* no observer */ nullptr); | 36 /* no observer */ nullptr); |
32 } | 37 } |
33 | 38 |
34 } // namespace chrome | 39 } // namespace chrome |
(...skipping 21 matching lines...) Expand all Loading... |
56 PaymentRequestDialogView::ObserverForTest* observer) | 61 PaymentRequestDialogView::ObserverForTest* observer) |
57 : request_(request), observer_for_testing_(observer), being_closed_(false) { | 62 : request_(request), observer_for_testing_(observer), being_closed_(false) { |
58 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 63 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
59 if (observer_for_testing_) | 64 if (observer_for_testing_) |
60 request->spec()->add_observer_for_testing(this); | 65 request->spec()->add_observer_for_testing(this); |
61 SetLayoutManager(new views::FillLayout()); | 66 SetLayoutManager(new views::FillLayout()); |
62 | 67 |
63 view_stack_.set_owned_by_client(); | 68 view_stack_.set_owned_by_client(); |
64 AddChildView(&view_stack_); | 69 AddChildView(&view_stack_); |
65 | 70 |
| 71 SetupSpinnerOverlay(); |
| 72 |
66 ShowInitialPaymentSheet(); | 73 ShowInitialPaymentSheet(); |
67 } | 74 } |
68 | 75 |
69 PaymentRequestDialogView::~PaymentRequestDialogView() {} | 76 PaymentRequestDialogView::~PaymentRequestDialogView() {} |
70 | 77 |
71 ui::ModalType PaymentRequestDialogView::GetModalType() const { | 78 ui::ModalType PaymentRequestDialogView::GetModalType() const { |
72 return ui::MODAL_TYPE_CHILD; | 79 return ui::MODAL_TYPE_CHILD; |
73 } | 80 } |
74 | 81 |
75 bool PaymentRequestDialogView::Cancel() { | 82 bool PaymentRequestDialogView::Cancel() { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 /* animate = */ true); | 228 /* animate = */ true); |
222 if (observer_for_testing_) | 229 if (observer_for_testing_) |
223 observer_for_testing_->OnShippingAddressEditorOpened(); | 230 observer_for_testing_->OnShippingAddressEditorOpened(); |
224 } | 231 } |
225 | 232 |
226 void PaymentRequestDialogView::EditorViewUpdated() { | 233 void PaymentRequestDialogView::EditorViewUpdated() { |
227 if (observer_for_testing_) | 234 if (observer_for_testing_) |
228 observer_for_testing_->OnEditorViewUpdated(); | 235 observer_for_testing_->OnEditorViewUpdated(); |
229 } | 236 } |
230 | 237 |
| 238 void PaymentRequestDialogView::ShowProcessingSpinner() { |
| 239 throbber_.Start(); |
| 240 throbber_overlay_.SetVisible(true); |
| 241 } |
| 242 |
231 void PaymentRequestDialogView::ShowInitialPaymentSheet() { | 243 void PaymentRequestDialogView::ShowInitialPaymentSheet() { |
232 view_stack_.Push(CreateViewAndInstallController( | 244 view_stack_.Push(CreateViewAndInstallController( |
233 base::MakeUnique<PaymentSheetViewController>( | 245 base::MakeUnique<PaymentSheetViewController>( |
234 request_->spec(), request_->state(), this), | 246 request_->spec(), request_->state(), this), |
235 &controller_map_), | 247 &controller_map_), |
236 /* animate = */ false); | 248 /* animate = */ false); |
237 if (observer_for_testing_) | 249 if (observer_for_testing_) |
238 observer_for_testing_->OnDialogOpened(); | 250 observer_for_testing_->OnDialogOpened(); |
239 } | 251 } |
240 | 252 |
| 253 void PaymentRequestDialogView::SetupSpinnerOverlay() { |
| 254 throbber_.set_owned_by_client(); |
| 255 |
| 256 throbber_overlay_.set_owned_by_client(); |
| 257 throbber_overlay_.SetPaintToLayer(); |
| 258 throbber_overlay_.SetVisible(false); |
| 259 // The throbber overlay has to have a solid white background to hide whatever |
| 260 // would be under it. |
| 261 throbber_overlay_.set_background( |
| 262 views::Background::CreateSolidBackground(SK_ColorWHITE)); |
| 263 |
| 264 std::unique_ptr<views::GridLayout> layout = |
| 265 base::MakeUnique<views::GridLayout>(&throbber_overlay_); |
| 266 views::ColumnSet* throbber_columns = layout->AddColumnSet(0); |
| 267 throbber_columns->AddPaddingColumn(0.5, 0); |
| 268 throbber_columns->AddColumn(views::GridLayout::Alignment::CENTER, |
| 269 views::GridLayout::Alignment::TRAILING, 0, |
| 270 views::GridLayout::SizeType::USE_PREF, 0, 0); |
| 271 throbber_columns->AddPaddingColumn(0.5, 0); |
| 272 |
| 273 views::ColumnSet* label_columns = layout->AddColumnSet(1); |
| 274 label_columns->AddPaddingColumn(0.5, 0); |
| 275 label_columns->AddColumn(views::GridLayout::Alignment::CENTER, |
| 276 views::GridLayout::Alignment::LEADING, 0, |
| 277 views::GridLayout::SizeType::USE_PREF, 0, 0); |
| 278 label_columns->AddPaddingColumn(0.5, 0); |
| 279 |
| 280 layout->StartRow(0.5, 0); |
| 281 layout->AddView(&throbber_); |
| 282 |
| 283 layout->StartRow(0.5, 1); |
| 284 layout->AddView(new views::Label( |
| 285 l10n_util::GetStringUTF16(IDS_PAYMENTS_PROCESSING_MESSAGE))); |
| 286 |
| 287 throbber_overlay_.SetLayoutManager(layout.release()); |
| 288 AddChildView(&throbber_overlay_); |
| 289 } |
| 290 |
241 gfx::Size PaymentRequestDialogView::GetPreferredSize() const { | 291 gfx::Size PaymentRequestDialogView::GetPreferredSize() const { |
242 return gfx::Size(kDialogWidth, kDialogHeight); | 292 return gfx::Size(kDialogWidth, kDialogHeight); |
243 } | 293 } |
244 | 294 |
245 void PaymentRequestDialogView::ViewHierarchyChanged( | 295 void PaymentRequestDialogView::ViewHierarchyChanged( |
246 const ViewHierarchyChangedDetails& details) { | 296 const ViewHierarchyChangedDetails& details) { |
247 if (being_closed_) | 297 if (being_closed_) |
248 return; | 298 return; |
249 | 299 |
250 // When a view that is associated with a controller is removed from this | 300 // When a view that is associated with a controller is removed from this |
251 // view's descendants, dispose of the controller. | 301 // view's descendants, dispose of the controller. |
252 if (!details.is_add && | 302 if (!details.is_add && |
253 controller_map_.find(details.child) != controller_map_.end()) { | 303 controller_map_.find(details.child) != controller_map_.end()) { |
254 DCHECK(!details.move_view); | 304 DCHECK(!details.move_view); |
255 controller_map_.erase(details.child); | 305 controller_map_.erase(details.child); |
256 } | 306 } |
257 } | 307 } |
258 | 308 |
259 } // namespace payments | 309 } // namespace payments |
OLD | NEW |