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

Unified 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: Fix test flakiness. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/payments/payment_request_item_list.h
diff --git a/chrome/browser/ui/views/payments/payment_request_item_list.h b/chrome/browser/ui/views/payments/payment_request_item_list.h
index 71f4c04812d6eb0903b96538f6c6f5dab4fb23ab..09aafea098284a14576c184557756470939649e4 100644
--- a/chrome/browser/ui/views/payments/payment_request_item_list.h
+++ b/chrome/browser/ui/views/payments/payment_request_item_list.h
@@ -16,17 +16,21 @@ class View;
namespace payments {
+class PaymentRequest;
+
// A control representing a list of selectable items in the PaymentRequest
// dialog. These lists enforce that only one of their elements be selectable at
// a time and that "incomplete" items (for example, a credit card with no known
-// expriration date) behave differently when selected. Most of the time, this
+// expiration date) behave differently when selected. Most of the time, this
// behavior is to show an editor screen.
class PaymentRequestItemList {
public:
// Represents an item in the item list.
class Item {
public:
- Item();
+ // Creates an item that will be owned by |list| with the initial state set
+ // to |selected|.
+ Item(PaymentRequest* request, PaymentRequestItemList* list, bool selected);
virtual ~Item();
// Gets the view associated with this item. It's owned by this object so
@@ -34,12 +38,33 @@ class PaymentRequestItemList {
// view.
views::View* GetItemView();
+ bool selected() const { return selected_; }
+ // Changes the selected state of this item to |selected| and calls
+ // SelectedStateChanged.
+ void SetSelected(bool selected);
+
+ // Returns a pointer to the PaymentRequestItemList that owns this object.
+ PaymentRequestItemList* list() { return list_; }
+
+ // Returns a pointer to the PaymentRequest object associated with this
+ // instance of the UI.
+ PaymentRequest* request() { return request_; }
+
protected:
// Creates and returns the view associated with this list item.
virtual std::unique_ptr<views::View> CreateItemView() = 0;
+ // Called when the selected state of this item changes. Subclasses may
+ // assume that they are the only selected item in |list| when this is
+ // called. This could be called before CreateItemView so subclasses should
+ // be aware that their views might not exist yet.
+ virtual void SelectedStateChanged() = 0;
+
private:
std::unique_ptr<views::View> item_view_;
+ PaymentRequest* request_;
+ PaymentRequestItemList* list_;
+ bool selected_;
DISALLOW_COPY_AND_ASSIGN(Item);
};
@@ -47,7 +72,7 @@ class PaymentRequestItemList {
PaymentRequestItemList();
~PaymentRequestItemList();
- // Adds an item to this list.
+ // Adds an item to this list. |item->list()| should return this object.
void AddItem(std::unique_ptr<Item> item);
// Creates and returns the UI representation of this list. It iterates over
@@ -55,8 +80,17 @@ class PaymentRequestItemList {
// hierarchy.
std::unique_ptr<views::View> CreateListView();
+ // Deselects the currently selected item and selects |item| instead.
+ void SelectItem(Item* item);
+
private:
+ // Unselects the currently selected item. This is private so that the list can
+ // use it when selecting a new item while avoiding consumers of this class
+ // putting the list in a state where no item is selected.
+ void UnselectSelectedItem();
+
std::vector<std::unique_ptr<Item>> items_;
+ Item* selected_item_;
DISALLOW_COPY_AND_ASSIGN(PaymentRequestItemList);
};

Powered by Google App Engine
This is Rietveld 408576698