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

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

Issue 2711973002: [Web Payments] Implement the credit card selection UI functionality. (Closed)
Patch Set: Address comments. Created 3 years, 10 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 12
13 namespace views { 13 namespace views {
14 class View; 14 class View;
15 } 15 }
16 16
17 namespace payments { 17 namespace payments {
18 18
19 // A control representing a list of selectable items in the PaymentRequest 19 // A control representing a list of selectable items in the PaymentRequest
20 // dialog. These lists enforce that only one of their elements be selectable at 20 // dialog. These lists enforce that only one of their elements be selectable at
21 // a time and that "incomplete" items (for example, a credit card with no known 21 // a time and that "incomplete" items (for example, a credit card with no known
22 // expriration date) behave differently when selected. Most of the time, this 22 // expiration date) behave differently when selected. Most of the time, this
23 // behavior is to show an editor screen. 23 // behavior is to show an editor screen.
24 class PaymentRequestItemList { 24 class PaymentRequestItemList {
25 public: 25 public:
26 // Represents an item in the item list. 26 // Represents an item in the item list.
27 class Item { 27 class Item {
28 public: 28 public:
29 Item(); 29 // Creates an item that will be owned by |list| with the initial state set
30 // to |selected|.
31 Item(PaymentRequestItemList* list, bool selected);
30 virtual ~Item(); 32 virtual ~Item();
31 33
32 // Gets the view associated with this item. It's owned by this object so 34 // Gets the view associated with this item. It's owned by this object so
33 // that it can listen to any changes to the underlying model and update the 35 // that it can listen to any changes to the underlying model and update the
34 // view. 36 // view.
35 views::View* GetItemView(); 37 views::View* GetItemView();
36 38
39 bool selected() const { return selected_; }
40 // Changes the selected state of this item to |selected| and calls
41 // SelectedStateChanged.
42 void SetSelected(bool selected);
43
44 // Returns a pointer to the PaymentRequestItemList that owns this object.
45 PaymentRequestItemList* list() { return list_; }
46
37 protected: 47 protected:
38 // Creates and returns the view associated with this list item. 48 // Creates and returns the view associated with this list item.
39 virtual std::unique_ptr<views::View> CreateItemView() = 0; 49 virtual std::unique_ptr<views::View> CreateItemView() = 0;
40 50
51 // Called when the selected state of this item changes. Subclasses may
52 // assume that they are the only selected item in |list| when this is
53 // called.
54 virtual void SelectedStateChanged() = 0;
55
41 private: 56 private:
42 std::unique_ptr<views::View> item_view_; 57 std::unique_ptr<views::View> item_view_;
58 PaymentRequestItemList* list_;
59 bool selected_;
43 60
44 DISALLOW_COPY_AND_ASSIGN(Item); 61 DISALLOW_COPY_AND_ASSIGN(Item);
45 }; 62 };
46 63
47 PaymentRequestItemList(); 64 PaymentRequestItemList();
48 ~PaymentRequestItemList(); 65 ~PaymentRequestItemList();
49 66
50 // Adds an item to this list. 67 // Adds an item to this list. |item->list()| should be equal to this object.
please use gerrit instead 2017/02/24 14:56:53 Please remove the words "equal to" to avoid confus
anthonyvd 2017/02/24 16:36:58 Done.
51 void AddItem(std::unique_ptr<Item> item); 68 void AddItem(std::unique_ptr<Item> item);
52 69
53 // Creates and returns the UI representation of this list. It iterates over 70 // Creates and returns the UI representation of this list. It iterates over
54 // the items it contains, creates their associated views, and adds them to the 71 // the items it contains, creates their associated views, and adds them to the
55 // hierarchy. 72 // hierarchy.
56 std::unique_ptr<views::View> CreateListView(); 73 std::unique_ptr<views::View> CreateListView();
57 74
75 // Deselects the currently selected item and selects |item| instead.
76 void SelectItem(Item* item);
77
58 private: 78 private:
59 std::vector<std::unique_ptr<Item>> items_; 79 std::vector<std::unique_ptr<Item>> items_;
60 80
61 DISALLOW_COPY_AND_ASSIGN(PaymentRequestItemList); 81 DISALLOW_COPY_AND_ASSIGN(PaymentRequestItemList);
62 }; 82 };
63 83
64 } // namespace payments 84 } // namespace payments
65 85
66 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_ITEM_LIST_H_ 86 #endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_PAYMENT_REQUEST_ITEM_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698