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

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

Issue 2725623004: [Web Payments] Add the contact info screen. (Closed)
Patch Set: Address comments. 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
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> 7 #include <vector>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #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_data_util.h" 13 #include "components/autofill/core/browser/autofill_data_util.h"
14 #include "components/autofill/core/browser/autofill_profile.h" 14 #include "components/autofill/core/browser/autofill_profile.h"
15 #include "components/autofill/core/browser/autofill_type.h" 15 #include "components/autofill/core/browser/autofill_type.h"
16 #include "components/autofill/core/browser/credit_card.h" 16 #include "components/autofill/core/browser/credit_card.h"
17 #include "components/autofill/core/browser/field_types.h" 17 #include "components/autofill/core/browser/field_types.h"
18 #include "third_party/skia/include/core/SkColor.h" 18 #include "third_party/skia/include/core/SkColor.h"
19 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/font_list.h"
21 #include "ui/gfx/geometry/insets.h" 22 #include "ui/gfx/geometry/insets.h"
22 #include "ui/gfx/geometry/point_f.h" 23 #include "ui/gfx/geometry/point_f.h"
23 #include "ui/gfx/paint_vector_icon.h" 24 #include "ui/gfx/paint_vector_icon.h"
24 #include "ui/vector_icons/vector_icons.h" 25 #include "ui/vector_icons/vector_icons.h"
25 #include "ui/views/border.h" 26 #include "ui/views/border.h"
26 #include "ui/views/bubble/bubble_frame_view.h" 27 #include "ui/views/bubble/bubble_frame_view.h"
27 #include "ui/views/controls/button/button.h" 28 #include "ui/views/controls/button/button.h"
28 #include "ui/views/controls/button/vector_icon_button.h" 29 #include "ui/views/controls/button/vector_icon_button.h"
29 #include "ui/views/controls/image_view.h" 30 #include "ui/views/controls/image_view.h"
30 #include "ui/views/controls/label.h" 31 #include "ui/views/controls/label.h"
31 #include "ui/views/controls/styled_label.h" 32 #include "ui/views/controls/styled_label.h"
33 #include "ui/views/layout/box_layout.h"
32 #include "ui/views/layout/grid_layout.h" 34 #include "ui/views/layout/grid_layout.h"
33 #include "ui/views/painter.h" 35 #include "ui/views/painter.h"
34 #include "ui/views/view.h" 36 #include "ui/views/view.h"
35 37
36 namespace { 38 namespace {
37 39
38 // TODO(tmartino): Consider combining this with the Android equivalent in 40 // TODO(tmartino): Consider combining this with the Android equivalent in
39 // PersonalDataManager.java 41 // PersonalDataManager.java
40 base::string16 GetAddressFromProfile(const autofill::AutofillProfile& profile, 42 base::string16 GetAddressFromProfile(const autofill::AutofillProfile& profile,
41 const std::string& locale) { 43 const std::string& locale) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 values.push_back(name_value); 170 values.push_back(name_value);
169 if (!address_value.empty()) 171 if (!address_value.empty())
170 values.push_back(address_value); 172 values.push_back(address_value);
171 if (!phone_value.empty()) 173 if (!phone_value.empty())
172 values.push_back(phone_value); 174 values.push_back(phone_value);
173 175
174 return base::MakeUnique<views::StyledLabel>( 176 return base::MakeUnique<views::StyledLabel>(
175 base::JoinString(values, base::ASCIIToUTF16("\n")), nullptr); 177 base::JoinString(values, base::ASCIIToUTF16("\n")), nullptr);
176 } 178 }
177 179
180 // TODO(anthonyvd): unit test the label layout.
178 std::unique_ptr<views::View> GetContactInfoLabel( 181 std::unique_ptr<views::View> GetContactInfoLabel(
179 AddressStyleType type, 182 AddressStyleType type,
180 const std::string& locale, 183 const std::string& locale,
181 const autofill::AutofillProfile& profile, 184 const autofill::AutofillProfile& profile,
182 bool show_payer_name, 185 bool show_payer_name,
183 bool show_payer_email, 186 bool show_payer_email,
184 bool show_payer_phone) { 187 bool show_payer_phone) {
185 base::string16 name_value; 188 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
186 base::string16 phone_value; 189 std::unique_ptr<views::BoxLayout> layout =
187 base::string16 email_value; 190 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0);
191 layout->set_cross_axis_alignment(
192 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
193 container->SetLayoutManager(layout.release());
188 194
189 if (show_payer_name) { 195 if (show_payer_name) {
190 name_value = 196 base::string16 name =
191 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); 197 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale);
192 198 if (!name.empty()) {
193 // TODO(tmartino): Add bold styling for name in DETAILED style. 199 std::unique_ptr<views::Label> label =
200 base::MakeUnique<views::Label>(name);
201 if (type == AddressStyleType::DETAILED) {
202 const gfx::FontList& font_list = label->font_list();
203 label->SetFontList(font_list.DeriveWithWeight(gfx::Font::Weight::BOLD));
204 }
205 container->AddChildView(label.release());
206 }
194 } 207 }
195 208
196 if (show_payer_phone) { 209 if (show_payer_phone) {
197 phone_value = profile.GetInfo( 210 base::string16 phone = profile.GetInfo(
198 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); 211 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale);
212 if (!phone.empty()) {
213 std::unique_ptr<views::Label> label =
214 base::MakeUnique<views::Label>(phone);
215 container->AddChildView(label.release());
216 }
199 } 217 }
200 218
201 if (show_payer_email) { 219 if (show_payer_email) {
202 email_value = profile.GetInfo( 220 base::string16 email = profile.GetInfo(
203 autofill::AutofillType(autofill::EMAIL_ADDRESS), locale); 221 autofill::AutofillType(autofill::EMAIL_ADDRESS), locale);
222 if (!email.empty()) {
223 std::unique_ptr<views::Label> label =
224 base::MakeUnique<views::Label>(email);
225 container->AddChildView(label.release());
226 }
204 } 227 }
205 228
206 std::vector<base::string16> values; 229 // TODO(anthonyvd): add the error label
207 if (!name_value.empty())
208 values.push_back(name_value);
209 if (!phone_value.empty())
210 values.push_back(phone_value);
211 if (!email_value.empty())
212 values.push_back(email_value);
213 230
214 return base::MakeUnique<views::StyledLabel>( 231 return container;
215 base::JoinString(values, base::ASCIIToUTF16("\n")), nullptr);
216 } 232 }
217 233
218 // Creates a views::Border object that can paint the gray horizontal ruler used 234 // Creates a views::Border object that can paint the gray horizontal ruler used
219 // as a separator between items in the Payment Request dialog. 235 // as a separator between items in the Payment Request dialog.
220 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() { 236 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() {
221 return views::CreateBorderPainter( 237 return views::CreateBorderPainter(
222 base::MakeUnique<PaymentRequestRowBorderPainter>(), 238 base::MakeUnique<PaymentRequestRowBorderPainter>(),
223 gfx::Insets()); 239 gfx::Insets());
224 } 240 }
225 241
226 } // namespace payments 242 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698