Skip to content

Commit

Permalink
Bug 1344910, part 2 - Add a '-moz-win-accentcolortext' color keyword …
Browse files Browse the repository at this point in the history
…to color text that will be drawn over an accent color background. r=jimm

on a CLOSED TREE, because it failed to autoland before bug 1344917 landed.

MozReview-Commit-ID: 9l2NsQlewIJ
  • Loading branch information
jwatt authored and emilio committed Jun 30, 2017
1 parent 887232f commit 2f64952
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions layout/style/nsCSSKeywordList.h
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ CSS_KEY(-moz-win-media-toolbox, _moz_win_media_toolbox)
CSS_KEY(-moz-win-communications-toolbox, _moz_win_communications_toolbox)
CSS_KEY(-moz-win-browsertabbar-toolbox, _moz_win_browsertabbar_toolbox)
CSS_KEY(-moz-win-accentcolor, _moz_win_accentcolor)
CSS_KEY(-moz-win-accentcolortext, _moz_win_accentcolortext)
CSS_KEY(-moz-win-mediatext, _moz_win_mediatext)
CSS_KEY(-moz-win-communicationstext, _moz_win_communicationstext)
CSS_KEY(-moz-win-glass, _moz_win_glass)
Expand Down
1 change: 1 addition & 0 deletions layout/style/nsCSSProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,7 @@ const KTableEntry nsCSSProps::kColorKTable[] = {
{ eCSSKeyword__moz_visitedhyperlinktext, NS_COLOR_MOZ_VISITEDHYPERLINKTEXT },
{ eCSSKeyword_currentcolor, NS_COLOR_CURRENTCOLOR },
{ eCSSKeyword__moz_win_accentcolor, LookAndFeel::eColorID__moz_win_accentcolor },
{ eCSSKeyword__moz_win_accentcolortext, LookAndFeel::eColorID__moz_win_accentcolortext },
{ eCSSKeyword__moz_win_mediatext, LookAndFeel::eColorID__moz_win_mediatext },
{ eCSSKeyword__moz_win_communicationstext, LookAndFeel::eColorID__moz_win_communicationstext },
{ eCSSKeyword__moz_nativehyperlinktext, LookAndFeel::eColorID__moz_nativehyperlinktext },
Expand Down
2 changes: 2 additions & 0 deletions widget/LookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class LookAndFeel

// accent color for title bar
eColorID__moz_win_accentcolor,
// color from drawing text over the accent color
eColorID__moz_win_accentcolortext,
// media rebar text
eColorID__moz_win_mediatext,
// communications rebar text
Expand Down
2 changes: 2 additions & 0 deletions widget/nsXPLookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,8 @@ nsXPLookAndFeel::GetStandinForNativeColor(ColorID aID)
case eColorID__moz_win_accentcolor:
// Seems to be the default color (hardcoded because of bug 1065998)
result = NS_RGB(0x9E, 0x9E, 0x9E); break;
case eColorID__moz_win_accentcolortext:
result = NS_RGB(0x00, 0x00, 0x00); break;
case eColorID__moz_win_mediatext:
result = NS_RGB(0xFF, 0xFF, 0xFF); break;
case eColorID__moz_win_communicationstext:
Expand Down
32 changes: 32 additions & 0 deletions widget/windows/nsLookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
// Seems to be the default color (hardcoded because of bug 1065998)
aColor = NS_RGB(158, 158, 158);
return NS_OK;
case eColorID__moz_win_accentcolortext:
res = GetAccentColorText(aColor);
if (NS_SUCCEEDED(res)) {
return res;
}
aColor = NS_RGB(0, 0, 0);
return NS_OK;
case eColorID__moz_win_mediatext:
if (IsAppThemed()) {
res = ::GetColorFromTheme(eUXMediaToolbar,
Expand Down Expand Up @@ -802,3 +809,28 @@ nsLookAndFeel::GetAccentColor(nscolor& aColor)

return rv;
}

/* static */ nsresult
nsLookAndFeel::GetAccentColorText(nscolor& aColor)
{
nscolor accentColor;
nsresult rv = GetAccentColor(accentColor);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

// We want the color that we return for text that will be drawn over
// a background that has the accent color to have good contrast with
// the accent color. Windows itself uses either white or black text
// depending on how light or dark the accent color is. We do the same
// here based on the luminance of the accent color with a threshhold
// value that seem consistent with what Windows does.

float luminance = 0.2125f * NS_GET_R(accentColor) +
0.7154f * NS_GET_G(accentColor) +
0.0721f * NS_GET_B(accentColor);

aColor = (luminance <= 110) ? NS_RGB(255, 255, 255) : NS_RGB(0, 0, 0);

return NS_OK;
}
9 changes: 9 additions & 0 deletions widget/windows/nsLookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ class nsLookAndFeel: public nsXPLookAndFeel {
*/
nsresult GetAccentColor(nscolor& aColor);

/**
* If the Windows accent color from the Windows settings is set
* to apply to the title bar, this computes the color that should
* be used for text that is to be written over a background that has
* the accent color. Otherwise, (if the accent color should not
* apply to the title bar) this returns an error code.
*/
nsresult GetAccentColorText(nscolor& aColor);

// Content process cached values that get shipped over from the browser
// process.
int32_t mUseAccessibilityTheme;
Expand Down

0 comments on commit 2f64952

Please sign in to comment.