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_SHEET_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_SHEET_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_SHEET_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_SHEET_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/logging.h" | |
| 11 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "ui/views/controls/button/vector_icon_button_delegate.h" | |
| 12 | 12 |
| 13 namespace views { | 13 namespace views { |
| 14 class Button; | |
| 14 class View; | 15 class View; |
| 15 } | 16 } |
| 16 | 17 |
| 17 namespace payments { | 18 namespace payments { |
| 18 | 19 |
| 19 class PaymentRequestDialogView; | 20 class PaymentRequestDialogView; |
| 20 class PaymentRequest; | 21 class PaymentRequest; |
| 21 | 22 |
| 22 // The base class for objects responsible for the creation and event handling in | 23 // The base class for objects responsible for the creation and event handling in |
| 23 // views shown in the PaymentRequestDialog. | 24 // views shown in the PaymentRequestDialog. |
| 24 class PaymentRequestSheetController { | 25 class PaymentRequestSheetController : public views::VectorIconButtonDelegate { |
| 25 public: | 26 public: |
| 26 // Objects of this class are owned by |dialog|, so it's a non-owned pointer | 27 // Objects of this class are owned by |dialog|, so it's a non-owned pointer |
| 27 // that should be valid throughout this object's lifetime. | 28 // that should be valid throughout this object's lifetime. |
| 28 // |request| is also not owned by this and is guaranteed to outlive dialog. | 29 // |request| is also not owned by this and is guaranteed to outlive dialog. |
| 29 // Neither |request| or |dialog| should be null. | 30 // Neither |request| or |dialog| should be null. |
| 30 PaymentRequestSheetController(PaymentRequest* request, | 31 PaymentRequestSheetController(PaymentRequest* request, |
| 31 PaymentRequestDialogView* dialog) | 32 PaymentRequestDialogView* dialog); |
| 32 : request_(request), dialog_(dialog) { | 33 ~PaymentRequestSheetController() override {} |
| 33 DCHECK(request_); | |
| 34 DCHECK(dialog_); | |
| 35 } | |
| 36 virtual ~PaymentRequestSheetController() {} | |
| 37 | 34 |
| 38 virtual std::unique_ptr<views::View> CreateView() = 0; | 35 virtual std::unique_ptr<views::View> CreateView() = 0; |
| 39 | 36 |
| 40 // The PaymentRequest object associated with this instance of the dialog. | 37 // The PaymentRequest object associated with this instance of the dialog. |
| 41 // Caller should not take ownership of the result. | 38 // Caller should not take ownership of the result. |
| 42 PaymentRequest* request() { return request_; } | 39 PaymentRequest* request() { return request_; } |
| 43 | 40 |
| 44 // The dialog that contains and owns this object. | 41 // The dialog that contains and owns this object. |
| 45 // Caller should not take ownership of the result. | 42 // Caller should not take ownership of the result. |
| 46 PaymentRequestDialogView* dialog() { return dialog_; } | 43 PaymentRequestDialogView* dialog() { return dialog_; } |
| 47 | 44 |
| 45 // Creates and returns the primary action button for this sheet. It's | |
| 46 // typically a blue button with the "Pay" or "Done" labels. Subclasses may | |
| 47 // return an empty std::unique_ptr to indicate that no primary button should | |
|
sky
2017/02/03 02:36:50
optional: I would say null rather than empty std::
anthonyvd
2017/02/03 16:50:57
Clarified that empty std::unique_ptr here means nu
| |
| 48 // be displayed. The caller takes ownership of the button but the view is | |
| 49 // guaranteed to be outlived by the controller so subclasses may retain a raw | |
| 50 // pointer to the returned button (for example to control its enabled state). | |
| 51 virtual std::unique_ptr<views::Button> CreatePrimaryButton(); | |
|
sky
2017/02/03 02:36:49
Can this be protected?
anthonyvd
2017/02/03 16:50:57
Sure can, done!
| |
| 52 | |
| 53 protected: | |
| 54 // views::VectorIconButtonDelegate: | |
| 55 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
| 56 | |
| 57 // Creates a view to be displayed in the PaymentRequestDialog. | |
| 58 // |header_view| is the view displayed on top of the dialog, containing title, | |
| 59 // (optional) back button, and close buttons. | |
| 60 // |content_view| is displayed between |header_view| and the pay/cancel | |
| 61 // buttons. Also adds the footer, returned by CreateFooterView(), which is | |
| 62 // clamped to the bottom of the containing view. The returned view takes | |
| 63 // ownership of |header_view|, |content_view|, and the footer. | |
| 64 // +---------------------------+ | |
| 65 // | HEADER VIEW | | |
| 66 // +---------------------------+ | |
| 67 // | CONTENT | | |
| 68 // | VIEW | | |
| 69 // +---------------------------+ | |
| 70 // | | CANCEL | PAY | <-- footer | |
| 71 // +---------------------------+ | |
| 72 std::unique_ptr<views::View> CreatePaymentView( | |
| 73 std::unique_ptr<views::View> header_view, | |
| 74 std::unique_ptr<views::View> content_view); | |
| 75 | |
| 76 // Creates the row of button containing the Pay, cancel, and extra buttons. | |
| 77 // |controller| is installed as the listener for button events. | |
| 78 std::unique_ptr<views::View> CreateFooterView(); | |
| 79 | |
| 48 private: | 80 private: |
| 49 // Not owned. Will outlive this. | 81 // Not owned. Will outlive this. |
| 50 PaymentRequest* request_; | 82 PaymentRequest* request_; |
| 51 // Not owned. Will outlive this. | 83 // Not owned. Will outlive this. |
| 52 PaymentRequestDialogView* dialog_; | 84 PaymentRequestDialogView* dialog_; |
| 53 | 85 |
| 54 DISALLOW_COPY_AND_ASSIGN(PaymentRequestSheetController); | 86 DISALLOW_COPY_AND_ASSIGN(PaymentRequestSheetController); |
| 55 }; | 87 }; |
| 56 | 88 |
| 57 } // namespace payments | 89 } // namespace payments |
| 58 | 90 |
| 59 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_SHEET_CONTROLLER_H_ | 91 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_SHEET_CONTROLLER_H_ |
| OLD | NEW |