summaryrefslogtreecommitdiffstats
path: root/widget
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2017-07-19 16:24:08 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-02-04 20:40:20 +0100
commit3019e0ff28bfd2d2a65b59501e582bb26356c6d7 (patch)
treed3a5f32d620fe242aa518a8823edb78b5b32851b /widget
parent3af2c1c8795312d6cbb947b50bc1912df0589e0e (diff)
downloadUXP-3019e0ff28bfd2d2a65b59501e582bb26356c6d7.tar
UXP-3019e0ff28bfd2d2a65b59501e582bb26356c6d7.tar.gz
UXP-3019e0ff28bfd2d2a65b59501e582bb26356c6d7.tar.lz
UXP-3019e0ff28bfd2d2a65b59501e582bb26356c6d7.tar.xz
UXP-3019e0ff28bfd2d2a65b59501e582bb26356c6d7.zip
Split out the check for accent color luminance.
Diffstat (limited to 'widget')
-rw-r--r--widget/windows/nsLookAndFeel.cpp20
-rw-r--r--widget/windows/nsLookAndFeel.h8
2 files changed, 20 insertions, 8 deletions
diff --git a/widget/windows/nsLookAndFeel.cpp b/widget/windows/nsLookAndFeel.cpp
index 63af65306..5c0358bd9 100644
--- a/widget/windows/nsLookAndFeel.cpp
+++ b/widget/windows/nsLookAndFeel.cpp
@@ -762,6 +762,16 @@ nsLookAndFeel::GetAccentColor(nscolor& aColor)
return rv;
}
+bool
+nsLookAndFeel::AccentColorIsDark(nscolor aColor)
+{
+ float luminance = (NS_GET_R(aColor) * 2 +
+ NS_GET_G(aColor) * 5 +
+ NS_GET_B(aColor)) / 8;
+
+ return luminance <= 128;
+}
+
/* static */ nsresult
nsLookAndFeel::GetAccentColorText(nscolor& aColor)
{
@@ -775,15 +785,9 @@ nsLookAndFeel::GetAccentColorText(nscolor& aColor)
// 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 and formula that are specified in the UWP guidelines.
- // See: https://docs.microsoft.com/en-us/windows/uwp/style/color
-
- float luminance = (NS_GET_R(accentColor) * 2 +
- NS_GET_G(accentColor) * 5 +
- NS_GET_B(accentColor)) / 8;
+ // here based on the luminance of the accent color.
- aColor = (luminance <= 128) ? NS_RGB(255, 255, 255) : NS_RGB(0, 0, 0);
+ aColor = AccentColorIsDark(accentColor) ? NS_RGB(255, 255, 255) : NS_RGB(0, 0, 0);
return NS_OK;
}
diff --git a/widget/windows/nsLookAndFeel.h b/widget/windows/nsLookAndFeel.h
index 29b6f4b78..6200541f5 100644
--- a/widget/windows/nsLookAndFeel.h
+++ b/widget/windows/nsLookAndFeel.h
@@ -68,6 +68,14 @@ private:
nsresult GetAccentColor(nscolor& aColor);
/**
+ * Determines whether the Windows accent color is considered dark
+ * with a threshhold value and formula that are specified in the
+ * UWP guidelines.
+ * See: https://docs.microsoft.com/en-us/windows/uwp/style/color
+ */
+ bool AccentColorIsDark(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