Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_DIALOG_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_DIALOG_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_DIALOG_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_DIALOG_VIEW_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "chrome/browser/ui/views/payments/view_stack.h" | 12 #include "chrome/browser/ui/views/payments/view_stack.h" |
| 13 #include "components/payments/payment_request_dialog.h" | |
| 13 #include "ui/views/window/dialog_delegate.h" | 14 #include "ui/views/window/dialog_delegate.h" |
| 14 | 15 |
| 15 namespace payments { | 16 namespace payments { |
| 16 | 17 |
| 17 class PaymentRequest; | 18 class PaymentRequest; |
| 18 class PaymentRequestSheetController; | 19 class PaymentRequestSheetController; |
| 19 | 20 |
| 20 // Maps views owned by PaymentRequestDialog::view_stack_ to their controller. | 21 // Maps views owned by PaymentRequestDialogView::view_stack_ to their |
| 21 // PaymentRequestDialog is responsible for listening for those views being | 22 // controller. PaymentRequestDialogView is responsible for listening for those |
| 22 // removed from the hierarchy and delete the associated controllers. | 23 // views being removed from the hierarchy and delete the associated controllers. |
| 23 using ControllerMap = | 24 using ControllerMap = |
| 24 std::map<views::View*, std::unique_ptr<PaymentRequestSheetController>>; | 25 std::map<views::View*, std::unique_ptr<PaymentRequestSheetController>>; |
| 25 | 26 |
| 26 // The dialog delegate that represents a desktop WebPayments dialog. This class | 27 // The dialog delegate that represents a desktop WebPayments dialog. This class |
| 27 // is responsible for displaying the view associated with the current state of | 28 // is responsible for displaying the view associated with the current state of |
| 28 // the WebPayments flow and managing the transition between those states. | 29 // the WebPayments flow and managing the transition between those states. |
| 29 class PaymentRequestDialog : public views::DialogDelegateView { | 30 class PaymentRequestDialogView : public views::DialogDelegateView, |
| 31 public PaymentRequestDialog { | |
| 30 public: | 32 public: |
| 31 class ObserverForTest { | 33 class ObserverForTest { |
| 32 public: | 34 public: |
| 33 virtual void OnDialogOpened() = 0; | 35 virtual void OnDialogOpened() = 0; |
| 34 }; | 36 }; |
| 35 | 37 |
| 36 // Build a Dialog around the PaymentRequest object. |observer| is used to | 38 // Build a Dialog around the PaymentRequest object. |observer| is used to |
| 37 // be notified of dialog events as they happen (but may be NULL) and should | 39 // be notified of dialog events as they happen (but may be NULL) and should |
| 38 // outlive this object. | 40 // outlive this object. |
| 39 PaymentRequestDialog(PaymentRequest* request, | 41 PaymentRequestDialogView(PaymentRequest* request, |
| 40 PaymentRequestDialog::ObserverForTest* observer); | 42 PaymentRequestDialogView::ObserverForTest* observer); |
| 41 ~PaymentRequestDialog() override; | 43 ~PaymentRequestDialogView() override; |
| 42 | 44 |
| 43 // views::WidgetDelegate | 45 // views::WidgetDelegate |
| 44 ui::ModalType GetModalType() const override; | 46 ui::ModalType GetModalType() const override; |
| 45 | 47 |
| 46 // views::DialogDelegate | 48 // views::DialogDelegate |
| 47 bool Cancel() override; | 49 bool Cancel() override; |
| 48 bool ShouldShowCloseButton() const override; | 50 bool ShouldShowCloseButton() const override; |
| 49 int GetDialogButtons() const override; | 51 int GetDialogButtons() const override; |
| 50 | 52 |
| 53 // payments::PaymentRequestDialog | |
| 54 void ShowDialog() override; | |
| 55 void CloseDialog(bool propagate_to_renderer) override; | |
| 56 | |
| 51 void GoBack(); | 57 void GoBack(); |
| 52 void ShowOrderSummary(); | 58 void ShowOrderSummary(); |
| 53 void ShowPaymentMethodSheet(); | 59 void ShowPaymentMethodSheet(); |
| 54 void CloseDialog(); | |
| 55 | 60 |
| 56 static void ShowWebModalPaymentDialog(PaymentRequestDialog* dialog, | 61 // Used for testing. |
| 57 PaymentRequest* request); | 62 views::Widget* widget() { return widget_; } |
|
please use gerrit instead
2017/01/23 15:02:08
widget_for_testing()
Mathieu
2017/01/23 20:58:36
Done.
| |
| 58 | 63 |
| 59 private: | 64 private: |
| 60 void ShowInitialPaymentSheet(); | 65 void ShowInitialPaymentSheet(); |
| 61 | 66 |
| 62 // views::View | 67 // views::View |
| 63 gfx::Size GetPreferredSize() const override; | 68 gfx::Size GetPreferredSize() const override; |
| 64 void ViewHierarchyChanged(const ViewHierarchyChangedDetails& details) | 69 void ViewHierarchyChanged( |
| 65 override; | 70 const ViewHierarchyChangedDetails& details) override; |
| 66 | 71 |
| 67 // Non-owned reference to the PaymentRequest that initiated this dialog. Since | 72 // Non-owned reference to the PaymentRequest that initiated this dialog. Since |
| 68 // the PaymentRequest object always outlives this one, the pointer should | 73 // the PaymentRequest object always outlives this one, the pointer should |
| 69 // always be valid even though there is no direct ownership relationship | 74 // always be valid even though there is no direct ownership relationship |
| 70 // between the two. | 75 // between the two. |
| 71 PaymentRequest* request_; | 76 PaymentRequest* request_; |
| 72 // May be null. | 77 // May be null. |
| 73 ObserverForTest* observer_; | 78 ObserverForTest* observer_; |
|
please use gerrit instead
2017/01/23 15:02:08
observer_for_testing_ to be consistent? Maybe good
Mathieu
2017/01/23 20:58:36
Done.
| |
| 74 ControllerMap controller_map_; | 79 ControllerMap controller_map_; |
| 75 ViewStack view_stack_; | 80 ViewStack view_stack_; |
| 81 // A reference to the widget created when the dialog is shown. | |
|
please use gerrit instead
2017/01/23 15:02:08
Add a note that this widget is owned by its parent
Mathieu
2017/01/23 20:58:36
Done.
| |
| 82 views::Widget* widget_; | |
|
please use gerrit instead
2017/01/23 15:02:08
widget_for_testing_
Mathieu
2017/01/23 20:58:36
Done.
| |
| 83 // Keeps track of whether this dialog should inform the renderer of its | |
| 84 // closure (through the PaymentRequest reference). | |
| 85 bool propagate_closure_to_renderer_; | |
| 76 | 86 |
| 77 DISALLOW_COPY_AND_ASSIGN(PaymentRequestDialog); | 87 DISALLOW_COPY_AND_ASSIGN(PaymentRequestDialogView); |
| 78 }; | 88 }; |
| 79 | 89 |
| 80 } // namespace payments | 90 } // namespace payments |
| 81 | 91 |
| 82 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_DIALOG_H_ | 92 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_DIALOG_VIEW_H_ |
| OLD | NEW |