mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 17:23:59 +00:00
Bug 544018 - print preview doesn't work in view source , r=dao
This commit is contained in:
parent
55b5f2a328
commit
9fdb936eb2
@ -333,13 +333,13 @@ var FullZoom = {
|
||||
* one.
|
||||
**/
|
||||
_applyPrefToSetting: function FullZoom__applyPrefToSetting(aValue, aBrowser) {
|
||||
if (!this.siteSpecific && !this._inPrivateBrowsing)
|
||||
if ((!this.siteSpecific && !this._inPrivateBrowsing) ||
|
||||
gInPrintPreviewMode)
|
||||
return;
|
||||
|
||||
var browser = aBrowser || gBrowser.selectedBrowser;
|
||||
try {
|
||||
if (gInPrintPreviewMode ||
|
||||
browser.contentDocument instanceof Ci.nsIImageDocument ||
|
||||
if (browser.contentDocument instanceof Ci.nsIImageDocument ||
|
||||
this._inPrivateBrowsing)
|
||||
ZoomManager.setZoomForBrowser(browser, 1);
|
||||
else if (typeof aValue != "undefined")
|
||||
|
@ -2536,11 +2536,34 @@ function BrowserReloadWithFlags(reloadFlags) {
|
||||
}
|
||||
|
||||
var PrintPreviewListener = {
|
||||
_printPreviewTab: null,
|
||||
_tabBeforePrintPreview: null,
|
||||
|
||||
getPrintPreviewBrowser: function () {
|
||||
if (!this._printPreviewTab) {
|
||||
this._tabBeforePrintPreview = gBrowser.selectedTab;
|
||||
this._printPreviewTab = gBrowser.loadOneTab("about:blank",
|
||||
{ inBackground: false });
|
||||
gBrowser.selectedTab = this._printPreviewTab;
|
||||
}
|
||||
return gBrowser.getBrowserForTab(this._printPreviewTab);
|
||||
},
|
||||
getSourceBrowser: function () {
|
||||
return this._tabBeforePrintPreview ?
|
||||
this._tabBeforePrintPreview.linkedBrowser : gBrowser.selectedBrowser;
|
||||
},
|
||||
getNavToolbox: function () {
|
||||
return gNavToolbox;
|
||||
},
|
||||
onEnter: function () {
|
||||
gInPrintPreviewMode = true;
|
||||
this._toggleAffectedChrome();
|
||||
},
|
||||
onExit: function () {
|
||||
gBrowser.selectedTab = this._tabBeforePrintPreview;
|
||||
this._tabBeforePrintPreview = null;
|
||||
gBrowser.removeTab(this._printPreviewTab);
|
||||
this._printPreviewTab = null;
|
||||
gInPrintPreviewMode = false;
|
||||
this._toggleAffectedChrome();
|
||||
},
|
||||
@ -2572,8 +2595,7 @@ var PrintPreviewListener = {
|
||||
this._chromeState.sidebarOpen = !sidebar.hidden;
|
||||
this._sidebarCommand = sidebar.getAttribute("sidebarcommand");
|
||||
|
||||
this._chromeState.hadTabStrip = gBrowser.getStripVisibility();
|
||||
gBrowser.setStripVisibilityTo(false);
|
||||
gBrowser.mStrip.setAttribute("moz-collapsed", "true");
|
||||
|
||||
var notificationBox = gBrowser.getNotificationBox();
|
||||
this._chromeState.notificationsOpen = !notificationBox.notificationsHidden;
|
||||
@ -2588,8 +2610,7 @@ var PrintPreviewListener = {
|
||||
gFindBar.close();
|
||||
},
|
||||
_showChrome: function () {
|
||||
if (this._chromeState.hadTabStrip)
|
||||
gBrowser.setStripVisibilityTo(true);
|
||||
gBrowser.mStrip.removeAttribute("moz-collapsed");
|
||||
|
||||
if (this._chromeState.notificationsOpen)
|
||||
gBrowser.getNotificationBox().notificationsHidden = false;
|
||||
@ -2602,11 +2623,6 @@ var PrintPreviewListener = {
|
||||
}
|
||||
}
|
||||
|
||||
function getPPBrowser()
|
||||
{
|
||||
return gBrowser;
|
||||
}
|
||||
|
||||
function getMarkupDocumentViewer()
|
||||
{
|
||||
return gBrowser.markupDocumentViewer;
|
||||
|
@ -1798,6 +1798,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDocument)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnloadBlocker)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstBaseNodeWithHref)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDOMImplementation)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOriginalDocument)
|
||||
|
||||
// An element will only be in the linkmap as long as it's in the
|
||||
// document, so we'll traverse the table here instead of from the element.
|
||||
@ -1851,6 +1852,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDisplayDocument)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstBaseNodeWithHref)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDOMImplementation)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOriginalDocument)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA
|
||||
|
||||
|
@ -87,32 +87,27 @@ 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 (aListenerOrEnterCallback, aExitCallback)
|
||||
// If aCallback is not null, it must be an object which has the following methods:
|
||||
// getPrintPreviewBrowser(), getSourceBrowser(),
|
||||
// getNavToolbox(), onEnter() and onExit().
|
||||
// If aCallback is null, then printPreview must previously have been called with
|
||||
// non-null aCallback and that object will be reused.
|
||||
printPreview: function (aCallback)
|
||||
{
|
||||
// if we're already in PP mode, don't set the callbacks; chances
|
||||
// are they're null because someone is calling printPreview() to
|
||||
// if we're already in PP mode, don't set the callback; chances
|
||||
// are it is null because someone is calling printPreview() to
|
||||
// get us to refresh the display.
|
||||
if (!document.getElementById("print-preview-toolbar")) {
|
||||
if (typeof aListenerOrEnterCallback == "object") {
|
||||
this._onEnterPP = function () { aListenerOrEnterCallback.onEnter(); };
|
||||
this._onExitPP = function () { aListenerOrEnterCallback.onExit(); };
|
||||
} else {
|
||||
this._onEnterPP = aListenerOrEnterCallback;
|
||||
this._onExitPP = aExitCallback;
|
||||
}
|
||||
this._callback = aCallback;
|
||||
this._sourceBrowser = aCallback.getSourceBrowser();
|
||||
this._originalTitle = this._sourceBrowser.contentDocument.title;
|
||||
this._originalURL = this._sourceBrowser.currentURI.spec;
|
||||
} else {
|
||||
// collapse the browser here -- it will be shown in
|
||||
// onEnterPrintPreview; this forces a reflow which fixes display
|
||||
// enterPrintPreview; this forces a reflow which fixes display
|
||||
// issues in bug 267422.
|
||||
var browser = getPPBrowser();
|
||||
if (browser)
|
||||
browser.collapsed = true;
|
||||
this._sourceBrowser = this._callback.getPrintPreviewBrowser();
|
||||
this._sourceBrowser.collapsed = true;
|
||||
}
|
||||
|
||||
this._webProgressPP = {};
|
||||
@ -133,17 +128,16 @@ var PrintUtils = {
|
||||
PPROMPTSVC.showProgress(window, webBrowserPrint, printSettings, this._obsPP, false,
|
||||
this._webProgressPP, ppParams, notifyOnOpen);
|
||||
if (ppParams.value) {
|
||||
var webNav = getWebNavigation();
|
||||
ppParams.value.docTitle = webNav.document.title;
|
||||
ppParams.value.docURL = webNav.currentURI.spec;
|
||||
ppParams.value.docTitle = this._originalTitle;
|
||||
ppParams.value.docURL = this._originalURL;
|
||||
}
|
||||
|
||||
// this tells us whether we should continue on with PP or
|
||||
// wait for the callback via the observer
|
||||
if (!notifyOnOpen.value.valueOf() || this._webProgressPP.value == null)
|
||||
this.enterPrintPreview(aWindow);
|
||||
this.enterPrintPreview();
|
||||
} catch (e) {
|
||||
this.enterPrintPreview(aWindow);
|
||||
this.enterPrintPreview();
|
||||
}
|
||||
},
|
||||
|
||||
@ -155,11 +149,7 @@ var PrintUtils = {
|
||||
},
|
||||
|
||||
getPrintPreview: function() {
|
||||
if (this._printPreviewTab) {
|
||||
var docShell = getPPBrowser().getBrowserForTab(this._printPreviewTab).docShell;
|
||||
return docShell.printPreview;
|
||||
}
|
||||
return null;
|
||||
return this._callback.getPrintPreviewBrowser().docShell.printPreview;
|
||||
},
|
||||
|
||||
////////////////////////////////////////
|
||||
@ -202,11 +192,12 @@ var PrintUtils = {
|
||||
return printSettings;
|
||||
},
|
||||
|
||||
_originalZoomValue: null,
|
||||
_closeHandlerPP: null,
|
||||
_webProgressPP: null,
|
||||
_onEnterPP: null,
|
||||
_onExitPP: null,
|
||||
_callback: null,
|
||||
_sourceBrowser: null,
|
||||
_originalTitle: "",
|
||||
_originalURL: "",
|
||||
|
||||
// This observer is called once the progress dialog has been "opened"
|
||||
_obsPP:
|
||||
@ -227,44 +218,19 @@ var PrintUtils = {
|
||||
}
|
||||
},
|
||||
|
||||
_originalTab: null,
|
||||
_printPreviewTab: null,
|
||||
|
||||
enterPrintPreview: function ()
|
||||
{
|
||||
gFocusedElement = document.commandDispatcher.focusedElement;
|
||||
|
||||
// Reset the zoom value and save it to be restored later.
|
||||
if (typeof ZoomManager == "object") {
|
||||
this._originalZoomValue = ZoomManager.zoom;
|
||||
ZoomManager.reset();
|
||||
}
|
||||
|
||||
var webBrowserPrint;
|
||||
var printSettings = this.getPrintSettings();
|
||||
var tabbrowser = getPPBrowser();
|
||||
var contentWindow = null;
|
||||
if (tabbrowser) {
|
||||
if (this._printPreviewTab) {
|
||||
contentWindow =
|
||||
tabbrowser.getBrowserForTab(this._printPreviewTab).contentWindow;
|
||||
} else {
|
||||
this._originalTab = tabbrowser.mCurrentTab;
|
||||
contentWindow = window.content
|
||||
this._printPreviewTab = tabbrowser.loadOneTab("about:blank", null, null,
|
||||
null, true, false);
|
||||
}
|
||||
}
|
||||
var originalWindow = this._sourceBrowser.contentWindow;
|
||||
|
||||
try {
|
||||
webBrowserPrint = this.getPrintPreview();
|
||||
webBrowserPrint.printPreview(printSettings, contentWindow,
|
||||
webBrowserPrint.printPreview(printSettings, originalWindow,
|
||||
this._webProgressPP.value);
|
||||
} catch (e) {
|
||||
this._printPreviewTab = null;
|
||||
this._originalTab = null;
|
||||
if (typeof ZoomManager == "object")
|
||||
ZoomManager.zoom = this._originalZoomValue;
|
||||
// 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
|
||||
@ -275,12 +241,9 @@ var PrintUtils = {
|
||||
var printPreviewTB = document.getElementById("print-preview-toolbar");
|
||||
if (printPreviewTB) {
|
||||
printPreviewTB.updateToolbar();
|
||||
var browser = getPPBrowser();
|
||||
if (browser)
|
||||
browser.collapsed = false;
|
||||
|
||||
tabbrowser.getBrowserForTab(this._printPreviewTab).contentWindow.focus();
|
||||
tabbrowser.selectedTab = this._printPreviewTab;
|
||||
var browser = this._callback.getPrintPreviewBrowser();
|
||||
browser.collapsed = false;
|
||||
browser.contentWindow.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -293,7 +256,7 @@ var PrintUtils = {
|
||||
printPreviewTB.id = "print-preview-toolbar";
|
||||
printPreviewTB.className = "toolbar-primary";
|
||||
|
||||
var navToolbox = getNavToolbox();
|
||||
var navToolbox = this._callback.getNavToolbox();
|
||||
navToolbox.parentNode.insertBefore(printPreviewTB, navToolbox);
|
||||
|
||||
// copy the window close handler
|
||||
@ -306,14 +269,12 @@ var PrintUtils = {
|
||||
// disable chrome shortcuts...
|
||||
window.addEventListener("keypress", this.onKeyPressPP, true);
|
||||
|
||||
tabbrowser.getBrowserForTab(this._printPreviewTab).contentWindow.focus();
|
||||
tabbrowser.selectedTab = this._printPreviewTab;
|
||||
var browser = this._callback.getPrintPreviewBrowser();
|
||||
browser.collapsed = false;
|
||||
browser.contentWindow.focus();
|
||||
|
||||
// on Enter PP Call back
|
||||
if (this._onEnterPP) {
|
||||
this._onEnterPP();
|
||||
this._onEnterPP = null;
|
||||
}
|
||||
this._callback.onEnter();
|
||||
},
|
||||
|
||||
exitPrintPreview: function ()
|
||||
@ -324,23 +285,12 @@ var PrintUtils = {
|
||||
document.documentElement.setAttribute("onclose", this._closeHandlerPP);
|
||||
this._closeHandlerPP = null;
|
||||
|
||||
var webBrowserPrint = this.getWebBrowserPrint();
|
||||
var webBrowserPrint = this.getPrintPreview();
|
||||
webBrowserPrint.exitPrintPreview();
|
||||
|
||||
var tabbrowser = getPPBrowser();
|
||||
if (tabbrowser) {
|
||||
tabbrowser.removeTab(this._printPreviewTab);
|
||||
tabbrowser.selectedTab = this._originalTab;
|
||||
this._originalTab = null;
|
||||
this._printPreviewTab = null;
|
||||
}
|
||||
|
||||
if (typeof ZoomManager == "object")
|
||||
ZoomManager.zoom = this._originalZoomValue;
|
||||
|
||||
// remove the print preview toolbar
|
||||
var printPreviewTB = document.getElementById("print-preview-toolbar");
|
||||
getNavToolbox().parentNode.removeChild(printPreviewTB);
|
||||
this._callback.getNavToolbox().parentNode.removeChild(printPreviewTB);
|
||||
|
||||
var fm = Components.classes["@mozilla.org/focus-manager;1"]
|
||||
.getService(Components.interfaces.nsIFocusManager);
|
||||
@ -350,11 +300,7 @@ var PrintUtils = {
|
||||
window.content.focus();
|
||||
gFocusedElement = null;
|
||||
|
||||
// on Exit PP Call back
|
||||
if (this._onExitPP) {
|
||||
this._onExitPP();
|
||||
this._onExitPP = null;
|
||||
}
|
||||
this._callback.onExit();
|
||||
},
|
||||
|
||||
onKeyPressPP: function (aEvent)
|
||||
|
@ -78,7 +78,7 @@
|
||||
|
||||
<command id="cmd_savePage" oncommand="ViewSourceSavePage();"/>
|
||||
<command id="cmd_print" oncommand="PrintUtils.print();"/>
|
||||
<command id="cmd_printpreview" oncommand="PrintUtils.printPreview(onEnterPP, onExitPP);"/>
|
||||
<command id="cmd_printpreview" oncommand="PrintUtils.printPreview(PrintPreviewListener);"/>
|
||||
<command id="cmd_pagesetup" oncommand="PrintUtils.showPageSetup();"/>
|
||||
<command id="cmd_close" oncommand="window.close();"/>
|
||||
<commandset id="editMenuCommands"/>
|
||||
|
@ -383,26 +383,34 @@ function ViewSourceSavePage()
|
||||
saveURL(window.content.location.href.substring(12), null, "SaveLinkTitle");
|
||||
}
|
||||
|
||||
function onEnterPP()
|
||||
{
|
||||
var toolbox = document.getElementById("viewSource-toolbox");
|
||||
toolbox.hidden = true;
|
||||
}
|
||||
|
||||
function onExitPP()
|
||||
{
|
||||
var toolbox = document.getElementById("viewSource-toolbox");
|
||||
toolbox.hidden = false;
|
||||
}
|
||||
|
||||
function getPPBrowser() {
|
||||
return gBrowser;
|
||||
}
|
||||
|
||||
// printUtils.js uses this
|
||||
function getNavToolbox()
|
||||
{
|
||||
return document.getElementById("appcontent");
|
||||
var PrintPreviewListener = {
|
||||
getPrintPreviewBrowser: function () {
|
||||
var browser = document.getElementById("ppBrowser");
|
||||
if (!browser) {
|
||||
browser = document.createElement("browser");
|
||||
browser.setAttribute("id", "ppBrowser");
|
||||
browser.setAttribute("flex", "1");
|
||||
document.getElementById("appcontent").
|
||||
insertBefore(browser, document.getElementById("FindToolbar"));
|
||||
}
|
||||
return browser;
|
||||
},
|
||||
getSourceBrowser: function () {
|
||||
return gBrowser;
|
||||
},
|
||||
getNavToolbox: function () {
|
||||
return document.getElementById("appcontent");
|
||||
},
|
||||
onEnter: function () {
|
||||
var toolbox = document.getElementById("viewSource-toolbox");
|
||||
toolbox.hidden = true;
|
||||
gBrowser.collapsed = true;
|
||||
},
|
||||
onExit: function () {
|
||||
document.getElementById("ppBrowser").collapsed = true;
|
||||
gBrowser.collapsed = false;
|
||||
document.getElementById("viewSource-toolbox").hidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
function getWebNavigation()
|
||||
|
@ -78,7 +78,7 @@
|
||||
|
||||
<command id="cmd_savePage" oncommand="ViewSourceSavePage();"/>
|
||||
<command id="cmd_print" oncommand="PrintUtils.print();"/>
|
||||
<command id="cmd_printpreview" oncommand="PrintUtils.printPreview(onEnterPP, onExitPP);"/>
|
||||
<command id="cmd_printpreview" oncommand="PrintUtils.printPreview(PrintPreviewListener);"/>
|
||||
<command id="cmd_pagesetup" oncommand="PrintUtils.showPageSetup();"/>
|
||||
<command id="cmd_close" oncommand="window.close();"/>
|
||||
<commandset id="editMenuCommands"/>
|
||||
|
Loading…
Reference in New Issue
Block a user