Commit 8f7db479 authored by Maria Villarreal's avatar Maria Villarreal Committed by Commit Bot

Eliminate hardcoded SkColorSet* use from textfield

This change moves STYLE_HINT from chrome/ to ui/ to be used as
textfield placeholder text color constant.

The current color used for the placeholder fails the contrast ratio.
For enabled state, this placeholder would have a color similar
to #8F9091 with a contrast ratio of 3.2. For disabled state, the
color would be similar to #B8BBBD with a ratio of 1.93.

With this change, the placeholder will have a text color constant
with a value similar to #5F6368 and a contrast ratio of 6.05.

Bug: 1056950
Change-Id: I66133508491fc79b2e91f1d8cb3013683d088722
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2113796Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Maria Villarreal <mavill@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#753093}
parent df7ef80c
...@@ -278,6 +278,7 @@ base::Optional<SkColor> SkColorFromColorId( ...@@ -278,6 +278,7 @@ base::Optional<SkColor> SkColorFromColorId(
case ui::NativeTheme::kColorId_TextfieldDefaultBackground: case ui::NativeTheme::kColorId_TextfieldDefaultBackground:
return GetBgColor(GtkCheckVersion(3, 20) ? "GtkTextView#textview.view" return GetBgColor(GtkCheckVersion(3, 20) ? "GtkTextView#textview.view"
: "GtkTextView.view"); : "GtkTextView.view");
case ui::NativeTheme::kColorId_TextfieldPlaceholderColor:
case ui::NativeTheme::kColorId_TextfieldReadOnlyColor: case ui::NativeTheme::kColorId_TextfieldReadOnlyColor:
return GetFgColor(GtkCheckVersion(3, 20) return GetFgColor(GtkCheckVersion(3, 20)
? "GtkTextView#textview.view:disabled #text" ? "GtkTextView#textview.view:disabled #text"
......
...@@ -67,9 +67,6 @@ enum ChromeTextStyle { ...@@ -67,9 +67,6 @@ enum ChromeTextStyle {
// Similar to views::style::STYLE_SECONDARY but with a monospaced typeface. // Similar to views::style::STYLE_SECONDARY but with a monospaced typeface.
STYLE_SECONDARY_MONOSPACED, STYLE_SECONDARY_MONOSPACED,
// "Hint" text, usually a line that gives context to something more important.
STYLE_HINT,
// A solid shade of red. // A solid shade of red.
STYLE_RED, STYLE_RED,
......
...@@ -113,9 +113,6 @@ SkColor ChromeTypographyProvider::GetColor(const views::View& view, ...@@ -113,9 +113,6 @@ SkColor ChromeTypographyProvider::GetColor(const views::View& view,
ui::NativeTheme::ColorId color_id; ui::NativeTheme::ColorId color_id;
switch (style) { switch (style) {
case STYLE_HINT:
color_id = ui::NativeTheme::kColorId_LabelSecondaryColor;
break;
case STYLE_RED: case STYLE_RED:
color_id = ui::NativeTheme::kColorId_AlertSeverityHigh; color_id = ui::NativeTheme::kColorId_AlertSeverityHigh;
break; break;
......
...@@ -49,7 +49,7 @@ PasswordAutoSignInView::PasswordAutoSignInView( ...@@ -49,7 +49,7 @@ PasswordAutoSignInView::PasswordAutoSignInView(
controller_.GetProfile()) controller_.GetProfile())
->GetURLLoaderFactoryForBrowserProcess() ->GetURLLoaderFactoryForBrowserProcess()
.get(), .get(),
STYLE_HINT, views::style::STYLE_PRIMARY); views::style::STYLE_HINT, views::style::STYLE_PRIMARY);
credential->SetEnabled(false); credential->SetEnabled(false);
AddChildView(credential); AddChildView(credential);
......
...@@ -376,7 +376,7 @@ std::unique_ptr<views::Label> CreateHintLabel( ...@@ -376,7 +376,7 @@ std::unique_ptr<views::Label> CreateHintLabel(
const base::string16& text, const base::string16& text,
gfx::HorizontalAlignment alignment) { gfx::HorizontalAlignment alignment) {
std::unique_ptr<views::Label> label = std::make_unique<views::Label>( std::unique_ptr<views::Label> label = std::make_unique<views::Label>(
text, views::style::CONTEXT_LABEL, STYLE_HINT); text, views::style::CONTEXT_LABEL, views::style::STYLE_HINT);
label->SetHorizontalAlignment(alignment); label->SetHorizontalAlignment(alignment);
return label; return label;
} }
......
...@@ -333,7 +333,7 @@ class PaymentSheetRowBuilder { ...@@ -333,7 +333,7 @@ class PaymentSheetRowBuilder {
DCHECK(accessible_content_.empty()); DCHECK(accessible_content_.empty());
std::unique_ptr<PreviewEliderLabel> content_view = std::unique_ptr<PreviewEliderLabel> content_view =
std::make_unique<PreviewEliderLabel>(preview_text, format_string, n, std::make_unique<PreviewEliderLabel>(preview_text, format_string, n,
STYLE_HINT); views::style::STYLE_HINT);
content_view->SetHorizontalAlignment(gfx::ALIGN_LEFT); content_view->SetHorizontalAlignment(gfx::ALIGN_LEFT);
return CreateWithButton(std::move(content_view), button_string, return CreateWithButton(std::move(content_view), button_string,
button_enabled); button_enabled);
......
...@@ -562,7 +562,7 @@ void ProfileMenuViewBase::SetProfileManagementHeading( ...@@ -562,7 +562,7 @@ void ProfileMenuViewBase::SetProfileManagementHeading(
// Add heading. // Add heading.
views::Label* label = profile_mgmt_heading_container_->AddChildView( views::Label* label = profile_mgmt_heading_container_->AddChildView(
std::make_unique<views::Label>(heading, views::style::CONTEXT_LABEL, std::make_unique<views::Label>(heading, views::style::CONTEXT_LABEL,
STYLE_HINT)); views::style::STYLE_HINT));
label->SetHorizontalAlignment(gfx::ALIGN_LEFT); label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
label->SetHandlesTooltips(false); label->SetHandlesTooltips(false);
} }
......
...@@ -108,6 +108,8 @@ ...@@ -108,6 +108,8 @@
NativeTheme::kColorId_TextfieldReadOnlyBackground) \ NativeTheme::kColorId_TextfieldReadOnlyBackground) \
E(kColorTextfieldDisabledForeground, \ E(kColorTextfieldDisabledForeground, \
NativeTheme::kColorId_TextfieldReadOnlyColor) \ NativeTheme::kColorId_TextfieldReadOnlyColor) \
E(kColorTextfieldPlaceholderForeground, \
NativeTheme::kColorId_TextfieldPlaceholderColor) \
E(kColorTextfieldForeground, NativeTheme::kColorId_TextfieldDefaultColor) \ E(kColorTextfieldForeground, NativeTheme::kColorId_TextfieldDefaultColor) \
E(kColorTextfieldSelectionBackground, \ E(kColorTextfieldSelectionBackground, \
NativeTheme::kColorId_TextfieldSelectionBackgroundFocused) \ NativeTheme::kColorId_TextfieldSelectionBackgroundFocused) \
......
...@@ -74,6 +74,8 @@ void AddUiColorMixers(ColorProvider* provider) { ...@@ -74,6 +74,8 @@ void AddUiColorMixers(ColorProvider* provider) {
GetColorWithMaxContrast(kColorTextfieldForeground); GetColorWithMaxContrast(kColorTextfieldForeground);
mixer[kColorTextfieldDisabledBackground] = {kColorPrimaryBackground}; mixer[kColorTextfieldDisabledBackground] = {kColorPrimaryBackground};
mixer[kColorTextfieldDisabledForeground] = {kColorDisabledForeground}; mixer[kColorTextfieldDisabledForeground] = {kColorDisabledForeground};
mixer[kColorTextfieldPlaceholderForeground] = {
kColorTextfieldDisabledForeground};
mixer[kColorTextfieldForeground] = {kColorPrimaryForeground}; mixer[kColorTextfieldForeground] = {kColorPrimaryForeground};
mixer[kColorTextfieldSelectionBackground] = {kColorTextSelectionBackground}; mixer[kColorTextfieldSelectionBackground] = {kColorTextSelectionBackground};
mixer[kColorTextfieldSelectionForeground] = {kColorTextfieldForeground}; mixer[kColorTextfieldSelectionForeground] = {kColorTextfieldForeground};
......
...@@ -391,6 +391,7 @@ SkColor GetDefaultColor(NativeTheme::ColorId color_id, ...@@ -391,6 +391,7 @@ SkColor GetDefaultColor(NativeTheme::ColorId color_id,
} }
case NativeTheme::kColorId_TextfieldReadOnlyBackground: case NativeTheme::kColorId_TextfieldReadOnlyBackground:
return SK_ColorWHITE; return SK_ColorWHITE;
case NativeTheme::kColorId_TextfieldPlaceholderColor:
case NativeTheme::kColorId_TextfieldReadOnlyColor: { case NativeTheme::kColorId_TextfieldReadOnlyColor: {
const SkColor bg = base_theme->GetSystemColor( const SkColor bg = base_theme->GetSystemColor(
NativeTheme::kColorId_TextfieldReadOnlyBackground, color_scheme); NativeTheme::kColorId_TextfieldReadOnlyBackground, color_scheme);
......
...@@ -116,6 +116,8 @@ NativeThemeColorIdToColorIdMap() { ...@@ -116,6 +116,8 @@ NativeThemeColorIdToColorIdMap() {
kColorTextfieldDisabledBackground}, kColorTextfieldDisabledBackground},
{NTCID::kColorId_TextfieldReadOnlyColor, {NTCID::kColorId_TextfieldReadOnlyColor,
kColorTextfieldDisabledForeground}, kColorTextfieldDisabledForeground},
{NTCID::kColorId_TextfieldPlaceholderColor,
kColorTextfieldPlaceholderForeground},
{NTCID::kColorId_TextfieldDefaultColor, kColorTextfieldForeground}, {NTCID::kColorId_TextfieldDefaultColor, kColorTextfieldForeground},
{NTCID::kColorId_TextfieldSelectionBackgroundFocused, {NTCID::kColorId_TextfieldSelectionBackgroundFocused,
kColorTextfieldSelectionBackground}, kColorTextfieldSelectionBackground},
......
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
/* Textfield */ \ /* Textfield */ \
OP(kColorId_TextfieldDefaultColor), \ OP(kColorId_TextfieldDefaultColor), \
OP(kColorId_TextfieldDefaultBackground), \ OP(kColorId_TextfieldDefaultBackground), \
OP(kColorId_TextfieldPlaceholderColor), \
OP(kColorId_TextfieldReadOnlyColor), \ OP(kColorId_TextfieldReadOnlyColor), \
OP(kColorId_TextfieldReadOnlyBackground), \ OP(kColorId_TextfieldReadOnlyBackground), \
OP(kColorId_TextfieldSelectionColor), \ OP(kColorId_TextfieldSelectionColor), \
......
...@@ -659,6 +659,7 @@ SkColor NativeThemeWin::GetPlatformHighContrastColor(ColorId color_id) const { ...@@ -659,6 +659,7 @@ SkColor NativeThemeWin::GetPlatformHighContrastColor(ColorId color_id) const {
case kColorId_TextfieldDefaultColor: case kColorId_TextfieldDefaultColor:
case kColorId_ButtonEnabledColor: case kColorId_ButtonEnabledColor:
case kColorId_UnfocusedBorderColor: case kColorId_UnfocusedBorderColor:
case kColorId_TextfieldPlaceholderColor:
case kColorId_TextfieldReadOnlyColor: case kColorId_TextfieldReadOnlyColor:
case kColorId_FocusedBorderColor: case kColorId_FocusedBorderColor:
case kColorId_TabTitleColorActive: case kColorId_TabTitleColorActive:
......
...@@ -2255,7 +2255,8 @@ void Textfield::PaintTextAndCursor(gfx::Canvas* canvas) { ...@@ -2255,7 +2255,8 @@ void Textfield::PaintTextAndCursor(gfx::Canvas* canvas) {
GetPlaceholderText(), GetPlaceholderText(),
placeholder_font_list_.has_value() ? placeholder_font_list_.value() placeholder_font_list_.has_value() ? placeholder_font_list_.value()
: GetFontList(), : GetFontList(),
placeholder_text_color_.value_or(SkColorSetA(GetTextColor(), 0x83)), placeholder_text_color_.value_or(style::GetColor(
*this, style::CONTEXT_TEXTFIELD, style::STYLE_HINT)),
render_text->display_rect(), placeholder_text_draw_flags); render_text->display_rect(), placeholder_text_draw_flags);
} }
......
...@@ -122,6 +122,7 @@ std::unique_ptr<View> CreateAllColorsView() { ...@@ -122,6 +122,7 @@ std::unique_ptr<View> CreateAllColorsView() {
InsertColorRow(layout, COLOR_LABEL_ARGS(kColorId_TabBottomBorder)); InsertColorRow(layout, COLOR_LABEL_ARGS(kColorId_TabBottomBorder));
InsertColorRow(layout, COLOR_LABEL_ARGS(kColorId_TextfieldDefaultColor)); InsertColorRow(layout, COLOR_LABEL_ARGS(kColorId_TextfieldDefaultColor));
InsertColorRow(layout, COLOR_LABEL_ARGS(kColorId_TextfieldDefaultBackground)); InsertColorRow(layout, COLOR_LABEL_ARGS(kColorId_TextfieldDefaultBackground));
InsertColorRow(layout, COLOR_LABEL_ARGS(kColorId_TextfieldPlaceholderColor));
InsertColorRow(layout, COLOR_LABEL_ARGS(kColorId_TextfieldReadOnlyColor)); InsertColorRow(layout, COLOR_LABEL_ARGS(kColorId_TextfieldReadOnlyColor));
InsertColorRow(layout, InsertColorRow(layout,
COLOR_LABEL_ARGS(kColorId_TextfieldReadOnlyBackground)); COLOR_LABEL_ARGS(kColorId_TextfieldReadOnlyBackground));
......
...@@ -77,6 +77,9 @@ enum TextStyle { ...@@ -77,6 +77,9 @@ enum TextStyle {
// Secondary text: Appears near the primary text. // Secondary text: Appears near the primary text.
STYLE_SECONDARY, STYLE_SECONDARY,
// "Hint" text, usually a line that gives context to something more important.
STYLE_HINT,
// Style for text that is displayed in a selection. // Style for text that is displayed in a selection.
STYLE_SELECTED, STYLE_SELECTED,
......
...@@ -97,6 +97,12 @@ ui::NativeTheme::ColorId GetMenuColorId(int style) { ...@@ -97,6 +97,12 @@ ui::NativeTheme::ColorId GetMenuColorId(int style) {
} }
} }
ui::NativeTheme::ColorId GetHintColorId(int context) {
return (context == style::CONTEXT_TEXTFIELD)
? ui::NativeTheme::kColorId_TextfieldPlaceholderColor
: ui::NativeTheme::kColorId_LabelSecondaryColor;
}
ui::NativeTheme::ColorId GetColorId(int context, int style) { ui::NativeTheme::ColorId GetColorId(int context, int style) {
if (style == style::STYLE_DIALOG_BUTTON_DEFAULT) if (style == style::STYLE_DIALOG_BUTTON_DEFAULT)
return ui::NativeTheme::kColorId_TextOnProminentButtonColor; return ui::NativeTheme::kColorId_TextOnProminentButtonColor;
...@@ -104,6 +110,8 @@ ui::NativeTheme::ColorId GetColorId(int context, int style) { ...@@ -104,6 +110,8 @@ ui::NativeTheme::ColorId GetColorId(int context, int style) {
return GetDisabledColorId(context); return GetDisabledColorId(context);
if (style == style::STYLE_LINK) if (style == style::STYLE_LINK)
return ui::NativeTheme::kColorId_LinkEnabled; return ui::NativeTheme::kColorId_LinkEnabled;
if (style == style::STYLE_HINT)
return GetHintColorId(context);
if (context == style::CONTEXT_BUTTON_MD) if (context == style::CONTEXT_BUTTON_MD)
return ui::NativeTheme::kColorId_ButtonEnabledColor; return ui::NativeTheme::kColorId_ButtonEnabledColor;
if (context == style::CONTEXT_LABEL && style == style::STYLE_SECONDARY) if (context == style::CONTEXT_LABEL && style == style::STYLE_SECONDARY)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment