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 12f398de86602ca2eecf59578b10c412bf3ed8a2..e69676add525d9e08403d9b631191d2b2960422d 100644 |
| --- a/chrome/browser/ui/views/payments/payment_request_views_util.cc |
| +++ b/chrome/browser/ui/views/payments/payment_request_views_util.cc |
| @@ -66,14 +66,13 @@ base::string16 GetAddressFromProfile(const autofill::AutofillProfile& profile, |
| } |
| // |s1|, |s2|, and |s3| are lines identifying the profile. |s1| is the |
| -// "headline" which may be emphasized depending on |type|. |error| is a |
| -// message indicating errors that need to be resolved before using this |
| -// profile. |
| -std::unique_ptr<views::View> GetProfileLabel(AddressStyleType type, |
| - const base::string16& s1, |
| - const base::string16& s2, |
| - const base::string16& s3, |
| - const base::string16& error) { |
| +// "headline" which may be emphasized depending on |type|. If |disabled_state| |
| +// is true, the labels will look disabled. |
| +std::unique_ptr<views::View> GetBaseProfileLabel(AddressStyleType type, |
| + const base::string16& s1, |
| + const base::string16& s2, |
| + const base::string16& s3, |
| + bool disabled_state = false) { |
| std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); |
| std::unique_ptr<views::BoxLayout> layout = |
| base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, 0, 0, 0); |
| @@ -89,6 +88,10 @@ std::unique_ptr<views::View> GetProfileLabel(AddressStyleType type, |
| } |
| label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_1)); |
| label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + if (disabled_state) { |
| + label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( |
| + ui::NativeTheme::kColorId_LabelDisabledColor)); |
| + } |
| container->AddChildView(label.release()); |
| } |
| @@ -96,6 +99,10 @@ std::unique_ptr<views::View> GetProfileLabel(AddressStyleType type, |
| std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s2); |
| label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_2)); |
| label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + if (disabled_state) { |
| + label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( |
| + ui::NativeTheme::kColorId_LabelDisabledColor)); |
| + } |
| container->AddChildView(label.release()); |
| } |
| @@ -103,19 +110,31 @@ std::unique_ptr<views::View> GetProfileLabel(AddressStyleType type, |
| std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(s3); |
| label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_LINE_3)); |
| label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| + if (disabled_state) { |
| + label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( |
| + ui::NativeTheme::kColorId_LabelDisabledColor)); |
| + } |
| container->AddChildView(label.release()); |
| } |
| + return container; |
| +} |
| - if (!error.empty()) { |
| - std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(error); |
| - label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR)); |
| - label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1)); |
| - label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( |
| - ui::NativeTheme::kColorId_LinkEnabled)); |
| - container->AddChildView(label.release()); |
| - } |
| +// Returns a label representing the |profile| as a shipping address. See |
| +// GetBaseProfileLabel() for more documentation. |
| +std::unique_ptr<views::View> GetShippingAddressLabel( |
| + AddressStyleType type, |
| + const std::string& locale, |
| + const autofill::AutofillProfile& profile, |
| + bool disabled_state) { |
| + base::string16 name = |
| + profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); |
| - return container; |
| + base::string16 address = GetAddressFromProfile(profile, locale); |
| + |
| + base::string16 phone = profile.GetInfo( |
| + autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); |
| + |
| + return GetBaseProfileLabel(type, name, address, phone, disabled_state); |
| } |
| // Paints the gray horizontal line that doesn't span the entire width of the |
| @@ -243,23 +262,48 @@ std::unique_ptr<views::View> CreateProductLogoFooterView() { |
| return content_view; |
| } |
| -std::unique_ptr<views::View> GetShippingAddressLabel( |
| +std::unique_ptr<views::View> GetShippingAddressLabelWithError( |
| AddressStyleType type, |
| const std::string& locale, |
| const autofill::AutofillProfile& profile, |
| - const PaymentOptionsProvider& options, |
| - const PaymentsProfileComparator& comp) { |
| - base::string16 name = |
| - profile.GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); |
| - |
| - base::string16 address = GetAddressFromProfile(profile, locale); |
| + const std::string& error, |
| + bool disabled_state) { |
| + std::unique_ptr<views::View> base_label = |
| + GetShippingAddressLabel(type, locale, profile, disabled_state); |
| - base::string16 phone = profile.GetInfo( |
| - autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); |
| + if (!error.empty()) { |
| + std::unique_ptr<views::Label> label = |
| + base::MakeUnique<views::Label>(base::UTF8ToUTF16(error)); |
| + label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR)); |
| + label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1)); |
| + // Error information is typically in red. |
| + label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( |
| + ui::NativeTheme::kColorId_AlertSeverityHigh)); |
| + base_label->AddChildView(label.release()); |
| + } |
| + return base_label; |
| +} |
| - base::string16 error = comp.GetStringForMissingShippingFields(profile); |
| +std::unique_ptr<views::View> GetShippingAddressLabelWithMissingInfo( |
| + AddressStyleType type, |
| + const std::string& locale, |
| + const autofill::AutofillProfile& profile, |
| + const PaymentsProfileComparator& comp) { |
| + std::unique_ptr<views::View> base_label = |
| + GetShippingAddressLabel(type, locale, profile, /*disabled_state=*/false); |
| - return GetProfileLabel(type, name, address, phone, error); |
| + base::string16 missing = comp.GetStringForMissingShippingFields(profile); |
| + if (!missing.empty()) { |
| + std::unique_ptr<views::Label> label = |
| + base::MakeUnique<views::Label>(missing); |
| + label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR)); |
| + label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1)); |
| + // Missing information typically has a nice shade of blue. |
| + label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( |
| + ui::NativeTheme::kColorId_LinkEnabled)); |
| + base_label->AddChildView(label.release()); |
| + } |
| + return base_label; |
| } |
| // TODO(anthonyvd): unit test the label layout. |
| @@ -287,9 +331,21 @@ std::unique_ptr<views::View> GetContactInfoLabel( |
| locale) |
| : base::string16(); |
| - base::string16 error = comp.GetStringForMissingContactFields(profile); |
| + std::unique_ptr<views::View> base_label = |
| + GetBaseProfileLabel(type, name, phone, email); |
| - return GetProfileLabel(type, name, phone, email, error); |
| + base::string16 missing = comp.GetStringForMissingContactFields(profile); |
| + if (!missing.empty()) { |
|
anthonyvd
2017/05/04 13:07:37
This entire block is the same as the one on line 2
Mathieu
2017/05/04 13:53:25
Done.
|
| + std::unique_ptr<views::Label> label = |
| + base::MakeUnique<views::Label>(missing); |
| + label->set_id(static_cast<int>(DialogViewID::PROFILE_LABEL_ERROR)); |
| + label->SetFontList(label->GetDefaultFontList().DeriveWithSizeDelta(-1)); |
| + // Missing information typically has a nice shade of blue. |
| + label->SetEnabledColor(label->GetNativeTheme()->GetSystemColor( |
| + ui::NativeTheme::kColorId_LinkEnabled)); |
| + base_label->AddChildView(label.release()); |
| + } |
| + return base_label; |
| } |
| std::unique_ptr<views::Border> CreatePaymentRequestRowBorder() { |