| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_ITEM_LIST_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_ITEM_LIST_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_ITEM_LIST_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_ITEM_LIST_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "ui/views/controls/button/button.h" | 12 #include "ui/views/controls/button/button.h" |
| 13 | 13 |
| 14 namespace views { | 14 namespace views { |
| 15 class ImageView; | 15 class ImageView; |
| 16 class View; | 16 class View; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace payments { | 19 namespace payments { |
| 20 | 20 |
| 21 class PaymentRequest; | 21 class PaymentRequestSpec; |
| 22 class PaymentRequestState; |
| 22 | 23 |
| 23 // A control representing a list of selectable items in the PaymentRequest | 24 // A control representing a list of selectable items in the PaymentRequest |
| 24 // dialog. These lists enforce that only one of their elements be selectable at | 25 // dialog. These lists enforce that only one of their elements be selectable at |
| 25 // a time and that "incomplete" items (for example, a credit card with no known | 26 // a time and that "incomplete" items (for example, a credit card with no known |
| 26 // expiration date) behave differently when selected. Most of the time, this | 27 // expiration date) behave differently when selected. Most of the time, this |
| 27 // behavior is to show an editor screen. | 28 // behavior is to show an editor screen. |
| 28 class PaymentRequestItemList { | 29 class PaymentRequestItemList { |
| 29 public: | 30 public: |
| 30 // Represents an item in the item list. | 31 // Represents an item in the item list. |
| 31 class Item : public views::ButtonListener { | 32 class Item : public views::ButtonListener { |
| 32 public: | 33 public: |
| 33 // Creates an item that will be owned by |list| with the initial state set | 34 // Creates an item that will be owned by |list| with the initial state set |
| 34 // to |selected|. | 35 // to |selected|. |
| 35 Item(PaymentRequest* request, PaymentRequestItemList* list, bool selected); | 36 Item(PaymentRequestSpec* spec, |
| 37 PaymentRequestState* state, |
| 38 PaymentRequestItemList* list, |
| 39 bool selected); |
| 36 ~Item() override; | 40 ~Item() override; |
| 37 | 41 |
| 38 // Gets the view associated with this item. It's owned by this object so | 42 // Gets the view associated with this item. It's owned by this object so |
| 39 // that it can listen to any changes to the underlying model and update the | 43 // that it can listen to any changes to the underlying model and update the |
| 40 // view. | 44 // view. |
| 41 views::View* GetItemView(); | 45 views::View* GetItemView(); |
| 42 | 46 |
| 43 bool selected() const { return selected_; } | 47 bool selected() const { return selected_; } |
| 44 // Changes the selected state of this item to |selected| and calls | 48 // Changes the selected state of this item to |selected| and calls |
| 45 // SelectedStateChanged. | 49 // SelectedStateChanged. |
| 46 void SetSelected(bool selected); | 50 void SetSelected(bool selected); |
| 47 | 51 |
| 48 // Returns a pointer to the PaymentRequestItemList that owns this object. | 52 // Returns a pointer to the PaymentRequestItemList that owns this object. |
| 49 PaymentRequestItemList* list() { return list_; } | 53 PaymentRequestItemList* list() { return list_; } |
| 50 | 54 |
| 51 // Returns a pointer to the PaymentRequest object associated with this | 55 // Returns a pointer to the PaymentRequestSpec/State objects associated with |
| 52 // instance of the UI. | 56 // this instance of the UI. |
| 53 PaymentRequest* request() { return request_; } | 57 PaymentRequestSpec* spec() { return spec_; } |
| 58 PaymentRequestState* state() { return state_; } |
| 54 | 59 |
| 55 protected: | 60 protected: |
| 56 // Creates and returns the view associated with this list item. | 61 // Creates and returns the view associated with this list item. |
| 57 virtual std::unique_ptr<views::View> CreateItemView() = 0; | 62 virtual std::unique_ptr<views::View> CreateItemView() = 0; |
| 58 | 63 |
| 59 // Called when the selected state of this item changes. Subclasses may | 64 // Called when the selected state of this item changes. Subclasses may |
| 60 // assume that they are the only selected item in |list| when this is | 65 // assume that they are the only selected item in |list| when this is |
| 61 // called. This could be called before CreateItemView so subclasses should | 66 // called. This could be called before CreateItemView so subclasses should |
| 62 // be aware that their views might not exist yet. | 67 // be aware that their views might not exist yet. |
| 63 virtual void SelectedStateChanged() = 0; | 68 virtual void SelectedStateChanged() = 0; |
| 64 | 69 |
| 65 // Creates an image of a large checkmark, used to indicate that an option is | 70 // Creates an image of a large checkmark, used to indicate that an option is |
| 66 // selected. | 71 // selected. |
| 67 std::unique_ptr<views::ImageView> CreateCheckmark(bool selected); | 72 std::unique_ptr<views::ImageView> CreateCheckmark(bool selected); |
| 68 | 73 |
| 69 private: | 74 private: |
| 70 // views::ButtonListener: | 75 // views::ButtonListener: |
| 71 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | 76 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| 72 } | 77 } |
| 73 | 78 |
| 74 std::unique_ptr<views::View> item_view_; | 79 std::unique_ptr<views::View> item_view_; |
| 75 PaymentRequest* request_; | 80 PaymentRequestSpec* spec_; |
| 81 PaymentRequestState* state_; |
| 76 PaymentRequestItemList* list_; | 82 PaymentRequestItemList* list_; |
| 77 bool selected_; | 83 bool selected_; |
| 78 | 84 |
| 79 DISALLOW_COPY_AND_ASSIGN(Item); | 85 DISALLOW_COPY_AND_ASSIGN(Item); |
| 80 }; | 86 }; |
| 81 | 87 |
| 82 PaymentRequestItemList(); | 88 PaymentRequestItemList(); |
| 83 virtual ~PaymentRequestItemList(); | 89 virtual ~PaymentRequestItemList(); |
| 84 | 90 |
| 85 // Adds an item to this list. |item->list()| should return this object. | 91 // Adds an item to this list. |item->list()| should return this object. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 101 | 107 |
| 102 std::vector<std::unique_ptr<Item>> items_; | 108 std::vector<std::unique_ptr<Item>> items_; |
| 103 Item* selected_item_; | 109 Item* selected_item_; |
| 104 | 110 |
| 105 DISALLOW_COPY_AND_ASSIGN(PaymentRequestItemList); | 111 DISALLOW_COPY_AND_ASSIGN(PaymentRequestItemList); |
| 106 }; | 112 }; |
| 107 | 113 |
| 108 } // namespace payments | 114 } // namespace payments |
| 109 | 115 |
| 110 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_ITEM_LIST_H_ | 116 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_ITEM_LIST_H_ |
| OLD | NEW |