diff --git a/editor/ui/composer/content/editor.js b/editor/ui/composer/content/editor.js
index 7e8c50cb1a29..b28fa08d8c6f 100644
--- a/editor/ui/composer/content/editor.js
+++ b/editor/ui/composer/content/editor.js
@@ -95,6 +95,12 @@ const kEditorToolbarPrefs = "editor.toolbars.showbutton.";
const kUseCssPref = "editor.use_css";
const kCRInParagraphsPref = "editor.CR_creates_new_p";
+function getEngineWebBrowserPrint()
+{
+ return content.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+ .getInterface(Components.interfaces.nsIWebBrowserPrint);
+}
+
function ShowHideToolbarSeparators(toolbar) {
var childNodes = toolbar.childNodes;
var separator = null;
diff --git a/mail/base/content/msgPrintEngine.xul b/mail/base/content/msgPrintEngine.xul
index edb6fa1eed39..b39ca28f04ab 100644
--- a/mail/base/content/msgPrintEngine.xul
+++ b/mail/base/content/msgPrintEngine.xul
@@ -46,7 +46,6 @@
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:nc="http://home.netscape.com/NC-rdf#"
onload="OnLoadPrintEngine()"
- onunload="OnUnloadPrintEngine()"
width="750"
height="500"
screenX="10" screenY="10"
@@ -62,7 +61,6 @@
-
diff --git a/mailnews/base/resources/content/msgPrintEngine.js b/mailnews/base/resources/content/msgPrintEngine.js
index 2873b89b0066..1f8b46903cf6 100644
--- a/mailnews/base/resources/content/msgPrintEngine.js
+++ b/mailnews/base/resources/content/msgPrintEngine.js
@@ -43,8 +43,6 @@ var printEngineContractID = "@mozilla.org/messenger/msgPrintEngine;1";
var printEngineWindow;
var printEngine;
var printSettings = null;
-var doingPrintPreview = false;
-var gWebProgress;
const kMsgBundle = "chrome://messenger/locale/messenger.properties";
@@ -52,71 +50,41 @@ const kMsgBundle = "chrome://messenger/locale/messenger.properties";
function OnLoadPrintEngine()
{
PrintEngineCreateGlobals();
- InitPrintEngineWindow();
+ InitPrintEngineWindow();
printEngine.startPrintOperation(printSettings);
}
-function OnUnloadPrintEngine()
-{
- if (printEngine.doPrintPreview) {
- var webBrowserPrint = printEngine.webBrowserPrint;
- webBrowserPrint.exitPrintPreview();
- }
-}
-
function PrintEngineCreateGlobals()
{
- /* get the print engine instance */
- printEngine = Components.classes[printEngineContractID].createInstance();
- printEngine = printEngine.QueryInterface(Components.interfaces.nsIMsgPrintEngine);
+ /* get the print engine instance */
+ printEngine = Components.classes[printEngineContractID].createInstance();
+ printEngine = printEngine.QueryInterface(Components.interfaces.nsIMsgPrintEngine);
+}
+
+function getEngineWebBrowserPrint()
+{
+ return printEngine.webBrowserPrint;
}
function getWebNavigation()
{
try {
- return document.getElementById("content").webNavigation;
+ return getPPBrowser().webNavigation;
} catch (e) {
return null;
}
}
-function showPrintPreviewToolbar()
+function getNavToolbox()
{
- const kXULNS =
- "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
-
- var printPreviewTB = document.createElementNS(kXULNS, "toolbar");
- printPreviewTB.setAttribute("printpreview", true);
- printPreviewTB.setAttribute("id", "print-preview-toolbar");
-
- var navToolbox = document.getElementById("content");
- navToolbox.parentNode.insertBefore(printPreviewTB, navToolbox);
-
+ return document.getElementById("content");
}
-function BrowserExitPrintPreview()
+function getPPBrowser()
{
- window.close();
+ return document.getElementById("content");
}
-// This observer is called once the progress dialog has been "opened"
-var gPrintPreviewObs = {
- observe: function(aSubject, aTopic, aData)
- {
- setTimeout(FinishPrintPreview, 0);
- },
-
- QueryInterface : function(iid)
- {
- if (iid.equals(Components.interfaces.nsIObserver) ||
- iid.equals(Components.interfaces.nsISupportsWeakReference) ||
- iid.equals(Components.interfaces.nsISupports))
- return this;
-
- throw Components.results.NS_NOINTERFACE;
- }
-};
-
function getBundle(aURI)
{
if (!aURI)
@@ -155,76 +123,23 @@ function setPPTitle(aTitle)
document.title = title;
}
-function PrintPreview()
+function onEnterPrintPreview()
{
- var webBrowserPrint = printEngine.webBrowserPrint;
-
- // Here we get the PrintingPromptService tso we can display the PP Progress from script
- // For the browser implemented via XUL with the PP toolbar we cannot let it be
- // automatically opened from the print engine because the XUL scrollbars in the PP window
- // will layout before the content window and a crash will occur.
- //
- // Doing it all from script, means it lays out before hand and we can let printing do it's own thing
- gWebProgress = new Object();
-
- var printPreviewParams = new Object();
- var notifyOnOpen = new Object();
- var printingPromptService = Components.classes["@mozilla.org/embedcomp/printingprompt-service;1"]
- .getService(Components.interfaces.nsIPrintingPromptService);
- if (printingPromptService) {
- // just in case we are already printing,
- // an error code could be returned if the Prgress Dialog is already displayed
- try {
- printingPromptService.showProgress(this, webBrowserPrint, printSettings, gPrintPreviewObs, false, gWebProgress,
- printPreviewParams, notifyOnOpen);
- if (printPreviewParams.value) {
- var webNav = getWebNavigation();
- printPreviewParams.value.docTitle = webNav.document.title;
- printPreviewParams.value.docURL = webNav.currentURI.spec;
- }
-
- // this tells us whether we should continue on with PP or
- // wait for the callback via the observer
- if (!notifyOnOpen.value.valueOf() || gWebProgress.value == null) {
- FinishPrintPreview();
- }
- } catch (e) {
- FinishPrintPreview();
- }
- }
-}
-
-function FinishPrintPreview()
-{
- var webBrowserPrint = printEngine.webBrowserPrint;
- try {
- if (webBrowserPrint) {
- webBrowserPrint.printPreview(printSettings, null, gWebProgress.value);
- }
-
- // show the toolbar after we go into print preview mode so
- // that we can initialize the toolbar with total num pages
- showPrintPreviewToolbar();
- setPPTitle(getWebNavigation().document.title);
-
- content.focus();
- } catch (e) {
- // Pressing cancel is expressed as an NS_ERROR_ABORT return value,
- // causing an exception to be thrown which we catch here.
- // Unfortunately this will also consume helpful failures, so add a
- //dump(e+"\n");
- }
+ setPPTitle(getWebNavigation().document.title);
printEngine.showWindow(true);
}
+function onExitPrintPreview()
+{
+ window.close();
+}
// Pref listener constants
const gStartupPPObserver =
{
- printengine:null,
observe: function(subject, topic, prefName)
{
- this.printengine.PrintPreview();
+ PrintUtils.printPreview(onEnterPrintPreview, onExitPrintPreview);
}
};
@@ -251,9 +166,7 @@ function InitPrintEngineWindow()
}
if (window.arguments[4]) {
- doingPrintPreview = window.arguments[4];
- //printEngine.showWindow(doingPrintPreview);
- printEngine.doPrintPreview = doingPrintPreview;
+ printEngine.doPrintPreview = window.arguments[4];
} else {
printEngine.doPrintPreview = false;
}
@@ -271,7 +184,6 @@ function InitPrintEngineWindow()
printEngine.setParentWindow(null);
}
- gStartupPPObserver.printengine = this;
printEngine.setStatusFeedback(statusFeedback);
printEngine.setStartupPPObserver(gStartupPPObserver);
diff --git a/mailnews/base/resources/content/msgPrintEngine.xul b/mailnews/base/resources/content/msgPrintEngine.xul
index de3d462c159b..b8982b569b30 100644
--- a/mailnews/base/resources/content/msgPrintEngine.xul
+++ b/mailnews/base/resources/content/msgPrintEngine.xul
@@ -45,7 +45,6 @@
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:nc="http://home.netscape.com/NC-rdf#"
onload="OnLoadPrintEngine()"
- onunload="OnUnloadPrintEngine()"
width="750"
height="500"
screenX="10" screenY="10"
diff --git a/xpfe/browser/resources/content/browser.js b/xpfe/browser/resources/content/browser.js
index 8c950a975cba..a113eeb1d4a8 100644
--- a/xpfe/browser/resources/content/browser.js
+++ b/xpfe/browser/resources/content/browser.js
@@ -42,9 +42,7 @@ const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
var gPrintSettingsAreGlobal = true;
var gSavePrintSettings = true;
var gChromeState = null; // chrome state before we went into print preview
-var gOldCloseHandler = null; // close handler before we went into print preview
var gInPrintPreviewMode = false;
-var gWebProgress = null;
function getWebNavigation()
{
@@ -144,156 +142,40 @@ function toggleAffectedChrome(aHide)
SidebarRebuild();
}
-function showPrintPreviewToolbar()
+function onEnterPrintPreview()
{
toggleAffectedChrome(true);
- const kXULNS =
- "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
-
- var printPreviewTB = document.createElementNS(kXULNS, "toolbar");
- printPreviewTB.setAttribute("printpreview", true);
- printPreviewTB.setAttribute("id", "print-preview-toolbar");
-
- var navToolbox = document.getElementById("navigator-toolbox");
- navToolbox.parentNode.insertBefore(printPreviewTB, navToolbox);
+ gInPrintPreviewMode = true;
}
-function BrowserExitPrintPreview()
+function onExitPrintPreview()
{
gInPrintPreviewMode = false;
-
- var browser = getBrowser();
- browser.setAttribute("handleCtrlPageUpDown", "true");
-
- // remove the print preview toolbar
- var navToolbox = document.getElementById("navigator-toolbox");
- var printPreviewTB = document.getElementById("print-preview-toolbar");
- navToolbox.parentNode.removeChild(printPreviewTB);
-
// restore chrome to original state
toggleAffectedChrome(false);
-
- // restore old onclose handler if we found one before previewing
- var mainWin = document.getElementById("main-window");
- mainWin.setAttribute("onclose", gOldCloseHandler);
-
- // exit print preview galley mode in content area
- var ifreq = content.QueryInterface(
- Components.interfaces.nsIInterfaceRequestor);
- var webBrowserPrint = ifreq.getInterface(
- Components.interfaces.nsIWebBrowserPrint);
- webBrowserPrint.exitPrintPreview();
- content.focus();
}
-// This observer is called once the progress dialog has been "opened"
-var gPrintPreviewObs = {
- observe: function(aSubject, aTopic, aData)
- {
- setTimeout(FinishPrintPreview, 0);
- },
+function getEngineWebBrowserPrint()
+{
+ return content.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+ .getInterface(Components.interfaces.nsIWebBrowserPrint);
+}
- QueryInterface : function(iid)
- {
- if (iid.equals(Components.interfaces.nsIObserver) ||
- iid.equals(Components.interfaces.nsISupportsWeakReference) ||
- iid.equals(Components.interfaces.nsISupports)) {
- return this;
- }
-
- throw Components.results.NS_NOINTERFACE;
- }
-};
+function getNavToolbox()
+{
+ return document.getElementById("navigator-toolbox");
+}
+
+function getPPBrowser()
+{
+ return document.getElementById("browser");
+}
function BrowserPrintPreview()
{
- var ifreq;
- var webBrowserPrint;
- try {
- ifreq = content.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
- webBrowserPrint = ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint);
- gPrintSettings = GetPrintSettings();
-
- } catch (e) {
- // Pressing cancel is expressed as an NS_ERROR_ABORT return value,
- // causing an exception to be thrown which we catch here.
- // Unfortunately this will also consume helpful failures, so add a
- // dump(e); // if you need to debug
- }
-
- // Here we get the PrintingPromptService tso we can display the PP Progress from script
- // For the browser implemented via XUL with the PP toolbar we cannot let it be
- // automatically opened from the print engine because the XUL scrollbars in the PP window
- // will layout before the content window and a crash will occur.
- //
- // Doing it all from script, means it lays out before hand and we can let printing do it's own thing
- gWebProgress = new Object();
-
- var printPreviewParams = new Object();
- var notifyOnOpen = new Object();
- var printingPromptService = Components.classes["@mozilla.org/embedcomp/printingprompt-service;1"]
- .getService(Components.interfaces.nsIPrintingPromptService);
- if (printingPromptService) {
- // just in case we are already printing,
- // an error code could be returned if the Prgress Dialog is already displayed
- try {
- printingPromptService.showProgress(this, webBrowserPrint, gPrintSettings, gPrintPreviewObs, false, gWebProgress,
- printPreviewParams, notifyOnOpen);
- if (printPreviewParams.value) {
- var webNav = getWebNavigation();
- printPreviewParams.value.docTitle = webNav.document.title;
- printPreviewParams.value.docURL = webNav.currentURI.spec;
- }
-
- // this tells us whether we should continue on with PP or
- // wait for the callback via the observer
- if (!notifyOnOpen.value.valueOf() || gWebProgress.value == null) {
- FinishPrintPreview();
- }
- } catch (e) {
- FinishPrintPreview();
- }
- }
+ PrintUtils.printPreview(onEnterPrintPreview, onExitPrintPreview);
}
-function FinishPrintPreview()
-{
- var browser = getBrowser();
- try {
- var ifreq = content.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
- var webBrowserPrint = ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint);
- if (webBrowserPrint) {
- gPrintSettings = GetPrintSettings();
- webBrowserPrint.printPreview(gPrintSettings, null, gWebProgress.value);
- }
-
- gInPrintPreviewMode = true;
-
- browser.setAttribute("handleCtrlPageUpDown", "false");
-
- var mainWin = document.getElementById("main-window");
-
- // save previous close handler to restoreon exiting print preview mode
- if (mainWin.hasAttribute("onclose"))
- gOldCloseHandler = mainWin.getAttribute("onclose");
- else
- gOldCloseHandler = null;
- mainWin.setAttribute("onclose", "BrowserExitPrintPreview(); return false;");
-
- // show the toolbar after we go into print preview mode so
- // that we can initialize the toolbar with total num pages
- showPrintPreviewToolbar();
-
- content.focus();
- } catch (e) {
- // Pressing cancel is expressed as an NS_ERROR_ABORT return value,
- // causing an exception to be thrown which we catch here.
- // Unfortunately this will also consume helpful failures, so add a
- // dump(e); // if you need to debug
- }
-}
-
-
function BrowserSetDefaultCharacterSet(aCharset)
{
// no longer needed; set when setting Force; see bug 79608
diff --git a/xpfe/communicator/resources/content/printPreviewBindings.xml b/xpfe/communicator/resources/content/printPreviewBindings.xml
index e6f3906d6544..9a3a5c04b10a 100644
--- a/xpfe/communicator/resources/content/printPreviewBindings.xml
+++ b/xpfe/communicator/resources/content/printPreviewBindings.xml
@@ -51,38 +51,36 @@
+ oncommand="PrintUtils.print();"/>
-
-
+ oncommand="this.parentNode.doPageSetup();"/>
-
+
+ oncommand="parentNode.navigate(0, 0, 'home');" tooltiptext="&homearrow.tooltip;"/>
+ oncommand="parentNode.navigate(-1, 0, 0);" tooltiptext="&leftarrow.tooltip;"/>
-
+ oncommand="parentNode.navigate(1, 0, 0);" tooltiptext="&rightarrow.tooltip;"/>
+ oncommand="parentNode.navigate(0, 0, 'end');" tooltiptext="&endarrow.tooltip;"/>
-
+
-
+
-
@@ -105,22 +103,21 @@
-
-
-
-
-
-
-
+
+
+
+
+
-
+
+ oncommand="PrintUtils.exitPrintPreview();"/>
@@ -132,28 +129,28 @@
document.getAnonymousNodes(this)[0]
- document.getAnonymousNodes(this)[6].firstChild
+ document.getAnonymousNodes(this)[5].firstChild
- document.getAnonymousNodes(this)[6].lastChild
+ document.getAnonymousNodes(this)[5].lastChild
- document.getAnonymousNodes(this)[10].firstChild
+ document.getAnonymousNodes(this)[9].firstChild
- document.getAnonymousNodes(this)[11].firstChild
+ document.getAnonymousNodes(this)[10].firstChild
- document.getAnonymousNodes(this)[13].firstChild
+ document.getAnonymousNodes(this)[12]
- this.mOrientButtonsBox.firstChild
+ this.mOrientButtonsBox.childNodes[0]
- this.mOrientButtonsBox.lastChild
+ this.mOrientButtonsBox.childNodes[1]
- document.getAnonymousNodes(this)[16].getAttribute("value");
+ document.getAnonymousNodes(this)[15].firstChild
@@ -164,12 +161,10 @@
@@ -244,13 +238,10 @@
0 && newPageNum <= print.printPreviewNumPages)
+ if (newPageNum > 0 && newPageNum <= total)
{
this.mPageTextBox.value = newPageNum;
print.printPreviewNavigate(
@@ -285,8 +278,10 @@
}
else
{
+ total = print.printPreviewNumPages;
+
// bounds check potentially user-entered number
- if (aPageNum > 0 && aPageNum <= print.printPreviewNumPages)
+ if (aPageNum > 0 && aPageNum <= total)
{
print.printPreviewNavigate(
print.PRINTPREVIEW_GOTO_PAGENUM, aPageNum);
@@ -315,13 +310,15 @@
-
-
-
-
-
-
-
-
-
-
-
@@ -467,43 +392,25 @@