From f94983c5616c499d4b01111a205aa7719e59198a Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Tue, 8 Oct 2002 13:17:56 +0000 Subject: [PATCH] This patch is a bit different, instead of having the DocShell figure out whether it or one of its children are printing or PP, it gets told whether it is, and it caches that value. This was done so navigation is as fast as possible, meaning it doesn't have to figure it out each time. The patch: 1) Adds a method to the nsIContentViewerContainer to tell it whether we are printing or in PP. 2) Fix up the DV and PrintEngine, the DV SetIsXXXX didn't need to set any values in the PrintEngine, but now instead makes calls and sets the values in DocShells 3) Cleaned up and add a macro to nsIDocumentViewerPrint Bug 171161 r=dcone sr=rpotts git-svn-id: svn://10.0.0.236/trunk@131423 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDocumentViewer.cpp | 105 ++++++++++++----- .../content/base/src/nsIDocumentViewerPrint.h | 25 +++- mozilla/content/base/src/nsPrintEngine.cpp | 19 +++ mozilla/content/base/src/nsPrintEngine.h | 4 +- mozilla/docshell/base/nsDocShell.cpp | 110 +++++++++++++++++- mozilla/docshell/base/nsDocShell.h | 7 ++ .../locale/en-US/appstrings.properties | 1 + mozilla/layout/base/nsDocumentViewer.cpp | 105 ++++++++++++----- mozilla/layout/base/nsIDocumentViewerPrint.h | 25 +++- mozilla/layout/printing/nsPrintEngine.cpp | 19 +++ mozilla/layout/printing/nsPrintEngine.h | 4 +- .../public/nsIContentViewerContainer.idl | 6 + 12 files changed, 356 insertions(+), 74 deletions(-) diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index ca2c11b8291..4e16a44c6f9 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -367,22 +367,7 @@ public: nsresult CallChildren(CallChildFunc aFunc, void* aClosure); // nsIDocumentViewerPrint Printing Methods - virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet); - virtual nsresult GetDocumentSelection(nsISelection **aSelection, nsIPresShell * aPresShell = nsnull); - virtual void IncrementDestroyRefCount(); - virtual void ReturnToGalleyPresentation(); - virtual void InstallNewPresentation(); - virtual void OnDonePrinting(); - virtual nsresult FindFrameSetWithIID(nsIContent * aParentContent, const nsIID& aIID); - virtual void GetPresShellAndRootContent(nsIWebShell * aWebShell, nsIPresShell** aPresShell, nsIContent** aContent); - - // Printing Helpers - PRBool GetIsPrinting(); - void SetIsPrinting(PRBool aIsPrinting); - PRBool GetIsPrintPreview(); - void SetIsPrintPreview(PRBool aIsPrintPreview); - PRBool GetIsCreatingPrintPreview(); - void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview); + NS_DECL_NSIDOCUMENTVIEWERPRINT // Helpers (also used by nsPrintEngine) PRBool IsWebShellAFrameSet(nsIWebShell * aParent); @@ -408,6 +393,14 @@ private: nsresult SyncParentSubDocMap(); +#ifdef NS_PRINTING + // Called when the DocViewer is notified that the state + // of Printing or PP has changed + void SetIsPrintingInDocShellTree(nsIDocShellTreeNode* aParentNode, + PRBool aIsPrintingOrPP, + PRBool aStartAtTop); +#endif // NS_PRINTING + protected: // IMPORTANT: The ownership implicit in the following member // variables has been explicitly checked and set using nsCOMPtr @@ -3519,10 +3512,57 @@ DocumentViewerImpl::GetIsRangeSelection(PRBool *aIsRangeSelection) } +#ifdef NS_PRINTING //---------------------------------------------------------------------------------- // Printing/Print Preview Helpers //---------------------------------------------------------------------------------- +//---------------------------------------------------------------------------------- +// Walks the document tree and tells each DocShell whether Printing/PP is happening +void +DocumentViewerImpl::SetIsPrintingInDocShellTree(nsIDocShellTreeNode* aParentNode, + PRBool aIsPrintingOrPP, + PRBool aStartAtTop) +{ + NS_ASSERTION(aParentNode, "Parent can't be NULL!"); + + nsCOMPtr parentItem(do_QueryInterface(aParentNode)); + + // find top of "same parent" tree + if (aStartAtTop) { + while (parentItem) { + nsCOMPtr parent; + parentItem->GetSameTypeParent(getter_AddRefs(parent)); + if (!parent) { + break; + } + parentItem = do_QueryInterface(parent); + } + } + NS_ASSERTION(parentItem, "parentItem can't be null"); + + // Check to see if the DocShell's ContentViewer is printing/PP + nsCOMPtr viewerContainer(do_QueryInterface(parentItem)); + if (viewerContainer) { + viewerContainer->SetIsPrinting(aIsPrintingOrPP); + } + + // Traverse children to see if any of them are printing. + PRInt32 n; + aParentNode->GetChildCount(&n); + for (PRInt32 i=0; i < n; i++) { + nsCOMPtr child; + aParentNode->GetChildAt(i, getter_AddRefs(child)); + nsCOMPtr childAsNode(do_QueryInterface(child)); + NS_ASSERTION(childAsNode, "child isn't nsIDocShellTreeNode"); + if (childAsNode) { + SetIsPrintingInDocShellTree(childAsNode, aIsPrintingOrPP, PR_FALSE); + } + } + +} +#endif // NS_PRINTING + //------------------------------------------------------------ PRBool DocumentViewerImpl::GetIsPrinting() @@ -3536,17 +3576,24 @@ DocumentViewerImpl::GetIsPrinting() } //------------------------------------------------------------ +// Notification from the PrintEngine of the current Printing status void DocumentViewerImpl::SetIsPrinting(PRBool aIsPrinting) { #ifdef NS_PRINTING - if (mPrintEngine) { - mPrintEngine->SetIsPrinting(aIsPrinting); + // Set all the docShells in the docshell tree to be printing. + // that way if anyone of them tries to "navigate" it can't + if (mContainer) { + nsCOMPtr docShellTreeNode(do_QueryInterface(mContainer)); + NS_ASSERTION(docShellTreeNode, "mContainer has to be a nsIDocShellTreeNode"); + SetIsPrintingInDocShellTree(docShellTreeNode, aIsPrinting, PR_TRUE); } #endif } //------------------------------------------------------------ +// The PrintEngine holds the current value +// this called from inside the DocViewer PRBool DocumentViewerImpl::GetIsPrintPreview() { @@ -3559,17 +3606,24 @@ DocumentViewerImpl::GetIsPrintPreview() } //------------------------------------------------------------ +// Notification from the PrintEngine of the current PP status void DocumentViewerImpl::SetIsPrintPreview(PRBool aIsPrintPreview) { #ifdef NS_PRINTING - if (mPrintEngine) { - mPrintEngine->SetIsPrintPreview(aIsPrintPreview); + // Set all the docShells in the docshell tree to be printing. + // that way if anyone of them tries to "navigate" it can't + if (mContainer) { + nsCOMPtr docShellTreeNode(do_QueryInterface(mContainer)); + NS_ASSERTION(docShellTreeNode, "mContainer has to be a nsIDocShellTreeNode"); + SetIsPrintingInDocShellTree(docShellTreeNode, aIsPrintPreview, PR_TRUE); } #endif } //------------------------------------------------------------ +// The PrintEngine holds the current value +// this called from inside the DocViewer PRBool DocumentViewerImpl::GetIsCreatingPrintPreview() { @@ -3581,17 +3635,6 @@ DocumentViewerImpl::GetIsCreatingPrintPreview() return PR_FALSE; } -//------------------------------------------------------------ -void -DocumentViewerImpl::SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview) -{ -#ifdef NS_PRINTING - if (mPrintEngine) { - mPrintEngine->SetIsCreatingPrintPreview(aIsCreatingPrintPreview); - } -#endif -} - //---------------------------------------------------------------------------------- // nsIDocumentViewerPrint IFace //---------------------------------------------------------------------------------- diff --git a/mozilla/content/base/src/nsIDocumentViewerPrint.h b/mozilla/content/base/src/nsIDocumentViewerPrint.h index dc5e64736ca..4c516a4b02c 100644 --- a/mozilla/content/base/src/nsIDocumentViewerPrint.h +++ b/mozilla/content/base/src/nsIDocumentViewerPrint.h @@ -55,8 +55,9 @@ class nsIWebShell; { 0xd0b7f354, 0xd575, 0x43fd, { 0x90, 0x3d, 0x5a, 0xa3, 0x5a, 0x19, 0x3e, 0xda } } /** - * A document viewer is a kind of content viewer that uses NGLayout - * to manage the presentation of the content. + * A DocumentViewerPrint is an INTERNAL Interface mainly used for interaction + * between the DocumentViewer and the PrintEngine, although other objects may + * use to find out if printing or print preview is currently underway */ class nsIDocumentViewerPrint : public nsISupports { @@ -64,10 +65,12 @@ public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_VIEWER_PRINT_IID) virtual void SetIsPrinting(PRBool aIsPrinting) = 0; + virtual PRBool GetIsPrinting() = 0; virtual void SetIsPrintPreview(PRBool aIsPrintPreview) = 0; + virtual PRBool GetIsPrintPreview() = 0; - virtual void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview) = 0; + virtual PRBool GetIsCreatingPrintPreview() = 0; virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet) = 0; @@ -87,4 +90,20 @@ public: virtual void GetPresShellAndRootContent(nsIWebShell * aWebShell, nsIPresShell** aPresShell, nsIContent** aContent) = 0; }; +/* Use this macro when declaring classes that implement this interface. */ +#define NS_DECL_NSIDOCUMENTVIEWERPRINT \ + virtual void SetIsPrinting(PRBool aIsPrinting); \ + virtual PRBool GetIsPrinting(); \ + virtual void SetIsPrintPreview(PRBool aIsPrintPreview); \ + virtual PRBool GetIsPrintPreview(); \ + virtual PRBool GetIsCreatingPrintPreview(); \ + virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet); \ + virtual nsresult GetDocumentSelection(nsISelection **aSelection, nsIPresShell * aPresShell = nsnull); \ + virtual void IncrementDestroyRefCount(); \ + virtual void ReturnToGalleyPresentation(); \ + virtual void InstallNewPresentation(); \ + virtual void OnDonePrinting(); \ + virtual nsresult FindFrameSetWithIID(nsIContent * aParentContent, const nsIID& aIID); \ + virtual void GetPresShellAndRootContent(nsIWebShell * aWebShell, nsIPresShell** aPresShell, nsIContent** aContent); + #endif /* nsIDocumentViewerPrint_h___ */ diff --git a/mozilla/content/base/src/nsPrintEngine.cpp b/mozilla/content/base/src/nsPrintEngine.cpp index 02931c3c8fa..3daaa630c5b 100644 --- a/mozilla/content/base/src/nsPrintEngine.cpp +++ b/mozilla/content/base/src/nsPrintEngine.cpp @@ -3969,6 +3969,25 @@ nsPrintEngine::GetPresShellFor(nsIDocShell* aDocShell) return shell; } +//--------------------------------------------------------------------- +void nsPrintEngine::SetIsPrinting(PRBool aIsPrinting) +{ + mIsDoingPrinting = aIsPrinting; + if (mDocViewerPrint) { + mDocViewerPrint->SetIsPrinting(aIsPrinting); + } +} + +//--------------------------------------------------------------------- +void nsPrintEngine::SetIsPrintPreview(PRBool aIsPrintPreview) +{ + mIsDoingPrintPreview = aIsPrintPreview; + + if (mDocViewerPrint) { + mDocViewerPrint->SetIsPrintPreview(aIsPrintPreview); + } +} + //--------------------------------------------------------------------- void nsPrintEngine::CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount) diff --git a/mozilla/content/base/src/nsPrintEngine.h b/mozilla/content/base/src/nsPrintEngine.h index b6a8d1bcedc..3d5357619f6 100644 --- a/mozilla/content/base/src/nsPrintEngine.h +++ b/mozilla/content/base/src/nsPrintEngine.h @@ -264,9 +264,9 @@ public: void SetDialogParent(nsIDOMWindowInternal* aDOMWin) { mDialogParentWin = aDOMWin; } // These calls also update the DocViewer - void SetIsPrinting(PRBool aIsPrinting) { mIsDoingPrinting = aIsPrinting; } + void SetIsPrinting(PRBool aIsPrinting); PRBool GetIsPrinting() { return mIsDoingPrinting; } - void SetIsPrintPreview(PRBool aIsPrintPreview) { mIsDoingPrintPreview = aIsPrintPreview; } + void SetIsPrintPreview(PRBool aIsPrintPreview); PRBool GetIsPrintPreview() { return mIsDoingPrintPreview; } void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview) { mIsCreatingPrintPreview = aIsCreatingPrintPreview; } PRBool GetIsCreatingPrintPreview() { return mIsCreatingPrintPreview; } diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 3a84ade1bb3..f961ba75a71 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -149,7 +149,7 @@ static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID); static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); -#if defined(DEBUG_rods) || defined(DEBUG_bryner) +#if defined(DEBUG_bryner) //#define DEBUG_DOCSHELL_FOCUS #endif @@ -163,6 +163,11 @@ static PRInt32 gNumberOfDocumentsLoading = 0; // native event dispatch priorites over performance #define NS_EVENT_STARVATION_DELAY_HINT 2000 +// This is needed for displaying an error message +// when navigation is attempted on a document when printing +// The value arbitrary as long as it doesn't conflict with +// any of the other values in the errors in DisplayLoadError +#define NS_ERROR_DOCUMENT_IS_PRINTMODE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GENERAL,2001) // // Local function prototypes // @@ -237,7 +242,8 @@ nsDocShell::nsDocShell(): mIsBeingDestroyed(PR_FALSE), mParent(nsnull), mTreeOwner(nsnull), - mChromeEventHandler(nsnull) + mChromeEventHandler(nsnull), + mIsPrintingOrPP(PR_FALSE) { NS_INIT_ISUPPORTS(); #ifdef PR_LOGGING @@ -408,6 +414,14 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID & aIID, void **aSink) NS_ADDREF((nsISupports*)*aSink); return NS_OK; } + else if (aIID.Equals(NS_GET_IID(nsIWebBrowserSpellCheck))) { + nsresult rv = EnsureSpellCheck(); + if (NS_FAILED(rv)) return rv; + + *aSink = mSpellCheck; + NS_ADDREF((nsISupports*)*aSink); + return NS_OK; + } else if (aIID.Equals(NS_GET_IID(nsIEditingSession)) && NS_SUCCEEDED(EnsureEditorData())) { nsCOMPtr editingSession; mEditorData->GetEditingSession(getter_AddRefs(editingSession)); @@ -2286,6 +2300,19 @@ nsDocShell::GetGlobalHistory(nsIGlobalHistory ** aGlobalHistory) return NS_OK; } +//------------------------------------- +//-- Helper Method for Print discovery +//------------------------------------- +PRBool +nsDocShell::IsPrintingOrPP(PRBool aDisplayErrorDialog) +{ + if (mIsPrintingOrPP && aDisplayErrorDialog) { + DisplayLoadError(NS_ERROR_DOCUMENT_IS_PRINTMODE, nsnull, nsnull); + } + + return mIsPrintingOrPP; +} + //***************************************************************************** // nsDocShell::nsIWebNavigation //***************************************************************************** @@ -2293,6 +2320,10 @@ nsDocShell::GetGlobalHistory(nsIGlobalHistory ** aGlobalHistory) NS_IMETHODIMP nsDocShell::GetCanGoBack(PRBool * aCanGoBack) { + if (IsPrintingOrPP(PR_FALSE)) { + *aCanGoBack = PR_FALSE; + return NS_OK; // JS may not handle returning of an error code + } nsresult rv; nsCOMPtr rootSH; rv = GetRootSessionHistory(getter_AddRefs(rootSH)); @@ -2306,6 +2337,10 @@ nsDocShell::GetCanGoBack(PRBool * aCanGoBack) NS_IMETHODIMP nsDocShell::GetCanGoForward(PRBool * aCanGoForward) { + if (IsPrintingOrPP(PR_FALSE)) { + *aCanGoForward = PR_FALSE; + return NS_OK; // JS may not handle returning of an error code + } nsresult rv; nsCOMPtr rootSH; rv = GetRootSessionHistory(getter_AddRefs(rootSH)); @@ -2319,6 +2354,9 @@ nsDocShell::GetCanGoForward(PRBool * aCanGoForward) NS_IMETHODIMP nsDocShell::GoBack() { + if (IsPrintingOrPP()) { + return NS_OK; // JS may not handle returning of an error code + } nsresult rv; nsCOMPtr rootSH; rv = GetRootSessionHistory(getter_AddRefs(rootSH)); @@ -2332,6 +2370,9 @@ nsDocShell::GoBack() NS_IMETHODIMP nsDocShell::GoForward() { + if (IsPrintingOrPP()) { + return NS_OK; // JS may not handle returning of an error code + } nsresult rv; nsCOMPtr rootSH; rv = GetRootSessionHistory(getter_AddRefs(rootSH)); @@ -2344,6 +2385,9 @@ nsDocShell::GoForward() NS_IMETHODIMP nsDocShell::GotoIndex(PRInt32 aIndex) { + if (IsPrintingOrPP()) { + return NS_OK; // JS may not handle returning of an error code + } nsresult rv; nsCOMPtr rootSH; rv = GetRootSessionHistory(getter_AddRefs(rootSH)); @@ -2362,6 +2406,9 @@ nsDocShell::LoadURI(const PRUnichar * aURI, nsIInputStream * aPostStream, nsIInputStream * aHeaderStream) { + if (IsPrintingOrPP()) { + return NS_OK; // JS may not handle returning of an error code + } nsCOMPtr uri; nsresult rv; // Create the fixup object if necessary @@ -2499,6 +2546,10 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI *aURI, const PRUnichar *aUR // contain a copy of the document. error.Assign(NS_LITERAL_STRING("netOffline")); break; + case NS_ERROR_DOCUMENT_IS_PRINTMODE: + // Doc navigation attempted while Printing or Print Preview + error.Assign(NS_LITERAL_STRING("isprinting")); + break; } } @@ -2598,6 +2649,9 @@ nsDocShell::LoadErrorPage(nsIURI *aURI, const PRUnichar *aURL, const PRUnichar * NS_IMETHODIMP nsDocShell::Reload(PRUint32 aReloadFlags) { + if (IsPrintingOrPP()) { + return NS_OK; // JS may not handle returning of an error code + } nsresult rv; NS_ASSERTION(((aReloadFlags & 0xf) == 0), "Reload command not updated to use load flags!"); @@ -4005,6 +4059,14 @@ nsDocShell::Embed(nsIContentViewer * aContentViewer, return NS_OK; } +/* void setIsPrinting (in boolean aIsPrinting); */ +NS_IMETHODIMP +nsDocShell::SetIsPrinting(PRBool aIsPrinting) +{ + mIsPrintingOrPP = aIsPrinting; + return NS_OK; +} + //***************************************************************************** // nsDocShell::nsIWebProgressListener //***************************************************************************** @@ -6552,6 +6614,50 @@ NS_IMETHODIMP nsDocShell::EnsureFind() return NS_OK; } +NS_IMETHODIMP nsDocShell::EnsureSpellCheck() +{ + nsresult rv; + if (!mSpellCheck) + { + mSpellCheck = do_CreateInstance("@mozilla.org/embedcomp/spellcheck;1", &rv); + if (NS_FAILED(rv)) return rv; + } + + // we promise that the nsIWebBrowserFind that we return has been set + // up to point to the focussed, or content window, so we have to + // set that up each time. + nsCOMPtr scriptGO; + rv = GetScriptGlobalObject(getter_AddRefs(scriptGO)); + if (NS_FAILED(rv)) return rv; + + // default to our window + nsCOMPtr rootWindow = do_QueryInterface(scriptGO); + nsCOMPtr windowToSearch = rootWindow; + + // if we can, search the focussed window + nsCOMPtr ourWindow = do_QueryInterface(scriptGO); + nsCOMPtr focusController; + if (ourWindow) + ourWindow->GetRootFocusController(getter_AddRefs(focusController)); + if (focusController) + { + nsCOMPtr focussedWindow; + focusController->GetFocusedWindow(getter_AddRefs(focussedWindow)); + if (focussedWindow) + windowToSearch = focussedWindow; + } + + nsCOMPtr spellCheckInFrames = do_QueryInterface(mSpellCheck); + if (!spellCheckInFrames) return NS_ERROR_NO_INTERFACE; + + rv = spellCheckInFrames->SetRootSearchFrame(rootWindow); + if (NS_FAILED(rv)) return rv; + rv = spellCheckInFrames->SetCurrentSearchFrame(windowToSearch); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + PRBool nsDocShell::IsFrame() { diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index c38e9574d47..fdd34ce7b68 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -78,6 +78,7 @@ #include "nsIDocShellHistory.h" #include "nsIURIFixup.h" #include "nsIWebBrowserFind.h" +#include "nsIWebBrowserSpellCheck.h" #include "nsIHttpChannel.h" @@ -247,9 +248,11 @@ protected: NS_IMETHOD EnsureScriptEnvironment(); NS_IMETHOD EnsureEditorData(); NS_IMETHOD EnsureFind(); + NS_IMETHOD EnsureSpellCheck(); NS_IMETHOD RefreshURIFromQueue(); NS_IMETHOD DisplayLoadError(nsresult aError, nsIURI *aURI, const PRUnichar *aURL); NS_IMETHOD LoadErrorPage(nsIURI *aURI, const PRUnichar *aURL, const PRUnichar *aPage, const PRUnichar *aDescription); + PRBool IsPrintingOrPP(PRBool aDisplayErrorDialog = PR_TRUE); nsresult SetBaseUrlForWyciwyg(nsIContentViewer * aContentViewer); @@ -301,6 +304,7 @@ protected: nsCOMPtr mLoadCookie; // the load cookie associated with the window context. nsCOMPtr mURIFixup; nsCOMPtr mFind; + nsCOMPtr mSpellCheck; PRInt32 mMarginWidth; PRInt32 mMarginHeight; PRInt32 mItemType; @@ -363,6 +367,9 @@ protected: nsIDocShellTreeOwner * mTreeOwner; // Weak Reference nsIChromeEventHandler * mChromeEventHandler; //Weak Reference + // Indivates that a DocShell in this "docshell tree" is printing + PRBool mIsPrintingOrPP; + public: class InterfaceRequestorProxy : public nsIInterfaceRequestor { public: diff --git a/mozilla/docshell/resources/locale/en-US/appstrings.properties b/mozilla/docshell/resources/locale/en-US/appstrings.properties index be57c7761d0..e6e597d3588 100644 --- a/mozilla/docshell/resources/locale/en-US/appstrings.properties +++ b/mozilla/docshell/resources/locale/en-US/appstrings.properties @@ -29,3 +29,4 @@ repostConfirm=The page you are trying to view contains POSTDATA. If you resend t unknownSocketType=This document cannot be displayed unless you install the Personal Security Manager (PSM). Download and install PSM and try again, or contact your system administrator. netReset=The document contains no data. netOffline=This document cannot be displayed while offline. +isprinting=The document cannot change while Printing or in Print Preview. diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index ca2c11b8291..4e16a44c6f9 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -367,22 +367,7 @@ public: nsresult CallChildren(CallChildFunc aFunc, void* aClosure); // nsIDocumentViewerPrint Printing Methods - virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet); - virtual nsresult GetDocumentSelection(nsISelection **aSelection, nsIPresShell * aPresShell = nsnull); - virtual void IncrementDestroyRefCount(); - virtual void ReturnToGalleyPresentation(); - virtual void InstallNewPresentation(); - virtual void OnDonePrinting(); - virtual nsresult FindFrameSetWithIID(nsIContent * aParentContent, const nsIID& aIID); - virtual void GetPresShellAndRootContent(nsIWebShell * aWebShell, nsIPresShell** aPresShell, nsIContent** aContent); - - // Printing Helpers - PRBool GetIsPrinting(); - void SetIsPrinting(PRBool aIsPrinting); - PRBool GetIsPrintPreview(); - void SetIsPrintPreview(PRBool aIsPrintPreview); - PRBool GetIsCreatingPrintPreview(); - void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview); + NS_DECL_NSIDOCUMENTVIEWERPRINT // Helpers (also used by nsPrintEngine) PRBool IsWebShellAFrameSet(nsIWebShell * aParent); @@ -408,6 +393,14 @@ private: nsresult SyncParentSubDocMap(); +#ifdef NS_PRINTING + // Called when the DocViewer is notified that the state + // of Printing or PP has changed + void SetIsPrintingInDocShellTree(nsIDocShellTreeNode* aParentNode, + PRBool aIsPrintingOrPP, + PRBool aStartAtTop); +#endif // NS_PRINTING + protected: // IMPORTANT: The ownership implicit in the following member // variables has been explicitly checked and set using nsCOMPtr @@ -3519,10 +3512,57 @@ DocumentViewerImpl::GetIsRangeSelection(PRBool *aIsRangeSelection) } +#ifdef NS_PRINTING //---------------------------------------------------------------------------------- // Printing/Print Preview Helpers //---------------------------------------------------------------------------------- +//---------------------------------------------------------------------------------- +// Walks the document tree and tells each DocShell whether Printing/PP is happening +void +DocumentViewerImpl::SetIsPrintingInDocShellTree(nsIDocShellTreeNode* aParentNode, + PRBool aIsPrintingOrPP, + PRBool aStartAtTop) +{ + NS_ASSERTION(aParentNode, "Parent can't be NULL!"); + + nsCOMPtr parentItem(do_QueryInterface(aParentNode)); + + // find top of "same parent" tree + if (aStartAtTop) { + while (parentItem) { + nsCOMPtr parent; + parentItem->GetSameTypeParent(getter_AddRefs(parent)); + if (!parent) { + break; + } + parentItem = do_QueryInterface(parent); + } + } + NS_ASSERTION(parentItem, "parentItem can't be null"); + + // Check to see if the DocShell's ContentViewer is printing/PP + nsCOMPtr viewerContainer(do_QueryInterface(parentItem)); + if (viewerContainer) { + viewerContainer->SetIsPrinting(aIsPrintingOrPP); + } + + // Traverse children to see if any of them are printing. + PRInt32 n; + aParentNode->GetChildCount(&n); + for (PRInt32 i=0; i < n; i++) { + nsCOMPtr child; + aParentNode->GetChildAt(i, getter_AddRefs(child)); + nsCOMPtr childAsNode(do_QueryInterface(child)); + NS_ASSERTION(childAsNode, "child isn't nsIDocShellTreeNode"); + if (childAsNode) { + SetIsPrintingInDocShellTree(childAsNode, aIsPrintingOrPP, PR_FALSE); + } + } + +} +#endif // NS_PRINTING + //------------------------------------------------------------ PRBool DocumentViewerImpl::GetIsPrinting() @@ -3536,17 +3576,24 @@ DocumentViewerImpl::GetIsPrinting() } //------------------------------------------------------------ +// Notification from the PrintEngine of the current Printing status void DocumentViewerImpl::SetIsPrinting(PRBool aIsPrinting) { #ifdef NS_PRINTING - if (mPrintEngine) { - mPrintEngine->SetIsPrinting(aIsPrinting); + // Set all the docShells in the docshell tree to be printing. + // that way if anyone of them tries to "navigate" it can't + if (mContainer) { + nsCOMPtr docShellTreeNode(do_QueryInterface(mContainer)); + NS_ASSERTION(docShellTreeNode, "mContainer has to be a nsIDocShellTreeNode"); + SetIsPrintingInDocShellTree(docShellTreeNode, aIsPrinting, PR_TRUE); } #endif } //------------------------------------------------------------ +// The PrintEngine holds the current value +// this called from inside the DocViewer PRBool DocumentViewerImpl::GetIsPrintPreview() { @@ -3559,17 +3606,24 @@ DocumentViewerImpl::GetIsPrintPreview() } //------------------------------------------------------------ +// Notification from the PrintEngine of the current PP status void DocumentViewerImpl::SetIsPrintPreview(PRBool aIsPrintPreview) { #ifdef NS_PRINTING - if (mPrintEngine) { - mPrintEngine->SetIsPrintPreview(aIsPrintPreview); + // Set all the docShells in the docshell tree to be printing. + // that way if anyone of them tries to "navigate" it can't + if (mContainer) { + nsCOMPtr docShellTreeNode(do_QueryInterface(mContainer)); + NS_ASSERTION(docShellTreeNode, "mContainer has to be a nsIDocShellTreeNode"); + SetIsPrintingInDocShellTree(docShellTreeNode, aIsPrintPreview, PR_TRUE); } #endif } //------------------------------------------------------------ +// The PrintEngine holds the current value +// this called from inside the DocViewer PRBool DocumentViewerImpl::GetIsCreatingPrintPreview() { @@ -3581,17 +3635,6 @@ DocumentViewerImpl::GetIsCreatingPrintPreview() return PR_FALSE; } -//------------------------------------------------------------ -void -DocumentViewerImpl::SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview) -{ -#ifdef NS_PRINTING - if (mPrintEngine) { - mPrintEngine->SetIsCreatingPrintPreview(aIsCreatingPrintPreview); - } -#endif -} - //---------------------------------------------------------------------------------- // nsIDocumentViewerPrint IFace //---------------------------------------------------------------------------------- diff --git a/mozilla/layout/base/nsIDocumentViewerPrint.h b/mozilla/layout/base/nsIDocumentViewerPrint.h index dc5e64736ca..4c516a4b02c 100644 --- a/mozilla/layout/base/nsIDocumentViewerPrint.h +++ b/mozilla/layout/base/nsIDocumentViewerPrint.h @@ -55,8 +55,9 @@ class nsIWebShell; { 0xd0b7f354, 0xd575, 0x43fd, { 0x90, 0x3d, 0x5a, 0xa3, 0x5a, 0x19, 0x3e, 0xda } } /** - * A document viewer is a kind of content viewer that uses NGLayout - * to manage the presentation of the content. + * A DocumentViewerPrint is an INTERNAL Interface mainly used for interaction + * between the DocumentViewer and the PrintEngine, although other objects may + * use to find out if printing or print preview is currently underway */ class nsIDocumentViewerPrint : public nsISupports { @@ -64,10 +65,12 @@ public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_VIEWER_PRINT_IID) virtual void SetIsPrinting(PRBool aIsPrinting) = 0; + virtual PRBool GetIsPrinting() = 0; virtual void SetIsPrintPreview(PRBool aIsPrintPreview) = 0; + virtual PRBool GetIsPrintPreview() = 0; - virtual void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview) = 0; + virtual PRBool GetIsCreatingPrintPreview() = 0; virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet) = 0; @@ -87,4 +90,20 @@ public: virtual void GetPresShellAndRootContent(nsIWebShell * aWebShell, nsIPresShell** aPresShell, nsIContent** aContent) = 0; }; +/* Use this macro when declaring classes that implement this interface. */ +#define NS_DECL_NSIDOCUMENTVIEWERPRINT \ + virtual void SetIsPrinting(PRBool aIsPrinting); \ + virtual PRBool GetIsPrinting(); \ + virtual void SetIsPrintPreview(PRBool aIsPrintPreview); \ + virtual PRBool GetIsPrintPreview(); \ + virtual PRBool GetIsCreatingPrintPreview(); \ + virtual nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet); \ + virtual nsresult GetDocumentSelection(nsISelection **aSelection, nsIPresShell * aPresShell = nsnull); \ + virtual void IncrementDestroyRefCount(); \ + virtual void ReturnToGalleyPresentation(); \ + virtual void InstallNewPresentation(); \ + virtual void OnDonePrinting(); \ + virtual nsresult FindFrameSetWithIID(nsIContent * aParentContent, const nsIID& aIID); \ + virtual void GetPresShellAndRootContent(nsIWebShell * aWebShell, nsIPresShell** aPresShell, nsIContent** aContent); + #endif /* nsIDocumentViewerPrint_h___ */ diff --git a/mozilla/layout/printing/nsPrintEngine.cpp b/mozilla/layout/printing/nsPrintEngine.cpp index 02931c3c8fa..3daaa630c5b 100644 --- a/mozilla/layout/printing/nsPrintEngine.cpp +++ b/mozilla/layout/printing/nsPrintEngine.cpp @@ -3969,6 +3969,25 @@ nsPrintEngine::GetPresShellFor(nsIDocShell* aDocShell) return shell; } +//--------------------------------------------------------------------- +void nsPrintEngine::SetIsPrinting(PRBool aIsPrinting) +{ + mIsDoingPrinting = aIsPrinting; + if (mDocViewerPrint) { + mDocViewerPrint->SetIsPrinting(aIsPrinting); + } +} + +//--------------------------------------------------------------------- +void nsPrintEngine::SetIsPrintPreview(PRBool aIsPrintPreview) +{ + mIsDoingPrintPreview = aIsPrintPreview; + + if (mDocViewerPrint) { + mDocViewerPrint->SetIsPrintPreview(aIsPrintPreview); + } +} + //--------------------------------------------------------------------- void nsPrintEngine::CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount) diff --git a/mozilla/layout/printing/nsPrintEngine.h b/mozilla/layout/printing/nsPrintEngine.h index b6a8d1bcedc..3d5357619f6 100644 --- a/mozilla/layout/printing/nsPrintEngine.h +++ b/mozilla/layout/printing/nsPrintEngine.h @@ -264,9 +264,9 @@ public: void SetDialogParent(nsIDOMWindowInternal* aDOMWin) { mDialogParentWin = aDOMWin; } // These calls also update the DocViewer - void SetIsPrinting(PRBool aIsPrinting) { mIsDoingPrinting = aIsPrinting; } + void SetIsPrinting(PRBool aIsPrinting); PRBool GetIsPrinting() { return mIsDoingPrinting; } - void SetIsPrintPreview(PRBool aIsPrintPreview) { mIsDoingPrintPreview = aIsPrintPreview; } + void SetIsPrintPreview(PRBool aIsPrintPreview); PRBool GetIsPrintPreview() { return mIsDoingPrintPreview; } void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview) { mIsCreatingPrintPreview = aIsCreatingPrintPreview; } PRBool GetIsCreatingPrintPreview() { return mIsCreatingPrintPreview; } diff --git a/mozilla/webshell/public/nsIContentViewerContainer.idl b/mozilla/webshell/public/nsIContentViewerContainer.idl index 6d68c38bd3f..c53ee6385b3 100644 --- a/mozilla/webshell/public/nsIContentViewerContainer.idl +++ b/mozilla/webshell/public/nsIContentViewerContainer.idl @@ -26,4 +26,10 @@ interface nsIContentViewer; [scriptable, uuid(ea2ce7a0-5c3d-11d4-90c2-0050041caf44)] interface nsIContentViewerContainer : nsISupports { void embed(in nsIContentViewer aDocViewer, in string aCommand, in nsISupports aExtraInfo); + + /** + * Allows the PrintEngine to make this call on + * an internal interface to the DocShell + */ + void setIsPrinting(in boolean aIsPrinting); };