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/harmony/chrome_typography.h" | |
| 12 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| 13 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" | 14 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" |
| 14 #include "chrome/grit/chromium_strings.h" | 15 #include "chrome/grit/chromium_strings.h" |
| 15 #include "chrome/grit/theme_resources.h" | 16 #include "chrome/grit/theme_resources.h" |
| 16 #include "components/autofill/core/browser/autofill_data_util.h" | 17 #include "components/autofill/core/browser/autofill_data_util.h" |
| 17 #include "components/autofill/core/browser/autofill_profile.h" | 18 #include "components/autofill/core/browser/autofill_profile.h" |
| 18 #include "components/autofill/core/browser/autofill_type.h" | 19 #include "components/autofill/core/browser/autofill_type.h" |
| 19 #include "components/autofill/core/browser/credit_card.h" | 20 #include "components/autofill/core/browser/credit_card.h" |
| 20 #include "components/autofill/core/browser/field_types.h" | 21 #include "components/autofill/core/browser/field_types.h" |
| 21 #include "components/payments/core/payment_options_provider.h" | 22 #include "components/payments/core/payment_options_provider.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 const base::string16& s3, | 75 const base::string16& s3, |
| 75 bool disabled_state = false) { | 76 bool disabled_state = false) { |
| 76 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); | 77 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); |
| 77 std::unique_ptr<views::BoxLayout> layout = | 78 std::unique_ptr<views::BoxLayout> layout = |
| 78 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); | 79 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); |
| 79 layout->set_cross_axis_alignment( | 80 layout->set_cross_axis_alignment( |
| 80 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | 81 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); |
| 81 container->SetLayoutManager(layout.release()); | 82 container->SetLayoutManager(layout.release()); |
| 82 | 83 |
| 83 if (!s1.empty()) { | 84 if (!s1.empty()) { |
| 84 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s1); | 85 const int text_style = type == AddressStyleType::DETAILED |
| 85 if (type == AddressStyleType::DETAILED) { | 86 ? STYLE_EMPHASIZED |
| 86 const gfx::FontList& font_list = label->font_list(); | 87 : views::style::STYLE_PRIMARY; |
| 87 label->SetFontList(font_list.DeriveWithWeight(gfx::Font::Weight::BOLD)); | 88 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>( |
| 88 } | 89 s1, views::style::CONTEXT_LABEL, text_style); |
| 89 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1)); | 90 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1)); |
| 90 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 91 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 91 if (disabled_state) { | 92 if (disabled_state) { |
| 92 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( | 93 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( |
| 93 ui::NativeTheme::kColorId_LabelDisabledColor)); | 94 ui::NativeTheme::kColorId_LabelDisabledColor)); |
| 94 } | 95 } |
| 95 container->AddChildView(label.release()); | 96 container->AddChildView(label.release()); |
| 96 } | 97 } |
| 97 | 98 |
| 98 if (!s2.empty()) { | 99 if (!s2.empty()) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 | 134 |
| 134 base::string16 phone = profile.GetInfo( | 135 base::string16 phone = profile.GetInfo( |
| 135 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); | 136 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); |
| 136 | 137 |
| 137 return GetBaseProfileLabel(type, name, address, phone, disabled_state); | 138 return GetBaseProfileLabel(type, name, address, phone, disabled_state); |
| 138 } | 139 } |
| 139 | 140 |
| 140 std::unique_ptr<views::Label> GetLabelForMissingInformation( | 141 std::unique_ptr<views::Label> GetLabelForMissingInformation( |
| 141 const base::string16& missing_info) { | 142 const base::string16& missing_info) { |
| 142 std::unique_ptr<views::Label> label = | 143 std::unique_ptr<views::Label> label = |
| 143 base::MakeUnique<views::Label>(missing_info); | 144 base::MakeUnique<views::Label>(missing_info, CONTEXT_DEPRECATED_SMALL); |
| 144 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR)); | 145 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR)); |
| 145 label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1)); | |
| 146 // Missing information typically has a nice shade of blue. | 146 // Missing information typically has a nice shade of blue. |
| 147 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( | 147 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( |
| 148 ui::NativeTheme::kColorId_LinkEnabled)); | 148 ui::NativeTheme::kColorId_LinkEnabled)); |
| 149 return label; | 149 return label; |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Paints the gray horizontal line that doesn't span the entire width of the | 152 // Paints the gray horizontal line that doesn't span the entire width of the |
| 153 // dialog at the bottom of the view it borders. | 153 // dialog at the bottom of the view it borders. |
| 154 class PaymentRequestRowBorderPainter : public views::Painter { | 154 class PaymentRequestRowBorderPainter : public views::Painter { |
| 155 public: | 155 public: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 views::SetImageFromVectorIcon(back_arrow, ui::kBackArrowIcon); | 219 views::SetImageFromVectorIcon(back_arrow, ui::kBackArrowIcon); |
| 220 constexpr int kBackArrowSize = 16; | 220 constexpr int kBackArrowSize = 16; |
| 221 back_arrow->SetSize(gfx::Size(kBackArrowSize, kBackArrowSize)); | 221 back_arrow->SetSize(gfx::Size(kBackArrowSize, kBackArrowSize)); |
| 222 back_arrow->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); | 222 back_arrow->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 223 back_arrow->set_tag(static_cast<int>( | 223 back_arrow->set_tag(static_cast<int>( |
| 224 PaymentRequestCommonTags::BACK_BUTTON_TAG)); | 224 PaymentRequestCommonTags::BACK_BUTTON_TAG)); |
| 225 back_arrow->set_id(static_cast<int>(DialogViewID::BACK_BUTTON)); | 225 back_arrow->set_id(static_cast<int>(DialogViewID::BACK_BUTTON)); |
| 226 layout->AddView(back_arrow); | 226 layout->AddView(back_arrow); |
| 227 } | 227 } |
| 228 | 228 |
| 229 views::Label* title_label = new views::Label(title); | 229 views::Label* title_label = |
| 230 new views::Label(title, views::style::CONTEXT_DIALOG_TITLE); | |
| 230 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 231 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 231 title_label->SetFontList( | |
| 232 title_label->GetDefaultFontList().DeriveWithSizeDelta( | |
| 233 ui::kTitleFontSizeDelta)); | |
| 234 layout->AddView(title_label); | 232 layout->AddView(title_label); |
| 235 | 233 |
| 236 return container; | 234 return container; |
| 237 } | 235 } |
| 238 | 236 |
| 239 std::unique_ptr<views::ImageView> CreateInstrumentIconView( | 237 std::unique_ptr<views::ImageView> CreateInstrumentIconView( |
| 240 int icon_resource_id, | 238 int icon_resource_id, |
| 241 const base::string16& tooltip_text) { | 239 const base::string16& tooltip_text) { |
| 242 std::unique_ptr<views::ImageView> card_icon_view = | 240 std::unique_ptr<views::ImageView> card_icon_view = |
| 243 base::MakeUnique<views::ImageView>(); | 241 base::MakeUnique<views::ImageView>(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 std::unique_ptr<views::View> GetShippingAddressLabelWithError( | 273 std::unique_ptr<views::View> GetShippingAddressLabelWithError( |
| 276 AddressStyleType type, | 274 AddressStyleType type, |
| 277 const std::string& locale, | 275 const std::string& locale, |
| 278 const autofill::AutofillProfile& profile, | 276 const autofill::AutofillProfile& profile, |
| 279 const base::string16& error, | 277 const base::string16& error, |
| 280 bool disabled_state) { | 278 bool disabled_state) { |
| 281 std::unique_ptr<views::View> base_label = | 279 std::unique_ptr<views::View> base_label = |
| 282 GetShippingAddressLabel(type, locale, profile, disabled_state); | 280 GetShippingAddressLabel(type, locale, profile, disabled_state); |
| 283 | 281 |
| 284 if (!error.empty()) { | 282 if (!error.empty()) { |
| 285 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(error); | 283 std::unique_ptr<views::Label> label = |
| 284 base::MakeUnique<views::Label>(error, CONTEXT_DEPRECATED_SMALL); | |
| 286 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR)); | 285 label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR)); |
| 287 label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1)); | |
| 288 // Error information is typically in red. | 286 // Error information is typically in red. |
| 289 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( | 287 label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( |
| 290 ui::NativeTheme::kColorId_AlertSeverityHigh)); | 288 ui::NativeTheme::kColorId_AlertSeverityHigh)); |
| 291 base_label->AddChildView(label.release()); | 289 base_label->AddChildView(label.release()); |
| 292 } | 290 } |
| 293 return base_label; | 291 return base_label; |
| 294 } | 292 } |
| 295 | 293 |
| 296 std::unique_ptr<views::View> GetShippingAddressLabelWithMissingInfo( | 294 std::unique_ptr<views::View> GetShippingAddressLabelWithMissingInfo( |
| 297 AddressStyleType type, | 295 AddressStyleType type, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 } | 342 } |
| 345 | 343 |
| 346 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder( | 344 std::unique_ptr<views::Border> CreatePaymentRequestRowBorder( |
| 347 SkColor color, | 345 SkColor color, |
| 348 const gfx::Insets& insets) { | 346 const gfx::Insets& insets) { |
| 349 return views::CreateBorderPainter( | 347 return views::CreateBorderPainter( |
| 350 base::MakeUnique<PaymentRequestRowBorderPainter>(color), insets); | 348 base::MakeUnique<PaymentRequestRowBorderPainter>(color), insets); |
| 351 } | 349 } |
| 352 | 350 |
| 353 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) { | 351 std::unique_ptr<views::Label> CreateBoldLabel(const base::string16& text) { |
| 352 return base::MakeUnique<views::Label>(text, views::style::CONTEXT_LABEL, | |
| 353 STYLE_EMPHASIZED); | |
| 354 } | |
| 355 | |
| 356 std::unique_ptr<views::Label> CreateMediumLabel(const base::string16& text) { | |
| 357 // TODO(tapted): This should refer to a style in the Chrome typography spec. | |
| 358 // Also, it needs to handle user setups where the default font is BOLD already | |
| 359 // since asking for a MEDIUM font will give a lighter font. | |
| 354 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text); | 360 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(text); |
| 355 | 361 label->SetFontList(ResourceBundle::GetSharedInstance().GetFontListWithDelta( |
|
anthonyvd
2017/05/22 13:10:32
Our UI specs typically request that we fallback to
tapted
2017/05/22 21:09:26
There is logic in the typography spec to do this f
| |
| 356 label->SetFontList( | 362 ui::kLabelFontSizeDelta, gfx::Font::NORMAL, gfx::Font::Weight::MEDIUM)); |
| 357 label->font_list().DeriveWithWeight(gfx::Font::Weight::BOLD)); | |
| 358 | |
| 359 return label; | 363 return label; |
| 360 } | 364 } |
| 361 | 365 |
| 362 std::unique_ptr<views::View> CreateShippingOptionLabel( | 366 std::unique_ptr<views::View> CreateShippingOptionLabel( |
| 363 payments::mojom::PaymentShippingOption* shipping_option, | 367 payments::mojom::PaymentShippingOption* shipping_option, |
| 364 const base::string16& formatted_amount, | 368 const base::string16& formatted_amount, |
| 365 bool emphasize_label) { | 369 bool emphasize_label) { |
| 366 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); | 370 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); |
| 367 | 371 |
| 368 std::unique_ptr<views::BoxLayout> layout = | 372 std::unique_ptr<views::BoxLayout> layout = |
| 369 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); | 373 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); |
| 370 layout->set_cross_axis_alignment( | 374 layout->set_cross_axis_alignment( |
| 371 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | 375 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); |
| 372 container->SetLayoutManager(layout.release()); | 376 container->SetLayoutManager(layout.release()); |
| 373 | 377 |
| 374 if (shipping_option) { | 378 if (shipping_option) { |
| 379 const base::string16& text = base::UTF8ToUTF16(shipping_option->label); | |
| 375 std::unique_ptr<views::Label> shipping_label = | 380 std::unique_ptr<views::Label> shipping_label = |
| 376 base::MakeUnique<views::Label>( | 381 emphasize_label ? CreateMediumLabel(text) |
| 377 base::UTF8ToUTF16(shipping_option->label)); | 382 : base::MakeUnique<views::Label>(text); |
| 378 shipping_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 383 shipping_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 379 shipping_label->set_id( | 384 shipping_label->set_id( |
| 380 static_cast<int>(DialogViewID::SHIPPING_OPTION_DESCRIPTION)); | 385 static_cast<int>(DialogViewID::SHIPPING_OPTION_DESCRIPTION)); |
| 381 if (emphasize_label) { | |
| 382 shipping_label->SetFontList(shipping_label->font_list().DeriveWithWeight( | |
| 383 gfx::Font::Weight::MEDIUM)); | |
| 384 } | |
| 385 container->AddChildView(shipping_label.release()); | 386 container->AddChildView(shipping_label.release()); |
| 386 | 387 |
| 387 std::unique_ptr<views::Label> amount_label = | 388 std::unique_ptr<views::Label> amount_label = |
| 388 base::MakeUnique<views::Label>(formatted_amount); | 389 base::MakeUnique<views::Label>(formatted_amount); |
| 389 amount_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 390 amount_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 390 amount_label->set_id( | 391 amount_label->set_id( |
| 391 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT)); | 392 static_cast<int>(DialogViewID::SHIPPING_OPTION_AMOUNT)); |
| 392 container->AddChildView(amount_label.release()); | 393 container->AddChildView(amount_label.release()); |
| 393 } | 394 } |
| 394 | 395 |
| 395 return container; | 396 return container; |
| 396 } | 397 } |
| 397 | 398 |
| 398 } // namespace payments | 399 } // namespace payments |
| OLD | NEW |