From b4dca54e304889ebaa8eb3274f33ddec7926658f Mon Sep 17 00:00:00 2001 From: "reed%reedloden.com" Date: Sat, 8 Mar 2008 09:49:02 +0000 Subject: [PATCH] Bug 421410 - "selected text in input box is cleared/unselected after print preview" [p=martijn.martijn@gmail.com (Martijn Wargers) r=Enn a1.9=beltzner] --- .../components/printing/content/printUtils.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/toolkit/components/printing/content/printUtils.js b/toolkit/components/printing/content/printUtils.js index 5f31eb92412..a352106fffc 100644 --- a/toolkit/components/printing/content/printUtils.js +++ b/toolkit/components/printing/content/printUtils.js @@ -41,6 +41,7 @@ var gPrintSettingsAreGlobal = false; var gSavePrintSettings = false; +var gFocusedElement = null; var PrintUtils = { @@ -215,6 +216,8 @@ var PrintUtils = { enterPrintPreview: function (aWindow) { + gFocusedElement = document.commandDispatcher.focusedElement; + var webBrowserPrint = this.getWebBrowserPrint(aWindow); var printSettings = this.getPrintSettings(); try { @@ -285,6 +288,21 @@ var PrintUtils = { var contentWindow = aWindow || window.content; contentWindow.focus(); + var cmdDispatcher = document.commandDispatcher; + cmdDispatcher.suppressFocusScroll = true; + if (gFocusedElement instanceof HTMLElement || + gFocusedElement instanceof XULElement || + gFocusedElement instanceof Window) { + gFocusedElement.focus(); + } + else if (gFocusedElement instanceof Node) { + var content = window.content; + if (content instanceof Components.interfaces.nsIInterfaceRequestor) + content.getInterface(Components.interfaces.nsIDOMWindowUtils).focus(gFocusedElement); + } + gFocusedElement = null; + cmdDispatcher.suppressFocusScroll = false; + // on Exit PP Call back if (this._onExitPP) { this._onExitPP();