Chromium Code Reviews| Index: chrome/browser/ui/views/payments/payment_request_views_util.cc |
| diff --git a/chrome/browser/ui/views/payments/payment_request_views_util.cc b/chrome/browser/ui/views/payments/payment_request_views_util.cc |
| index 6192515c801ea311145bb98e2eefdb74ce41f6ab..5d91acfd880d744de776711a1396259163e95999 100644 |
| --- a/chrome/browser/ui/views/payments/payment_request_views_util.cc |
| +++ b/chrome/browser/ui/views/payments/payment_request_views_util.cc |
| @@ -4,18 +4,45 @@ |
| #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| +#include <vector> |
| + |
| #include "base/memory/ptr_util.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "chrome/app/vector_icons/vector_icons.h" |
| #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" |
| +#include "components/autofill/core/browser/autofill_type.h" |
| +#include "components/autofill/core/browser/field_types.h" |
| #include "third_party/skia/include/core/SkColor.h" |
| #include "ui/views/background.h" |
| #include "ui/views/bubble/bubble_frame_view.h" |
| #include "ui/views/controls/button/button.h" |
| #include "ui/views/controls/button/vector_icon_button.h" |
| #include "ui/views/controls/label.h" |
| +#include "ui/views/controls/styled_label.h" |
| #include "ui/views/layout/grid_layout.h" |
| #include "ui/views/view.h" |
| +namespace { |
| + |
| +// TODO(tmartino): Consider combining this with the Android equivalent in |
| +// PersonalDataManager.java |
| +base::string16 GetAddressFromProfile(autofill::AutofillProfile* profile, |
|
please use gerrit instead
2017/01/18 18:50:47
const-ref parameter
|
| + std::string locale) { |
|
please use gerrit instead
2017/01/18 18:50:47
const-ref
|
| + std::vector<autofill::ServerFieldType> fields; |
| + fields.push_back(autofill::COMPANY_NAME); |
| + fields.push_back(autofill::ADDRESS_HOME_LINE1); |
| + fields.push_back(autofill::ADDRESS_HOME_LINE2); |
| + fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY); |
| + fields.push_back(autofill::ADDRESS_HOME_CITY); |
| + fields.push_back(autofill::ADDRESS_HOME_STATE); |
| + fields.push_back(autofill::ADDRESS_HOME_ZIP); |
| + fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE); |
| + |
| + return profile->ConstructInferredLabel(fields, fields.size(), locale); |
| +} |
| + |
| +} // namespace |
| + |
| namespace payments { |
| std::unique_ptr<views::View> CreateSheetHeaderView( |
| @@ -87,4 +114,78 @@ std::unique_ptr<views::View> CreatePaymentView( |
| return view; |
| } |
| +std::unique_ptr<views::View> GetShippingAddressLabel( |
| + AddressStyleType type, |
| + std::string locale, |
| + autofill::AutofillProfile* profile) { |
| + base::string16 name_value = |
| + profile->GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); |
| + |
| + // TODO(tmartino): Add bold styling for name in DETAILED style. |
| + |
| + base::string16 address_value = GetAddressFromProfile(profile, locale); |
| + |
| + base::string16 phone_value = profile->GetInfo( |
| + autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); |
| + |
| + std::vector<base::string16> values; |
| + if (!name_value.empty()) |
| + values.push_back(name_value); |
| + if (!address_value.empty()) |
| + values.push_back(address_value); |
| + if (!phone_value.empty()) |
| + values.push_back(phone_value); |
| + |
| + base::string16 label = base::JoinString(values, base::ASCIIToUTF16("\n")); |
| + |
| + std::unique_ptr<views::StyledLabel> styled_label = |
| + base::MakeUnique<views::StyledLabel>(label, nullptr); |
| + |
| + return styled_label; |
|
please use gerrit instead
2017/01/18 18:50:47
nit: Avoid local variables that are used only once
tmartino
2017/01/18 20:39:13
Done to both
|
| +} |
| + |
| +std::unique_ptr<views::View> GetContactInfoLabel( |
| + AddressStyleType type, |
| + std::string locale, |
| + autofill::AutofillProfile* profile, |
| + bool show_payer_name, |
| + bool show_payer_email, |
| + bool show_payer_phone) { |
| + base::string16 name_value; |
| + base::string16 phone_value; |
| + base::string16 email_value; |
| + |
| + if (show_payer_name) { |
| + name_value = |
| + profile->GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); |
| + |
| + // TODO(tmartino): Add bold styling for name in DETAILED style. |
| + } |
| + |
| + if (show_payer_phone) { |
| + phone_value = profile->GetInfo( |
| + autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); |
| + } |
| + |
| + if (show_payer_email) { |
| + email_value = profile->GetInfo( |
| + autofill::AutofillType(autofill::EMAIL_ADDRESS), locale); |
| + } |
| + |
| + std::vector<base::string16> values; |
| + if (!name_value.empty()) |
| + values.push_back(name_value); |
| + if (!phone_value.empty()) |
| + values.push_back(phone_value); |
| + if (!email_value.empty()) |
| + values.push_back(email_value); |
| + |
| + base::string16 label = base::JoinString(values, base::ASCIIToUTF16("\n")); |
| + |
| + std::unique_ptr<views::StyledLabel> styled_label = |
| + base::MakeUnique<views::StyledLabel>(label, nullptr); |
| + |
| + return styled_label; |
|
please use gerrit instead
2017/01/18 18:50:47
Ditto
|
| +} |
| + |
| } // namespace payments |