Chromium Code Reviews| 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 | 13 |
| 13 namespace views { | 14 namespace views { |
| 14 class ImageView; | 15 class ImageView; |
| 15 class View; | 16 class View; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace payments { | 19 namespace payments { |
| 19 | 20 |
| 20 class PaymentRequest; | 21 class PaymentRequest; |
| 21 | 22 |
| 22 // A control representing a list of selectable items in the PaymentRequest | 23 // A control representing a list of selectable items in the PaymentRequest |
| 23 // dialog. These lists enforce that only one of their elements be selectable at | 24 // dialog. These lists enforce that only one of their elements be selectable at |
| 24 // a time and that "incomplete" items (for example, a credit card with no known | 25 // a time and that "incomplete" items (for example, a credit card with no known |
| 25 // expiration date) behave differently when selected. Most of the time, this | 26 // expiration date) behave differently when selected. Most of the time, this |
| 26 // behavior is to show an editor screen. | 27 // behavior is to show an editor screen. |
| 27 class PaymentRequestItemList { | 28 class PaymentRequestItemList { |
| 28 public: | 29 public: |
| 29 // Represents an item in the item list. | 30 // Represents an item in the item list. |
| 30 class Item { | 31 class Item : public views::ButtonListener { |
| 31 public: | 32 public: |
| 32 // Creates an item that will be owned by |list| with the initial state set | 33 // Creates an item that will be owned by |list| with the initial state set |
| 33 // to |selected|. | 34 // to |selected|. |
| 34 Item(PaymentRequest* request, PaymentRequestItemList* list, bool selected); | 35 Item(PaymentRequest* request, PaymentRequestItemList* list, bool selected); |
| 35 virtual ~Item(); | 36 ~Item() override; |
| 36 | 37 |
| 37 // Gets the view associated with this item. It's owned by this object so | 38 // Gets the view associated with this item. It's owned by this object so |
| 38 // that it can listen to any changes to the underlying model and update the | 39 // that it can listen to any changes to the underlying model and update the |
| 39 // view. | 40 // view. |
| 40 views::View* GetItemView(); | 41 views::View* GetItemView(); |
| 41 | 42 |
| 42 bool selected() const { return selected_; } | 43 bool selected() const { return selected_; } |
| 43 // Changes the selected state of this item to |selected| and calls | 44 // Changes the selected state of this item to |selected| and calls |
| 44 // SelectedStateChanged. | 45 // SelectedStateChanged. |
| 45 void SetSelected(bool selected); | 46 void SetSelected(bool selected); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 59 // assume that they are the only selected item in |list| when this is | 60 // assume that they are the only selected item in |list| when this is |
| 60 // called. This could be called before CreateItemView so subclasses should | 61 // called. This could be called before CreateItemView so subclasses should |
| 61 // be aware that their views might not exist yet. | 62 // be aware that their views might not exist yet. |
| 62 virtual void SelectedStateChanged() = 0; | 63 virtual void SelectedStateChanged() = 0; |
| 63 | 64 |
| 64 // Creates an image of a large checkmark, used to indicate that an option is | 65 // Creates an image of a large checkmark, used to indicate that an option is |
| 65 // selected. | 66 // selected. |
| 66 std::unique_ptr<views::ImageView> CreateCheckmark(bool selected); | 67 std::unique_ptr<views::ImageView> CreateCheckmark(bool selected); |
| 67 | 68 |
| 68 private: | 69 private: |
| 70 // views::ButtonListener: | |
| 71 void ButtonPressed(views::Button* sender, const ui::Event& event) override { | |
|
please use gerrit instead
2017/03/10 20:23:12
Shouldn't this be protected, so that deriving clas
tmartino
2017/03/10 23:46:23
Per anthonyvd's comment, we're going to first try
| |
| 72 } | |
| 73 | |
| 69 std::unique_ptr<views::View> item_view_; | 74 std::unique_ptr<views::View> item_view_; |
| 70 PaymentRequest* request_; | 75 PaymentRequest* request_; |
| 71 PaymentRequestItemList* list_; | 76 PaymentRequestItemList* list_; |
| 72 bool selected_; | 77 bool selected_; |
| 73 | 78 |
| 74 DISALLOW_COPY_AND_ASSIGN(Item); | 79 DISALLOW_COPY_AND_ASSIGN(Item); |
| 75 }; | 80 }; |
| 76 | 81 |
| 77 PaymentRequestItemList(); | 82 PaymentRequestItemList(); |
| 78 ~PaymentRequestItemList(); | 83 ~PaymentRequestItemList(); |
|
please use gerrit instead
2017/03/10 20:23:12
Needs to be virtual. Deriving classes should overr
tmartino
2017/03/10 23:46:23
Done
| |
| 79 | 84 |
| 80 // Adds an item to this list. |item->list()| should return this object. | 85 // Adds an item to this list. |item->list()| should return this object. |
| 81 void AddItem(std::unique_ptr<Item> item); | 86 void AddItem(std::unique_ptr<Item> item); |
| 82 | 87 |
| 83 // Creates and returns the UI representation of this list. It iterates over | 88 // Creates and returns the UI representation of this list. It iterates over |
| 84 // the items it contains, creates their associated views, and adds them to the | 89 // the items it contains, creates their associated views, and adds them to the |
| 85 // hierarchy. | 90 // hierarchy. |
| 86 std::unique_ptr<views::View> CreateListView(); | 91 std::unique_ptr<views::View> CreateListView(); |
| 87 | 92 |
| 88 // Deselects the currently selected item and selects |item| instead. | 93 // Deselects the currently selected item and selects |item| instead. |
| 89 void SelectItem(Item* item); | 94 void SelectItem(Item* item); |
| 90 | 95 |
| 91 private: | 96 private: |
| 92 // Unselects the currently selected item. This is private so that the list can | 97 // Unselects the currently selected item. This is private so that the list can |
| 93 // use it when selecting a new item while avoiding consumers of this class | 98 // use it when selecting a new item while avoiding consumers of this class |
| 94 // putting the list in a state where no item is selected. | 99 // putting the list in a state where no item is selected. |
| 95 void UnselectSelectedItem(); | 100 void UnselectSelectedItem(); |
| 96 | 101 |
| 97 std::vector<std::unique_ptr<Item>> items_; | 102 std::vector<std::unique_ptr<Item>> items_; |
| 98 Item* selected_item_; | 103 Item* selected_item_; |
| 99 | 104 |
| 100 DISALLOW_COPY_AND_ASSIGN(PaymentRequestItemList); | 105 DISALLOW_COPY_AND_ASSIGN(PaymentRequestItemList); |
| 101 }; | 106 }; |
| 102 | 107 |
| 103 } // namespace payments | 108 } // namespace payments |
| 104 | 109 |
| 105 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_ITEM_LIST_H_ | 110 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_ITEM_LIST_H_ |
| OLD | NEW |