Commit 8275c264 authored by ellyjones's avatar ellyjones Committed by Commit bot

views: refactor away PlatformStyle::BackgroundColorForMdButton

This change:
1) Introduces color_utils::ImplicitAlphaBlend, which does an alpha
   blend using the alpha of the foreground color;
2) Introduces a NativeTheme color ID for the shading of a pressed
   button;
3) Uses ImplicitAlphaBlend to blend that shade, instead of calling
   into PlatformStyle;
4) Deletes PlatformStyle::BackgroundColorForMdButton

BUG=644543

Review-Url: https://codereview.chromium.org/2319313003
Cr-Commit-Position: refs/heads/master@{#417366}
parent 7d69521b
......@@ -329,6 +329,8 @@ SkColor NativeThemeGtk2::GetSystemColor(ColorId color_id) const {
return GetSystemColor(kColorId_LinkEnabled);
case kColorId_TextOnCallToActionColor:
return GetTextColor(GetLabel(), SELECTED);
case kColorId_ButtonPressedShade:
return SK_ColorTRANSPARENT;
// Textfield
case kColorId_TextfieldDefaultColor:
......
......@@ -284,6 +284,11 @@ SkColor AlphaBlend(SkColor foreground, SkColor background, SkAlpha alpha) {
static_cast<int>(std::round(b)));
}
SkColor GetResultingPaintColor(SkColor foreground, SkColor background) {
return AlphaBlend(SkColorSetA(foreground, SK_AlphaOPAQUE), background,
SkColorGetA(foreground));
}
bool IsDark(SkColor color) {
return GetLuma(color) < 128;
}
......
......@@ -94,6 +94,11 @@ GFX_EXPORT double CalculateBoringScore(const SkBitmap& bitmap);
GFX_EXPORT SkColor AlphaBlend(SkColor foreground, SkColor background,
SkAlpha alpha);
// Returns the color that results from painting |foreground| on top of
// |background|.
GFX_EXPORT SkColor GetResultingPaintColor(SkColor foreground,
SkColor background);
// Returns true if the luma of |color| is closer to black than white.
GFX_EXPORT bool IsDark(SkColor color);
......
......@@ -155,6 +155,7 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
static const SkColor kBlueButtonShadowColor = SkColorSetRGB(0x53, 0x8C, 0xEA);
static const SkColor kCallToActionColor = gfx::kGoogleBlue500;
static const SkColor kTextOnCallToActionColor = SK_ColorWHITE;
static const SkColor kButtonPressedShade = SK_ColorTRANSPARENT;
// MenuItem:
static const SkColor kMenuBackgroundColor = SK_ColorWHITE;
static const SkColor kMenuHighlightBackgroundColor =
......@@ -291,6 +292,8 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
return kCallToActionColor;
case NativeTheme::kColorId_TextOnCallToActionColor:
return kTextOnCallToActionColor;
case NativeTheme::kColorId_ButtonPressedShade:
return kButtonPressedShade;
// MenuItem
case NativeTheme::kColorId_MenuBorderColor:
......
......@@ -259,6 +259,7 @@ class NATIVE_THEME_EXPORT NativeTheme {
kColorId_ButtonHighlightColor,
kColorId_ButtonHoverColor,
kColorId_ButtonHoverBackgroundColor,
kColorId_ButtonPressedShade,
kColorId_BlueButtonEnabledColor,
kColorId_BlueButtonDisabledColor,
kColorId_BlueButtonPressedColor,
......
......@@ -91,6 +91,7 @@ SkColor NativeThemeDarkAura::GetSystemColor(ColorId color_id) const {
// Intentional pass-throughs to NativeThemeAura.
case kColorId_TextOnCallToActionColor:
case kColorId_ButtonPressedShade:
case kColorId_ResultsTableHoveredBackground:
case kColorId_ResultsTableSelectedBackground:
case kColorId_ResultsTableNormalUrl:
......
......@@ -126,7 +126,8 @@ SkColor NativeThemeMac::ApplySystemControlTint(SkColor color) {
}
SkColor NativeThemeMac::GetSystemColor(ColorId color_id) const {
// Even with --secondary-ui-md, menus use the platform colors and styling.
// Even with --secondary-ui-md, menus use the platform colors and styling, and
// Mac has a couple of specific color overrides.
switch (color_id) {
case kColorId_EnabledMenuItemForegroundColor:
return NSSystemColorToSkColor([NSColor controlTextColor]);
......@@ -145,6 +146,9 @@ SkColor NativeThemeMac::GetSystemColor(ColorId color_id) const {
: kMenuSeparatorColor;
case kColorId_MenuBorderColor:
return kMenuBorderColor;
case kColorId_ButtonPressedShade:
return SkColorSetA(SK_ColorBLACK, 0x08);
default:
break;
}
......
......@@ -312,9 +312,11 @@ void MdTextButton::UpdateColors() {
bg_color = color_utils::BlendTowardOppositeLuma(text_color, 0xD8);
}
// TODO(ellyjones): Excise this, in favor of a helper function wrapping
// |color_utils::AlphaBlend| and a new NativeTheme color constant.
bg_color = PlatformStyle::BackgroundColorForMdButton(bg_color, state());
if (state() == STATE_PRESSED) {
SkColor shade =
theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonPressedShade);
bg_color = color_utils::GetResultingPaintColor(shade, bg_color);
}
const SkAlpha kStrokeOpacity = 0x1A;
SkColor stroke_color = (is_cta_ || color_utils::IsDark(text_color))
......
......@@ -89,12 +89,6 @@ SkColor PlatformStyle::TextColorForButton(
return color_by_state[button.state()];
}
SkColor PlatformStyle::BackgroundColorForMdButton(
SkColor color,
Button::ButtonState state) {
return color;
}
#endif // OS_MACOSX
#if !defined(DESKTOP_LINUX) && !defined(OS_MACOSX)
......
......@@ -88,11 +88,6 @@ class VIEWS_EXPORT PlatformStyle {
static void ApplyLabelButtonTextStyle(Label* label,
ButtonColorByState* color_by_state);
// Returns the background color that should be used for an MdTextButton or
// other MD controls when in the given state.
static SkColor BackgroundColorForMdButton(SkColor color,
Button::ButtonState state);
// Applies the current system theme to the default border created by |button|.
static std::unique_ptr<Border> CreateThemedLabelButtonBorder(
LabelButton* button);
......
......@@ -96,14 +96,4 @@ void PlatformStyle::ApplyLabelButtonTextStyle(
theme->GetSystemColor(ui::NativeTheme::kColorId_ButtonHighlightColor);
}
// static
SkColor PlatformStyle::BackgroundColorForMdButton(
SkColor color,
Button::ButtonState state) {
// Per Harmony specs: Pressed state on Mac is + #000 at 0.05 alpha.
if (state == Button::STATE_PRESSED)
return color_utils::AlphaBlend(SK_ColorBLACK, color, 0x08);
return color;
}
} // namespace views
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