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

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

Issue 2855203002: [Payments] Display the shipping option error alongside the address (Closed)
Patch Set: added tests 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"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY); 59 fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY);
60 fields.push_back(autofill::ADDRESS_HOME_CITY); 60 fields.push_back(autofill::ADDRESS_HOME_CITY);
61 fields.push_back(autofill::ADDRESS_HOME_STATE); 61 fields.push_back(autofill::ADDRESS_HOME_STATE);
62 fields.push_back(autofill::ADDRESS_HOME_ZIP); 62 fields.push_back(autofill::ADDRESS_HOME_ZIP);
63 fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE); 63 fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE);
64 64
65 return profile.ConstructInferredLabel(fields, fields.size(), locale); 65 return profile.ConstructInferredLabel(fields, fields.size(), locale);
66 } 66 }
67 67
68 // |s1|, |s2|, and |s3| are lines identifying the profile. |s1| is the 68 // |s1|, |s2|, and |s3| are lines identifying the profile. |s1| is the
69 // "headline" which may be emphasized depending on |type|. |error| is a 69 // "headline" which may be emphasized depending on |type|. If |disabled_state|
70 // message indicating errors that need to be resolved before using this 70 // is true, the labels will look disabled.
71 // profile. 71 std::unique_ptr<views::View> GetBaseProfileLabel(AddressStyleType type,
72 std::unique_ptr<views::View> GetProfileLabel(AddressStyleType type, 72 const base::string16& s1,
73 const base::string16& s1, 73 const base::string16& s2,
74 const base::string16& s2, 74 const base::string16& s3,
75 const base::string16& s3, 75 bool disabled_state = false) {
76 const base::string16& error) {
77 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); 76 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
78 std::unique_ptr<views::BoxLayout> layout = 77 std::unique_ptr<views::BoxLayout> layout =
79 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); 78 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0);
80 layout->set_cross_axis_alignment( 79 layout->set_cross_axis_alignment(
81 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); 80 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
82 container->SetLayoutManager(layout.release()); 81 container->SetLayoutManager(layout.release());
83 82
84 if (!s1.empty()) { 83 if (!s1.empty()) {
85 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s1); 84 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s1);
86 if (type == AddressStyleType::DETAILED) { 85 if (type == AddressStyleType::DETAILED) {
87 const gfx::FontList& font_list = label->font_list(); 86 const gfx::FontList& font_list = label->font_list();
88 label->SetFontList(font_list.DeriveWithWeight(gfx::Font::Weight::BOLD)); 87 label->SetFontList(font_list.DeriveWithWeight(gfx::Font::Weight::BOLD));
89 } 88 }
90 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1)); 89 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1));
91 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 90 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
91 if (disabled_state) {
92 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
93 ui::NativeTheme::kColorId_LabelDisabledColor));
94 }
92 container->AddChildView(label.release()); 95 container->AddChildView(label.release());
93 } 96 }
94 97
95 if (!s2.empty()) { 98 if (!s2.empty()) {
96 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s2); 99 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s2);
97 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_2)); 100 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_2));
98 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 101 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
102 if (disabled_state) {
103 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
104 ui::NativeTheme::kColorId_LabelDisabledColor));
105 }
99 container->AddChildView(label.release()); 106 container->AddChildView(label.release());
100 } 107 }
101 108
102 if (!s3.empty()) { 109 if (!s3.empty()) {
103 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s3); 110 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s3);
104 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_3)); 111 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_3));
105 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 112 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
113 if (disabled_state) {
114 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
115 ui::NativeTheme::kColorId_LabelDisabledColor));
116 }
106 container->AddChildView(label.release()); 117 container->AddChildView(label.release());
107 } 118 }
108
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 }
117
118 return container; 119 return container;
119 } 120 }
120 121
122 // Returns a label representing the |profile| as a shipping address. See
123 // GetBaseProfileLabel() for more documentation.
124 std::unique_ptr<views::View> GetShippingAddressLabel(
125 AddressStyleType type,
126 const std::string& locale,
127 const autofill::AutofillProfile& profile,
128 bool disabled_state) {
129 base::string16 name =
130 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale);
131
132 base::string16 address = GetAddressFromProfile(profile, locale);
133
134 base::string16 phone = profile.GetInfo(
135 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale);
136
137 return GetBaseProfileLabel(type, name, address, phone, disabled_state);
138 }
139
121 // Paints the gray horizontal line that doesn't span the entire width of the 140 // Paints the gray horizontal line that doesn't span the entire width of the
122 // dialog at the bottom of the view it borders. 141 // dialog at the bottom of the view it borders.
123 class PaymentRequestRowBorderPainter : public views::Painter { 142 class PaymentRequestRowBorderPainter : public views::Painter {
124 public: 143 public:
125 PaymentRequestRowBorderPainter() {} 144 PaymentRequestRowBorderPainter() {}
126 ~PaymentRequestRowBorderPainter() override {} 145 ~PaymentRequestRowBorderPainter() override {}
127 146
128 // views::Painter: 147 // views::Painter:
129 gfx::Size GetMinimumSize() const override { 148 gfx::Size GetMinimumSize() const override {
130 return gfx::Size(2 * payments::kPaymentRequestRowHorizontalInsets, 1); 149 return gfx::Size(2 * payments::kPaymentRequestRowHorizontalInsets, 1);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 chrome_logo->set_can_process_events_within_subtree(false); 255 chrome_logo->set_can_process_events_within_subtree(false);
237 chrome_logo->SetImage(ResourceBundle::GetSharedInstance() 256 chrome_logo->SetImage(ResourceBundle::GetSharedInstance()
238 .GetImageNamed(IDR_PRODUCT_LOGO_NAME_22) 257 .GetImageNamed(IDR_PRODUCT_LOGO_NAME_22)
239 .AsImageSkia()); 258 .AsImageSkia());
240 chrome_logo->SetTooltipText(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); 259 chrome_logo->SetTooltipText(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
241 content_view->AddChildView(chrome_logo.release()); 260 content_view->AddChildView(chrome_logo.release());
242 261
243 return content_view; 262 return content_view;
244 } 263 }
245 264
246 std::unique_ptr<views::View> GetShippingAddressLabel( 265 std::unique_ptr<views::View> GetShippingAddressLabelWithError(
247 AddressStyleType type, 266 AddressStyleType type,
248 const std::string& locale, 267 const std::string& locale,
249 const autofill::AutofillProfile& profile, 268 const autofill::AutofillProfile& profile,
250 const PaymentOptionsProvider& options, 269 const std::string& error,
270 bool disabled_state) {
271 std::unique_ptr<views::View> base_label =
272 GetShippingAddressLabel(type, locale, profile, disabled_state);
273
274 if (!error.empty()) {
275 std::unique_ptr<views::Label> label =
276 base::MakeUnique<views::Label>(base::UTF8ToUTF16(error));
277 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR));
278 label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1));
279 // Error information is typically in red.
280 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
281 ui::NativeTheme::kColorId_AlertSeverityHigh));
282 base_label->AddChildView(label.release());
283 }
284 return base_label;
285 }
286
287 std::unique_ptr<views::View> GetShippingAddressLabelWithMissingInfo(
288 AddressStyleType type,
289 const std::string& locale,
290 const autofill::AutofillProfile& profile,
251 const PaymentsProfileComparator& comp) { 291 const PaymentsProfileComparator& comp) {
252 base::string16 name = 292 std::unique_ptr<views::View> base_label =
253 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); 293 GetShippingAddressLabel(type, locale, profile, /*disabled_state=*/false);
254 294
255 base::string16 address = GetAddressFromProfile(profile, locale); 295 base::string16 missing = comp.GetStringForMissingShippingFields(profile);
256 296 if (!missing.empty()) {
257 base::string16 phone = profile.GetInfo( 297 std::unique_ptr<views::Label> label =
258 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); 298 base::MakeUnique<views::Label>(missing);
259 299 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR));
260 base::string16 error = comp.GetStringForMissingShippingFields(profile); 300 label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1));
261 301 // Missing information typically has a nice shade of blue.
262 return GetProfileLabel(type, name, address, phone, error); 302 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
303 ui::NativeTheme::kColorId_LinkEnabled));
304 base_label->AddChildView(label.release());
305 }
306 return base_label;
263 } 307 }
264 308
265 // TODO(anthonyvd): unit test the label layout. 309 // TODO(anthonyvd): unit test the label layout.
266 std::unique_ptr<views::View> GetContactInfoLabel( 310 std::unique_ptr<views::View> GetContactInfoLabel(
267 AddressStyleType type, 311 AddressStyleType type,
268 const std::string& locale, 312 const std::string& locale,
269 const autofill::AutofillProfile& profile, 313 const autofill::AutofillProfile& profile,
270 const PaymentOptionsProvider& options, 314 const PaymentOptionsProvider& options,
271 const PaymentsProfileComparator& comp) { 315 const PaymentsProfileComparator& comp) {
272 base::string16 name = 316 base::string16 name =
273 options.request_payer_name() 317 options.request_payer_name()
274 ? profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale) 318 ? profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale)
275 : base::string16(); 319 : base::string16();
276 320
277 base::string16 phone = 321 base::string16 phone =
278 options.request_payer_phone() 322 options.request_payer_phone()
279 ? profile.GetInfo( 323 ? profile.GetInfo(
280 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), 324 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
281 locale) 325 locale)
282 : base::string16(); 326 : base::string16();
283 327
284 base::string16 email = 328 base::string16 email =
285 options.request_payer_email() 329 options.request_payer_email()
286 ? profile.GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS), 330 ? profile.GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS),
287 locale) 331 locale)
288 : base::string16(); 332 : base::string16();
289 333
290 base::string16 error = comp.GetStringForMissingContactFields(profile); 334 std::unique_ptr<views::View> base_label =
335 GetBaseProfileLabel(type, name, phone, email);
291 336
292 return GetProfileLabel(type, name, phone, email, error); 337 base::string16 missing = comp.GetStringForMissingContactFields(profile);
338 if (!missing.empty()) {
anthonyvd 2017/05/04 13:07:37 This entire block is the same as the one on line 2
Mathieu 2017/05/04 13:53:25 Done.
339 std::unique_ptr<views::Label> label =
340 base::MakeUnique<views::Label>(missing);
341 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR));
342 label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1));
343 // Missing information typically has a nice shade of blue.
344 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
345 ui::NativeTheme::kColorId_LinkEnabled));
346 base_label->AddChildView(label.release());
347 }
348 return base_label;
293 } 349 }
294 350
295 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() { 351 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() {
296 return views::CreateBorderPainter( 352 return views::CreateBorderPainter(
297 base::MakeUnique<PaymentRequestRowBorderPainter>(), 353 base::MakeUnique<PaymentRequestRowBorderPainter>(),
298 gfx::Insets()); 354 gfx::Insets());
299 } 355 }
300 356
301 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) { 357 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) {
302 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text); 358 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text);
(...skipping 29 matching lines...) Expand all
332 amount_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 388 amount_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
333 amount_label->set_id( 389 amount_label->set_id(
334 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT)); 390 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT));
335 container->AddChildView(amount_label.release()); 391 container->AddChildView(amount_label.release());
336 } 392 }
337 393
338 return container; 394 return container;
339 } 395 }
340 396
341 } // namespace payments 397 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698