Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(552)

Side by Side Diff: chrome/browser/ui/views/payments/payment_request_item_list.h

Issue 2872623002: [Web Payments] Add "pencil" edit button to lists. (Closed)
Patch Set: Move and rename icon. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 ImageButton;
15 class ImageView; 16 class ImageView;
16 class View; 17 class View;
17 } 18 }
18 19
19 namespace payments { 20 namespace payments {
20 21
21 class PaymentRequestSpec; 22 class PaymentRequestSpec;
22 class PaymentRequestState; 23 class PaymentRequestState;
23 24
24 // A control representing a list of selectable items in the PaymentRequest 25 // A control representing a list of selectable items in the PaymentRequest
25 // dialog. These lists enforce that only one of their elements be selectable at 26 // dialog. These lists enforce that only one of their elements be selectable at
26 // a time and that "incomplete" items (for example, a credit card with no known 27 // a time and that "incomplete" items (for example, a credit card with no known
27 // expiration date) behave differently when selected. Most of the time, this 28 // expiration date) behave differently when selected. Most of the time, this
28 // behavior is to show an editor screen. 29 // behavior is to show an editor screen.
29 class PaymentRequestItemList { 30 class PaymentRequestItemList {
30 public: 31 public:
31 // Represents an item in the item list. 32 // Represents an item in the item list.
32 class Item : public views::ButtonListener { 33 class Item : public views::ButtonListener {
33 public: 34 public:
34 // Creates an item that will be owned by |list| with the initial state set 35 // Creates an item that will be owned by |list| with the initial state set
35 // to |selected|. 36 // to |selected|.
36 Item(PaymentRequestSpec* spec, 37 Item(PaymentRequestSpec* spec,
37 PaymentRequestState* state, 38 PaymentRequestState* state,
38 PaymentRequestItemList* list, 39 PaymentRequestItemList* list,
39 bool selected); 40 bool selected,
41 bool show_edit_button);
40 ~Item() override; 42 ~Item() override;
41 43
42 // Gets the view associated with this item. It's owned by this object so 44 // Gets the view associated with this item. It's owned by this object so
43 // that it can listen to any changes to the underlying model and update the 45 // that it can listen to any changes to the underlying model and update the
44 // view. 46 // view.
45 views::View* GetItemView(); 47 views::View* GetItemView();
46 48
47 bool selected() const { return selected_; } 49 bool selected() const { return selected_; }
48 // Changes the selected state of this item to |selected|. 50 // Changes the selected state of this item to |selected|.
49 // SelectedStateChanged is called if |notify| is true. 51 // SelectedStateChanged is called if |notify| is true.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 84
83 // Returns whether this item is complete/valid and can be selected by the 85 // Returns whether this item is complete/valid and can be selected by the
84 // user. If this returns false when the user attempts to select this item, 86 // user. If this returns false when the user attempts to select this item,
85 // PerformSelectionFallback will be called instead. 87 // PerformSelectionFallback will be called instead.
86 virtual bool CanBeSelected() = 0; 88 virtual bool CanBeSelected() = 0;
87 89
88 // Performs the action that replaces selection when CanBeSelected returns 90 // Performs the action that replaces selection when CanBeSelected returns
89 // false. This will usually be to display an editor. 91 // false. This will usually be to display an editor.
90 virtual void PerformSelectionFallback() = 0; 92 virtual void PerformSelectionFallback() = 0;
91 93
94 // Called when the edit button is pressed. Subclasses should open the editor
95 // appropriate for the item they represent.
96 virtual void EditButtonPressed() = 0;
97
92 private: 98 private:
93 // Creates and returns the view associated with this list item. 99 // Creates and returns the view associated with this list item.
94 std::unique_ptr<views::View> CreateItemView(); 100 std::unique_ptr<views::View> CreateItemView();
95 101
96 // views::ButtonListener: 102 // views::ButtonListener:
97 void ButtonPressed(views::Button* sender, const ui::Event& event) override; 103 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
98 104
99 std::unique_ptr<views::View> item_view_; 105 std::unique_ptr<views::View> item_view_;
100 PaymentRequestSpec* spec_; 106 PaymentRequestSpec* spec_;
101 PaymentRequestState* state_; 107 PaymentRequestState* state_;
102 PaymentRequestItemList* list_; 108 PaymentRequestItemList* list_;
103 std::unique_ptr<views::ImageView> checkmark_; 109 std::unique_ptr<views::ImageView> checkmark_;
110 std::unique_ptr<views::ImageButton> edit_button_;
sky 2017/05/12 01:28:48 I think a better approach here is to not have the
104 bool selected_; 111 bool selected_;
112 bool show_edit_button_;
105 113
106 DISALLOW_COPY_AND_ASSIGN(Item); 114 DISALLOW_COPY_AND_ASSIGN(Item);
107 }; 115 };
108 116
109 PaymentRequestItemList(); 117 PaymentRequestItemList();
110 virtual ~PaymentRequestItemList(); 118 virtual ~PaymentRequestItemList();
111 119
112 // Adds an item to this list. |item->list()| should return this object. 120 // Adds an item to this list. |item->list()| should return this object.
113 void AddItem(std::unique_ptr<Item> item); 121 void AddItem(std::unique_ptr<Item> item);
114 122
(...skipping 13 matching lines...) Expand all
128 136
129 std::vector<std::unique_ptr<Item>> items_; 137 std::vector<std::unique_ptr<Item>> items_;
130 Item* selected_item_; 138 Item* selected_item_;
131 139
132 DISALLOW_COPY_AND_ASSIGN(PaymentRequestItemList); 140 DISALLOW_COPY_AND_ASSIGN(PaymentRequestItemList);
133 }; 141 };
134 142
135 } // namespace payments 143 } // namespace payments
136 144
137 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_ITEM_LIST_H_ 145 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_ITEM_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698