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

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

Issue 2625183002: [WebPayments] Adding Shipping Address and Contact Info display to order summary (Closed)
Patch Set: Rebasing with anthonyvd changes Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_request_views_util.h" 5 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
6 6
7 #include <vector>
8
7 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/app/vector_icons/vector_icons.h" 11 #include "chrome/app/vector_icons/vector_icons.h"
9 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" 12 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h"
13 #include "components/autofill/core/browser/autofill_type.h"
14 #include "components/autofill/core/browser/field_types.h"
10 #include "third_party/skia/include/core/SkColor.h" 15 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/views/background.h" 16 #include "ui/views/background.h"
12 #include "ui/views/bubble/bubble_frame_view.h" 17 #include "ui/views/bubble/bubble_frame_view.h"
13 #include "ui/views/controls/button/button.h" 18 #include "ui/views/controls/button/button.h"
14 #include "ui/views/controls/button/vector_icon_button.h" 19 #include "ui/views/controls/button/vector_icon_button.h"
15 #include "ui/views/controls/label.h" 20 #include "ui/views/controls/label.h"
21 #include "ui/views/controls/styled_label.h"
16 #include "ui/views/layout/grid_layout.h" 22 #include "ui/views/layout/grid_layout.h"
17 #include "ui/views/view.h" 23 #include "ui/views/view.h"
18 24
25 namespace {
26
27 // TODO(tmartino): Consider combining this with the Android equivalent in
28 // PersonalDataManager.java
29 base::string16 GetAddressFromProfile(autofill::AutofillProfile* profile,
please use gerrit instead 2017/01/18 18:50:47 const-ref parameter
30 std::string locale) {
please use gerrit instead 2017/01/18 18:50:47 const-ref
31 std::vector<autofill::ServerFieldType> fields;
32 fields.push_back(autofill::COMPANY_NAME);
33 fields.push_back(autofill::ADDRESS_HOME_LINE1);
34 fields.push_back(autofill::ADDRESS_HOME_LINE2);
35 fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY);
36 fields.push_back(autofill::ADDRESS_HOME_CITY);
37 fields.push_back(autofill::ADDRESS_HOME_STATE);
38 fields.push_back(autofill::ADDRESS_HOME_ZIP);
39 fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE);
40
41 return profile->ConstructInferredLabel(fields, fields.size(), locale);
42 }
43
44 } // namespace
45
19 namespace payments { 46 namespace payments {
20 47
21 std::unique_ptr<views::View> CreateSheetHeaderView( 48 std::unique_ptr<views::View> CreateSheetHeaderView(
22 bool show_back_arrow, 49 bool show_back_arrow,
23 const base::string16& title, 50 const base::string16& title,
24 views::VectorIconButtonDelegate* delegate) { 51 views::VectorIconButtonDelegate* delegate) {
25 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); 52 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
26 views::GridLayout* layout = new views::GridLayout(container.get()); 53 views::GridLayout* layout = new views::GridLayout(container.get());
27 container->SetLayoutManager(layout); 54 container->SetLayoutManager(layout);
28 55
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // |header_view| will be deleted when |view| is. 107 // |header_view| will be deleted when |view| is.
81 layout->AddView(header_view.release()); 108 layout->AddView(header_view.release());
82 109
83 layout->StartRow(0, 0); 110 layout->StartRow(0, 0);
84 // |content_view| will be deleted when |view| is. 111 // |content_view| will be deleted when |view| is.
85 layout->AddView(content_view.release()); 112 layout->AddView(content_view.release());
86 113
87 return view; 114 return view;
88 } 115 }
89 116
117 std::unique_ptr<views::View> GetShippingAddressLabel(
118 AddressStyleType type,
119 std::string locale,
120 autofill::AutofillProfile* profile) {
121 base::string16 name_value =
122 profile->GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale);
123
124 // TODO(tmartino): Add bold styling for name in DETAILED style.
125
126 base::string16 address_value = GetAddressFromProfile(profile, locale);
127
128 base::string16 phone_value = profile->GetInfo(
129 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale);
130
131 std::vector<base::string16> values;
132 if (!name_value.empty())
133 values.push_back(name_value);
134 if (!address_value.empty())
135 values.push_back(address_value);
136 if (!phone_value.empty())
137 values.push_back(phone_value);
138
139 base::string16 label = base::JoinString(values, base::ASCIIToUTF16("\n"));
140
141 std::unique_ptr<views::StyledLabel> styled_label =
142 base::MakeUnique<views::StyledLabel>(label, nullptr);
143
144 return styled_label;
please use gerrit instead 2017/01/18 18:50:47 nit: Avoid local variables that are used only once
tmartino 2017/01/18 20:39:13 Done to both
145 }
146
147 std::unique_ptr<views::View> GetContactInfoLabel(
148 AddressStyleType type,
149 std::string locale,
150 autofill::AutofillProfile* profile,
151 bool show_payer_name,
152 bool show_payer_email,
153 bool show_payer_phone) {
154 base::string16 name_value;
155 base::string16 phone_value;
156 base::string16 email_value;
157
158 if (show_payer_name) {
159 name_value =
160 profile->GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale);
161
162 // TODO(tmartino): Add bold styling for name in DETAILED style.
163 }
164
165 if (show_payer_phone) {
166 phone_value = profile->GetInfo(
167 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale);
168 }
169
170 if (show_payer_email) {
171 email_value = profile->GetInfo(
172 autofill::AutofillType(autofill::EMAIL_ADDRESS), locale);
173 }
174
175 std::vector<base::string16> values;
176 if (!name_value.empty())
177 values.push_back(name_value);
178 if (!phone_value.empty())
179 values.push_back(phone_value);
180 if (!email_value.empty())
181 values.push_back(email_value);
182
183 base::string16 label = base::JoinString(values, base::ASCIIToUTF16("\n"));
184
185 std::unique_ptr<views::StyledLabel> styled_label =
186 base::MakeUnique<views::StyledLabel>(label, nullptr);
187
188 return styled_label;
please use gerrit instead 2017/01/18 18:50:47 Ditto
189 }
190
90 } // namespace payments 191 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698