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

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: ios namespace 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/profile_util.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 15 matching lines...) Expand all
55 fields.push_back(autofill::ADDRESS_HOME_LINE2); 57 fields.push_back(autofill::ADDRESS_HOME_LINE2);
56 fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY); 58 fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY);
57 fields.push_back(autofill::ADDRESS_HOME_CITY); 59 fields.push_back(autofill::ADDRESS_HOME_CITY);
58 fields.push_back(autofill::ADDRESS_HOME_STATE); 60 fields.push_back(autofill::ADDRESS_HOME_STATE);
59 fields.push_back(autofill::ADDRESS_HOME_ZIP); 61 fields.push_back(autofill::ADDRESS_HOME_ZIP);
60 fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE); 62 fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE);
61 63
62 return profile.ConstructInferredLabel(fields, fields.size(), locale); 64 return profile.ConstructInferredLabel(fields, fields.size(), locale);
63 } 65 }
64 66
65 std::unique_ptr<views::View> GetThreeLineLabel(AddressStyleType type, 67 // |s1|, |s2|, and |s3| are lines identifying the profile. |s1| is the
66 const base::string16& s1, 68 // "headline" which may be emphasized depending on |type|. |error| is a
67 const base::string16& s2, 69 // message indicating errors that need to be resolved before using this
68 const base::string16& s3) { 70 // profile.
71 std::unique_ptr<views::View> GetProfileLabel(AddressStyleType type,
72 const base::string16& s1,
73 const base::string16& s2,
74 const base::string16& s3,
75 const base::string16& error) {
69 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); 76 std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
70 std::unique_ptr<views::BoxLayout> layout = 77 std::unique_ptr<views::BoxLayout> layout =
71 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); 78 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0);
72 layout->set_cross_axis_alignment( 79 layout->set_cross_axis_alignment(
73 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); 80 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
74 container->SetLayoutManager(layout.release()); 81 container->SetLayoutManager(layout.release());
75 82
76 if (!s1.empty()) { 83 if (!s1.empty()) {
77 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s1); 84 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s1);
78 if (type == AddressStyleType::DETAILED) { 85 if (type == AddressStyleType::DETAILED) {
79 const gfx::FontList& font_list = label->font_list(); 86 const gfx::FontList& font_list = label->font_list();
80 label->SetFontList(font_list.DeriveWithWeight(gfx::Font::Weight::BOLD)); 87 label->SetFontList(font_list.DeriveWithWeight(gfx::Font::Weight::BOLD));
81 } 88 }
82 label->set_id(static_cast<int>(DialogViewID::THREE_LINE_LABEL_LINE_1)); 89 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1));
83 container->AddChildView(label.release()); 90 container->AddChildView(label.release());
84 } 91 }
85 92
86 if (!s2.empty()) { 93 if (!s2.empty()) {
87 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s2); 94 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s2);
88 label->set_id(static_cast<int>(DialogViewID::THREE_LINE_LABEL_LINE_2)); 95 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_2));
89 container->AddChildView(label.release()); 96 container->AddChildView(label.release());
90 } 97 }
91 98
92 if (!s3.empty()) { 99 if (!s3.empty()) {
93 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s3); 100 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s3);
94 label->set_id(static_cast<int>(DialogViewID::THREE_LINE_LABEL_LINE_3)); 101 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_3));
95 container->AddChildView(label.release()); 102 container->AddChildView(label.release());
96 } 103 }
97 104
98 // TODO(anthonyvd): add the error label 105 if (!error.empty()) {
106 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(error);
107 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR));
108 label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1));
109 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor(
110 ui::NativeTheme::kColorId_LinkEnabled));
111 container->AddChildView(label.release());
112 }
99 113
100 return container; 114 return container;
101 } 115 }
102 116
103 // Paints the gray horizontal line that doesn't span the entire width of the 117 // Paints the gray horizontal line that doesn't span the entire width of the
104 // dialog at the bottom of the view it borders. 118 // dialog at the bottom of the view it borders.
105 class PaymentRequestRowBorderPainter : public views::Painter { 119 class PaymentRequestRowBorderPainter : public views::Painter {
106 public: 120 public:
107 PaymentRequestRowBorderPainter() {} 121 PaymentRequestRowBorderPainter() {}
108 ~PaymentRequestRowBorderPainter() override {} 122 ~PaymentRequestRowBorderPainter() override {}
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 .AsImageSkia()); 227 .AsImageSkia());
214 chrome_logo->SetTooltipText(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); 228 chrome_logo->SetTooltipText(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
215 content_view->AddChildView(chrome_logo.release()); 229 content_view->AddChildView(chrome_logo.release());
216 230
217 return content_view; 231 return content_view;
218 } 232 }
219 233
220 std::unique_ptr<views::View> GetShippingAddressLabel( 234 std::unique_ptr<views::View> GetShippingAddressLabel(
221 AddressStyleType type, 235 AddressStyleType type,
222 const std::string& locale, 236 const std::string& locale,
223 const autofill::AutofillProfile& profile) { 237 const autofill::AutofillProfile& profile,
238 const PaymentOptionsProvider& options,
239 const PaymentsProfileComparator& comp) {
224 base::string16 name = 240 base::string16 name =
225 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); 241 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale);
226 242
227 base::string16 address = GetAddressFromProfile(profile, locale); 243 base::string16 address = GetAddressFromProfile(profile, locale);
228 244
229 base::string16 phone = profile.GetInfo( 245 base::string16 phone = profile.GetInfo(
230 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); 246 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale);
231 247
232 return GetThreeLineLabel(type, name, address, phone); 248 base::string16 error = comp.GetStringForMissingShippingFields(profile);
249
250 return GetProfileLabel(type, name, address, phone, error);
233 } 251 }
234 252
235 // TODO(anthonyvd): unit test the label layout. 253 // TODO(anthonyvd): unit test the label layout.
236 std::unique_ptr<views::View> GetContactInfoLabel( 254 std::unique_ptr<views::View> GetContactInfoLabel(
237 AddressStyleType type, 255 AddressStyleType type,
238 const std::string& locale, 256 const std::string& locale,
239 const autofill::AutofillProfile& profile, 257 const autofill::AutofillProfile& profile,
240 const PaymentOptionsProvider& options) { 258 const PaymentOptionsProvider& options,
259 const PaymentsProfileComparator& comp) {
241 base::string16 name = 260 base::string16 name =
242 options.request_payer_name() 261 options.request_payer_name()
243 ? profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale) 262 ? profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale)
244 : base::string16(); 263 : base::string16();
245 264
246 base::string16 phone = 265 base::string16 phone =
247 options.request_payer_phone() 266 options.request_payer_phone()
248 ? profile.GetInfo( 267 ? profile.GetInfo(
249 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), 268 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
250 locale) 269 locale)
251 : base::string16(); 270 : base::string16();
252 271
253 base::string16 email = 272 base::string16 email =
254 options.request_payer_email() 273 options.request_payer_email()
255 ? profile.GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS), 274 ? profile.GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS),
256 locale) 275 locale)
257 : base::string16(); 276 : base::string16();
258 277
259 return GetThreeLineLabel(type, name, phone, email); 278 base::string16 error = comp.GetStringForMissingContactFields(profile);
279
280 return GetProfileLabel(type, name, phone, email, error);
260 } 281 }
261 282
262 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() { 283 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() {
263 return views::CreateBorderPainter( 284 return views::CreateBorderPainter(
264 base::MakeUnique<PaymentRequestRowBorderPainter>(), 285 base::MakeUnique<PaymentRequestRowBorderPainter>(),
265 gfx::Insets()); 286 gfx::Insets());
266 } 287 }
267 288
268 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) { 289 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) {
269 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text); 290 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text);
(...skipping 27 matching lines...) Expand all
297 base::MakeUnique<views::Label>(formatted_amount); 318 base::MakeUnique<views::Label>(formatted_amount);
298 amount_label->set_id( 319 amount_label->set_id(
299 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT)); 320 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT));
300 container->AddChildView(amount_label.release()); 321 container->AddChildView(amount_label.release());
301 } 322 }
302 323
303 return container; 324 return container;
304 } 325 }
305 326
306 } // namespace payments 327 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698