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

Side by Side Diff: chrome/browser/ui/views/payments/payment_method_view_controller.cc

Issue 2755493005: [Web Payments] Consolidate list code. (Closed)
Patch Set: Fix test compile. Created 3 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/ui/views/payments/payment_request_item_list.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h" 5 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector>
9 10
10 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
11 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" 13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 14 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
14 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" 15 #include "chrome/browser/ui/views/payments/payment_request_row_view.h"
15 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 16 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
16 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
17 #include "components/payments/content/payment_request_state.h" 18 #include "components/payments/content/payment_request_state.h"
18 #include "components/payments/core/payment_instrument.h" 19 #include "components/payments/core/payment_instrument.h"
(...skipping 29 matching lines...) Expand all
48 PaymentRequestSpec* spec, 49 PaymentRequestSpec* spec,
49 PaymentRequestState* state, 50 PaymentRequestState* state,
50 PaymentRequestItemList* list, 51 PaymentRequestItemList* list,
51 bool selected) 52 bool selected)
52 : payments::PaymentRequestItemList::Item(spec, state, list, selected), 53 : payments::PaymentRequestItemList::Item(spec, state, list, selected),
53 instrument_(instrument) {} 54 instrument_(instrument) {}
54 ~PaymentMethodListItem() override {} 55 ~PaymentMethodListItem() override {}
55 56
56 private: 57 private:
57 // payments::PaymentRequestItemList::Item: 58 // payments::PaymentRequestItemList::Item:
58 std::unique_ptr<views::View> CreateItemView() override { 59 std::unique_ptr<views::View> CreateExtraView() override {
59 std::unique_ptr<PaymentRequestRowView> row = 60 std::unique_ptr<views::ImageView> card_icon_view = CreateInstrumentIconView(
60 base::MakeUnique<PaymentRequestRowView>(this); 61 instrument_->icon_resource_id(), instrument_->label());
61 views::GridLayout* layout = new views::GridLayout(row.get()); 62 card_icon_view->SetImageSize(gfx::Size(32, 20));
62 layout->SetInsets( 63 return std::move(card_icon_view);
63 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets, 64 }
64 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets);
65 row->SetLayoutManager(layout);
66 views::ColumnSet* columns = layout->AddColumnSet(0);
67 65
68 // A column for the masked number and name on card 66 std::unique_ptr<views::View> CreateContentView() override {
69 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0,
70 views::GridLayout::USE_PREF, 0, 0);
71
72 // A padding column that resizes to take up the empty space between the
73 // leading and trailing parts.
74 columns->AddPaddingColumn(1, 0);
75
76 // A column for the checkmark when the row is selected.
77 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
78 0, views::GridLayout::USE_PREF, 0, 0);
79
80 columns->AddPaddingColumn(0, kPaymentRequestButtonSpacing);
81
82 // A column for the card icon
83 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
84 0, views::GridLayout::USE_PREF, 0, 0);
85
86 // A column for the edit button
87 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
88 0, views::GridLayout::USE_PREF, 0, 0);
89
90 layout->StartRow(0, 0);
91 std::unique_ptr<views::View> card_info_container = 67 std::unique_ptr<views::View> card_info_container =
92 base::MakeUnique<views::View>(); 68 base::MakeUnique<views::View>();
93 card_info_container->set_can_process_events_within_subtree(false); 69 card_info_container->set_can_process_events_within_subtree(false);
94 70
95 std::unique_ptr<views::BoxLayout> box_layout = 71 std::unique_ptr<views::BoxLayout> box_layout =
96 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 72 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0,
97 kPaymentRequestRowVerticalInsets, 0); 73 kPaymentRequestRowVerticalInsets, 0);
98 box_layout->set_cross_axis_alignment( 74 box_layout->set_cross_axis_alignment(
99 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); 75 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
100 card_info_container->SetLayoutManager(box_layout.release()); 76 card_info_container->SetLayoutManager(box_layout.release());
101 77
102 card_info_container->AddChildView(new views::Label(instrument_->label())); 78 card_info_container->AddChildView(new views::Label(instrument_->label()));
103 card_info_container->AddChildView( 79 card_info_container->AddChildView(
104 new views::Label(instrument_->sublabel())); 80 new views::Label(instrument_->sublabel()));
105 // TODO(anthonyvd): Add the "card is incomplete" label once the 81 // TODO(anthonyvd): Add the "card is incomplete" label once the
106 // completedness logic is implemented. 82 // completedness logic is implemented.
107 layout->AddView(card_info_container.release()); 83 return card_info_container;
108
109 checkmark_ = CreateCheckmark(selected());
110 layout->AddView(checkmark_.get());
111
112 std::unique_ptr<views::ImageView> card_icon_view = CreateInstrumentIconView(
113 instrument_->icon_resource_id(), instrument_->label());
114 card_icon_view->SetImageSize(gfx::Size(32, 20));
115 layout->AddView(card_icon_view.release());
116
117 return std::move(row);
118 } 84 }
119 85
120 void SelectedStateChanged() override { 86 void SelectedStateChanged() override {
121 // This could be called before CreateItemView, so before |checkmark_| is
122 // instantiated.
123 if (checkmark_)
124 checkmark_->SetVisible(selected());
125
126 state()->SetSelectedInstrument(instrument_); 87 state()->SetSelectedInstrument(instrument_);
127 } 88 }
128 89
129 // views::ButtonListener: 90 bool CanBeSelected() const override {
130 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 91 // TODO(anthonyvd): Check for card completedness.
131 if (IsComplete()) {
132 list()->SelectItem(this);
133 } else {
134 // TODO(anthonyvd): Display the editor, pre-populated with the data that
135 // already exists in |card|.
136 }
137 }
138
139 bool IsComplete() const {
140 // TODO(anthonyvd): Hook this up to the card completedness logic when it's
141 // implemented in PaymentRequest.
142 return true; 92 return true;
143 } 93 }
144 94
95 void PerformSelectionFallback() override {
96 // TODO(anthonyvd): Open the editor pre-populated with this card's data.
97 }
98
145 PaymentInstrument* instrument_; 99 PaymentInstrument* instrument_;
146 std::unique_ptr<views::ImageView> checkmark_; 100 std::unique_ptr<views::ImageView> checkmark_;
147 101
148 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem); 102 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem);
149 }; 103 };
150 104
151 } // namespace 105 } // namespace
152 106
153 PaymentMethodViewController::PaymentMethodViewController( 107 PaymentMethodViewController::PaymentMethodViewController(
154 PaymentRequestSpec* spec, 108 PaymentRequestSpec* spec,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON): 163 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON):
210 dialog()->ShowCreditCardEditor(); 164 dialog()->ShowCreditCardEditor();
211 break; 165 break;
212 default: 166 default:
213 PaymentRequestSheetController::ButtonPressed(sender, event); 167 PaymentRequestSheetController::ButtonPressed(sender, event);
214 break; 168 break;
215 } 169 }
216 } 170 }
217 171
218 } // namespace payments 172 } // namespace payments
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/payments/payment_request_item_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698