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

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

Issue 2847503002: [WebPayments] Show labels on incomplete profiles (Closed)
Patch Set: test fix Created 3 years, 7 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_dialog_view_ids.h" 12 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
13 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" 13 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h"
14 #include "chrome/grit/chromium_strings.h" 14 #include "chrome/grit/chromium_strings.h"
15 #include "chrome/grit/theme_resources.h" 15 #include "chrome/grit/theme_resources.h"
16 #include "components/autofill/core/browser/autofill_data_util.h" 16 #include "components/autofill/core/browser/autofill_data_util.h"
17 #include "components/autofill/core/browser/autofill_profile.h" 17 #include "components/autofill/core/browser/autofill_profile.h"
18 #include "components/autofill/core/browser/autofill_type.h" 18 #include "components/autofill/core/browser/autofill_type.h"
19 #include "components/autofill/core/browser/credit_card.h" 19 #include "components/autofill/core/browser/credit_card.h"
20 #include "components/autofill/core/browser/field_types.h" 20 #include "components/autofill/core/browser/field_types.h"
21 #include "components/payments/core/payment_options_provider.h" 21 #include "components/payments/core/payment_options_provider.h"
22 #include "components/payments/core/payments_profile_comparator.h"
22 #include "third_party/skia/include/core/SkColor.h" 23 #include "third_party/skia/include/core/SkColor.h"
23 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/canvas.h" 26 #include "ui/gfx/canvas.h"
26 #include "ui/gfx/font_list.h" 27 #include "ui/gfx/font_list.h"
27 #include "ui/gfx/geometry/insets.h" 28 #include "ui/gfx/geometry/insets.h"
28 #include "ui/gfx/geometry/point_f.h" 29 #include "ui/gfx/geometry/point_f.h"
29 #include "ui/gfx/paint_vector_icon.h" 30 #include "ui/gfx/paint_vector_icon.h"
31 #include "ui/native_theme/native_theme.h"
30 #include "ui/vector_icons/vector_icons.h" 32 #include "ui/vector_icons/vector_icons.h"
31 #include "ui/views/border.h" 33 #include "ui/views/border.h"
32 #include "ui/views/bubble/bubble_frame_view.h" 34 #include "ui/views/bubble/bubble_frame_view.h"
33 #include "ui/views/controls/button/button.h" 35 #include "ui/views/controls/button/button.h"
34 #include "ui/views/controls/button/image_button.h" 36 #include "ui/views/controls/button/image_button.h"
35 #include "ui/views/controls/button/image_button_factory.h" 37 #include "ui/views/controls/button/image_button_factory.h"
36 #include "ui/views/controls/image_view.h" 38 #include "ui/views/controls/image_view.h"
37 #include "ui/views/controls/label.h" 39 #include "ui/views/controls/label.h"
38 #include "ui/views/controls/styled_label.h" 40 #include "ui/views/controls/styled_label.h"
39 #include "ui/views/layout/box_layout.h" 41 #include "ui/views/layout/box_layout.h"
(...skipping 16 matching lines...) Expand all
56 fields.push_back(autofill::ADDRESS_HOME_LINE2); 58 fields.push_back(autofill::ADDRESS_HOME_LINE2);
57 fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY); 59 fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY);
58 fields.push_back(autofill::ADDRESS_HOME_CITY); 60 fields.push_back(autofill::ADDRESS_HOME_CITY);
59 fields.push_back(autofill::ADDRESS_HOME_STATE); 61 fields.push_back(autofill::ADDRESS_HOME_STATE);
60 fields.push_back(autofill::ADDRESS_HOME_ZIP); 62 fields.push_back(autofill::ADDRESS_HOME_ZIP);
61 fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE); 63 fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE);
62 64
63 return profile.ConstructInferredLabel(fields, fields.size(), locale); 65 return profile.ConstructInferredLabel(fields, fields.size(), locale);
64 } 66 }
65 67
66 std::unique_ptr<views::View> GetThreeLineLabel(AddressStyleType type, 68 // |s1|, |s2|, and |s3| are lines identifying the profile. |s1| is the
67 const base::string16& s1, 69 // "headline" which may be emphasized depending on |type|. |error| is a
68 const base::string16& s2, 70 // message indicating errors that need to be resolved before using this
69 const base::string16& s3) { 71 // profile.
72 std::unique_ptr<views::View> GetProfileLabel(AddressStyleType type,
73 const base::string16& s1,
74 const base::string16& s2,
75 const base::string16& s3,
76 const base::string16& error) {
70 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); 77 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
71 std::unique_ptr<views::BoxLayout> layout = 78 std::unique_ptr<views::BoxLayout> layout =
72 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); 79 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0);
73 layout->set_cross_axis_alignment( 80 layout->set_cross_axis_alignment(
74 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); 81 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
75 container->SetLayoutManager(layout.release()); 82 container->SetLayoutManager(layout.release());
76 83
77 if (!s1.empty()) { 84 if (!s1.empty()) {
78 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s1); 85 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s1);
79 if (type == AddressStyleType::DETAILED) { 86 if (type == AddressStyleType::DETAILED) {
80 const gfx::FontList& font_list = label->font_list(); 87 const gfx::FontList& font_list = label->font_list();
81 label->SetFontList(font_list.DeriveWithWeight(gfx::Font::Weight::BOLD)); 88 label->SetFontList(font_list.DeriveWithWeight(gfx::Font::Weight::BOLD));
82 } 89 }
83 label->set_id(static_cast<int>(DialogViewID::THREE_LINE_LABEL_LINE_1)); 90 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1));
84 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 91 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
85 container->AddChildView(label.release()); 92 container->AddChildView(label.release());
86 } 93 }
87 94
88 if (!s2.empty()) { 95 if (!s2.empty()) {
89 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s2); 96 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s2);
90 label->set_id(static_cast<int>(DialogViewID::THREE_LINE_LABEL_LINE_2)); 97 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_2));
91 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 98 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
92 container->AddChildView(label.release()); 99 container->AddChildView(label.release());
93 } 100 }
94 101
95 if (!s3.empty()) { 102 if (!s3.empty()) {
96 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s3); 103 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s3);
97 label->set_id(static_cast<int>(DialogViewID::THREE_LINE_LABEL_LINE_3)); 104 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_3));
98 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 105 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
99 container->AddChildView(label.release()); 106 container->AddChildView(label.release());
100 } 107 }
101 108
102 // TODO(anthonyvd): add the error label 109 if (!error.empty()) {
110 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(error);
111 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR));
112 label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1));
113 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
114 ui::NativeTheme::kColorId_LinkEnabled));
115 container->AddChildView(label.release());
116 }
103 117
104 return container; 118 return container;
105 } 119 }
106 120
107 // Paints the gray horizontal line that doesn't span the entire width of the 121 // Paints the gray horizontal line that doesn't span the entire width of the
108 // dialog at the bottom of the view it borders. 122 // dialog at the bottom of the view it borders.
109 class PaymentRequestRowBorderPainter : public views::Painter { 123 class PaymentRequestRowBorderPainter : public views::Painter {
110 public: 124 public:
111 PaymentRequestRowBorderPainter() {} 125 PaymentRequestRowBorderPainter() {}
112 ~PaymentRequestRowBorderPainter() override {} 126 ~PaymentRequestRowBorderPainter() override {}
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 .AsImageSkia()); 238 .AsImageSkia());
225 chrome_logo->SetTooltipText(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); 239 chrome_logo->SetTooltipText(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
226 content_view->AddChildView(chrome_logo.release()); 240 content_view->AddChildView(chrome_logo.release());
227 241
228 return content_view; 242 return content_view;
229 } 243 }
230 244
231 std::unique_ptr<views::View> GetShippingAddressLabel( 245 std::unique_ptr<views::View> GetShippingAddressLabel(
232 AddressStyleType type, 246 AddressStyleType type,
233 const std::string& locale, 247 const std::string& locale,
234 const autofill::AutofillProfile& profile) { 248 const autofill::AutofillProfile& profile,
249 const PaymentOptionsProvider& options,
250 const PaymentsProfileComparator& comp) {
235 base::string16 name = 251 base::string16 name =
236 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); 252 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale);
237 253
238 base::string16 address = GetAddressFromProfile(profile, locale); 254 base::string16 address = GetAddressFromProfile(profile, locale);
239 255
240 base::string16 phone = profile.GetInfo( 256 base::string16 phone = profile.GetInfo(
241 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); 257 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale);
242 258
243 return GetThreeLineLabel(type, name, address, phone); 259 base::string16 error = comp.GetStringForMissingShippingFields(profile);
260
261 return GetProfileLabel(type, name, address, phone, error);
244 } 262 }
245 263
246 // TODO(anthonyvd): unit test the label layout. 264 // TODO(anthonyvd): unit test the label layout.
247 std::unique_ptr<views::View> GetContactInfoLabel( 265 std::unique_ptr<views::View> GetContactInfoLabel(
248 AddressStyleType type, 266 AddressStyleType type,
249 const std::string& locale, 267 const std::string& locale,
250 const autofill::AutofillProfile& profile, 268 const autofill::AutofillProfile& profile,
251 const PaymentOptionsProvider& options) { 269 const PaymentOptionsProvider& options,
270 const PaymentsProfileComparator& comp) {
252 base::string16 name = 271 base::string16 name =
253 options.request_payer_name() 272 options.request_payer_name()
254 ? profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale) 273 ? profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale)
255 : base::string16(); 274 : base::string16();
256 275
257 base::string16 phone = 276 base::string16 phone =
258 options.request_payer_phone() 277 options.request_payer_phone()
259 ? profile.GetInfo( 278 ? profile.GetInfo(
260 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), 279 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
261 locale) 280 locale)
262 : base::string16(); 281 : base::string16();
263 282
264 base::string16 email = 283 base::string16 email =
265 options.request_payer_email() 284 options.request_payer_email()
266 ? profile.GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS), 285 ? profile.GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS),
267 locale) 286 locale)
268 : base::string16(); 287 : base::string16();
269 288
270 return GetThreeLineLabel(type, name, phone, email); 289 base::string16 error = comp.GetStringForMissingContactFields(profile);
290
291 return GetProfileLabel(type, name, phone, email, error);
271 } 292 }
272 293
273 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() { 294 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() {
274 return views::CreateBorderPainter( 295 return views::CreateBorderPainter(
275 base::MakeUnique<PaymentRequestRowBorderPainter>(), 296 base::MakeUnique<PaymentRequestRowBorderPainter>(),
276 gfx::Insets()); 297 gfx::Insets());
277 } 298 }
278 299
279 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) { 300 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) {
280 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text); 301 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text);
(...skipping 29 matching lines...) Expand all
310 amount_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 331 amount_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
311 amount_label->set_id( 332 amount_label->set_id(
312 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT)); 333 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT));
313 container->AddChildView(amount_label.release()); 334 container->AddChildView(amount_label.release());
314 } 335 }
315 336
316 return container; 337 return container;
317 } 338 }
318 339
319 } // namespace payments 340 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698