зеркало из https://github.com/mozilla/pjs.git
Bug 720294 - Refactor style sheet switching code in browser.js. r=gavin
This commit is contained in:
Родитель
707da996a6
Коммит
8b7acad108
|
@ -6133,103 +6133,114 @@ function charsetLoadListener(event) {
|
|||
}
|
||||
}
|
||||
|
||||
/* Begin Page Style Functions */
|
||||
function getAllStyleSheets(frameset) {
|
||||
var styleSheetsArray = Array.slice(frameset.document.styleSheets);
|
||||
for (let i = 0; i < frameset.frames.length; i++) {
|
||||
let frameSheets = getAllStyleSheets(frameset.frames[i]);
|
||||
styleSheetsArray = styleSheetsArray.concat(frameSheets);
|
||||
}
|
||||
return styleSheetsArray;
|
||||
}
|
||||
|
||||
function stylesheetFillPopup(menuPopup) {
|
||||
var noStyle = menuPopup.firstChild;
|
||||
var persistentOnly = noStyle.nextSibling;
|
||||
var sep = persistentOnly.nextSibling;
|
||||
while (sep.nextSibling)
|
||||
menuPopup.removeChild(sep.nextSibling);
|
||||
var gPageStyleMenu = {
|
||||
|
||||
var styleSheets = getAllStyleSheets(window.content);
|
||||
var currentStyleSheets = {};
|
||||
var styleDisabled = getMarkupDocumentViewer().authorStyleDisabled;
|
||||
var haveAltSheets = false;
|
||||
var altStyleSelected = false;
|
||||
getAllStyleSheets: function (frameset) {
|
||||
var styleSheetsArray = Array.slice(frameset.document.styleSheets);
|
||||
for (let i = 0; i < frameset.frames.length; i++) {
|
||||
let frameSheets = this.getAllStyleSheets(frameset.frames[i]);
|
||||
styleSheetsArray = styleSheetsArray.concat(frameSheets);
|
||||
}
|
||||
return styleSheetsArray;
|
||||
},
|
||||
|
||||
for (let i = 0; i < styleSheets.length; ++i) {
|
||||
let currentStyleSheet = styleSheets[i];
|
||||
stylesheetFillPopup: function (menuPopup) {
|
||||
var noStyle = menuPopup.firstChild;
|
||||
var persistentOnly = noStyle.nextSibling;
|
||||
var sep = persistentOnly.nextSibling;
|
||||
while (sep.nextSibling)
|
||||
menuPopup.removeChild(sep.nextSibling);
|
||||
|
||||
if (!currentStyleSheet.title)
|
||||
continue;
|
||||
var styleSheets = this.getAllStyleSheets(window.content);
|
||||
var currentStyleSheets = {};
|
||||
var styleDisabled = getMarkupDocumentViewer().authorStyleDisabled;
|
||||
var haveAltSheets = false;
|
||||
var altStyleSelected = false;
|
||||
|
||||
// Skip any stylesheets whose media attribute doesn't match.
|
||||
if (currentStyleSheet.media.length > 0) {
|
||||
let mediaQueryList = currentStyleSheet.media.mediaText;
|
||||
if (!window.content.matchMedia(mediaQueryList).matches)
|
||||
for (let i = 0; i < styleSheets.length; ++i) {
|
||||
let currentStyleSheet = styleSheets[i];
|
||||
|
||||
if (!currentStyleSheet.title)
|
||||
continue;
|
||||
|
||||
// Skip any stylesheets whose media attribute doesn't match.
|
||||
if (currentStyleSheet.media.length > 0) {
|
||||
let mediaQueryList = currentStyleSheet.media.mediaText;
|
||||
if (!window.content.matchMedia(mediaQueryList).matches)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!currentStyleSheet.disabled)
|
||||
altStyleSelected = true;
|
||||
|
||||
haveAltSheets = true;
|
||||
|
||||
let lastWithSameTitle = null;
|
||||
if (currentStyleSheet.title in currentStyleSheets)
|
||||
lastWithSameTitle = currentStyleSheets[currentStyleSheet.title];
|
||||
|
||||
if (!lastWithSameTitle) {
|
||||
let menuItem = document.createElement("menuitem");
|
||||
menuItem.setAttribute("type", "radio");
|
||||
menuItem.setAttribute("label", currentStyleSheet.title);
|
||||
menuItem.setAttribute("data", currentStyleSheet.title);
|
||||
menuItem.setAttribute("checked", !currentStyleSheet.disabled && !styleDisabled);
|
||||
menuPopup.appendChild(menuItem);
|
||||
currentStyleSheets[currentStyleSheet.title] = menuItem;
|
||||
} else if (currentStyleSheet.disabled) {
|
||||
lastWithSameTitle.removeAttribute("checked");
|
||||
}
|
||||
}
|
||||
|
||||
if (!currentStyleSheet.disabled)
|
||||
altStyleSelected = true;
|
||||
noStyle.setAttribute("checked", styleDisabled);
|
||||
persistentOnly.setAttribute("checked", !altStyleSelected && !styleDisabled);
|
||||
persistentOnly.hidden = (window.content.document.preferredStyleSheetSet) ? haveAltSheets : false;
|
||||
sep.hidden = (noStyle.hidden && persistentOnly.hidden) || !haveAltSheets;
|
||||
return true;
|
||||
},
|
||||
|
||||
haveAltSheets = true;
|
||||
stylesheetInFrame: function (frame, title) {
|
||||
return Array.some(frame.document.styleSheets,
|
||||
function (stylesheet) stylesheet.title == title);
|
||||
},
|
||||
|
||||
let lastWithSameTitle = null;
|
||||
if (currentStyleSheet.title in currentStyleSheets)
|
||||
lastWithSameTitle = currentStyleSheets[currentStyleSheet.title];
|
||||
stylesheetSwitchFrame: function (frame, title) {
|
||||
var docStyleSheets = frame.document.styleSheets;
|
||||
|
||||
if (!lastWithSameTitle) {
|
||||
let menuItem = document.createElement("menuitem");
|
||||
menuItem.setAttribute("type", "radio");
|
||||
menuItem.setAttribute("label", currentStyleSheet.title);
|
||||
menuItem.setAttribute("data", currentStyleSheet.title);
|
||||
menuItem.setAttribute("checked", !currentStyleSheet.disabled && !styleDisabled);
|
||||
menuPopup.appendChild(menuItem);
|
||||
currentStyleSheets[currentStyleSheet.title] = menuItem;
|
||||
} else if (currentStyleSheet.disabled) {
|
||||
lastWithSameTitle.removeAttribute("checked");
|
||||
for (let i = 0; i < docStyleSheets.length; ++i) {
|
||||
let docStyleSheet = docStyleSheets[i];
|
||||
|
||||
if (title == "_nostyle")
|
||||
docStyleSheet.disabled = true;
|
||||
else if (docStyleSheet.title)
|
||||
docStyleSheet.disabled = (docStyleSheet.title != title);
|
||||
else if (docStyleSheet.disabled)
|
||||
docStyleSheet.disabled = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
noStyle.setAttribute("checked", styleDisabled);
|
||||
persistentOnly.setAttribute("checked", !altStyleSelected && !styleDisabled);
|
||||
persistentOnly.hidden = (window.content.document.preferredStyleSheetSet) ? haveAltSheets : false;
|
||||
sep.hidden = (noStyle.hidden && persistentOnly.hidden) || !haveAltSheets;
|
||||
return true;
|
||||
}
|
||||
stylesheetSwitchAll: function (frameset, title) {
|
||||
if (!title || title == "_nostyle" || this.stylesheetInFrame(frameset, title))
|
||||
this.stylesheetSwitchFrame(frameset, title);
|
||||
|
||||
function stylesheetInFrame(frame, title) {
|
||||
return Array.some(frame.document.styleSheets,
|
||||
function (stylesheet) stylesheet.title == title);
|
||||
}
|
||||
for (let i = 0; i < frameset.frames.length; i++)
|
||||
this.stylesheetSwitchAll(frameset.frames[i], title);
|
||||
},
|
||||
|
||||
function stylesheetSwitchFrame(frame, title) {
|
||||
var docStyleSheets = frame.document.styleSheets;
|
||||
setStyleDisabled: function (disabled) {
|
||||
getMarkupDocumentViewer().authorStyleDisabled = disabled;
|
||||
},
|
||||
};
|
||||
|
||||
for (let i = 0; i < docStyleSheets.length; ++i) {
|
||||
let docStyleSheet = docStyleSheets[i];
|
||||
/* Legacy global page-style functions */
|
||||
var getAllStyleSheets = gPageStyleMenu.getAllStyleSheets;
|
||||
var stylesheetFillPopup = gPageStyleMenu.stylesheetFillPopup;
|
||||
var stylesheetInFrame = gPageStyleMenu.stylesheetInFrame;
|
||||
var stylesheetSwitchFrame = gPageStyleMenu.stylesheetSwitchFrame;
|
||||
var stylesheetSwitchAll = gPageStyleMenu.stylesheetSwitchAll;
|
||||
var setStyleDisabled = gPageStyleMenu.setStyleDisabled;
|
||||
|
||||
if (title == "_nostyle")
|
||||
docStyleSheet.disabled = true;
|
||||
else if (docStyleSheet.title)
|
||||
docStyleSheet.disabled = (docStyleSheet.title != title);
|
||||
else if (docStyleSheet.disabled)
|
||||
docStyleSheet.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
function stylesheetSwitchAll(frameset, title) {
|
||||
if (!title || title == "_nostyle" || stylesheetInFrame(frameset, title))
|
||||
stylesheetSwitchFrame(frameset, title);
|
||||
|
||||
for (let i = 0; i < frameset.frames.length; i++)
|
||||
stylesheetSwitchAll(frameset.frames[i], title);
|
||||
}
|
||||
|
||||
function setStyleDisabled(disabled) {
|
||||
getMarkupDocumentViewer().authorStyleDisabled = disabled;
|
||||
}
|
||||
/* End of the Page Style functions */
|
||||
|
||||
var BrowserOffline = {
|
||||
_inited: false,
|
||||
|
|
Загрузка…
Ссылка в новой задаче