Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> | |
| 8 | |
| 7 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "chrome/app/vector_icons/vector_icons.h" | 11 #include "chrome/app/vector_icons/vector_icons.h" |
| 9 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" | 12 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" |
| 13 #include "components/autofill/core/browser/autofill_profile.h" | |
| 14 #include "components/autofill/core/browser/autofill_type.h" | |
| 15 #include "components/autofill/core/browser/field_types.h" | |
| 10 #include "third_party/skia/include/core/SkColor.h" | 16 #include "third_party/skia/include/core/SkColor.h" |
| 11 #include "ui/views/background.h" | 17 #include "ui/views/background.h" |
| 12 #include "ui/views/bubble/bubble_frame_view.h" | 18 #include "ui/views/bubble/bubble_frame_view.h" |
| 13 #include "ui/views/controls/button/button.h" | 19 #include "ui/views/controls/button/button.h" |
| 14 #include "ui/views/controls/button/vector_icon_button.h" | 20 #include "ui/views/controls/button/vector_icon_button.h" |
| 15 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
| 22 #include "ui/views/controls/styled_label.h" | |
| 16 #include "ui/views/layout/grid_layout.h" | 23 #include "ui/views/layout/grid_layout.h" |
| 17 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
| 18 | 25 |
| 26 namespace { | |
| 27 | |
| 28 // TODO(tmartino): Consider combining this with the Android equivalent in | |
| 29 // PersonalDataManager.java | |
| 30 base::string16 GetAddressFromProfile(const autofill::AutofillProfile& profile, | |
| 31 const std::string& locale) { | |
| 32 std::vector<autofill::ServerFieldType> fields; | |
| 33 fields.push_back(autofill::COMPANY_NAME); | |
| 34 fields.push_back(autofill::ADDRESS_HOME_LINE1); | |
| 35 fields.push_back(autofill::ADDRESS_HOME_LINE2); | |
| 36 fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY); | |
| 37 fields.push_back(autofill::ADDRESS_HOME_CITY); | |
| 38 fields.push_back(autofill::ADDRESS_HOME_STATE); | |
| 39 fields.push_back(autofill::ADDRESS_HOME_ZIP); | |
| 40 fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE); | |
| 41 | |
| 42 return profile.ConstructInferredLabel(fields, fields.size(), locale); | |
| 43 } | |
| 44 | |
| 45 } // namespace | |
| 46 | |
| 19 namespace payments { | 47 namespace payments { |
| 20 | 48 |
| 21 std::unique_ptr<views::View> CreateSheetHeaderView( | 49 std::unique_ptr<views::View> CreateSheetHeaderView( |
| 22 bool show_back_arrow, | 50 bool show_back_arrow, |
| 23 const base::string16& title, | 51 const base::string16& title, |
| 24 views::VectorIconButtonDelegate* delegate) { | 52 views::VectorIconButtonDelegate* delegate) { |
| 25 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); | 53 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); |
| 26 views::GridLayout* layout = new views::GridLayout(container.get()); | 54 views::GridLayout* layout = new views::GridLayout(container.get()); |
| 27 container->SetLayoutManager(layout); | 55 container->SetLayoutManager(layout); |
| 28 | 56 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 // |header_view| will be deleted when |view| is. | 108 // |header_view| will be deleted when |view| is. |
| 81 layout->AddView(header_view.release()); | 109 layout->AddView(header_view.release()); |
| 82 | 110 |
| 83 layout->StartRow(0, 0); | 111 layout->StartRow(0, 0); |
| 84 // |content_view| will be deleted when |view| is. | 112 // |content_view| will be deleted when |view| is. |
| 85 layout->AddView(content_view.release()); | 113 layout->AddView(content_view.release()); |
| 86 | 114 |
| 87 return view; | 115 return view; |
| 88 } | 116 } |
| 89 | 117 |
| 118 std::unique_ptr<views::View> GetShippingAddressLabel( | |
| 119 AddressStyleType type, | |
| 120 const std::string& locale, | |
| 121 const autofill::AutofillProfile& profile) { | |
| 122 base::string16 name_value = | |
| 123 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); | |
| 124 | |
| 125 // TODO(tmartino): Add bold styling for name in DETAILED style. | |
| 126 | |
| 127 base::string16 address_value = GetAddressFromProfile(profile, locale); | |
| 128 | |
| 129 base::string16 phone_value = profile.GetInfo( | |
| 130 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); | |
| 131 | |
| 132 std::vector<base::string16> values; | |
| 133 if (!name_value.empty()) | |
| 134 values.push_back(name_value); | |
| 135 if (!address_value.empty()) | |
| 136 values.push_back(address_value); | |
| 137 if (!phone_value.empty()) | |
| 138 values.push_back(phone_value); | |
| 139 | |
| 140 return base::MakeUnique<views::StyledLabel>( | |
| 141 base::JoinString(values, base::ASCIIToUTF16("\n")), nullptr); | |
| 142 } | |
| 143 | |
| 144 std::unique_ptr<views::View> GetContactInfoLabel( | |
|
sky
2017/01/18 23:19:25
I see one call to this that passes in true for all
tmartino
2017/01/19 16:36:59
The show_payer_* values will be specified by the m
| |
| 145 AddressStyleType type, | |
| 146 const std::string& locale, | |
| 147 const autofill::AutofillProfile& profile, | |
| 148 bool show_payer_name, | |
| 149 bool show_payer_email, | |
| 150 bool show_payer_phone) { | |
| 151 base::string16 name_value; | |
| 152 base::string16 phone_value; | |
| 153 base::string16 email_value; | |
| 154 | |
| 155 if (show_payer_name) { | |
| 156 name_value = | |
|
sky
2017/01/18 23:19:25
Why bother with the temp? Why not add directly to
tmartino
2017/01/19 16:36:59
For the bold styling described in the TODO below,
| |
| 157 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); | |
| 158 | |
| 159 // TODO(tmartino): Add bold styling for name in DETAILED style. | |
| 160 } | |
| 161 | |
| 162 if (show_payer_phone) { | |
| 163 phone_value = profile.GetInfo( | |
| 164 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); | |
| 165 } | |
| 166 | |
| 167 if (show_payer_email) { | |
| 168 email_value = profile.GetInfo( | |
| 169 autofill::AutofillType(autofill::EMAIL_ADDRESS), locale); | |
| 170 } | |
| 171 | |
| 172 std::vector<base::string16> values; | |
| 173 if (!name_value.empty()) | |
| 174 values.push_back(name_value); | |
| 175 if (!phone_value.empty()) | |
| 176 values.push_back(phone_value); | |
| 177 if (!email_value.empty()) | |
| 178 values.push_back(email_value); | |
| 179 | |
| 180 return base::MakeUnique<views::StyledLabel>( | |
| 181 base::JoinString(values, base::ASCIIToUTF16("\n")), nullptr); | |
| 182 } | |
| 183 | |
| 90 } // namespace payments | 184 } // namespace payments |
| OLD | NEW |