| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "ui/views/controls/button/button.h" | 30 #include "ui/views/controls/button/button.h" |
| 31 #include "ui/views/controls/button/vector_icon_button.h" | 31 #include "ui/views/controls/button/vector_icon_button.h" |
| 32 #include "ui/views/controls/image_view.h" | 32 #include "ui/views/controls/image_view.h" |
| 33 #include "ui/views/controls/label.h" | 33 #include "ui/views/controls/label.h" |
| 34 #include "ui/views/controls/styled_label.h" | 34 #include "ui/views/controls/styled_label.h" |
| 35 #include "ui/views/layout/box_layout.h" | 35 #include "ui/views/layout/box_layout.h" |
| 36 #include "ui/views/layout/grid_layout.h" | 36 #include "ui/views/layout/grid_layout.h" |
| 37 #include "ui/views/painter.h" | 37 #include "ui/views/painter.h" |
| 38 #include "ui/views/view.h" | 38 #include "ui/views/view.h" |
| 39 | 39 |
| 40 namespace payments { |
| 41 |
| 40 namespace { | 42 namespace { |
| 41 | 43 |
| 42 // TODO(tmartino): Consider combining this with the Android equivalent in | 44 // TODO(tmartino): Consider combining this with the Android equivalent in |
| 43 // PersonalDataManager.java | 45 // PersonalDataManager.java |
| 44 base::string16 GetAddressFromProfile(const autofill::AutofillProfile& profile, | 46 base::string16 GetAddressFromProfile(const autofill::AutofillProfile& profile, |
| 45 const std::string& locale) { | 47 const std::string& locale) { |
| 46 std::vector<autofill::ServerFieldType> fields; | 48 std::vector<autofill::ServerFieldType> fields; |
| 47 fields.push_back(autofill::COMPANY_NAME); | 49 fields.push_back(autofill::COMPANY_NAME); |
| 48 fields.push_back(autofill::ADDRESS_HOME_LINE1); | 50 fields.push_back(autofill::ADDRESS_HOME_LINE1); |
| 49 fields.push_back(autofill::ADDRESS_HOME_LINE2); | 51 fields.push_back(autofill::ADDRESS_HOME_LINE2); |
| 50 fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY); | 52 fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY); |
| 51 fields.push_back(autofill::ADDRESS_HOME_CITY); | 53 fields.push_back(autofill::ADDRESS_HOME_CITY); |
| 52 fields.push_back(autofill::ADDRESS_HOME_STATE); | 54 fields.push_back(autofill::ADDRESS_HOME_STATE); |
| 53 fields.push_back(autofill::ADDRESS_HOME_ZIP); | 55 fields.push_back(autofill::ADDRESS_HOME_ZIP); |
| 54 fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE); | 56 fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE); |
| 55 | 57 |
| 56 return profile.ConstructInferredLabel(fields, fields.size(), locale); | 58 return profile.ConstructInferredLabel(fields, fields.size(), locale); |
| 57 } | 59 } |
| 58 | 60 |
| 61 std::unique_ptr<views::View> GetThreeLineLabel(AddressStyleType type, |
| 62 const base::string16& s1, |
| 63 const base::string16& s2, |
| 64 const base::string16& s3) { |
| 65 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); |
| 66 std::unique_ptr<views::BoxLayout> layout = |
| 67 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); |
| 68 layout->set_cross_axis_alignment( |
| 69 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); |
| 70 container->SetLayoutManager(layout.release()); |
| 71 |
| 72 if (!s1.empty()) { |
| 73 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s1); |
| 74 if (type == AddressStyleType::DETAILED) { |
| 75 const gfx::FontList& font_list = label->font_list(); |
| 76 label->SetFontList(font_list.DeriveWithWeight(gfx::Font::Weight::BOLD)); |
| 77 } |
| 78 container->AddChildView(label.release()); |
| 79 } |
| 80 |
| 81 if (!s2.empty()) { |
| 82 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s2); |
| 83 container->AddChildView(label.release()); |
| 84 } |
| 85 |
| 86 if (!s3.empty()) { |
| 87 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s3); |
| 88 container->AddChildView(label.release()); |
| 89 } |
| 90 |
| 91 // TODO(anthonyvd): add the error label |
| 92 |
| 93 return container; |
| 94 } |
| 95 |
| 59 // Paints the gray horizontal line that doesn't span the entire width of the | 96 // Paints the gray horizontal line that doesn't span the entire width of the |
| 60 // dialog at the bottom of the view it borders. | 97 // dialog at the bottom of the view it borders. |
| 61 class PaymentRequestRowBorderPainter : public views::Painter { | 98 class PaymentRequestRowBorderPainter : public views::Painter { |
| 62 public: | 99 public: |
| 63 PaymentRequestRowBorderPainter() {} | 100 PaymentRequestRowBorderPainter() {} |
| 64 ~PaymentRequestRowBorderPainter() override {} | 101 ~PaymentRequestRowBorderPainter() override {} |
| 65 | 102 |
| 66 // views::Painter: | 103 // views::Painter: |
| 67 gfx::Size GetMinimumSize() const override { | 104 gfx::Size GetMinimumSize() const override { |
| 68 return gfx::Size(2 * payments::kPaymentRequestRowHorizontalInsets, 1); | 105 return gfx::Size(2 * payments::kPaymentRequestRowHorizontalInsets, 1); |
| 69 } | 106 } |
| 70 | 107 |
| 71 void Paint(gfx::Canvas* canvas, const gfx::Size& size) override { | 108 void Paint(gfx::Canvas* canvas, const gfx::Size& size) override { |
| 72 int line_height = size.height() - 1; | 109 int line_height = size.height() - 1; |
| 73 canvas->DrawLine( | 110 canvas->DrawLine( |
| 74 gfx::PointF(payments::kPaymentRequestRowHorizontalInsets, line_height), | 111 gfx::PointF(payments::kPaymentRequestRowHorizontalInsets, line_height), |
| 75 gfx::PointF(size.width() - payments::kPaymentRequestRowHorizontalInsets, | 112 gfx::PointF(size.width() - payments::kPaymentRequestRowHorizontalInsets, |
| 76 line_height), | 113 line_height), |
| 77 SK_ColorLTGRAY); | 114 SK_ColorLTGRAY); |
| 78 } | 115 } |
| 79 | 116 |
| 80 private: | 117 private: |
| 81 DISALLOW_COPY_AND_ASSIGN(PaymentRequestRowBorderPainter); | 118 DISALLOW_COPY_AND_ASSIGN(PaymentRequestRowBorderPainter); |
| 82 }; | 119 }; |
| 83 | 120 |
| 84 } // namespace | 121 } // namespace |
| 85 | 122 |
| 86 namespace payments { | |
| 87 | |
| 88 std::unique_ptr<views::View> CreateSheetHeaderView( | 123 std::unique_ptr<views::View> CreateSheetHeaderView( |
| 89 bool show_back_arrow, | 124 bool show_back_arrow, |
| 90 const base::string16& title, | 125 const base::string16& title, |
| 91 views::VectorIconButtonDelegate* delegate) { | 126 views::VectorIconButtonDelegate* delegate) { |
| 92 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); | 127 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); |
| 93 views::GridLayout* layout = new views::GridLayout(container.get()); | 128 views::GridLayout* layout = new views::GridLayout(container.get()); |
| 94 container->SetLayoutManager(layout); | 129 container->SetLayoutManager(layout); |
| 95 | 130 |
| 96 constexpr int kHeaderTopVerticalInset = 14; | 131 constexpr int kHeaderTopVerticalInset = 14; |
| 97 constexpr int kHeaderBottomVerticalInset = 8; | 132 constexpr int kHeaderBottomVerticalInset = 8; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 card_icon_view->SetBorder(views::CreateRoundedRectBorder( | 185 card_icon_view->SetBorder(views::CreateRoundedRectBorder( |
| 151 1, 3, card_icon_view->GetNativeTheme()->GetSystemColor( | 186 1, 3, card_icon_view->GetNativeTheme()->GetSystemColor( |
| 152 ui::NativeTheme::kColorId_UnfocusedBorderColor))); | 187 ui::NativeTheme::kColorId_UnfocusedBorderColor))); |
| 153 return card_icon_view; | 188 return card_icon_view; |
| 154 } | 189 } |
| 155 | 190 |
| 156 std::unique_ptr<views::View> GetShippingAddressLabel( | 191 std::unique_ptr<views::View> GetShippingAddressLabel( |
| 157 AddressStyleType type, | 192 AddressStyleType type, |
| 158 const std::string& locale, | 193 const std::string& locale, |
| 159 const autofill::AutofillProfile& profile) { | 194 const autofill::AutofillProfile& profile) { |
| 160 base::string16 name_value = | 195 base::string16 name = |
| 161 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); | 196 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); |
| 162 | 197 |
| 163 // TODO(tmartino): Add bold styling for name in DETAILED style. | 198 base::string16 address = GetAddressFromProfile(profile, locale); |
| 164 | 199 |
| 165 base::string16 address_value = GetAddressFromProfile(profile, locale); | 200 base::string16 phone = profile.GetInfo( |
| 166 | |
| 167 base::string16 phone_value = profile.GetInfo( | |
| 168 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); | 201 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); |
| 169 | 202 |
| 170 std::vector<base::string16> values; | 203 return GetThreeLineLabel(type, name, address, phone); |
| 171 if (!name_value.empty()) | |
| 172 values.push_back(name_value); | |
| 173 if (!address_value.empty()) | |
| 174 values.push_back(address_value); | |
| 175 if (!phone_value.empty()) | |
| 176 values.push_back(phone_value); | |
| 177 | |
| 178 return base::MakeUnique<views::StyledLabel>( | |
| 179 base::JoinString(values, base::ASCIIToUTF16("\n")), nullptr); | |
| 180 } | 204 } |
| 181 | 205 |
| 182 // TODO(anthonyvd): unit test the label layout. | 206 // TODO(anthonyvd): unit test the label layout. |
| 183 std::unique_ptr<views::View> GetContactInfoLabel( | 207 std::unique_ptr<views::View> GetContactInfoLabel( |
| 184 AddressStyleType type, | 208 AddressStyleType type, |
| 185 const std::string& locale, | 209 const std::string& locale, |
| 186 const autofill::AutofillProfile& profile, | 210 const autofill::AutofillProfile& profile, |
| 187 bool show_payer_name, | 211 bool show_payer_name, |
| 188 bool show_payer_email, | 212 bool show_payer_phone, |
| 189 bool show_payer_phone) { | 213 bool show_payer_email) { |
| 190 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); | 214 base::string16 name = |
| 191 std::unique_ptr<views::BoxLayout> layout = | 215 show_payer_name |
| 192 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); | 216 ? profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale) |
| 193 layout->set_cross_axis_alignment( | 217 : base::string16(); |
| 194 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | |
| 195 container->SetLayoutManager(layout.release()); | |
| 196 | 218 |
| 197 if (show_payer_name) { | 219 base::string16 phone = |
| 198 base::string16 name = | 220 show_payer_phone |
| 199 profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); | 221 ? profile.GetInfo( |
| 200 if (!name.empty()) { | 222 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), |
| 201 std::unique_ptr<views::Label> label = | 223 locale) |
| 202 base::MakeUnique<views::Label>(name); | 224 : base::string16(); |
| 203 if (type == AddressStyleType::DETAILED) { | |
| 204 const gfx::FontList& font_list = label->font_list(); | |
| 205 label->SetFontList(font_list.DeriveWithWeight(gfx::Font::Weight::BOLD)); | |
| 206 } | |
| 207 container->AddChildView(label.release()); | |
| 208 } | |
| 209 } | |
| 210 | 225 |
| 211 if (show_payer_phone) { | 226 base::string16 email = |
| 212 base::string16 phone = profile.GetInfo( | 227 show_payer_email |
| 213 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); | 228 ? profile.GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS), |
| 214 if (!phone.empty()) { | 229 locale) |
| 215 std::unique_ptr<views::Label> label = | 230 : base::string16(); |
| 216 base::MakeUnique<views::Label>(phone); | |
| 217 container->AddChildView(label.release()); | |
| 218 } | |
| 219 } | |
| 220 | 231 |
| 221 if (show_payer_email) { | 232 return GetThreeLineLabel(type, name, phone, email); |
| 222 base::string16 email = profile.GetInfo( | |
| 223 autofill::AutofillType(autofill::EMAIL_ADDRESS), locale); | |
| 224 if (!email.empty()) { | |
| 225 std::unique_ptr<views::Label> label = | |
| 226 base::MakeUnique<views::Label>(email); | |
| 227 container->AddChildView(label.release()); | |
| 228 } | |
| 229 } | |
| 230 | |
| 231 // TODO(anthonyvd): add the error label | |
| 232 | |
| 233 return container; | |
| 234 } | 233 } |
| 235 | 234 |
| 236 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() { | 235 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() { |
| 237 return views::CreateBorderPainter( | 236 return views::CreateBorderPainter( |
| 238 base::MakeUnique<PaymentRequestRowBorderPainter>(), | 237 base::MakeUnique<PaymentRequestRowBorderPainter>(), |
| 239 gfx::Insets()); | 238 gfx::Insets()); |
| 240 } | 239 } |
| 241 | 240 |
| 242 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) { | 241 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) { |
| 243 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text); | 242 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 272 return l10n_util::GetStringUTF16(IDS_PAYMENTS_PICKUP_OPTION_LABEL); | 271 return l10n_util::GetStringUTF16(IDS_PAYMENTS_PICKUP_OPTION_LABEL); |
| 273 case payments::mojom::PaymentShippingType::SHIPPING: | 272 case payments::mojom::PaymentShippingType::SHIPPING: |
| 274 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL); | 273 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL); |
| 275 } | 274 } |
| 276 // MSVC doesn't compile with only the above switch statement because it can't | 275 // MSVC doesn't compile with only the above switch statement because it can't |
| 277 // see that all control paths return a value. | 276 // see that all control paths return a value. |
| 278 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL); | 277 return l10n_util::GetStringUTF16(IDS_PAYMENTS_SHIPPING_OPTION_LABEL); |
| 279 } | 278 } |
| 280 | 279 |
| 281 } // namespace payments | 280 } // namespace payments |
| OLD | NEW |