backout Bug 544018

This commit is contained in:
Olli Pettay 2010-02-08 19:00:41 +02:00
parent 93a48e52ac
commit f09ebf9810
6 changed files with 108 additions and 92 deletions

View File

@ -2536,34 +2536,11 @@ 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();
},
@ -2595,7 +2572,8 @@ var PrintPreviewListener = {
this._chromeState.sidebarOpen = !sidebar.hidden;
this._sidebarCommand = sidebar.getAttribute("sidebarcommand");
gBrowser.mStrip.setAttribute("moz-collapsed", "true");
this._chromeState.hadTabStrip = gBrowser.getStripVisibility();
gBrowser.setStripVisibilityTo(false);
var notificationBox = gBrowser.getNotificationBox();
this._chromeState.notificationsOpen = !notificationBox.notificationsHidden;
@ -2610,7 +2588,8 @@ var PrintPreviewListener = {
gFindBar.close();
},
_showChrome: function () {
gBrowser.mStrip.removeAttribute("moz-collapsed");
if (this._chromeState.hadTabStrip)
gBrowser.setStripVisibilityTo(true);
if (this._chromeState.notificationsOpen)
gBrowser.getNotificationBox().notificationsHidden = false;
@ -2623,6 +2602,11 @@ var PrintPreviewListener = {
}
}
function getPPBrowser()
{
return gBrowser;
}
function getMarkupDocumentViewer()
{
return gBrowser.markupDocumentViewer;

View File

@ -1798,7 +1798,6 @@ 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.
@ -1852,7 +1851,6 @@ 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

View File

@ -87,27 +87,32 @@ var PrintUtils = {
}
},
// 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)
// 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 we're already in PP mode, don't set the callback; chances
// are it is null because someone is calling printPreview() to
// if we're already in PP mode, don't set the callbacks; chances
// are they're null because someone is calling printPreview() to
// get us to refresh the display.
if (!document.getElementById("print-preview-toolbar")) {
this._callback = aCallback;
this._sourceBrowser = aCallback.getSourceBrowser();
this._originalTitle = this._sourceBrowser.contentDocument.title;
this._originalURL = this._sourceBrowser.currentURI.spec;
if (typeof aListenerOrEnterCallback == "object") {
this._onEnterPP = function () { aListenerOrEnterCallback.onEnter(); };
this._onExitPP = function () { aListenerOrEnterCallback.onExit(); };
} else {
this._onEnterPP = aListenerOrEnterCallback;
this._onExitPP = aExitCallback;
}
} else {
// collapse the browser here -- it will be shown in
// enterPrintPreview; this forces a reflow which fixes display
// onEnterPrintPreview; this forces a reflow which fixes display
// issues in bug 267422.
this._sourceBrowser = this._callback.getPrintPreviewBrowser();
this._sourceBrowser.collapsed = true;
var browser = getPPBrowser();
if (browser)
browser.collapsed = true;
}
this._webProgressPP = {};
@ -128,8 +133,9 @@ var PrintUtils = {
PPROMPTSVC.showProgress(window, webBrowserPrint, printSettings, this._obsPP, false,
this._webProgressPP, ppParams, notifyOnOpen);
if (ppParams.value) {
ppParams.value.docTitle = this._originalTitle;
ppParams.value.docURL = this._originalURL;
var webNav = getWebNavigation();
ppParams.value.docTitle = webNav.document.title;
ppParams.value.docURL = webNav.currentURI.spec;
}
// this tells us whether we should continue on with PP or
@ -149,7 +155,11 @@ var PrintUtils = {
},
getPrintPreview: function() {
return this._callback.getPrintPreviewBrowser().docShell.printPreview;
if (this._printPreviewTab) {
var docShell = getPPBrowser().getBrowserForTab(this._printPreviewTab).docShell;
return docShell.printPreview;
}
return null;
},
////////////////////////////////////////
@ -195,10 +205,8 @@ var PrintUtils = {
_originalZoomValue: null,
_closeHandlerPP: null,
_webProgressPP: null,
_callback: null,
_sourceBrowser: null,
_originalTitle: "",
_originalURL: "",
_onEnterPP: null,
_onExitPP: null,
// This observer is called once the progress dialog has been "opened"
_obsPP:
@ -219,6 +227,9 @@ var PrintUtils = {
}
},
_originalTab: null,
_printPreviewTab: null,
enterPrintPreview: function ()
{
gFocusedElement = document.commandDispatcher.focusedElement;
@ -231,13 +242,27 @@ var PrintUtils = {
var webBrowserPrint;
var printSettings = this.getPrintSettings();
var originalWindow = this._sourceBrowser.contentWindow;
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);
}
}
try {
webBrowserPrint = this.getPrintPreview();
webBrowserPrint.printPreview(printSettings, originalWindow,
webBrowserPrint.printPreview(printSettings, contentWindow,
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,
@ -250,9 +275,12 @@ var PrintUtils = {
var printPreviewTB = document.getElementById("print-preview-toolbar");
if (printPreviewTB) {
printPreviewTB.updateToolbar();
var browser = this._callback.getPrintPreviewBrowser();
browser.collapsed = false;
browser.contentWindow.focus();
var browser = getPPBrowser();
if (browser)
browser.collapsed = false;
tabbrowser.getBrowserForTab(this._printPreviewTab).contentWindow.focus();
tabbrowser.selectedTab = this._printPreviewTab;
return;
}
@ -265,7 +293,7 @@ var PrintUtils = {
printPreviewTB.id = "print-preview-toolbar";
printPreviewTB.className = "toolbar-primary";
var navToolbox = this._callback.getNavToolbox();
var navToolbox = getNavToolbox();
navToolbox.parentNode.insertBefore(printPreviewTB, navToolbox);
// copy the window close handler
@ -278,12 +306,14 @@ var PrintUtils = {
// disable chrome shortcuts...
window.addEventListener("keypress", this.onKeyPressPP, true);
var browser = this._callback.getPrintPreviewBrowser();
browser.collapsed = false;
browser.contentWindow.focus();
tabbrowser.getBrowserForTab(this._printPreviewTab).contentWindow.focus();
tabbrowser.selectedTab = this._printPreviewTab;
// on Enter PP Call back
this._callback.onEnter();
if (this._onEnterPP) {
this._onEnterPP();
this._onEnterPP = null;
}
},
exitPrintPreview: function ()
@ -294,15 +324,23 @@ var PrintUtils = {
document.documentElement.setAttribute("onclose", this._closeHandlerPP);
this._closeHandlerPP = null;
var webBrowserPrint = this.getPrintPreview();
var webBrowserPrint = this.getWebBrowserPrint();
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");
this._callback.getNavToolbox().parentNode.removeChild(printPreviewTB);
getNavToolbox().parentNode.removeChild(printPreviewTB);
var fm = Components.classes["@mozilla.org/focus-manager;1"]
.getService(Components.interfaces.nsIFocusManager);
@ -312,7 +350,11 @@ var PrintUtils = {
window.content.focus();
gFocusedElement = null;
this._callback.onExit();
// on Exit PP Call back
if (this._onExitPP) {
this._onExitPP();
this._onExitPP = null;
}
},
onKeyPressPP: function (aEvent)

View File

@ -78,7 +78,7 @@
<command id="cmd_savePage" oncommand="ViewSourceSavePage();"/>
<command id="cmd_print" oncommand="PrintUtils.print();"/>
<command id="cmd_printpreview" oncommand="PrintUtils.printPreview(PrintPreviewListener);"/>
<command id="cmd_printpreview" oncommand="PrintUtils.printPreview(onEnterPP, onExitPP);"/>
<command id="cmd_pagesetup" oncommand="PrintUtils.showPageSetup();"/>
<command id="cmd_close" oncommand="window.close();"/>
<commandset id="editMenuCommands"/>

View File

@ -383,34 +383,26 @@ function ViewSourceSavePage()
saveURL(window.content.location.href.substring(12), null, "SaveLinkTitle");
}
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 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");
}
function getWebNavigation()

View File

@ -78,7 +78,7 @@
<command id="cmd_savePage" oncommand="ViewSourceSavePage();"/>
<command id="cmd_print" oncommand="PrintUtils.print();"/>
<command id="cmd_printpreview" oncommand="PrintUtils.printPreview(PrintPreviewListener);"/>
<command id="cmd_printpreview" oncommand="PrintUtils.printPreview(onEnterPP, onExitPP);"/>
<command id="cmd_pagesetup" oncommand="PrintUtils.showPageSetup();"/>
<command id="cmd_close" oncommand="window.close();"/>
<commandset id="editMenuCommands"/>