mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 08:42:13 +00:00
Bug 454562 - clean up onEnterPrintPreview, onExitPrintPreview and related code. r=mano
This commit is contained in:
parent
c1be9664b8
commit
32c8f9d7d5
@ -66,7 +66,7 @@
|
||||
|
||||
<command id="cmd_pageSetup" oncommand="PrintUtils.showPageSetup();"/>
|
||||
<command id="cmd_print" oncommand="PrintUtils.print();"/>
|
||||
<command id="cmd_printPreview" oncommand="PrintUtils.printPreview(onEnterPrintPreview, onExitPrintPreview);"/>
|
||||
<command id="cmd_printPreview" oncommand="PrintUtils.printPreview(PrintPreviewListener);"/>
|
||||
<command id="cmd_close" oncommand="BrowserCloseTabOrWindow()"/>
|
||||
<command id="cmd_closeWindow" oncommand="BrowserTryToCloseWindow()"/>
|
||||
<command id="cmd_toggleTaskbar" oncommand="goToggleToolbar('status-bar','toggle_taskbar');"/>
|
||||
|
@ -74,15 +74,12 @@ var gPrevCharset = null;
|
||||
var gProxyFavIcon = null;
|
||||
var gLastValidURLStr = "";
|
||||
var gProgressCollapseTimer = null;
|
||||
var gSidebarCommand = "";
|
||||
var gInPrintPreviewMode = false;
|
||||
let gDownloadMgr = null;
|
||||
|
||||
// Global variable that holds the nsContextMenu instance.
|
||||
var gContextMenu = null;
|
||||
|
||||
var gChromeState = null; // chrome state before we went into print preview
|
||||
|
||||
var gAutoHideTabbarPrefListener = null;
|
||||
var gBookmarkAllTabsHandler = null;
|
||||
|
||||
@ -2516,74 +2513,71 @@ function BrowserReloadWithFlags(reloadFlags) {
|
||||
}
|
||||
}
|
||||
|
||||
function toggleAffectedChrome(aHide)
|
||||
{
|
||||
// chrome to toggle includes:
|
||||
// (*) menubar
|
||||
// (*) navigation bar
|
||||
// (*) bookmarks toolbar
|
||||
// (*) tabstrip
|
||||
// (*) browser messages
|
||||
// (*) sidebar
|
||||
// (*) find bar
|
||||
// (*) statusbar
|
||||
var PrintPreviewListener = {
|
||||
onEnter: function () {
|
||||
gInPrintPreviewMode = true;
|
||||
this._toggleAffectedChrome();
|
||||
},
|
||||
onExit: function () {
|
||||
gInPrintPreviewMode = false;
|
||||
this._toggleAffectedChrome();
|
||||
},
|
||||
_toggleAffectedChrome: function () {
|
||||
// chrome to toggle includes:
|
||||
// (*) menubar
|
||||
// (*) navigation bar
|
||||
// (*) bookmarks toolbar
|
||||
// (*) tabstrip
|
||||
// (*) browser messages
|
||||
// (*) sidebar
|
||||
// (*) find bar
|
||||
// (*) statusbar
|
||||
|
||||
gNavToolbox.hidden = gInPrintPreviewMode;
|
||||
|
||||
if (gInPrintPreviewMode)
|
||||
this._hideChrome();
|
||||
else
|
||||
this._showChrome();
|
||||
|
||||
if (this._chromeState.sidebarOpen)
|
||||
toggleSidebar(this._sidebarCommand);
|
||||
},
|
||||
_hideChrome: function () {
|
||||
this._chromeState = {};
|
||||
|
||||
gNavToolbox.hidden = aHide;
|
||||
if (aHide)
|
||||
{
|
||||
gChromeState = {};
|
||||
var sidebar = document.getElementById("sidebar-box");
|
||||
gChromeState.sidebarOpen = !sidebar.hidden;
|
||||
gSidebarCommand = sidebar.getAttribute("sidebarcommand");
|
||||
this._chromeState.sidebarOpen = !sidebar.hidden;
|
||||
this._sidebarCommand = sidebar.getAttribute("sidebarcommand");
|
||||
|
||||
gChromeState.hadTabStrip = gBrowser.getStripVisibility();
|
||||
this._chromeState.hadTabStrip = gBrowser.getStripVisibility();
|
||||
gBrowser.setStripVisibilityTo(false);
|
||||
|
||||
var notificationBox = gBrowser.getNotificationBox();
|
||||
gChromeState.notificationsOpen = !notificationBox.notificationsHidden;
|
||||
notificationBox.notificationsHidden = aHide;
|
||||
this._chromeState.notificationsOpen = !notificationBox.notificationsHidden;
|
||||
notificationBox.notificationsHidden = true;
|
||||
|
||||
document.getElementById("sidebar").setAttribute("src", "about:blank");
|
||||
var statusbar = document.getElementById("status-bar");
|
||||
gChromeState.statusbarOpen = !statusbar.hidden;
|
||||
statusbar.hidden = aHide;
|
||||
this._chromeState.statusbarOpen = !statusbar.hidden;
|
||||
statusbar.hidden = true;
|
||||
|
||||
gChromeState.findOpen = !gFindBar.hidden;
|
||||
this._chromeState.findOpen = !gFindBar.hidden;
|
||||
gFindBar.close();
|
||||
}
|
||||
else {
|
||||
if (gChromeState.hadTabStrip) {
|
||||
},
|
||||
_showChrome: function () {
|
||||
if (this._chromeState.hadTabStrip)
|
||||
gBrowser.setStripVisibilityTo(true);
|
||||
}
|
||||
|
||||
if (gChromeState.notificationsOpen) {
|
||||
gBrowser.getNotificationBox().notificationsHidden = aHide;
|
||||
}
|
||||
if (this._chromeState.notificationsOpen)
|
||||
gBrowser.getNotificationBox().notificationsHidden = false;
|
||||
|
||||
if (gChromeState.statusbarOpen) {
|
||||
var statusbar = document.getElementById("status-bar");
|
||||
statusbar.hidden = aHide;
|
||||
}
|
||||
if (this._chromeState.statusbarOpen)
|
||||
document.getElementById("status-bar").hidden = false;
|
||||
|
||||
if (gChromeState.findOpen)
|
||||
if (this._chromeState.findOpen)
|
||||
gFindBar.open();
|
||||
}
|
||||
|
||||
if (gChromeState.sidebarOpen)
|
||||
toggleSidebar(gSidebarCommand);
|
||||
}
|
||||
|
||||
function onEnterPrintPreview()
|
||||
{
|
||||
gInPrintPreviewMode = true;
|
||||
toggleAffectedChrome(true);
|
||||
}
|
||||
|
||||
function onExitPrintPreview()
|
||||
{
|
||||
// restore chrome to original state
|
||||
gInPrintPreviewMode = false;
|
||||
toggleAffectedChrome(false);
|
||||
}
|
||||
|
||||
function getPPBrowser()
|
||||
|
@ -98,23 +98,23 @@ function testPrintPreview(aTab, aCallback) {
|
||||
FullZoom.enlarge();
|
||||
let level = ZoomManager.zoom;
|
||||
|
||||
function onEnterPP() {
|
||||
toggleAffectedChromeOrig.apply(null, arguments);
|
||||
|
||||
function onExitPP() {
|
||||
toggleAffectedChromeOrig.apply(null, arguments);
|
||||
toggleAffectedChrome = toggleAffectedChromeOrig;
|
||||
|
||||
zoomTest(aTab, level, "Toggling print preview mode should not affect zoom level");
|
||||
|
||||
FullZoom.reset();
|
||||
aCallback();
|
||||
}
|
||||
toggleAffectedChrome = onExitPP;
|
||||
let onEnterOrig = PrintPreviewListener.onEnter;
|
||||
PrintPreviewListener.onEnter = function () {
|
||||
PrintPreviewListener.onEnter = onEnterOrig;
|
||||
PrintPreviewListener.onEnter.apply(PrintPreviewListener, arguments);
|
||||
PrintUtils.exitPrintPreview();
|
||||
}
|
||||
let toggleAffectedChromeOrig = toggleAffectedChrome;
|
||||
toggleAffectedChrome = onEnterPP;
|
||||
};
|
||||
|
||||
let onExitOrig = PrintPreviewListener.onExit;
|
||||
PrintPreviewListener.onExit = function () {
|
||||
PrintPreviewListener.onExit = onExitOrig;
|
||||
PrintPreviewListener.onExit.apply(PrintPreviewListener, arguments);
|
||||
|
||||
zoomTest(aTab, level, "Toggling print preview mode should not affect zoom level");
|
||||
|
||||
FullZoom.reset();
|
||||
aCallback();
|
||||
};
|
||||
|
||||
let printPreview = new Function(document.getElementById("cmd_printPreview")
|
||||
.getAttribute("oncommand"));
|
||||
|
@ -112,24 +112,24 @@ function testPrintPreview(aBrowser, aCallback) {
|
||||
FullZoom.enlarge();
|
||||
let level = ZoomManager.getZoomForBrowser(aBrowser);
|
||||
|
||||
function onEnterPP(aHide) {
|
||||
toggleAffectedChromeOrig(aHide);
|
||||
|
||||
function onExitPP(aHide) {
|
||||
toggleAffectedChromeOrig(aHide);
|
||||
toggleAffectedChrome = toggleAffectedChromeOrig;
|
||||
|
||||
is(ZoomManager.getZoomForBrowser(aBrowser), level,
|
||||
"Toggling print preview mode should not affect zoom level");
|
||||
|
||||
FullZoom.reset();
|
||||
aCallback();
|
||||
}
|
||||
toggleAffectedChrome = onExitPP;
|
||||
let onEnterOrig = PrintPreviewListener.onEnter;
|
||||
PrintPreviewListener.onEnter = function () {
|
||||
PrintPreviewListener.onEnter = onEnterOrig;
|
||||
PrintPreviewListener.onEnter.apply(PrintPreviewListener, arguments);
|
||||
PrintUtils.exitPrintPreview();
|
||||
}
|
||||
let toggleAffectedChromeOrig = toggleAffectedChrome;
|
||||
toggleAffectedChrome = onEnterPP;
|
||||
};
|
||||
|
||||
let onExitOrig = PrintPreviewListener.onExit;
|
||||
PrintPreviewListener.onExit = function () {
|
||||
PrintPreviewListener.onExit = onExitOrig;
|
||||
PrintPreviewListener.onExit.apply(PrintPreviewListener, arguments);
|
||||
|
||||
is(ZoomManager.getZoomForBrowser(aBrowser), level,
|
||||
"Toggling print preview mode should not affect zoom level");
|
||||
|
||||
FullZoom.reset();
|
||||
aCallback();
|
||||
};
|
||||
|
||||
let printPreview = new Function(document.getElementById("cmd_printPreview")
|
||||
.getAttribute("oncommand"));
|
||||
|
@ -93,15 +93,19 @@ var PrintUtils = {
|
||||
// (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 (aListenerOrEnterCallback, aExitCallback)
|
||||
{
|
||||
// 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.
|
||||
var pptoolbar = document.getElementById("print-preview-toolbar");
|
||||
if (!pptoolbar) {
|
||||
this._onEnterPP = aEnterPPCallback;
|
||||
this._onExitPP = aExitPPCallback;
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
// collapse the browser here -- it will be shown in
|
||||
// onEnterPrintPreview; this forces a reflow which fixes display
|
||||
@ -114,7 +118,7 @@ var PrintUtils = {
|
||||
this._webProgressPP = {};
|
||||
var ppParams = {};
|
||||
var notifyOnOpen = {};
|
||||
var webBrowserPrint = this.getWebBrowserPrint(aWindow);
|
||||
var webBrowserPrint = this.getWebBrowserPrint();
|
||||
var printSettings = this.getPrintSettings();
|
||||
// Here we get the PrintingPromptService so we can display the PP Progress from script
|
||||
// For the browser implemented via XUL with the PP toolbar we cannot let it be
|
||||
@ -215,7 +219,7 @@ var PrintUtils = {
|
||||
}
|
||||
},
|
||||
|
||||
enterPrintPreview: function (aWindow)
|
||||
enterPrintPreview: function ()
|
||||
{
|
||||
gFocusedElement = document.commandDispatcher.focusedElement;
|
||||
|
||||
@ -225,7 +229,7 @@ var PrintUtils = {
|
||||
ZoomManager.reset();
|
||||
}
|
||||
|
||||
var webBrowserPrint = this.getWebBrowserPrint(aWindow);
|
||||
var webBrowserPrint = this.getWebBrowserPrint();
|
||||
var printSettings = this.getPrintSettings();
|
||||
try {
|
||||
webBrowserPrint.printPreview(printSettings, null, this._webProgressPP.value);
|
||||
@ -269,9 +273,8 @@ var PrintUtils = {
|
||||
|
||||
// disable chrome shortcuts...
|
||||
window.addEventListener("keypress", this.onKeyPressPP, true);
|
||||
|
||||
var contentWindow = aWindow || window.content;
|
||||
contentWindow.focus();
|
||||
|
||||
window.content.focus();
|
||||
|
||||
// on Enter PP Call back
|
||||
if (this._onEnterPP) {
|
||||
@ -280,7 +283,7 @@ var PrintUtils = {
|
||||
}
|
||||
},
|
||||
|
||||
exitPrintPreview: function (aWindow)
|
||||
exitPrintPreview: function ()
|
||||
{
|
||||
window.removeEventListener("keypress", this.onKeyPressPP, true);
|
||||
|
||||
@ -288,7 +291,7 @@ var PrintUtils = {
|
||||
document.documentElement.setAttribute("onclose", this._closeHandlerPP);
|
||||
this._closeHandlerPP = null;
|
||||
|
||||
var webBrowserPrint = this.getWebBrowserPrint(aWindow);
|
||||
var webBrowserPrint = this.getWebBrowserPrint();
|
||||
webBrowserPrint.exitPrintPreview();
|
||||
if (typeof ZoomManager == "object")
|
||||
ZoomManager.zoom = this._originalZoomValue;
|
||||
@ -302,7 +305,7 @@ var PrintUtils = {
|
||||
if (gFocusedElement)
|
||||
fm.setFocus(gFocusedElement, fm.FLAG_NOSCROLL);
|
||||
else
|
||||
(aWindow || window.content).focus();
|
||||
window.content.focus();
|
||||
gFocusedElement = null;
|
||||
|
||||
// on Exit PP Call back
|
||||
|
Loading…
Reference in New Issue
Block a user