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

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: android 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"
(...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
140 std::unique_ptr<views::Label> GetLabelForMissingInformation(
141 const base::string16& missing_info) {
142 std::unique_ptr<views::Label> label =
143 base::MakeUnique<views::Label>(missing_info);
144 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR));
145 label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1));
146 // Missing information typically has a nice shade of blue.
147 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
148 ui::NativeTheme::kColorId_LinkEnabled));
149 return label;
150 }
151
121 // Paints the gray horizontal line that doesn't span the entire width of the 152 // Paints the gray horizontal line that doesn't span the entire width of the
122 // dialog at the bottom of the view it borders. 153 // dialog at the bottom of the view it borders.
123 class PaymentRequestRowBorderPainter : public views::Painter { 154 class PaymentRequestRowBorderPainter : public views::Painter {
124 public: 155 public:
125 PaymentRequestRowBorderPainter() {} 156 PaymentRequestRowBorderPainter() {}
126 ~PaymentRequestRowBorderPainter() override {} 157 ~PaymentRequestRowBorderPainter() override {}
127 158
128 // views::Painter: 159 // views::Painter:
129 gfx::Size GetMinimumSize() const override { 160 gfx::Size GetMinimumSize() const override {
130 return gfx::Size(2 * payments::kPaymentRequestRowHorizontalInsets, 1); 161 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); 267 chrome_logo->set_can_process_events_within_subtree(false);
237 chrome_logo->SetImage(ResourceBundle::GetSharedInstance() 268 chrome_logo->SetImage(ResourceBundle::GetSharedInstance()
238 .GetImageNamed(IDR_PRODUCT_LOGO_NAME_22) 269 .GetImageNamed(IDR_PRODUCT_LOGO_NAME_22)
239 .AsImageSkia()); 270 .AsImageSkia());
240 chrome_logo->SetTooltipText(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); 271 chrome_logo->SetTooltipText(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
241 content_view->AddChildView(chrome_logo.release()); 272 content_view->AddChildView(chrome_logo.release());
242 273
243 return content_view; 274 return content_view;
244 } 275 }
245 276
246 std::unique_ptr<views::View> GetShippingAddressLabel( 277 std::unique_ptr<views::View> GetShippingAddressLabelWithError(
247 AddressStyleType type, 278 AddressStyleType type,
248 const std::string& locale, 279 const std::string& locale,
249 const autofill::AutofillProfile& profile, 280 const autofill::AutofillProfile& profile,
250 const PaymentOptionsProvider& options, 281 const base::string16& error,
282 bool disabled_state) {
283 std::unique_ptr<views::View> base_label =
284 GetShippingAddressLabel(type, locale, profile, disabled_state);
285
286 if (!error.empty()) {
287 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(error);
288 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR));
289 label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1));
290 // Error information is typically in red.
291 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
292 ui::NativeTheme::kColorId_AlertSeverityHigh));
293 base_label->AddChildView(label.release());
294 }
295 return base_label;
296 }
297
298 std::unique_ptr<views::View> GetShippingAddressLabelWithMissingInfo(
299 AddressStyleType type,
300 const std::string& locale,
301 const autofill::AutofillProfile& profile,
251 const PaymentsProfileComparator& comp) { 302 const PaymentsProfileComparator& comp) {
252 base::string16 name = 303 std::unique_ptr<views::View> base_label =
253 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); 304 GetShippingAddressLabel(type, locale, profile, /*disabled_state=*/false);
254 305
255 base::string16 address = GetAddressFromProfile(profile, locale); 306 base_label->AddChildView(GetLabelForMissingInformation(
256 307 comp.GetStringForMissingShippingFields(profile))
257 base::string16 phone = profile.GetInfo( 308 .release());
258 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); 309 return base_label;
259
260 base::string16 error = comp.GetStringForMissingShippingFields(profile);
261
262 return GetProfileLabel(type, name, address, phone, error);
263 } 310 }
264 311
265 // TODO(anthonyvd): unit test the label layout. 312 // TODO(anthonyvd): unit test the label layout.
266 std::unique_ptr<views::View> GetContactInfoLabel( 313 std::unique_ptr<views::View> GetContactInfoLabel(
267 AddressStyleType type, 314 AddressStyleType type,
268 const std::string& locale, 315 const std::string& locale,
269 const autofill::AutofillProfile& profile, 316 const autofill::AutofillProfile& profile,
270 const PaymentOptionsProvider& options, 317 const PaymentOptionsProvider& options,
271 const PaymentsProfileComparator& comp) { 318 const PaymentsProfileComparator& comp) {
272 base::string16 name = 319 base::string16 name =
273 options.request_payer_name() 320 options.request_payer_name()
274 ? profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale) 321 ? profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale)
275 : base::string16(); 322 : base::string16();
276 323
277 base::string16 phone = 324 base::string16 phone =
278 options.request_payer_phone() 325 options.request_payer_phone()
279 ? profile.GetInfo( 326 ? profile.GetInfo(
280 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), 327 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
281 locale) 328 locale)
282 : base::string16(); 329 : base::string16();
283 330
284 base::string16 email = 331 base::string16 email =
285 options.request_payer_email() 332 options.request_payer_email()
286 ? profile.GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS), 333 ? profile.GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS),
287 locale) 334 locale)
288 : base::string16(); 335 : base::string16();
289 336
290 base::string16 error = comp.GetStringForMissingContactFields(profile); 337 std::unique_ptr<views::View> base_label =
338 GetBaseProfileLabel(type, name, phone, email);
291 339
292 return GetProfileLabel(type, name, phone, email, error); 340 base_label->AddChildView(GetLabelForMissingInformation(
341 comp.GetStringForMissingContactFields(profile))
342 .release());
343 return base_label;
293 } 344 }
294 345
295 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() { 346 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() {
296 return views::CreateBorderPainter( 347 return views::CreateBorderPainter(
297 base::MakeUnique<PaymentRequestRowBorderPainter>(), 348 base::MakeUnique<PaymentRequestRowBorderPainter>(),
298 gfx::Insets()); 349 gfx::Insets());
299 } 350 }
300 351
301 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) { 352 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) {
302 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text); 353 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text);
(...skipping 29 matching lines...) Expand all
332 amount_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 383 amount_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
333 amount_label->set_id( 384 amount_label->set_id(
334 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT)); 385 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT));
335 container->AddChildView(amount_label.release()); 386 container->AddChildView(amount_label.release());
336 } 387 }
337 388
338 return container; 389 return container;
339 } 390 }
340 391
341 } // namespace payments 392 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698