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> | 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_sheet_controller.h" | 12 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" |
| 13 #include "components/autofill/core/browser/autofill_data_util.h" | 13 #include "components/autofill/core/browser/autofill_data_util.h" |
| 14 #include "components/autofill/core/browser/autofill_profile.h" | 14 #include "components/autofill/core/browser/autofill_profile.h" |
| 15 #include "components/autofill/core/browser/autofill_type.h" | 15 #include "components/autofill/core/browser/autofill_type.h" |
| 16 #include "components/autofill/core/browser/credit_card.h" | 16 #include "components/autofill/core/browser/credit_card.h" |
| 17 #include "components/autofill/core/browser/field_types.h" | 17 #include "components/autofill/core/browser/field_types.h" |
| 18 #include "third_party/skia/include/core/SkColor.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
| 21 #include "ui/gfx/font_list.h" | |
| 21 #include "ui/gfx/geometry/insets.h" | 22 #include "ui/gfx/geometry/insets.h" |
| 22 #include "ui/gfx/geometry/point_f.h" | 23 #include "ui/gfx/geometry/point_f.h" |
| 23 #include "ui/gfx/paint_vector_icon.h" | 24 #include "ui/gfx/paint_vector_icon.h" |
| 24 #include "ui/vector_icons/vector_icons.h" | 25 #include "ui/vector_icons/vector_icons.h" |
| 25 #include "ui/views/border.h" | 26 #include "ui/views/border.h" |
| 26 #include "ui/views/bubble/bubble_frame_view.h" | 27 #include "ui/views/bubble/bubble_frame_view.h" |
| 27 #include "ui/views/controls/button/button.h" | 28 #include "ui/views/controls/button/button.h" |
| 28 #include "ui/views/controls/button/vector_icon_button.h" | 29 #include "ui/views/controls/button/vector_icon_button.h" |
| 29 #include "ui/views/controls/image_view.h" | 30 #include "ui/views/controls/image_view.h" |
| 30 #include "ui/views/controls/label.h" | 31 #include "ui/views/controls/label.h" |
| 31 #include "ui/views/controls/styled_label.h" | 32 #include "ui/views/controls/styled_label.h" |
| 33 #include "ui/views/layout/box_layout.h" | |
| 32 #include "ui/views/layout/grid_layout.h" | 34 #include "ui/views/layout/grid_layout.h" |
| 33 #include "ui/views/painter.h" | 35 #include "ui/views/painter.h" |
| 34 #include "ui/views/view.h" | 36 #include "ui/views/view.h" |
| 35 | 37 |
| 36 namespace { | 38 namespace { |
| 37 | 39 |
| 38 // TODO(tmartino): Consider combining this with the Android equivalent in | 40 // TODO(tmartino): Consider combining this with the Android equivalent in |
| 39 // PersonalDataManager.java | 41 // PersonalDataManager.java |
| 40 base::string16 GetAddressFromProfile(const autofill::AutofillProfile& profile, | 42 base::string16 GetAddressFromProfile(const autofill::AutofillProfile& profile, |
| 41 const std::string& locale) { | 43 const std::string& locale) { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 values.push_back(name_value); | 170 values.push_back(name_value); |
| 169 if (!address_value.empty()) | 171 if (!address_value.empty()) |
| 170 values.push_back(address_value); | 172 values.push_back(address_value); |
| 171 if (!phone_value.empty()) | 173 if (!phone_value.empty()) |
| 172 values.push_back(phone_value); | 174 values.push_back(phone_value); |
| 173 | 175 |
| 174 return base::MakeUnique<views::StyledLabel>( | 176 return base::MakeUnique<views::StyledLabel>( |
| 175 base::JoinString(values, base::ASCIIToUTF16("\n")), nullptr); | 177 base::JoinString(values, base::ASCIIToUTF16("\n")), nullptr); |
| 176 } | 178 } |
| 177 | 179 |
| 178 std::unique_ptr<views::View> GetContactInfoLabel( | 180 std::unique_ptr<views::View> GetContactInfoLabel( |
|
Mathieu
2017/02/28 21:15:16
Add a TODO: there needs to be a unit test for how
anthonyvd
2017/03/01 15:27:55
Good point. Done.
| |
| 179 AddressStyleType type, | 181 AddressStyleType type, |
| 180 const std::string& locale, | 182 const std::string& locale, |
| 181 const autofill::AutofillProfile& profile, | 183 const autofill::AutofillProfile& profile, |
| 182 bool show_payer_name, | 184 bool show_payer_name, |
| 183 bool show_payer_email, | 185 bool show_payer_email, |
| 184 bool show_payer_phone) { | 186 bool show_payer_phone) { |
| 185 base::string16 name_value; | 187 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); |
| 186 base::string16 phone_value; | 188 std::unique_ptr<views::BoxLayout> layout = |
| 187 base::string16 email_value; | 189 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); |
| 190 layout->set_cross_axis_alignment( | |
| 191 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | |
| 192 container->SetLayoutManager(layout.release()); | |
| 193 | |
| 194 constexpr int kMissingName = 1; | |
| 195 constexpr int kMissingPhone = 1 << 1; | |
| 196 constexpr int kMissingEmail = 1 << 2; | |
| 197 int missing_fields = 0; | |
| 188 | 198 |
| 189 if (show_payer_name) { | 199 if (show_payer_name) { |
| 190 name_value = | 200 base::string16 name = |
| 191 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); | 201 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); |
| 192 | 202 if (!name.empty()) { |
| 193 // TODO(tmartino): Add bold styling for name in DETAILED style. | 203 std::unique_ptr<views::Label> label = |
| 204 base::MakeUnique<views::Label>(name); | |
| 205 if (type == AddressStyleType::DETAILED) { | |
| 206 const gfx::FontList& font_list = label->font_list(); | |
| 207 label->SetFontList(font_list.DeriveWithWeight(gfx::Font::Weight::BOLD)); | |
| 208 } | |
| 209 container->AddChildView(label.release()); | |
| 210 } else { | |
| 211 missing_fields |= kMissingName; | |
| 212 } | |
| 194 } | 213 } |
| 195 | 214 |
| 196 if (show_payer_phone) { | 215 if (show_payer_phone) { |
| 197 phone_value = profile.GetInfo( | 216 base::string16 phone = profile.GetInfo( |
| 198 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); | 217 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); |
| 218 if (!phone.empty()) { | |
| 219 std::unique_ptr<views::Label> label = | |
| 220 base::MakeUnique<views::Label>(phone); | |
| 221 container->AddChildView(label.release()); | |
| 222 } else { | |
| 223 missing_fields |= kMissingPhone; | |
| 224 } | |
| 199 } | 225 } |
| 200 | 226 |
| 201 if (show_payer_email) { | 227 if (show_payer_email) { |
| 202 email_value = profile.GetInfo( | 228 base::string16 email = profile.GetInfo( |
| 203 autofill::AutofillType(autofill::EMAIL_ADDRESS), locale); | 229 autofill::AutofillType(autofill::EMAIL_ADDRESS), locale); |
| 230 if (!email.empty()) { | |
| 231 std::unique_ptr<views::Label> label = | |
| 232 base::MakeUnique<views::Label>(email); | |
| 233 container->AddChildView(label.release()); | |
| 234 } else { | |
| 235 missing_fields |= kMissingEmail; | |
| 236 } | |
| 204 } | 237 } |
| 205 | 238 |
| 206 std::vector<base::string16> values; | 239 // TODO(anthonyvd): add the error label based on the value of |missing_fields| |
| 207 if (!name_value.empty()) | |
| 208 values.push_back(name_value); | |
| 209 if (!phone_value.empty()) | |
| 210 values.push_back(phone_value); | |
| 211 if (!email_value.empty()) | |
| 212 values.push_back(email_value); | |
| 213 | 240 |
| 214 return base::MakeUnique<views::StyledLabel>( | 241 return container; |
| 215 base::JoinString(values, base::ASCIIToUTF16("\n")), nullptr); | |
| 216 } | 242 } |
| 217 | 243 |
| 218 // Creates a views::Border object that can paint the gray horizontal ruler used | 244 // Creates a views::Border object that can paint the gray horizontal ruler used |
| 219 // as a separator between items in the Payment Request dialog. | 245 // as a separator between items in the Payment Request dialog. |
| 220 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() { | 246 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() { |
| 221 return views::CreateBorderPainter( | 247 return views::CreateBorderPainter( |
| 222 base::MakeUnique<PaymentRequestRowBorderPainter>(), | 248 base::MakeUnique<PaymentRequestRowBorderPainter>(), |
| 223 gfx::Insets()); | 249 gfx::Insets()); |
| 224 } | 250 } |
| 225 | 251 |
| 226 } // namespace payments | 252 } // namespace payments |
| OLD | NEW |