Bug 1381833 - Port bug 1279717 to TB [introduce a Color.jsm module that implements common color math operations in a single place]. r=jorgk
authorRichard Marti <richard.marti@gmail.com>
Tue, 18 Jul 2017 16:11:49 +0200
changeset 28458 36c79355c7779d7198aa242e94f58738b6e467ca
parent 28457 580c3bee501632ffd24d1b0d2b37da6bdbe4fffa
child 28459 c581127bdaff3f5f3cfbee6af84f5e7290a79773
push id1986
push userclokep@gmail.com
push dateWed, 02 Aug 2017 14:43:31 +0000
treeherdercomm-beta@b51c9adf2c9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk
bugs1381833, 1279717
Bug 1381833 - Port bug 1279717 to TB [introduce a Color.jsm module that implements common color math operations in a single place]. r=jorgk
mail/base/content/msgMail3PaneWindow.js
--- a/mail/base/content/msgMail3PaneWindow.js
+++ b/mail/base/content/msgMail3PaneWindow.js
@@ -12,16 +12,17 @@ Components.utils.import("resource:///mod
 Components.utils.import("resource:///modules/mailInstrumentation.js");
 Components.utils.import("resource:///modules/mailnewsMigrator.js");
 Components.utils.import("resource:///modules/mailServices.js");
 Components.utils.import("resource:///modules/msgDBCacheManager.js");
 Components.utils.import("resource:///modules/sessionStoreManager.js");
 Components.utils.import("resource:///modules/summaryFrameManager.js");
 Components.utils.import("resource:///modules/MailUtils.js");
 Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource://gre/modules/Color.jsm");
 
 /* This is where functions related to the 3 pane window are kept */
 
 // from MailNewsTypes.h
 var nsMsgKey_None = 0xFFFFFFFF;
 var nsMsgViewIndex_None = 0xFFFFFFFF;
 var kMailCheckOncePrefName = "mail.startup.enabledMailCheckOnce";
 
@@ -352,33 +353,20 @@ function OnLoadMessenger()
   // in delayedOnLoadMessenger...
   UpdateMailPaneConfig(false);
   document.loadBindingDocument('chrome://global/content/bindings/textbox.xml');
 
 #ifdef XP_WIN
   // On Win8 set an attribute when the window frame color is too dark for black text.
   if (window.matchMedia("(-moz-os-version: windows-win8)").matches &&
       window.matchMedia("(-moz-windows-default-theme)").matches) {
-    let windows8WindowFrameColor = Cu.import("resource:///modules/Windows8WindowFrameColor.jsm", {}).Windows8WindowFrameColor;
-    let windowFrameColor = windows8WindowFrameColor.get();
-
-    // Formula from W3C's WCAG 2.0 spec's color ratio and relative luminance,
-    // section 1.3.4, http://www.w3.org/TR/WCAG20/ .
-    windowFrameColor = windowFrameColor.map((color) => {
-      if (color <= 10) {
-        return color / 255 / 12.92;
-      }
-      return Math.pow(((color / 255) + 0.055) / 1.055, 2.4);
-    });
-    let backgroundLuminance = windowFrameColor[0] * 0.2126 +
-                              windowFrameColor[1] * 0.7152 +
-                              windowFrameColor[2] * 0.0722;
-    let foregroundLuminance = 0; // Default to black for foreground text.
-    let contrastRatio = (backgroundLuminance + 0.05) / (foregroundLuminance + 0.05);
-    if (contrastRatio < 3) {
+    let windowFrameColor = new Color(...Cu.import("resource:///modules/Windows8WindowFrameColor.jsm", {})
+                                          .Windows8WindowFrameColor.get());
+    // Default to black for foreground text.
+    if (!windowFrameColor.isContrastRatioAcceptable(new Color(0, 0, 0))) {
       document.documentElement.setAttribute("darkwindowframe", "true");
     }
   }
 #endif
 
   ToolbarIconColor.init();
 
   // Set a sane starting width/height for all resolutions on new profiles.