Bug 988191 - change to WCAG algorithm for titlebar font, r=jaws

This commit is contained in:
Gijs Kruitbosch 2014-03-29 22:08:20 +00:00
parent 45def71ffd
commit 0a7c156907

View File

@ -1187,22 +1187,20 @@ var gBrowserInit = {
let windows8WindowFrameColor = Cu.import("resource:///modules/Windows8WindowFrameColor.jsm", {}).Windows8WindowFrameColor;
let windowFrameColor = windows8WindowFrameColor.get();
// Formula from W3C Techniques For Accessibility Evaluation And
// Repair Tools, Section 2.2 http://www.w3.org/TR/AERT#color
let brightnessThreshold = 125;
let colorThreshold = 500;
let bY = windowFrameColor[0] * .299 +
windowFrameColor[1] * .587 +
windowFrameColor[2] * .114;
let fY = 0; // Default to black for foreground text.
let brightnessDifference = Math.abs(bY - fY);
// Color difference calculation is simplified because black is 0 for R,G,B.
let colorDifference = windowFrameColor[0] + windowFrameColor[1] + windowFrameColor[2];
// Brightness is defined within {0, 255}. Set an attribute
// if the window frame color doesn't reach these thresholds
// so the theme can be adjusted for readability.
if (brightnessDifference < brightnessThreshold && colorDifference < colorThreshold) {
// 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) {
document.documentElement.setAttribute("darkwindowframe", "true");
}
}