зеркало из https://github.com/mozilla/pjs.git
Bug 344452 Don't add universal style rules for calendars and categories, r=dmose
This commit is contained in:
Родитель
179829f9ba
Коммит
74efc308ff
|
@ -50,7 +50,7 @@
|
|||
|
||||
<binding id="calendar-month-day-box-item" extends="chrome://calendar/content/calendar-view-core.xml#calendar-editable-item">
|
||||
<content>
|
||||
<xul:hbox flex="1">
|
||||
<xul:hbox flex="1" class="calendar-item">
|
||||
<xul:label anonid="item-label" class="calendar-month-day-box-item-label" xbl:inherits="context"/>
|
||||
<xul:vbox class="calendar-event-box-container" xbl:inherits="context" flex="1" align="left">
|
||||
<xul:label anonid="event-name" style="margin: 0px;" flex="1" crop="end"/>
|
||||
|
|
|
@ -1458,7 +1458,7 @@
|
|||
|
||||
var eventbox = document.getAnonymousElementByAttribute(this, "anonid", "eventbox");
|
||||
eventbox.setAttribute("orient", val);
|
||||
eventbox.setAttribute("class", "calendar-event-box-" + val);
|
||||
eventbox.setAttribute("class", "calendar-item calendar-event-box-" + val);
|
||||
var gb1 = document.getAnonymousElementByAttribute(this, "anonid", "gripbar1");
|
||||
gb1.parentorient = val;
|
||||
var gb2 = document.getAnonymousElementByAttribute(this, "anonid", "gripbar2");
|
||||
|
|
|
@ -47,7 +47,8 @@
|
|||
|
||||
<binding id="calendar-editable-item">
|
||||
<content>
|
||||
<xul:vbox class="calendar-event-box-container" xbl:inherits="context" flex="1" align="left">
|
||||
<xul:vbox class="calendar-event-box-container calendar-item"
|
||||
xbl:inherits="context" flex="1" align="left">
|
||||
<xul:label anonid="event-name" style="margin: 0px;" flex="1" crop="right"/>
|
||||
<xul:textbox class="plain" style="background: transparent !important"
|
||||
anonid="event-name-textbox" crop="right" hidden="true" wrap="true"/>
|
||||
|
|
|
@ -183,3 +183,68 @@ function getViewDeck() {
|
|||
function currentView() {
|
||||
return getViewDeck().selectedPanel;
|
||||
}
|
||||
|
||||
// Returns the actual style sheet object with the specified path. Callers are
|
||||
// responsible for any caching they may want to do.
|
||||
function getStyleSheet(aStyleSheetPath) {
|
||||
for each (var sheet in document.styleSheets) {
|
||||
if (sheet.href == aStyleSheetPath) {
|
||||
return sheet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Updates the style rules for a particular object. If the object is a
|
||||
// category (and hence doesn't have a uri), we set the border color. If
|
||||
// it's a calendar, we set the background color
|
||||
function updateStyleSheetForObject(aObject, aSheet) {
|
||||
var name;
|
||||
if (aObject.uri)
|
||||
name = aObject.uri.spec;
|
||||
else
|
||||
name = aObject.replace(' ','_');
|
||||
|
||||
// Returns an equality selector for calendars (which have a uri), since an
|
||||
// event can only belong to one calendar. For categories, however, returns
|
||||
// the ~= selector which matches anything in a space-separated list.
|
||||
function selectorForObject(name)
|
||||
{
|
||||
if (aObject.uri)
|
||||
return '.calendar-item[item-calendar="' + name + '"]';
|
||||
return '.calendar-item[item-category~="' + name + '"]';
|
||||
}
|
||||
|
||||
function getRuleForObject(name)
|
||||
{
|
||||
for (var i = 0; i < aSheet.cssRules.length; i++) {
|
||||
var rule = aSheet.cssRules[i];
|
||||
if (rule.selectorText && (rule.selectorText == selectorForObject(name)))
|
||||
return rule;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
var rule = getRuleForObject(name);
|
||||
if (!rule) {
|
||||
aSheet.insertRule(selectorForObject(name) + ' { }',
|
||||
aSheet.cssRules.length);
|
||||
rule = aSheet.cssRules[aSheet.cssRules.length-1];
|
||||
}
|
||||
|
||||
var color;
|
||||
if (aObject.uri) {
|
||||
color = getCalendarManager().getCalendarPref(aObject, 'color');
|
||||
if (!color)
|
||||
color = "#A8C2E1";
|
||||
rule.style.backgroundColor = color;
|
||||
rule.style.color = getContrastingTextColor(color);
|
||||
return;
|
||||
}
|
||||
var categoryPrefBranch = prefService.getBranch("calendar.category.color.");
|
||||
try {
|
||||
color = categoryPrefBranch.getCharPref(aObject);
|
||||
}
|
||||
catch(ex) { return; }
|
||||
|
||||
rule.style.border = color + " solid 2px";
|
||||
}
|
||||
|
|
|
@ -2,50 +2,7 @@
|
|||
// calendar-management.js
|
||||
//
|
||||
|
||||
var calendarPrefStyleSheet = null;
|
||||
for each(sheet in document.styleSheets) {
|
||||
if (sheet.href == "chrome://lightning/skin/lightning.css") {
|
||||
calendarPrefStyleSheet = sheet;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!calendarPrefStyleSheet)
|
||||
Components.utils.reportError("Couldn't find the lightning style sheet.")
|
||||
|
||||
function updateStyleSheetForCalendar(aCalendar)
|
||||
{
|
||||
var spec = aCalendar.uri.spec;
|
||||
var cpss = calendarPrefStyleSheet;
|
||||
function selectorForCalendar(spec)
|
||||
{
|
||||
return '*[item-calendar="' + spec + '"]';
|
||||
}
|
||||
|
||||
function getRuleForCalendar(spec)
|
||||
{
|
||||
for (var i = 0; i < cpss.cssRules.length; i++) {
|
||||
var rule = cpss.cssRules[i];
|
||||
if (rule.selectorText == selectorForCalendar(spec))
|
||||
return rule;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
var rule = getRuleForCalendar(spec);
|
||||
if (!rule) {
|
||||
cpss.insertRule(selectorForCalendar(spec) + ' { }', 0);
|
||||
rule = cpss.cssRules[0];
|
||||
}
|
||||
|
||||
var color = getCalendarManager().getCalendarPref(aCalendar, 'color');
|
||||
// This color looks nice with the gripbars, etc.
|
||||
if (!color)
|
||||
color = "#A8C2E1";
|
||||
|
||||
rule.style.backgroundColor = color;
|
||||
rule.style.color = getContrastingTextColor(color);
|
||||
}
|
||||
|
||||
var gCachedStyleSheet;
|
||||
function addCalendarToTree(aCalendar)
|
||||
{
|
||||
var boxobj = document.getElementById("calendarTree").treeBoxObject;
|
||||
|
@ -58,8 +15,12 @@ function addCalendarToTree(aCalendar)
|
|||
sip.dataIID = Components.interfaces.calICalendar;
|
||||
|
||||
boxobj.rowCountChanged(getCalendars().indexOf(sip.data), 1);
|
||||
|
||||
updateStyleSheetForCalendar(aCalendar);
|
||||
|
||||
if (!gCachedStyleSheet) {
|
||||
gCachedStyleSheet = getStyleSheet("chrome://calendar/content/calendar-view-bindings.css");
|
||||
}
|
||||
alert("1"+gCachedStyleSheet);
|
||||
updateStyleSheetForObject(aCalendar, gCachedStyleSheet);
|
||||
}
|
||||
|
||||
function removeCalendarFromTree(aCalendar)
|
||||
|
@ -101,7 +62,10 @@ var ltnCalendarManagerObserver = {
|
|||
},
|
||||
|
||||
onCalendarPrefSet: function(aCalendar, aName, aValue) {
|
||||
updateStyleSheetForCalendar(aCalendar);
|
||||
if (!gCachedStyleSheet) {
|
||||
gCachedStyleSheet = getStyleSheet("chrome://calendar/content/calendar-view-bindings.css");
|
||||
}
|
||||
updateStyleSheetForObject(aCalendar, gCachedStyleSheet);
|
||||
},
|
||||
|
||||
onCalendarPrefDeleting: function(aCalendar, aName) {
|
||||
|
|
|
@ -109,7 +109,7 @@ var calCalendarManagerObserver = {
|
|||
var colorCell = item.childNodes[1];
|
||||
colorCell.style.background = aValue;
|
||||
}
|
||||
updateStyleSheetForObject(aCalendar);
|
||||
updateStyleSheetForObject(aCalendar, gCachedStyleSheet);
|
||||
} else if (aName == 'name') {
|
||||
if (item) {
|
||||
var nameCell = item.childNodes[2];
|
||||
|
@ -124,7 +124,7 @@ var calCalendarManagerObserver = {
|
|||
}
|
||||
setCalendarManagerUI();
|
||||
if (aName == 'color')
|
||||
updateStyleSheetForObject(aCalendar);
|
||||
updateStyleSheetForObject(aCalendar, gCachedStyleSheet);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -317,27 +317,17 @@ function reloadCalendars()
|
|||
getCompositeCalendar().refresh();
|
||||
}
|
||||
|
||||
function getCalendarStyleSheet() {
|
||||
var calStyleSheet = null;
|
||||
for (var i = 0; i < document.styleSheets.length; i++) {
|
||||
if (document.styleSheets[i].href.match(
|
||||
/chrome.*\/skin.*\/calendar.css$/ )) {
|
||||
calStyleSheet = document.styleSheets[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return calStyleSheet;
|
||||
}
|
||||
|
||||
var gCachedStyleSheet;
|
||||
function initColors() {
|
||||
var calendars = getCalendarManager().getCalendars({});
|
||||
gCachedStyleSheet = getStyleSheet("chrome://calendar/content/calendar-view-bindings.css");
|
||||
for (var j in calendars)
|
||||
updateStyleSheetForObject(calendars[j]);
|
||||
updateStyleSheetForObject(calendars[j], gCachedStyleSheet);
|
||||
|
||||
var categoryPrefBranch = prefService.getBranch("calendar.category.color.");
|
||||
var prefArray = categoryPrefBranch.getChildList("", {});
|
||||
for (var i = 0; i < prefArray.length; i++)
|
||||
updateStyleSheetForObject(prefArray[i]);
|
||||
updateStyleSheetForObject(prefArray[i], gCachedStyleSheet);
|
||||
|
||||
// Setup css classes for category colors
|
||||
var catergoryPrefBranch = prefService.getBranch("");
|
||||
|
@ -347,59 +337,6 @@ function initColors() {
|
|||
categoryPrefObserver.observe(null, null, "");
|
||||
}
|
||||
|
||||
function updateStyleSheetForObject(object) {
|
||||
var calStyleSheet = getCalendarStyleSheet();
|
||||
var name;
|
||||
if (object.uri)
|
||||
name = object.uri.spec;
|
||||
else
|
||||
name = object.replace(' ','_');
|
||||
|
||||
// Returns an equality selector for calendars (which have a uri), since an
|
||||
// event can only belong to one calendar. For categories, however, returns
|
||||
// the ~= selector which matches anything in a space-separated list.
|
||||
function selectorForObject(name)
|
||||
{
|
||||
if (object.uri)
|
||||
return '*[item-calendar="' + name + '"]';
|
||||
return '*[item-category~="' + name + '"]';
|
||||
}
|
||||
|
||||
function getRuleForObject(name)
|
||||
{
|
||||
for (var i = 0; i < calStyleSheet.cssRules.length; i++) {
|
||||
var rule = calStyleSheet.cssRules[i];
|
||||
if (rule.selectorText && (rule.selectorText == selectorForObject(name)))
|
||||
return rule;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
var rule = getRuleForObject(name);
|
||||
if (!rule) {
|
||||
calStyleSheet.insertRule(selectorForObject(name) + ' { }',
|
||||
calStyleSheet.cssRules.length);
|
||||
rule = calStyleSheet.cssRules[calStyleSheet.cssRules.length-1];
|
||||
}
|
||||
|
||||
var color;
|
||||
if (object.uri) {
|
||||
color = getCalendarManager().getCalendarPref(object, 'color');
|
||||
if (!color)
|
||||
color = "#A8C2E1";
|
||||
rule.style.backgroundColor = color;
|
||||
rule.style.color = getContrastingTextColor(color);
|
||||
return;
|
||||
}
|
||||
var categoryPrefBranch = prefService.getBranch("calendar.category.color.");
|
||||
try {
|
||||
color = categoryPrefBranch.getCharPref(object);
|
||||
}
|
||||
catch(ex) { return; }
|
||||
|
||||
rule.style.border = color + " solid 2px";
|
||||
}
|
||||
|
||||
var categoryPrefObserver =
|
||||
{
|
||||
observe: function(aSubject, aTopic, aPrefName)
|
||||
|
@ -408,7 +345,7 @@ var categoryPrefObserver =
|
|||
// We only want the actual category name. 24 is the length of the
|
||||
// leading 'calendar.category.color.' term
|
||||
name = name.substr(24, aPrefName.length - 24);
|
||||
updateStyleSheetForObject(name);
|
||||
updateStyleSheetForObject(name, gCachedStyleSheet);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче