Bug 1513401 - Increase contrast of unsaturated selection colors in nsLookAndFeel.mm. r=mstange, a=RyanVM
authorTim Nguyen <ntim.bugs@gmail.com>
Fri, 14 Dec 2018 19:00:18 +0000
changeset 506237 7cc9c0386e876a8768f0b78fd11372851a29c3a1
parent 506236 8f78e91a61b8a533c282ce009be7ed195c1a03b9
child 506238 5281e679d23227f2074b569ee6532cb221634461
push id10340
push userryanvm@gmail.com
push dateSat, 15 Dec 2018 19:26:47 +0000
treeherdermozilla-beta@7cc9c0386e87 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, RyanVM
bugs1513401
milestone65.0
Bug 1513401 - Increase contrast of unsaturated selection colors in nsLookAndFeel.mm. r=mstange, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D14566
widget/cocoa/nsLookAndFeel.mm
--- a/widget/cocoa/nsLookAndFeel.mm
+++ b/widget/cocoa/nsLookAndFeel.mm
@@ -149,17 +149,25 @@ nscolor
 nsLookAndFeel::ProcessSelectionBackground(nscolor aColor)
 {
   uint16_t hue, sat, value;
   uint8_t alpha;
   nscolor resultColor = aColor;
   NS_RGB2HSV(resultColor, hue, sat, value, alpha);
   int factor = 2;
   alpha = alpha / factor;
-  sat = sat * factor;
+  if (sat > 0) {
+    // The color is not a shade of grey, restore the saturation taken away by
+    // the transparency.
+    sat = sat * factor;
+  } else {
+    // The color is a shade of grey, find the value that looks equivalent
+    // on a white background with the given opacity.
+    value = 255 - (255 - value) * factor;
+  }
   NS_HSV2RGB(resultColor, hue, sat, value, alpha);
   return resultColor;
 }
 
 nsresult
 nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
 {
   EnsureInit();