Closed Bug 544018 Opened 15 years ago Closed 15 years ago

print preview doesn't work in view source

Categories

(Core :: Print Preview, defect)

x86
All
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: smaug, Assigned: smaug)

References

Details

Attachments

(2 files, 6 obsolete files)

Attached patch patch (obsolete) (deleted) — Splinter Review
I made a silly mistake to mix toolkit and browser code in bug 487667. Fixing that here. printutils requires now two more methods to be implemented. That way browser.js can open a new tab for print preview, and viewsource can lazily create a browser for the print preview. This patch simplifies the code and makes it more re-usable. The changes to printUtils.js are need also because of TB and SM. I am sorry about not really thinking about this before. Clone-doc-for-printing patch was big and important enough as such, so I focused on getting the most commonly used UI working. There is also a bug that autohide tabs become visible after printpreview. That is fixed by the maybeShowStrip code. Trivial change to nsDocument.cpp to make more things cycle collected.
Attachment #425008 - Flags: review?(dao)
Blocks: 543205
Comment on attachment 425008 [details] [diff] [review] patch > gBrowser.setStripVisibilityTo(false); >- if (this._chromeState.hadTabStrip) >- gBrowser.setStripVisibilityTo(true); >+ gBrowser.maybeShowStrip(); >+ <method name="maybeShowStrip"> >+ <body> >+ <![CDATA[ >+ if (this.mStrip.collapsed && >+ ((this.mTabs.length - this._removingTabs.length > 1) || >+ !this.mPrefs.getBoolPref("browser.tabs.autoHide"))) >+ this.setStripVisibilityTo(true); >+ ]]> >+ </body> >+ </method> Instead of this, you can do gBrowser.mStrip.setAttribute("moz-collapsed", true/false) like FullScreen.mouseoverToggle does it... no new API needed. >+ // calling PrintUtils.printPreview() requires that you have five functions >+ // in the global scope: getBrowserToPP(), which returns the browser for which >+ // the print preview should be created, getPPBrowser(), which returns the browser >+ // element in the window print preview uses, doneWithPPBrowser() which is called >+ // when print preview browser isn't needed anymore, 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 Rather than messing with the global scope, can these be callbacks on the PrintPreviewListener object that browser.js passes to PrintUtils.printPreview? Since we're breaking consumers anyway, this seems like a good opportunity to do this.
(In reply to comment #1) > Instead of this, you can do gBrowser.mStrip.setAttribute("moz-collapsed", > true/false) like FullScreen.mouseoverToggle does it... no new API needed. Ah, will do. > Rather than messing with the global scope, can these be callbacks on the > PrintPreviewListener object that browser.js passes to PrintUtils.printPreview? > Since we're breaking consumers anyway, this seems like a good opportunity to do > this. Yeah, sounds good.
Attachment #425008 - Flags: review?(dao)
Attached patch patch (obsolete) (deleted) — Splinter Review
Remove the requirement for global functions.
Attachment #425008 - Attachment is obsolete: true
Attachment #425309 - Flags: review?(dao)
Comment on attachment 425309 [details] [diff] [review] patch > var PrintPreviewListener = { >+ _printPreviewTab: null, >+ _tabBeforePrintPreview: null, >+ >+ getPPBrowser: function () { Since there's already a host object, please remove PP from the method names. >+ if (!this._printPreviewTab) { >+ this._tabBeforePrintPreview = gBrowser.mCurrentTab; s/mCurrentTab/selectedTab/ >+ this._printPreviewTab = gBrowser.loadOneTab("about:blank", null, null, >+ null, true, false); >+ gBrowser.selectedTab = this._printPreviewTab; this._printPreviewTab = gBrowser.loadOneTab("about:blank", {inBackground: false}); >+ doneWithPPBrowser: function () { >+ gBrowser.removeTab(this._printPreviewTab); >+ this._printPreviewTab = null; >+ gBrowser.selectedTab = this._tabBeforePrintPreview; >+ this._tabBeforePrintPreview = null; >+ }, >+ getBrowserToPP: function () { >+ return gBrowser; >+ }, Apart from "PP", could you find better names for these methods? I really don't understand their current names offhand. >+ printPreview: function (aListenerOrGetBrowserToPPCallback, >+ aGetPPBrowserCallback, >+ aDoneWithPPBrowserCallback, >+ aGetWebNavigationCallback, >+ aGetNavToolboxCallback, >+ aListenerOrEnterCallback, >+ aExitCallback) Again, since this breaks existing consumers anyway, no need to maintain the old way of passing the callbacks separately. We should always expect the single object and viewSource.js should implement it just like browser.js, imho.
Comment on attachment 425309 [details] [diff] [review] patch >+ doneWithPPBrowser: function () { >+ gBrowser.removeTab(this._printPreviewTab); >+ this._printPreviewTab = null; >+ gBrowser.selectedTab = this._tabBeforePrintPreview; >+ this._tabBeforePrintPreview = null; Setting selectedTab before calling removeTab would be better, as it would prevent removeTab from temporarily selecting some other tab.
(In reply to comment #4) > (From update of attachment 425309 [details] [diff] [review]) > Again, since this breaks existing consumers anyway, no need to maintain the old > way of passing the callbacks separately. We should always expect the single > object and viewSource.js should implement it just like browser.js, imho. Yeah, I was thinking about that, but wanted to keep the changes as small as possible. Will post a new patch tomorrow, I hope.
Attached patch patch (obsolete) (deleted) — Splinter Review
I expanded the method names. Hopefully they are easier to understand now. The idea is that there is a browser which wants to be print previewed and there is another browser which shows the print preview. If we're already showing print preview, and settings are changed, we want to re-print-preview the current print preview browser.
Attachment #425309 - Attachment is obsolete: true
Attachment #425443 - Flags: review?(dao)
Attachment #425309 - Flags: review?(dao)
Comment on attachment 425443 [details] [diff] [review] patch >--- a/browser/base/content/browser.js >+++ b/browser/base/content/browser.js >+ this._printPreviewTab = gBrowser.loadOneTab("about:blank", { inBackground: false}); Either add a space before } or remove the one after { ;-) >+ getBrowserToPrintPreview: function () { >+ return gBrowser; >+ }, May I suggest getSourceBrowser as the name for this? >+ getWebNavigation: function () { >+ return window.getWebNavigation(); >+ }, Is this actually needed? Could printUtils.js use getSourceBrowser().webNavigation instead? >--- a/toolkit/components/viewsource/content/viewSource.js >+++ b/toolkit/components/viewsource/content/viewSource.js >+ getBrowserToPrintPreview: function () { >+ var browser = document.getElementById("ppBrowser"); >+ return browser && !browser.collapsed ? browser : gBrowser; >+ }, I don't understand this. Shouldn't this always return gBrowser?
(In reply to comment #8) > I don't understand this. Shouldn't this always return gBrowser? We want to re-create the print preview presentation based on the already print previewed presentation. In view-source that doesn't really matter, unless someone somehow manages to load a new view-source document. > Either add a space before } or remove the one after { ;-) Sure, will do > May I suggest getSourceBrowser as the name for this? If that sounds better to you, will do. > Is this actually needed? Could printUtils.js use > getSourceBrowser().webNavigation instead? Right, that should work, and would be even more correct. I won't be able to update the patch before Monday morning. (Traveling and I have only a mac with me :/ ) Do you want to still review the final patch, or do I get r+ for the current patch if comments fixed? :)
(In reply to comment #9) > We want to re-create the print preview presentation based on the already > print previewed presentation. In view-source that doesn't really matter, unless > someone somehow manages to load a new view-source document. Shouldn't printUtils.js call getPrintPreviewBrowser in that case?
Could do it that way too, sure.
With tabbrowser that just happens sort of automatically, since we want to print preview always the currently visible tab (which can be the print preview tab).
Comment on attachment 425443 [details] [diff] [review] patch >+ getNavToolbox: function () { >+ return window.getNavToolbox(); return gNavToolbox; (In reply to comment #12) > With tabbrowser that just happens sort of automatically, since > we want to print preview always the currently visible tab (which can be > the print preview tab). Yeah, I didn't realize this. I really think printUtils.js should explicitly take care of this. Would it do that based on aCallback being null?
(In reply to comment #13) > I really think printUtils.js should explicitly > take care of this. Ok, I'll change that. Whenever callback is used, I could take the sourceBrowser and use that, in other case the print preview browser should be used.
Attachment #425443 - Flags: review?(dao) → review-
Comment on attachment 425443 [details] [diff] [review] patch >+ // If aCallback is not null, it must be an object which has the following methods: >+ // getPrintPreviewBrowser(), getBrowserToPrintPreview(), >+ // getWebNavigation(), getNavToolbox(), onEnter() and onExit(). >+ printPreview: function (aCallback) As I understand it, aCallback should never be null when printPreview is called from the outside (i.e. only toolkit/components/printing/ code should call it without a callback). I think the comment could be clearer about this. I'd like to take another look at this on Monday, but should be a quick review.
Attached patch v4 (obsolete) (deleted) — Splinter Review
Attachment #425443 - Attachment is obsolete: true
Attachment #425778 - Flags: review?(dao)
Comment on attachment 425778 [details] [diff] [review] v4 >+++ b/browser/base/content/browser.js >+ getSourceBrowser: function () { >+ return gBrowser; Shouldn't this be this._tabBeforePrintPreview.linkedBrowser || gBrowser.selectedTab, so that getSourceBrowser won't point to the print preview browser depending on when it's called? >+++ b/toolkit/components/printing/content/printUtils.js >+ // 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 have been called with non-null aCallback and >+ // that object will be reused. s/must have been called/must previously have been called/? > // collapse the browser here -- it will be shown in > // onEnterPrintPreview; this forces a reflow which fixes display > // issues in bug 267422. Can you adjust this comment? onEnterPrintPreview doesn't exist, I think enterPrintPreview is meant. >+ if (this._sourceBrowser) >+ this._sourceBrowser.collapsed = true; Why the null check? >- var webNav = getWebNavigation(); >+ var webNav = this._sourceBrowser.webNavigation; > ppParams.value.docTitle = webNav.document.title; > ppParams.value.docURL = webNav.currentURI.spec; You can just use this._sourceBrowser.contentDocument and this._sourceBrowser.currentURI here. >+++ b/toolkit/components/viewsource/content/viewSource.js >+var PrintPreviewListener = { >+ getPrintPreviewBrowser: function () { >+ var browser = document.getElementById("ppBrowser"); >+ if (!browser) { >+ const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; >+ browser = document.createElementNS(XUL_NS, "browser"); browser = document.createElement("browser");?
Attached patch v5 (obsolete) (deleted) — Splinter Review
Attachment #425778 - Attachment is obsolete: true
Attachment #425794 - Flags: review?(dao)
Attachment #425778 - Flags: review?(dao)
Comment on attachment 425794 [details] [diff] [review] v5 >+ getSourceBrowser: function () { >+ return this._tabBeforePrintPreview ? >+ this._tabBeforePrintPreview.linkedBrowser : >+ gBrowser.selectedTab.linkedBrowser; nit: selectedBrowser instead of selectedTab.linkedBrowser >+ ppParams.value.docTitle = this._sourceBrowser.contentDocument.title; >+ ppParams.value.docURL = this._sourceBrowser.currentURI.spec; In case this._sourceBrowser is the print preview browser, currentURI.spec seems to be about:blank. Is this expected?
(In reply to comment #19) > (From update of attachment 425794 [details] [diff] [review]) > >+ getSourceBrowser: function () { > >+ return this._tabBeforePrintPreview ? > >+ this._tabBeforePrintPreview.linkedBrowser : > >+ gBrowser.selectedTab.linkedBrowser; > > nit: selectedBrowser instead of selectedTab.linkedBrowser also, trailing space after '?'
Attached patch v6 (obsolete) (deleted) — Splinter Review
Attachment #425794 - Attachment is obsolete: true
Attachment #425813 - Flags: review?(dao)
Attachment #425794 - Flags: review?(dao)
Attachment #425813 - Flags: review?(dao) → review+
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Arg, I'm never going to get this simple thing fixed. There are some tests I need to change.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Backed out http://hg.mozilla.org/mozilla-central/rev/4760079804e4 Will push the patch later with the fix for a testcase.
This looks like a real failure to me at first glance, i.e. it needs a fix in printUtils.js rather than browser_bug386835.js.
bummer Dão and Olli. I guess I'll have to wait a little longer for this print preview bug to get fixed. another similar print preview bug mentioned in 543205: https://bugzilla.mozilla.org/show_bug.cgi?id=543205
(In reply to comment #25) > This looks like a real failure to me at first glance, i.e. it needs a fix in > printUtils.js rather than browser_bug386835.js. Indeed. It was working ok at some point, but then, when I removed the doneWithPPBrowser I guess, I changed zoom handling.
Attached patch v7 (deleted) — Splinter Review
This removes the zoom handling hacks from printutils.js and makes FullZoom__applyPrefToSetting to do nothing when browser is in print preview mode.
Attachment #425813 - Attachment is obsolete: true
Attachment #425958 - Flags: review?(dao)
Blocks: 535343
Comment on attachment 425958 [details] [diff] [review] v7 > _applyPrefToSetting: function FullZoom__applyPrefToSetting(aValue, aBrowser) { >- if (!this.siteSpecific && !this._inPrivateBrowsing) >+ if ((!this.siteSpecific && !this._inPrivateBrowsing) || gInPrintPreviewMode) > return; please add a line break after || > // 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); > } catch (e) { > this.enterPrintPreview(aWindow); aWindow seems bogus, it's not declared here and enterPrintPreview doesn't expect it. You added this in bug 487667.
Attachment #425958 - Flags: review?(dao) → review+
Huh, I wonder why I did that. Will fix.
(In reply to comment #29) > please add a line break after || I don't understand why, but will do.
I find it harder to parse the way it is. With the line break you might also want to remove the parentheses around !this.siteSpecific && !this._inPrivateBrowsing.
I certainly want to keep the parentheses.
Status: REOPENED → RESOLVED
Closed: 15 years ago15 years ago
Resolution: --- → FIXED
Depends on: 566849
Depends on: 694748
Blocks: 448936
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: