From 856750ef5cf4f84ed67c69d178c6996b269b5550 Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Mon, 22 Apr 2002 23:12:18 +0000 Subject: [PATCH] Fixing printing crash bug 127891. Make the destruction of printing related frames not hide iframe's document viewers. r=rods@netscape.com, sr=rpotts@netscape.com git-svn-id: svn://10.0.0.236/trunk@119570 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDocumentViewer.cpp | 79 ++++++++++++++----- .../browser/webBrowser/nsIWebBrowserPrint.idl | 5 ++ mozilla/layout/base/nsDocumentViewer.cpp | 79 ++++++++++++++----- mozilla/layout/generic/nsFrameFrame.cpp | 8 ++ .../layout/html/document/src/nsFrameFrame.cpp | 8 ++ .../plugin/base/src/nsPluginViewer.cpp | 7 ++ 6 files changed, 148 insertions(+), 38 deletions(-) diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index 831551f3cdc..ab61b009486 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -2041,11 +2041,22 @@ DocumentViewerImpl::Show(void) NS_IMETHODIMP DocumentViewerImpl::Hide(void) { - PRBool is_in_print_preview = PR_FALSE; + PRBool is_in_print_mode = PR_FALSE; - GetDoingPrintPreview(&is_in_print_preview); + GetDoingPrint(&is_in_print_mode); - if (is_in_print_preview) { + if (is_in_print_mode) { + // If we, or one of our parents, is in print mode it means we're + // right now returning from print and the layout frame that was + // created for this document is being destroyed. In such a case we + // ignore the Hide() call. + + return NS_OK; + } + + GetDoingPrintPreview(&is_in_print_mode); + + if (is_in_print_mode) { // If we, or one of our parents, is in print preview mode it means // we're right now returning from print preview and the layout // frame that was created for this document is being destroyed. In @@ -2973,9 +2984,9 @@ DocumentViewerImpl::DonePrintingPages(PrintObject* aPO) DoProgressForAsIsFrames(); DoProgressForSeparateFrames(); - mIsDoingPrinting = PR_FALSE; delete mPrt; mPrt = nsnull; + mIsDoingPrinting = PR_FALSE; NS_IF_RELEASE(mPagePrintTimer); @@ -8154,6 +8165,49 @@ DocumentViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSetti return rv; } +static void +GetParentWebBrowserPrint(nsISupports *aContainer, nsIWebBrowserPrint **aParent) +{ + *aParent = nsnull; + + nsCOMPtr item(do_QueryInterface(aContainer)); + + if (item) { + nsCOMPtr parent; + item->GetParent(getter_AddRefs(parent)); + + nsCOMPtr docShell(do_QueryInterface(parent)); + + if (docShell) { + nsCOMPtr viewer; + docShell->GetContentViewer(getter_AddRefs(viewer)); + + if (viewer) { + CallQueryInterface(viewer, aParent); + } + } + } +} + +/* readonly attribute boolean doingPrint; */ +NS_IMETHODIMP +DocumentViewerImpl::GetDoingPrint(PRBool *aDoingPrint) +{ + NS_ENSURE_ARG_POINTER(aDoingPrint); + *aDoingPrint = mIsDoingPrinting; + + if (!*aDoingPrint) { + nsCOMPtr wbp; + GetParentWebBrowserPrint(mContainer, getter_AddRefs(wbp)); + + if (wbp) { + return wbp->GetDoingPrint(aDoingPrint); + } + } + + return NS_OK; +} + /* readonly attribute boolean doingPrintPreview; */ NS_IMETHODIMP DocumentViewerImpl::GetDoingPrintPreview(PRBool *aDoingPrintPreview) @@ -8162,21 +8216,8 @@ DocumentViewerImpl::GetDoingPrintPreview(PRBool *aDoingPrintPreview) *aDoingPrintPreview = mIsDoingPrintPreview; if (!*aDoingPrintPreview) { - nsCOMPtr item(do_QueryInterface(mContainer)); - nsCOMPtr viewer; - - if (item) { - nsCOMPtr parent; - item->GetParent(getter_AddRefs(parent)); - - nsCOMPtr docShell(do_QueryInterface(parent)); - - if (docShell) { - docShell->GetContentViewer(getter_AddRefs(viewer)); - } - } - - nsCOMPtr wbp(do_QueryInterface(viewer)); + nsCOMPtr wbp; + GetParentWebBrowserPrint(mContainer, getter_AddRefs(wbp)); if (wbp) { return wbp->GetDoingPrintPreview(aDoingPrintPreview); diff --git a/mozilla/embedding/browser/webBrowser/nsIWebBrowserPrint.idl b/mozilla/embedding/browser/webBrowser/nsIWebBrowserPrint.idl index 8ec2d1f812a..1ffedd604d1 100644 --- a/mozilla/embedding/browser/webBrowser/nsIWebBrowserPrint.idl +++ b/mozilla/embedding/browser/webBrowser/nsIWebBrowserPrint.idl @@ -75,6 +75,11 @@ interface nsIWebBrowserPrint : nsISupports */ readonly attribute nsIPrintSettings currentPrintSettings; + /** + * Returns whether it is in Print mode + */ + readonly attribute boolean doingPrint; + /** * Returns whether it is in Print Preview mode */ diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 831551f3cdc..ab61b009486 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -2041,11 +2041,22 @@ DocumentViewerImpl::Show(void) NS_IMETHODIMP DocumentViewerImpl::Hide(void) { - PRBool is_in_print_preview = PR_FALSE; + PRBool is_in_print_mode = PR_FALSE; - GetDoingPrintPreview(&is_in_print_preview); + GetDoingPrint(&is_in_print_mode); - if (is_in_print_preview) { + if (is_in_print_mode) { + // If we, or one of our parents, is in print mode it means we're + // right now returning from print and the layout frame that was + // created for this document is being destroyed. In such a case we + // ignore the Hide() call. + + return NS_OK; + } + + GetDoingPrintPreview(&is_in_print_mode); + + if (is_in_print_mode) { // If we, or one of our parents, is in print preview mode it means // we're right now returning from print preview and the layout // frame that was created for this document is being destroyed. In @@ -2973,9 +2984,9 @@ DocumentViewerImpl::DonePrintingPages(PrintObject* aPO) DoProgressForAsIsFrames(); DoProgressForSeparateFrames(); - mIsDoingPrinting = PR_FALSE; delete mPrt; mPrt = nsnull; + mIsDoingPrinting = PR_FALSE; NS_IF_RELEASE(mPagePrintTimer); @@ -8154,6 +8165,49 @@ DocumentViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSetti return rv; } +static void +GetParentWebBrowserPrint(nsISupports *aContainer, nsIWebBrowserPrint **aParent) +{ + *aParent = nsnull; + + nsCOMPtr item(do_QueryInterface(aContainer)); + + if (item) { + nsCOMPtr parent; + item->GetParent(getter_AddRefs(parent)); + + nsCOMPtr docShell(do_QueryInterface(parent)); + + if (docShell) { + nsCOMPtr viewer; + docShell->GetContentViewer(getter_AddRefs(viewer)); + + if (viewer) { + CallQueryInterface(viewer, aParent); + } + } + } +} + +/* readonly attribute boolean doingPrint; */ +NS_IMETHODIMP +DocumentViewerImpl::GetDoingPrint(PRBool *aDoingPrint) +{ + NS_ENSURE_ARG_POINTER(aDoingPrint); + *aDoingPrint = mIsDoingPrinting; + + if (!*aDoingPrint) { + nsCOMPtr wbp; + GetParentWebBrowserPrint(mContainer, getter_AddRefs(wbp)); + + if (wbp) { + return wbp->GetDoingPrint(aDoingPrint); + } + } + + return NS_OK; +} + /* readonly attribute boolean doingPrintPreview; */ NS_IMETHODIMP DocumentViewerImpl::GetDoingPrintPreview(PRBool *aDoingPrintPreview) @@ -8162,21 +8216,8 @@ DocumentViewerImpl::GetDoingPrintPreview(PRBool *aDoingPrintPreview) *aDoingPrintPreview = mIsDoingPrintPreview; if (!*aDoingPrintPreview) { - nsCOMPtr item(do_QueryInterface(mContainer)); - nsCOMPtr viewer; - - if (item) { - nsCOMPtr parent; - item->GetParent(getter_AddRefs(parent)); - - nsCOMPtr docShell(do_QueryInterface(parent)); - - if (docShell) { - docShell->GetContentViewer(getter_AddRefs(viewer)); - } - } - - nsCOMPtr wbp(do_QueryInterface(viewer)); + nsCOMPtr wbp; + GetParentWebBrowserPrint(mContainer, getter_AddRefs(wbp)); if (wbp) { return wbp->GetDoingPrintPreview(aDoingPrintPreview); diff --git a/mozilla/layout/generic/nsFrameFrame.cpp b/mozilla/layout/generic/nsFrameFrame.cpp index 1f1cec80283..3ee4e4fcafb 100644 --- a/mozilla/layout/generic/nsFrameFrame.cpp +++ b/mozilla/layout/generic/nsFrameFrame.cpp @@ -1204,6 +1204,14 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext, aStatus = NS_FRAME_COMPLETE; + // If doing Printing or Print Preview return here + // the printing/print preview mechanism will resize the subshell + PRBool isPaginated; + aPresContext->IsPaginated(&isPaginated); + if (isPaginated) { + return NS_OK; + } + nsCOMPtr docShell; GetDocShell(getter_AddRefs(docShell)); diff --git a/mozilla/layout/html/document/src/nsFrameFrame.cpp b/mozilla/layout/html/document/src/nsFrameFrame.cpp index 1f1cec80283..3ee4e4fcafb 100644 --- a/mozilla/layout/html/document/src/nsFrameFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameFrame.cpp @@ -1204,6 +1204,14 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext, aStatus = NS_FRAME_COMPLETE; + // If doing Printing or Print Preview return here + // the printing/print preview mechanism will resize the subshell + PRBool isPaginated; + aPresContext->IsPaginated(&isPaginated); + if (isPaginated) { + return NS_OK; + } + nsCOMPtr docShell; GetDocShell(getter_AddRefs(docShell)); diff --git a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp index 9370b5e5fda..34a3ef3ebfa 100644 --- a/mozilla/modules/plugin/base/src/nsPluginViewer.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginViewer.cpp @@ -875,6 +875,13 @@ PluginViewerImpl::GetDoingPrintPreview(PRBool *aDoingPrintPreview) return NS_ERROR_NOT_IMPLEMENTED; } +/* readonly attribute boolean doingPrint; */ +NS_IMETHODIMP +PluginViewerImpl::GetDoingPrint(PRBool *aDoingPrint) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + /* readonly attribute nsIPrintSettings currentPrintSettings; */ NS_IMETHODIMP PluginViewerImpl::GetCurrentPrintSettings(nsIPrintSettings * *aCurrentPrintSettings)