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

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

Issue 2735803003: [WebPayments] Extracting common code from Shipping + Contact Info views. (Closed)
Patch Set: removing extraneous todo 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/payments/profile_list_view_controller.h"
6
7 #include "chrome/browser/ui/views/payments/payment_request_row_view.h"
8 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
9 #include "components/payments/content/payment_request.h"
10 #include "components/strings/grit/components_strings.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/views/controls/image_view.h"
13 #include "ui/views/layout/grid_layout.h"
14
15 namespace payments {
16
17 namespace {
18
19 class ProfileItem : public PaymentRequestItemList::Item,
20 public views::ButtonListener {
21 public:
22 // Constructs an object owned by |parent_list|, representing one element in
23 // the list. |request| is the PaymentRequest object that is represented by the
24 // current instance of the dialog. |parent_view| points to the controller
25 // which owns |parent_list|. |profile| is the AutofillProfile that this
26 // specific list item represents. It's a cached profile owned by |request|.
27 ProfileItem(autofill::AutofillProfile* profile,
28 PaymentRequest* request,
29 PaymentRequestItemList* parent_list,
30 ProfileListViewController* parent_view,
31 bool selected)
32 : payments::PaymentRequestItemList::Item(request, parent_list, selected),
33 parent_view_(parent_view),
34 profile_(profile) {}
35 ~ProfileItem() override {}
36
37 private:
38 // payments::PaymentRequestItemList::Item:
39 std::unique_ptr<views::View> CreateItemView() override {
40 DCHECK(profile_);
41
42 std::unique_ptr<views::View> content = parent_view_->GetLabel(profile_);
43
44 std::unique_ptr<PaymentRequestRowView> row =
45 base::MakeUnique<PaymentRequestRowView>(this);
46 views::GridLayout* layout = new views::GridLayout(row.get());
47 row->SetLayoutManager(layout);
48
49 layout->SetInsets(
50 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets,
51 kPaymentRequestRowVerticalInsets,
52 kPaymentRequestRowHorizontalInsets + kPaymentRequestRowExtraRightInset);
53
54 // Add a column listing the profile information.
55 views::ColumnSet* columns = layout->AddColumnSet(0);
56 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
anthonyvd 2017/03/07 15:13:14 Should the first argument be views::GridLayout::LE
tmartino 2017/03/10 15:53:48 Done
57 views::GridLayout::USE_PREF, 0, 0);
58
59 columns->AddPaddingColumn(1, 0);
60
61 // Add a column for the checkmark shown next to the selected profile.
62 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
63 0, views::GridLayout::USE_PREF, 0, 0);
64
65 layout->StartRow(0, 0);
66 content->set_can_process_events_within_subtree(false);
67 layout->AddView(content.release());
68
69 checkmark_ = CreateCheckmark(selected());
70 layout->AddView(checkmark_.get());
71
72 return std::move(row);
73 }
74
75 void SelectedStateChanged() override {}
76
77 // views::ButtonListener:
78 void ButtonPressed(views::Button* sender, const ui::Event& event) override {}
anthonyvd 2017/03/07 15:13:14 Can we move this to the base item class and have s
tmartino 2017/03/10 15:53:48 Agreed, moved. Not adding virtual methods until we
79
80 ProfileListViewController* parent_view_;
81 autofill::AutofillProfile* profile_;
82 std::unique_ptr<views::ImageView> checkmark_;
83 };
84
85 // The ProfileListViewController subtype for the Shipping address list
86 // screen of the Payment Request flow.
87 class ShippingProfileViewController : public ProfileListViewController {
88 public:
89 ShippingProfileViewController(PaymentRequest* request,
90 PaymentRequestDialogView* dialog)
91 : ProfileListViewController(request, dialog), request_(request) {}
92 ~ShippingProfileViewController() override {}
93
94 protected:
95 // ProfileListViewController:
96 std::unique_ptr<views::View> GetLabel(
97 autofill::AutofillProfile* profile) override {
98 return GetShippingAddressLabel(AddressStyleType::DETAILED,
99 request_->locale(), *profile);
100 }
101
102 std::vector<autofill::AutofillProfile*> GetProfiles() override {
103 return request_->shipping_profiles();
104 }
105
106 base::string16 GetHeaderString() override {
107 return l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_SHIPPING_SECTION_NAME);
108 }
109
110 private:
111 PaymentRequest* request_;
anthonyvd 2017/03/07 15:13:14 nit: This could be on the base with a protected ac
tmartino 2017/03/10 15:53:48 Done
112 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController);
113 };
114
115 class ContactProfileViewController : public ProfileListViewController {
116 public:
117 ContactProfileViewController(PaymentRequest* request,
118 PaymentRequestDialogView* dialog)
119 : ProfileListViewController(request, dialog), request_(request) {}
120 ~ContactProfileViewController() override {}
121
122 protected:
123 // ProfileListViewController:
124 std::unique_ptr<views::View> GetLabel(
125 autofill::AutofillProfile* profile) override {
126 return GetContactInfoLabel(AddressStyleType::DETAILED, request_->locale(),
127 *profile, request_->request_payer_name(),
128 request_->request_payer_email(),
129 request_->request_payer_phone());
130 }
131
132 std::vector<autofill::AutofillProfile*> GetProfiles() override {
133 return request_->contact_profiles();
134 }
135
136 base::string16 GetHeaderString() override {
137 return l10n_util::GetStringUTF16(
138 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME);
139 }
140
141 private:
142 PaymentRequest* request_;
143 DISALLOW_COPY_AND_ASSIGN(ContactProfileViewController);
144 };
145
146 } // namespace
147
148 // static
149 std::unique_ptr<ProfileListViewController>
150 ProfileListViewController::GetShippingProfileViewController(
151 PaymentRequest* request,
152 PaymentRequestDialogView* dialog) {
153 return base::MakeUnique<ShippingProfileViewController>(request, dialog);
154 }
155
156 // static
157 std::unique_ptr<ProfileListViewController>
158 ProfileListViewController::GetContactProfileViewController(
159 PaymentRequest* request,
160 PaymentRequestDialogView* dialog) {
161 return base::MakeUnique<ContactProfileViewController>(request, dialog);
162 }
163
164 ProfileListViewController::ProfileListViewController(
165 PaymentRequest* request,
166 PaymentRequestDialogView* dialog)
167 : PaymentRequestSheetController(request, dialog) {}
168
169 ProfileListViewController::~ProfileListViewController() {}
170
171 std::unique_ptr<views::View> ProfileListViewController::CreateView() {
172 auto* selected_profile = request()->selected_shipping_profile();
anthonyvd 2017/03/07 15:13:14 I *think* the style guide prohibits the use of aut
tmartino 2017/03/10 15:53:48 Nope: https://google.github.io/styleguide/cppguide
173
174 // This must be done at Create-time, rather than construct-time, because
175 // the subclass method GetProfiles can't be called in the ctor.
176 for (auto* profile : GetProfiles()) {
177 list_.AddItem(base::MakeUnique<ProfileItem>(
178 profile, request(), &list_, this, profile == selected_profile));
179 }
180
181 return CreatePaymentView(
182 CreateSheetHeaderView(
183 /* show_back_arrow = */ true, GetHeaderString(), this),
184 list_.CreateListView());
185 }
186
187 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698