Bug 298357 Switch to coloring the background of events instead of the font. r=dmose

git-svn-id: svn://10.0.0.236/trunk@181780 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
jminta%gmail.com
2005-10-07 17:51:22 +00:00
parent 2c6d4a8622
commit 552c2b397b
4 changed files with 35 additions and 34 deletions

View File

@@ -70,7 +70,6 @@ calendar-event-box {
}
.calendar-event-box-container {
background: #4e84c2;
padding: 2px;
overflow: hidden;
}

View File

@@ -38,10 +38,12 @@ function updateStyleSheetForCalendar(aCalendar)
}
var color = getCalendarManager().getCalendarPref(aCalendar, 'color');
// This color looks nice with the gripbars, etc.
if (!color)
color = "black";
color = "#4e84c2";
rule.style.color = color;
rule.style.backgroundColor = color;
rule.style.color = getContrastingTextColor(color);
}
function addCalendarToTree(aCalendar)

View File

@@ -1249,37 +1249,6 @@ function CalendarToolboxCustomizeDone(aToolboxChanged)
window.focus();
}
/**
* Pick whichever of "black" or "white" will look better when used as a text
* color against a background of bgColor.
*
* @param bgColor the background color as a "#RRGGBB" string
*/
function getContrastingTextColor(bgColor)
{
var calcColor = bgColor.replace(/#/g, "");
var red = parseInt(calcColor.substring(0, 2), 16);
var green = parseInt(calcColor.substring(2, 4), 16);
var blue = parseInt(calcColor.substring(4, 6), 16);
// Calculate the L(ightness) value of the HSL color system.
// L = (max(R, G, B) + min(R, G, B)) / 2
var max = Math.max(Math.max(red, green), blue);
var min = Math.min(Math.min(red, green), blue);
var lightness = (max + min) / 2;
// Consider all colors with less than 50% Lightness as dark colors
// and use white as the foreground color; otherwise use black.
// Actually we use a threshold a bit below 50%, so colors like
// #FF0000, #00FF00 and #0000FF still get black text which looked
// better when we tested this.
if (lightness < 120) {
return "white";
}
return "black";
}
var gTransactionMgr = Components.classes["@mozilla.org/transactionmanager;1"]
.createInstance(Components.interfaces.nsITransactionManager);
function doTransaction(aAction, aItem, aCalendar, aOldItem, aListener) {

View File

@@ -321,3 +321,34 @@ function guessSystemTimezone()
// Everything failed, so this is our only option.
return "floating";
}
/**
* Pick whichever of "black" or "white" will look better when used as a text
* color against a background of bgColor.
*
* @param bgColor the background color as a "#RRGGBB" string
*/
function getContrastingTextColor(bgColor)
{
var calcColor = bgColor.replace(/#/g, "");
var red = parseInt(calcColor.substring(0, 2), 16);
var green = parseInt(calcColor.substring(2, 4), 16);
var blue = parseInt(calcColor.substring(4, 6), 16);
// Calculate the L(ightness) value of the HSL color system.
// L = (max(R, G, B) + min(R, G, B)) / 2
var max = Math.max(Math.max(red, green), blue);
var min = Math.min(Math.min(red, green), blue);
var lightness = (max + min) / 2;
// Consider all colors with less than 50% Lightness as dark colors
// and use white as the foreground color; otherwise use black.
// Actually we use a threshold a bit below 50%, so colors like
// #FF0000, #00FF00 and #0000FF still get black text which looked
// better when we tested this.
if (lightness < 120) {
return "white";
}
return "black";
}