Bug 321954 - Make it easier for apps to hook into toolkit's printing component, patch nearly all by Ian Neal <iann_bugzilla@blueyonder.co.uk> with very little from me, r=gavin

This commit is contained in:
philringnalda@gmail.com 2007-08-22 21:07:30 -07:00
Родитель 6a854e4ffa
Коммит 36d38a4df6
3 изменённых файлов: 66 добавлений и 34 удалений

Просмотреть файл

@ -99,6 +99,7 @@ var gProgressCollapseTimer = null;
var gPrefService = null; var gPrefService = null;
var appCore = null; var appCore = null;
var gBrowser = null; var gBrowser = null;
var gNavToolbox = null;
var gSidebarCommand = ""; var gSidebarCommand = "";
// Global variable that holds the nsContextMenu instance. // Global variable that holds the nsContextMenu instance.
@ -1029,8 +1030,7 @@ function delayedStartup()
SetPageProxyState("invalid"); SetPageProxyState("invalid");
var toolbox = document.getElementById("navigator-toolbox"); getNavToolbox().customizeDone = BrowserToolboxCustomizeDone;
toolbox.customizeDone = BrowserToolboxCustomizeDone;
// Set up Sanitize Item // Set up Sanitize Item
gSanitizeListener = new SanitizeListener(); gSanitizeListener = new SanitizeListener();
@ -2279,13 +2279,13 @@ function toggleAffectedChrome(aHide)
// (*) menubar // (*) menubar
// (*) navigation bar // (*) navigation bar
// (*) bookmarks toolbar // (*) bookmarks toolbar
// (*) tabstrip
// (*) browser messages // (*) browser messages
// (*) sidebar // (*) sidebar
// (*) find bar // (*) find bar
// (*) statusbar // (*) statusbar
var navToolbox = document.getElementById("navigator-toolbox"); getNavToolbox().hidden = aHide;
navToolbox.hidden = aHide;
if (aHide) if (aHide)
{ {
gChromeState = {}; gChromeState = {};
@ -2293,6 +2293,9 @@ function toggleAffectedChrome(aHide)
gChromeState.sidebarOpen = !sidebar.hidden; gChromeState.sidebarOpen = !sidebar.hidden;
gSidebarCommand = sidebar.getAttribute("sidebarcommand"); gSidebarCommand = sidebar.getAttribute("sidebarcommand");
gChromeState.hadTabStrip = gBrowser.getStripVisibility();
gBrowser.setStripVisibilityTo(false);
var notificationBox = gBrowser.getNotificationBox(); var notificationBox = gBrowser.getNotificationBox();
gChromeState.notificationsOpen = !notificationBox.notificationsHidden; gChromeState.notificationsOpen = !notificationBox.notificationsHidden;
notificationBox.notificationsHidden = aHide; notificationBox.notificationsHidden = aHide;
@ -2305,6 +2308,10 @@ function toggleAffectedChrome(aHide)
gFindBar.close(); gFindBar.close();
} }
else { else {
if (gChromeState.hadTabStrip) {
gBrowser.setStripVisibilityTo(true);
}
if (gChromeState.notificationsOpen) { if (gChromeState.notificationsOpen) {
gBrowser.getNotificationBox().notificationsHidden = aHide; gBrowser.getNotificationBox().notificationsHidden = aHide;
} }
@ -2333,6 +2340,11 @@ function onExitPrintPreview()
toggleAffectedChrome(false); toggleAffectedChrome(false);
} }
function getPPBrowser()
{
return document.getElementById("content");
}
function getMarkupDocumentViewer() function getMarkupDocumentViewer()
{ {
return gBrowser.markupDocumentViewer; return gBrowser.markupDocumentViewer;
@ -3049,7 +3061,7 @@ function BrowserCustomizeToolbar()
window.openDialog("chrome://global/content/customizeToolbar.xul", window.openDialog("chrome://global/content/customizeToolbar.xul",
"CustomizeToolbar", "CustomizeToolbar",
"chrome,all,dependent", "chrome,all,dependent",
document.getElementById("navigator-toolbox")); getNavToolbox());
#endif #endif
} }
@ -3173,7 +3185,7 @@ var FullScreen =
} }
} }
var toolbox = document.getElementById("navigator-toolbox"); var toolbox = getNavToolbox();
if (aShow) if (aShow)
toolbox.removeAttribute("inFullscreen"); toolbox.removeAttribute("inFullscreen");
else else
@ -3872,7 +3884,7 @@ function onViewToolbarsPopupShowing(aEvent)
var firstMenuItem = popup.firstChild; var firstMenuItem = popup.firstChild;
var toolbox = document.getElementById("navigator-toolbox"); var toolbox = getNavToolbox();
for (i = 0; i < toolbox.childNodes.length; ++i) { for (i = 0; i < toolbox.childNodes.length; ++i) {
var toolbar = toolbox.childNodes[i]; var toolbar = toolbox.childNodes[i];
var toolbarName = toolbar.getAttribute("toolbarname"); var toolbarName = toolbar.getAttribute("toolbarname");
@ -3894,7 +3906,7 @@ function onViewToolbarsPopupShowing(aEvent)
function onViewToolbarCommand(aEvent) function onViewToolbarCommand(aEvent)
{ {
var toolbox = document.getElementById("navigator-toolbox"); var toolbox = getNavToolbox();
var index = aEvent.originalTarget.getAttribute("toolbarindex"); var index = aEvent.originalTarget.getAttribute("toolbarindex");
var toolbar = toolbox.childNodes[index]; var toolbar = toolbox.childNodes[index];
@ -4386,7 +4398,6 @@ var contentAreaDNDObserver = {
}; };
// For extensions
function getBrowser() function getBrowser()
{ {
if (!gBrowser) if (!gBrowser)
@ -4394,6 +4405,13 @@ function getBrowser()
return gBrowser; return gBrowser;
} }
function getNavToolbox()
{
if (!gNavToolbox)
gNavToolbox = document.getElementById("navigator-toolbox");
return gNavToolbox;
}
function MultiplexHandler(event) function MultiplexHandler(event)
{ try { { try {
var node = event.target; var node = event.target;

Просмотреть файл

@ -39,8 +39,6 @@
# #
# ***** END LICENSE BLOCK ***** # ***** END LICENSE BLOCK *****
var XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
var gPrintSettingsAreGlobal = false; var gPrintSettingsAreGlobal = false;
var gSavePrintSettings = false; var gSavePrintSettings = false;
@ -88,6 +86,12 @@ var PrintUtils = {
} }
}, },
// calling PrintUtils.printPreview() requires that you have three functions
// in the global scope: getPPBrowser(), which returns the browser element in
// the window print preview uses, getNavToolbox(), which returns the element
// (usually the main toolbox element) before which the print preview toolbar
// should be inserted, and getWebNavigation(), which returns the document's
// nsIWebNavigation object
printPreview: function (aEnterPPCallback, aExitPPCallback, aWindow) printPreview: function (aEnterPPCallback, aExitPPCallback, aWindow)
{ {
// if we're already in PP mode, don't set the callbacks; chances // if we're already in PP mode, don't set the callbacks; chances
@ -98,10 +102,12 @@ var PrintUtils = {
this._onEnterPP = aEnterPPCallback; this._onEnterPP = aEnterPPCallback;
this._onExitPP = aExitPPCallback; this._onExitPP = aExitPPCallback;
} else { } else {
// hide the toolbar here -- it will be shown in // collapse the browser here -- it will be shown in
// onEnterPrintPreview; this forces a reflow which fixes display // onEnterPrintPreview; this forces a reflow which fixes display
// issues in bug 267422. // issues in bug 267422.
pptoolbar.hidden = true; var browser = getPPBrowser();
if (browser)
browser.collapsed = true;
} }
this._webProgressPP = {}; this._webProgressPP = {};
@ -122,7 +128,7 @@ var PrintUtils = {
PPROMPTSVC.showProgress(this, webBrowserPrint, printSettings, this._obsPP, false, PPROMPTSVC.showProgress(this, webBrowserPrint, printSettings, this._obsPP, false,
this._webProgressPP, ppParams, notifyOnOpen); this._webProgressPP, ppParams, notifyOnOpen);
if (ppParams.value) { if (ppParams.value) {
var webNav = getBrowser().webNavigation; var webNav = getWebNavigation();
ppParams.value.docTitle = webNav.document.title; ppParams.value.docTitle = webNav.document.title;
ppParams.value.docURL = webNav.currentURI.spec; ppParams.value.docURL = webNav.currentURI.spec;
} }
@ -183,7 +189,6 @@ var PrintUtils = {
return printSettings; return printSettings;
}, },
_chromeState: {},
_closeHandlerPP: null, _closeHandlerPP: null,
_webProgressPP: null, _webProgressPP: null,
_onEnterPP: null, _onEnterPP: null,
@ -223,25 +228,22 @@ var PrintUtils = {
var printPreviewTB = document.getElementById("print-preview-toolbar"); var printPreviewTB = document.getElementById("print-preview-toolbar");
if (printPreviewTB) { if (printPreviewTB) {
printPreviewTB.updateToolbar(); printPreviewTB.updateToolbar();
printPreviewTB.hidden = false; var browser = getPPBrowser();
if (browser)
browser.collapsed = false;
return; return;
} }
// show the toolbar after we go into print preview mode so // show the toolbar after we go into print preview mode so
// that we can initialize the toolbar with total num pages // that we can initialize the toolbar with total num pages
var XUL_NS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
printPreviewTB = document.createElementNS(XUL_NS, "toolbar"); printPreviewTB = document.createElementNS(XUL_NS, "toolbar");
printPreviewTB.setAttribute("printpreview", true); printPreviewTB.setAttribute("printpreview", true);
printPreviewTB.setAttribute("id", "print-preview-toolbar"); printPreviewTB.setAttribute("id", "print-preview-toolbar");
#ifdef MOZ_PHOENIX var navToolbox = getNavToolbox();
getBrowser().parentNode.insertBefore(printPreviewTB, getBrowser()); navToolbox.parentNode.insertBefore(printPreviewTB, navToolbox);
// Tab browser...
if ("getStripVisibility" in getBrowser()) {
this._chromeState.hadTabStrip = getBrowser().getStripVisibility();
getBrowser().setStripVisibilityTo(false);
}
#endif
// copy the window close handler // copy the window close handler
if (document.documentElement.hasAttribute("onclose")) if (document.documentElement.hasAttribute("onclose"))
@ -267,24 +269,17 @@ var PrintUtils = {
{ {
window.removeEventListener("keypress", this.onKeyPressPP, true); window.removeEventListener("keypress", this.onKeyPressPP, true);
#ifdef MOZ_THUNDERBIRD
BrowserExitPrintPreview(); // make the traditional call..don't do any of the inline toolbar browser stuff
return;
#endif
// restore the old close handler // restore the old close handler
document.documentElement.setAttribute("onclose", this._closeHandlerPP); document.documentElement.setAttribute("onclose", this._closeHandlerPP);
this._closeHandlerPP = null; this._closeHandlerPP = null;
if ("getStripVisibility" in getBrowser())
getBrowser().setStripVisibilityTo(this._chromeState.hadTabStrip);
var webBrowserPrint = this.getWebBrowserPrint(aWindow); var webBrowserPrint = this.getWebBrowserPrint(aWindow);
webBrowserPrint.exitPrintPreview(); webBrowserPrint.exitPrintPreview();
// remove the print preview toolbar // remove the print preview toolbar
var navToolbox = getNavToolbox();
var printPreviewTB = document.getElementById("print-preview-toolbar"); var printPreviewTB = document.getElementById("print-preview-toolbar");
getBrowser().parentNode.removeChild(printPreviewTB); navToolbox.parentNode.removeChild(printPreviewTB);
var contentWindow = aWindow || window.content; var contentWindow = aWindow || window.content;
contentWindow.focus(); contentWindow.focus();

Просмотреть файл

@ -272,6 +272,25 @@ function onExitPP()
toolbox.hidden = false; toolbox.hidden = false;
} }
function getPPBrowser()
{
return document.getElementById("content");
}
function getNavToolbox()
{
return document.getElementById("appcontent");
}
function getWebNavigation()
{
try {
return gBrowser.webNavigation;
} catch (e) {
return null;
}
}
function ViewSourceGoToLine() function ViewSourceGoToLine()
{ {
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]