From 4a4dd9b44f5a1940774d5abddcdeb7e779dbd55a Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Fri, 1 Feb 2002 14:52:11 +0000 Subject: [PATCH] 1) Removes the arg of nsIDOMWindow in the nsIWebBrowserPrint calls 2) Adds a couple of new methods and an attr to nsIWebBrowserPrint (navigate, is frameset, & exitPP) 3) Removes all but one method from nsIContentViewerFile.idl/h the remaining call is for print regression testing 4) Removes the "static" implementation of nsIContentViewerFile.h 5) Fixed up nsIContentViewerFile.idl and turned it back on so it is now generating the header file 6) Removed all uses of nsIContentViewerFile.h except for the WebCrawler (uses it for Printing Regression testing) 7) nsDocumentViewer.cpp now implements nsIWebBrowserPrint.idl this makes it easier to add new print functionality in one place 8) You can now ask an instance of the ContentViewer for a nsIWebBrowserPrint to do printing (it retruns the nsIWebBrowserPrint interface implemented by the nsDocumentViewer) 9) Anybody who was using nsIContentViewerFile to print will now use nsIWebBrowserPrint 10) You can now do a "GetInterface()" on a GlobalWindow for a nsIWebBrowserPrint 11) The browser UI now uses the GetInterface on the GlobalWindow to get a nsIWebBrowserPrint object to do printing and this can be used for all printing functionality Bug 120622 r=dcone sr=waterson --- content/base/src/Makefile.in | 1 + content/base/src/makefile.win | 1 + content/base/src/nsDocumentViewer.cpp | 456 +++++++++++++++--- docshell/base/MANIFEST_IDL | 1 + docshell/base/Makefile.in | 1 + docshell/base/makefile.win | 2 +- docshell/base/nsDocShell.cpp | 6 +- docshell/base/nsIContentViewerFile.idl | 23 +- dom/public/idl/base/nsIDOMWindowInternal.idl | 3 - dom/src/base/nsGlobalWindow.cpp | 61 ++- dom/src/base/nsGlobalWindow.h | 2 - editor/composer/src/nsEditorShell.cpp | 7 +- .../activex/src/control/MozillaBrowser.cpp | 15 +- embedding/browser/photon/src/EmbedPrivate.cpp | 14 +- embedding/browser/photon/src/PtMozilla.cpp | 1 - .../browser/webBrowser/nsIWebBrowserPrint.idl | 98 +++- embedding/browser/webBrowser/nsWebBrowser.cpp | 174 +------ embedding/browser/webBrowser/nsWebBrowser.h | 10 +- embedding/qa/testembed/BrowserView.cpp | 4 +- .../qa/testembed/PrintProgressDialog.cpp | 4 +- embedding/qa/testembed/PrintProgressDialog.h | 1 - embedding/tests/mfcembed/BrowserView.cpp | 48 +- .../tests/mfcembed/PrintProgressDialog.cpp | 6 +- .../tests/mfcembed/PrintProgressDialog.h | 3 - embedding/tests/winEmbed/winEmbed.cpp | 29 +- layout/base/nsDocumentViewer.cpp | 456 +++++++++++++++--- mailnews/addrbook/src/nsAddressBook.cpp | 1 - mailnews/base/build/Makefile.in | 1 + mailnews/base/build/makefile.win | 91 ---- mailnews/base/src/Makefile.in | 1 + mailnews/base/src/makefile.win | 1 + mailnews/base/src/nsMessenger.cpp | 11 +- mailnews/base/src/nsMsgPrintEngine.cpp | 20 +- mailnews/base/src/nsMsgPrintEngine.h | 4 +- modules/plugin/base/src/nsPluginViewer.cpp | 124 +++-- webshell/public/MANIFEST | 9 - webshell/public/Makefile.in | 1 - webshell/public/makefile.win | 45 -- webshell/public/nsIContentViewerFile.h | 0 webshell/tests/viewer/nsBrowserWindow.cpp | 4 +- webshell/tests/viewer/nsWebCrawler.cpp | 6 +- xpfe/browser/resources/content/browser.js | 103 ++-- 42 files changed, 1154 insertions(+), 695 deletions(-) delete mode 100644 webshell/public/nsIContentViewerFile.h diff --git a/content/base/src/Makefile.in b/content/base/src/Makefile.in index 85b5390fdb0..8ab479860ce 100644 --- a/content/base/src/Makefile.in +++ b/content/base/src/Makefile.in @@ -56,6 +56,7 @@ REQUIRES = xpcom \ gfx2 \ uriloader \ webbrwsr \ + webBrowser_core \ $(NULL) CPPSRCS = \ diff --git a/content/base/src/makefile.win b/content/base/src/makefile.win index 059d9b1f544..3aff0db1d8b 100644 --- a/content/base/src/makefile.win +++ b/content/base/src/makefile.win @@ -57,6 +57,7 @@ REQUIRES = xpcom \ gfx2 \ uriloader \ webBrowser_core\ + embedding\ $(NULL) CPP_OBJS= \ diff --git a/content/base/src/nsDocumentViewer.cpp b/content/base/src/nsDocumentViewer.cpp index 7e327c50156..1eb62126307 100644 --- a/content/base/src/nsDocumentViewer.cpp +++ b/content/base/src/nsDocumentViewer.cpp @@ -133,6 +133,7 @@ static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); #include "nsIEventQueueService.h" // Printing +#include "nsIWebBrowserPrint.h" #include "nsIDOMHTMLFrameElement.h" #include "nsIDOMHTMLFrameSetElement.h" #include "nsIDOMHTMLIFrameElement.h" @@ -140,6 +141,8 @@ static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); // Print Preview #include "nsIPrintPreviewContext.h" #include "imgIContainer.h" // image animation mode constants +#include "nsIScrollableView.h" +#include "nsIWebBrowserPrint.h" // needed for PrintPreview Navigation constants // Print Progress #include "nsPrintProgress.h" @@ -409,7 +412,8 @@ private: class DocumentViewerImpl : public nsIDocumentViewer, public nsIContentViewerEdit, public nsIContentViewerFile, - public nsIMarkupDocumentViewer + public nsIMarkupDocumentViewer, + public nsIWebBrowserPrint { friend class nsDocViewerSelectionListener; friend class nsPagePrintTimer; @@ -445,6 +449,9 @@ public: // nsIMarkupDocumentViewer NS_DECL_NSIMARKUPDOCUMENTVIEWER + // nsIWebBrowserPrint + NS_DECL_NSIWEBBROWSERPRINT + typedef void (*CallChildFunc)(nsIMarkupDocumentViewer* aViewer, void* aClosure); nsresult CallChildren(CallChildFunc aFunc, void* aClosure); @@ -513,6 +520,7 @@ private: nsIPrintSettings* aPrintSettings, PRUint32 aErrorCode, PRBool aIsPrinting); + void CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount); // get the currently infocus frame for the document viewer nsIDOMWindowInternal * FindFocusedDOMWindowInternal(); @@ -602,6 +610,7 @@ protected: PRBool mIsDoingPrintPreview; // per DocumentViewer nsIWidget* mParentWidget; // purposely won't be ref counted PrintData* mPrtPreview; + PrintData* mOldPrtPreview; #endif #ifdef NS_DEBUG @@ -886,6 +895,7 @@ static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); PRBool DocumentViewerImpl::mIsCreatingPrintPreview = PR_FALSE; PRBool DocumentViewerImpl::mIsDoingPrinting = PR_FALSE; +//------------------------------------------------------------------ nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult) { @@ -922,6 +932,7 @@ void DocumentViewerImpl::PrepareToStartLoad() { #ifdef NS_PRINT_PREVIEW mIsDoingPrintPreview = PR_FALSE; mPrtPreview = nsnull; + mOldPrtPreview = nsnull; #endif #ifdef NS_DEBUG @@ -938,12 +949,13 @@ DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext) PrepareToStartLoad(); } -NS_IMPL_ISUPPORTS5(DocumentViewerImpl, +NS_IMPL_ISUPPORTS6(DocumentViewerImpl, nsIContentViewer, nsIDocumentViewer, nsIMarkupDocumentViewer, nsIContentViewerFile, - nsIContentViewerEdit) + nsIContentViewerEdit, + nsIWebBrowserPrint) DocumentViewerImpl::~DocumentViewerImpl() { @@ -1362,6 +1374,12 @@ DocumentViewerImpl::Destroy() delete mPrtPreview; mPrtPreview = nsnull; } + + // This is insruance + if (mOldPrtPreview) { + delete mOldPrtPreview; + mOldPrtPreview = nsnull; + } #endif // Avoid leaking the old viewer. @@ -1906,7 +1924,7 @@ static void DumpPrintObjectsList(nsVoidArray * aDocList, FILE* aFD = nsnull) po->mPresShell->GetRootFrame(&rootFrame); while (rootFrame != nsnull) { nsIPageSequenceFrame * sqf = nsnull; - if (NS_SUCCEEDED(CallQueryInterface(rootFrame, &sqf)) && sqf) { + if (NS_SUCCEEDED(CallQueryInterface(rootFrame, &sqf))) { break; } rootFrame->FirstChild(po->mPresContext, nsnull, &rootFrame); @@ -3314,21 +3332,6 @@ DocumentViewerImpl::FindPrintObjectByDOMWin(PrintObject* aPO, nsIDOMWindowIntern return nsnull; } - -//------------------------------------------------------- -nsresult -DocumentViewerImpl::PrintContent(nsIWebShell * aParent, - nsIDeviceContext * aDContext, - nsIDOMWindow * aDOMWin, - PRBool aIsSubDoc) -{ - // XXX Once we get printing for plugins going we will - // have to revist this method. - NS_ASSERTION(0, "Still may be needed for plugins"); - - return NS_ERROR_FAILURE; -} - //------------------------------------------------------- // return the DOMWindowInternal for a WebShell nsIDOMWindowInternal * @@ -4470,23 +4473,6 @@ NS_IMETHODIMP DocumentViewerImpl::GetPasteable(PRBool *aPasteable) #pragma mark - #endif -/* ======================================================================================== - * nsIContentViewerFile - * ======================================================================================== */ -NS_IMETHODIMP -DocumentViewerImpl::Save() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -DocumentViewerImpl::GetSaveable(PRBool *aSaveable) -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID); nsresult DocumentViewerImpl::GetSelectionDocument(nsIDeviceContextSpec * aDevSpec, nsIDocument ** aNewDoc) @@ -4660,6 +4646,143 @@ DocumentViewerImpl::TurnScriptingOn(PRBool aDoTurnOn) scx->SetScriptsEnabled(aDoTurnOn); } +//---------------------------------------------------------------------- +NS_IMETHODIMP +DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum) +{ + nsIScrollableView* scrollableView; + mViewManager->GetRootScrollableView(&scrollableView); + if (scrollableView == nsnull) return NS_OK; + + // Check to see if we can short circut scrolling to the top + if (aType == nsIWebBrowserPrint::PRINTPREVIEW_HOME || + (aType == nsIWebBrowserPrint::PRINTPREVIEW_GOTO_PAGENUM && aPageNum == 1)) { + scrollableView->ScrollTo(0, 0, PR_TRUE); + return NS_OK; + } + + // Finds the SimplePageSequencer frame + // in PP mPrtPreview->mPrintObject->mSeqFrame is null + nsIFrame* rootFrame; + nsIFrame* seqFrame = nsnull; + mPrtPreview->mPrintObject->mPresShell->GetRootFrame(&rootFrame); + while (rootFrame != nsnull) { + nsIPageSequenceFrame * sqf = nsnull; + if (NS_SUCCEEDED(CallQueryInterface(rootFrame, &sqf)) && sqf) { + seqFrame = rootFrame; + break; + } + rootFrame->FirstChild(mPrtPreview->mPrintObject->mPresContext, nsnull, &rootFrame); + } + if (seqFrame == nsnull) return NS_OK; + + // Figure where we are currently scrolled to + const nsIView * clippedView; + scrollableView->GetClipView(&clippedView); + nscoord x; + nscoord y; + scrollableView->GetScrollPosition(x, y); + + PRInt32 pageNum = 1; + nsIFrame * pageFrame; + nsIFrame * fndPageFrame = nsnull; + nsIFrame * currentPage = nsnull; + + // first count the total number of pages + PRInt32 pageCount = 0; + seqFrame->FirstChild(mPresContext, nsnull, &pageFrame); + while (pageFrame != nsnull) { + pageCount++; + pageFrame->GetNextSibling(&pageFrame); + } + + // If it is "End" then just do a "goto" to the last page + if (aType == nsIWebBrowserPrint::PRINTPREVIEW_END) { + aType = nsIWebBrowserPrint::PRINTPREVIEW_GOTO_PAGENUM; + aPageNum = pageCount; + } + + // Now, locate the current page we are on and + // and the page of the page number + nscoord gap = 0; + seqFrame->FirstChild(mPresContext, nsnull, &pageFrame); + while (pageFrame != nsnull) { + nsRect pageRect; + pageFrame->GetRect(pageRect); + if (pageNum == 1) { + gap = pageRect.y; + } + pageRect.y -= gap; + if (pageRect.Contains(pageRect.x, y)) { + currentPage = pageFrame; + } + if (pageNum == aPageNum) { + fndPageFrame = pageFrame; + break; + } + pageNum++; + pageFrame->GetNextSibling(&pageFrame); + } + + if (aType == nsIWebBrowserPrint::PRINTPREVIEW_PREV_PAGE) { + if (currentPage) { + currentPage->GetPrevInFlow(&fndPageFrame); + if (!fndPageFrame) { + return NS_OK; + } + } else { + return NS_OK; + } + } else if (aType == nsIWebBrowserPrint::PRINTPREVIEW_NEXT_PAGE) { + if (currentPage) { + currentPage->GetNextInFlow(&fndPageFrame); + if (!fndPageFrame) { + return NS_OK; + } + } else { + return NS_OK; + } + } else { // If we get here we are doing "GoTo" + if (aPageNum < 0 || aPageNum > pageCount) { + return NS_OK; + } + } + + if (fndPageFrame && scrollableView) { + // get the child rect + nsRect fRect; + fndPageFrame->GetRect(fRect); + // find offset from view + nsPoint pnt; + nsIView * view; + fndPageFrame->GetOffsetFromView(mPresContext, pnt, &view); + + // scroll so that top of page is at the top of the scroll area + scrollableView->ScrollTo(pnt.x, fRect.y, PR_TRUE); + } + return NS_OK; +} + +/* readonly attribute boolean isFramesetDocument; */ +NS_IMETHODIMP +DocumentViewerImpl::GetIsFramesetDocument(PRBool *aIsFramesetDocument) +{ + nsCOMPtr webContainer(do_QueryInterface(mContainer)); + *aIsFramesetDocument = IsParentAFrameSet(webContainer); + return NS_OK; +} + +/* void exitPrintPreview (); */ +NS_IMETHODIMP +DocumentViewerImpl::ExitPrintPreview() +{ + if (mIsDoingPrintPreview) { + ReturnToGalleyPresentation(); + } + return NS_OK; +} + + void DocumentViewerImpl::InstallNewPresentation() { @@ -4713,14 +4836,66 @@ DocumentViewerImpl::InstallNewPresentation() mViewManager = nsnull; mWindow = nsnull; - // Install the new Presentation - PrintObject * po = mPrt->mPrintObject; - mPresShell = po->mPresShell; - mPresContext = po->mPresContext; - mViewManager = po->mViewManager; - mWindow = po->mWindow; + // Default to the main Print Object + PrintObject * prtObjToDisplay = mPrt->mPrintObject; - po->mSharedPresShell = PR_TRUE; + // This is the new code for selecting the appropriate Frame of a Frameset + // for Print Preview. But it can't be turned on yet +#if 0 + // If it is a Frameset then choose the selected one + // or select the one with the largest area + if (mPrt->mPrintObject->mFrameType == eFrameSet) { + if (mPrt->mCurrentFocusWin) { + PRInt32 cnt = mPrt->mPrintObject->mKids.Count(); + // Start at "1" and skip the FrameSet document itself + for (PRInt32 i=1;imPrintObject->mKids[i]; + nsCOMPtr domWin(getter_AddRefs(GetDOMWinForWebShell(po->mWebShell))); + if (domWin.get() == mPrt->mCurrentFocusWin.get()) { + prtObjToDisplay = po; + break; + } + } + } else { + PrintObject* largestPO = nsnull; + nscoord area = 0; + PRInt32 cnt = mPrt->mPrintObject->mKids.Count(); + // Start at "1" and skip the FrameSet document itself + for (PRInt32 i=1;imPrintObject->mKids[i]; + nsCOMPtr domWin(getter_AddRefs(GetDOMWinForWebShell(po->mWebShell))); + if (domWin.get() == mPrt->mCurrentFocusWin.get()) { + nscoord width; + nscoord height; + domWin->GetInnerWidth(&width); + domWin->GetInnerHeight(&height); + nscoord newArea = width * height; + if (newArea > area) { + largestPO = po; + area = newArea; + } + } + } + // make sure we got one + if (largestPO) { + prtObjToDisplay = largestPO; + } + } + } +#endif + + // Install the new Presentation + mPresShell = prtObjToDisplay->mPresShell; + mPresContext = prtObjToDisplay->mPresContext; + mViewManager = prtObjToDisplay->mViewManager; + mWindow = prtObjToDisplay->mWindow; + + if (mIsDoingPrintPreview) { + delete mOldPrtPreview; + mOldPrtPreview = nsnull; + } + + prtObjToDisplay->mSharedPresShell = PR_TRUE; mPresShell->BeginObservingDocument(); nscoord width = bounds.width; @@ -4889,6 +5064,9 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) #ifdef NS_PRINT_PREVIEW + // Use the "else" case when the UI is checked in + // and remove "if-then" part +#if 1 // if we are printing another URL, then exit // the reason we check here is because this method can be called while // another is still in here (the printing dialog is a good example). @@ -4897,6 +5075,12 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) ReturnToGalleyPresentation(); return NS_OK; } +#else + if (mIsDoingPrintPreview) { + mOldPrtPreview = mPrtPreview; + mPrtPreview = nsnull; + } +#endif mPrt = new PrintData(); if (mPrt == nsnull) { @@ -4904,6 +5088,12 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) return NS_ERROR_OUT_OF_MEMORY; } + // You have to have both a PrintOptions and a PrintSetting to call CheckForPrinters. + // The user can pass in a null PrintSettings, + // but you can only create one if you have a PrintOptions. + // So we we might as check to if we have a PrintOptions first, + // because we can't do anything below without it + // then inside we check to se if the printSettings is null to know if we need to create on. mPrt->mPrintSettings = aPrintSettings; mPrt->mPrintOptions = do_GetService(kPrintOptionsCID, &rv); if (NS_SUCCEEDED(rv) && mPrt->mPrintOptions) { @@ -5160,7 +5350,9 @@ DocumentViewerImpl::DoPrintProgress(PRBool aIsForPrinting) } } -#ifdef NS_DEBUG +/* ======================================================================================== + * nsIContentViewerFile + * ======================================================================================== */ /** --------------------------------------------------- * See documentation above in the nsIContentViewerfile class definition * @update 01/24/00 dwc @@ -5170,18 +5362,33 @@ DocumentViewerImpl::Print(PRBool aSilent, FILE * aDebugFile, nsIPrintSettings* aPrintSettings) { + nsCOMPtr printSettings; +#ifdef NS_DEBUG + nsresult rv = NS_ERROR_FAILURE; + mDebugFile = aDebugFile; - return Print(aSilent, aPrintSettings, nsnull); -} + // if they don't pass in a PrintSettings, then make one + // it will have all the default values + printSettings = aPrintSettings; + nsCOMPtr printOptions = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv)) { + // if they don't pass in a PrintSettings, then make one + if (printSettings == nsnull) { + printOptions->CreatePrintSettings(getter_AddRefs(printSettings)); + } + NS_ASSERTION(printSettings, "You can't PrintPreview without a PrintSettings!"); + } + if (printSettings) printSettings->SetPrintSilent(aSilent); #endif + return Print(printSettings, nsnull); +} + /** --------------------------------------------------- - * See documentation above in the nsIContentViewerfile class definition - * @update 01/24/00 dwc + * From nsIWebBrowserPrint */ NS_IMETHODIMP -DocumentViewerImpl::Print(PRBool aSilent, - nsIPrintSettings* aPrintSettings, +DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, nsIWebProgressListener* aWebProgressListener) { #ifdef DEBUG_PRINTING @@ -5190,7 +5397,7 @@ DocumentViewerImpl::Print(PRBool aSilent, gDumpLOFileNameCnt = 0; #endif - nsresult rv; + nsresult rv = NS_ERROR_FAILURE; if (mIsDoingPrintPreview) { PRBool okToPrint = PR_FALSE; @@ -5238,7 +5445,6 @@ DocumentViewerImpl::Print(PRBool aSilent, return NS_ERROR_FAILURE; } } - mPrt->mPrintSettings->SetPrintSilent(aSilent); // Let's print ... mIsDoingPrinting = PR_TRUE; @@ -5525,8 +5731,9 @@ DocumentViewerImpl::Print(PRBool aSilent, /* cleanup done, let's fire-up an error dialog to notify the user * what went wrong... */ - if (rv != NS_ERROR_ABORT) + if (rv != NS_ERROR_ABORT) { ShowPrintErrorDialog(rv); + } } return rv; @@ -5616,7 +5823,7 @@ DocumentViewerImpl::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrintin } } - +// nsIContentViewerFile interface NS_IMETHODIMP DocumentViewerImpl::GetPrintable(PRBool *aPrintable) { @@ -6498,6 +6705,147 @@ DocumentViewerImpl::IsWindowsInOurSubTree(nsIDOMWindowInternal * aDOMWindow) return found; } + +//---------------------------------------------------------------------------------- +void +DocumentViewerImpl::CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount) +{ + for (PRInt32 i = aCount - 1; i >= 0; i--) { + nsMemory::Free(aArray[i]); + } + nsMemory::Free(aArray); + aArray = NULL; + aCount = 0; +} + +//---------------------------------------------------------------------------------- +// Enumerate all the documents for their titles +NS_IMETHODIMP +DocumentViewerImpl::EnumerateDocumentNames(PRUint32* aCount, + PRUnichar*** aResult) +{ + NS_ENSURE_ARG(aCount); + NS_ENSURE_ARG_POINTER(aResult); + + *aCount = 0; + *aResult = nsnull; + + PRInt32 numDocs = mPrt->mPrintDocList->Count(); + PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numDocs * sizeof(PRUnichar*)); + if (!array) + return NS_ERROR_OUT_OF_MEMORY; + + for (PRInt32 i=0;imPrintDocList->ElementAt(i); + NS_ASSERTION(po, "PrintObject can't be null!"); + PRUnichar * docTitleStr; + PRUnichar * docURLStr; + GetWebShellTitleAndURL(po->mWebShell, nsnull, &docTitleStr, &docURLStr); + + // Use the URL if the doc is empty + if (!docTitleStr || !*docTitleStr) { + if (docURLStr && nsCRT::strlen(docURLStr) > 0) { + nsMemory::Free(docTitleStr); + docTitleStr = docURLStr; + } else { + nsMemory::Free(docURLStr); + } + docURLStr = nsnull; + if (!docTitleStr || !*docTitleStr) { + CleanupDocTitleArray(array, i); + return NS_ERROR_OUT_OF_MEMORY; + } + } + array[i] = docTitleStr; + if (docURLStr) nsMemory::Free(docURLStr); + } + *aCount = numDocs; + *aResult = array; + + return NS_OK; + +} + +/* readonly attribute nsIPrintSettings newPrintSettings; */ +NS_IMETHODIMP +DocumentViewerImpl::GetNewPrintSettings(nsIPrintSettings * *aNewPrintSettings) +{ + NS_ENSURE_ARG_POINTER(aNewPrintSettings); + + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = printService->CreatePrintSettings(aNewPrintSettings); + } + return rv; +} + +/* readonly attribute nsIPrintSettings globalPrintSettings; */ +NS_IMETHODIMP +DocumentViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSettings) +{ + NS_ENSURE_ARG_POINTER(aGlobalPrintSettings); + + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = printService->GetGlobalPrintSettings(aGlobalPrintSettings); + } + return rv; +} + +/* readonly attribute boolean doingPrintPreview; */ +NS_IMETHODIMP +DocumentViewerImpl::GetDoingPrintPreview(PRBool *aDoingPrintPreview) +{ + NS_ENSURE_ARG_POINTER(aDoingPrintPreview); + *aDoingPrintPreview = mIsDoingPrintPreview; + return NS_OK; +} + +/* attribute nsIPrintSettings globalPrintSettingsValues; */ +NS_IMETHODIMP +DocumentViewerImpl::GetGlobalPrintSettingsValues(nsIPrintSettings * *aGlobalPrintSettingsValues) +{ + NS_ENSURE_ARG_POINTER(aGlobalPrintSettingsValues); + NS_ENSURE_ARG_POINTER(*aGlobalPrintSettingsValues); + + nsresult rv = NS_ERROR_FAILURE; + if (aGlobalPrintSettingsValues && *aGlobalPrintSettingsValues) { + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = printService->GetPrintSettingsValues(aGlobalPrintSettingsValues); + } + } + return rv; +} + +NS_IMETHODIMP +DocumentViewerImpl::SetGlobalPrintSettingsValues(nsIPrintSettings * aGlobalPrintSettingsValues) +{ + NS_ENSURE_ARG_POINTER(aGlobalPrintSettingsValues); + + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = printService->SetPrintSettingsValues(aGlobalPrintSettingsValues); + } + return rv; +} + +/* void cancel (); */ +NS_IMETHODIMP +DocumentViewerImpl::Cancel() +{ + nsresult rv; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv) && printService) { + return printService->SetIsCancelled(PR_TRUE); + } + return NS_OK; +} + + /** --------------------------------------------------- * Get the Focused Frame for a documentviewer * diff --git a/docshell/base/MANIFEST_IDL b/docshell/base/MANIFEST_IDL index ae91ead772d..457b627a079 100644 --- a/docshell/base/MANIFEST_IDL +++ b/docshell/base/MANIFEST_IDL @@ -32,4 +32,5 @@ nsIScrollable.idl nsITextScroll.idl nsIContentViewer.idl nsIContentViewerEdit.idl +nsIContentViewerFile.idl nsIURIFixup.idl diff --git a/docshell/base/Makefile.in b/docshell/base/Makefile.in index f94eeda8578..ad30e498ffb 100644 --- a/docshell/base/Makefile.in +++ b/docshell/base/Makefile.in @@ -75,6 +75,7 @@ XPIDLSRCS = \ nsIWebNavigation.idl \ nsIContentViewer.idl \ nsIContentViewerEdit.idl \ + nsIContentViewerFile.idl \ nsIURIFixup.idl \ $(NULL) diff --git a/docshell/base/makefile.win b/docshell/base/makefile.win index aaf99bcce64..426f03a5fd7 100644 --- a/docshell/base/makefile.win +++ b/docshell/base/makefile.win @@ -65,7 +65,7 @@ XPIDLSRCS= \ .\nsIDocShellTreeOwner.idl \ .\nsIContentViewer.idl \ .\nsIContentViewerEdit.idl \ -# .\nsIContentViewerFile.idl \ + .\nsIContentViewerFile.idl \ .\nsIMarkupDocumentViewer.idl \ .\nsIScrollable.idl \ .\nsITextScroll.idl \ diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index dc3fd88ada4..a6d066e93bd 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -277,10 +277,14 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID & aIID, void **aSink) if (aIID.Equals(NS_GET_IID(nsIURIContentListener)) && NS_SUCCEEDED(EnsureContentListener())) { *aSink = mContentListener; + NS_IF_ADDREF(mContentListener); } else if (aIID.Equals(NS_GET_IID(nsIScriptGlobalObject)) && NS_SUCCEEDED(EnsureScriptEnvironment())) { - *aSink = mScriptGlobal; + nsIScriptGlobalObject* scrGlobObj = (nsIScriptGlobalObject*)mScriptGlobal.get(); + NS_ASSERTION(scrGlobObj, "This MUST support this interface!"); + NS_ADDREF(scrGlobObj); + *aSink = scrGlobObj; } else if (aIID.Equals(NS_GET_IID(nsIDOMWindowInternal)) && NS_SUCCEEDED(EnsureScriptEnvironment())) { diff --git a/docshell/base/nsIContentViewerFile.idl b/docshell/base/nsIContentViewerFile.idl index 797e8209403..d9427a16b62 100644 --- a/docshell/base/nsIContentViewerFile.idl +++ b/docshell/base/nsIContentViewerFile.idl @@ -21,17 +21,14 @@ */ #include "nsISupports.idl" +#include "nsIPrintSettings.idl" %{ C++ -class nsIDeviceContext; -class nsIWebShell; -class nsIDOMWindow; +#include %} -[ptr] native nsIDeviceContext(nsIDeviceContext); -[ptr] native nsIWebShell(nsIWebShell); -[ptr] native nsIDOMWindow(nsIDOMWindow); +[ptr] native FILE(FILE); /** * The nsIDocShellFile @@ -40,15 +37,11 @@ class nsIDOMWindow; [scriptable, uuid(6317f32c-9bc7-11d3-bccc-0060b0fc76bd)] interface nsIContentViewerFile : nsISupports { - void Save(); - readonly attribute boolean saveable; + /* readonly attribute boolean printable; */ + readonly attribute boolean printable; - void Print(); - readonly attribute boolean printable; - - [noscript] void PrintContent(in nsIWebShell parent, - in nsIDeviceContext DContext, - in nsIDOMWindow aDOMWin, - in PRBool aIsSubDoc); + [noscript] void Print(in boolean aSilent, + in FILE aDebugFile, + in nsIPrintSettings aPrintSettings); }; diff --git a/dom/public/idl/base/nsIDOMWindowInternal.idl b/dom/public/idl/base/nsIDOMWindowInternal.idl index 91a22a7bf2a..956485a240e 100644 --- a/dom/public/idl/base/nsIDOMWindowInternal.idl +++ b/dom/public/idl/base/nsIDOMWindowInternal.idl @@ -44,7 +44,6 @@ interface nsISidebar; interface nsIPrompt; interface nsIControllers; interface nsIDOMLocation; -interface nsIPrintSettings; [scriptable, uuid(9c911860-7dd9-11d4-9a83-000064657374)] interface nsIDOMWindowInternal : nsIDOMWindow @@ -131,8 +130,6 @@ interface nsIDOMWindowInternal : nsIDOMWindow void stop(); void print(); - void printPreview(in nsIPrintSettings aPS); - void printWithSettings(in nsIPrintSettings aPS); void moveTo(in long xPos, in long yPos); void moveBy(in long xDif, in long yDif); diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 062e8dcfe79..51f9233d4fa 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -74,7 +74,7 @@ #include "nsICharsetConverterManager.h" #include "nsICodebasePrincipal.h" #include "nsIContent.h" -#include "nsIContentViewerFile.h" +#include "nsIWebBrowserPrint.h" #include "nsIContentViewerEdit.h" #include "nsIDocShell.h" #include "nsIDocShellLoadInfo.h" @@ -1980,39 +1980,13 @@ NS_IMETHODIMP GlobalWindowImpl::Stop() return webNav->Stop(nsIWebNavigation::STOP_ALL); } -nsresult GlobalWindowImpl::DoPrint(PRBool aDoPreview, - nsIPrintSettings* aPS) -{ - if (mDocShell) { - nsCOMPtr viewer; - mDocShell->GetContentViewer(getter_AddRefs(viewer)); - if (viewer) { - nsCOMPtr viewerFile(do_QueryInterface(viewer)); - if (viewerFile) { - if (aDoPreview) { - return viewerFile->PrintPreview(aPS); - } else { - return viewerFile->Print(PR_FALSE, aPS, nsnull); - } - } - } - } - return NS_OK; -} - NS_IMETHODIMP GlobalWindowImpl::Print() { - return DoPrint(PR_FALSE); -} - -NS_IMETHODIMP GlobalWindowImpl::PrintPreview(nsIPrintSettings* aPS) -{ - return DoPrint(PR_TRUE, aPS); -} - -NS_IMETHODIMP GlobalWindowImpl::PrintWithSettings(nsIPrintSettings* aPS) -{ - return DoPrint(PR_FALSE, aPS); + nsCOMPtr webBrowserPrint; + if (NS_SUCCEEDED(GetInterface(NS_GET_IID(nsIWebBrowserPrint), getter_AddRefs(webBrowserPrint)))) { + webBrowserPrint->Print(nsnull, nsnull); + } + return NS_OK; } NS_IMETHODIMP GlobalWindowImpl::MoveTo(PRInt32 aXPos, PRInt32 aYPos) @@ -3404,15 +3378,34 @@ NS_IMETHODIMP GlobalWindowImpl::GetInterface(const nsIID & aIID, void **aSink) if (aIID.Equals(NS_GET_IID(nsIDocCharset))) { if (mDocShell) { nsCOMPtr docCharset(do_QueryInterface(mDocShell)); - *aSink = docCharset; + nsIDocCharset* docCS = (nsIDocCharset*)docCharset.get(); + NS_ASSERTION(docCS, "This MUST support this interface!"); + NS_ADDREF(docCS); + *aSink = docCS; } } else if (aIID.Equals(NS_GET_IID(nsIWebNavigation))) { if (mDocShell) { - nsCOMPtr webNav(do_QueryInterface(mDocShell)); + nsCOMPtr webNavigation(do_QueryInterface(mDocShell)); + nsIWebNavigation* webNav = (nsIWebNavigation*)webNavigation.get(); + NS_ASSERTION(webNav, "This MUST support this interface!"); + NS_ADDREF(webNav); *aSink = webNav; } } + else if (aIID.Equals(NS_GET_IID(nsIWebBrowserPrint))) { + if (mDocShell) { + nsCOMPtr viewer; + mDocShell->GetContentViewer(getter_AddRefs(viewer)); + if (viewer) { + nsCOMPtr webBrowserPrint(do_QueryInterface(viewer)); + nsIWebBrowserPrint* print = (nsIWebBrowserPrint*)webBrowserPrint.get(); + NS_ASSERTION(print, "This MUST support this interface!"); + NS_ADDREF(print); + *aSink = print; + } + } + } else { return QueryInterface(aIID, aSink); } diff --git a/dom/src/base/nsGlobalWindow.h b/dom/src/base/nsGlobalWindow.h index f208f19ca74..c42ca751032 100644 --- a/dom/src/base/nsGlobalWindow.h +++ b/dom/src/base/nsGlobalWindow.h @@ -237,8 +237,6 @@ protected: nsresult CheckSecurityWidthAndHeight(PRInt32* width, PRInt32* height); nsresult CheckSecurityLeftAndTop(PRInt32* left, PRInt32* top); - nsresult DoPrint(PRBool aDoPreview, nsIPrintSettings* aPS = nsnull); - // Helper for window.find() nsresult FindInternal(nsAReadableString& aStr, PRBool caseSensitive, PRBool backwards, PRBool wrapAround, PRBool wholeWord, diff --git a/editor/composer/src/nsEditorShell.cpp b/editor/composer/src/nsEditorShell.cpp index 557cb61de56..a2862840c77 100644 --- a/editor/composer/src/nsEditorShell.cpp +++ b/editor/composer/src/nsEditorShell.cpp @@ -118,6 +118,7 @@ #include "nsHTMLTags.h" #include "nsEditorParserObserver.h" #include "nsIDOMEventReceiver.h" +#include "nsIWebBrowserPrint.h" /////////////////////////////////////// @@ -1800,9 +1801,9 @@ nsEditorShell::Print() mContentAreaDocShell->GetContentViewer(getter_AddRefs(viewer)); if (nsnull != viewer) { - nsCOMPtr viewerFile = do_QueryInterface(viewer); - if (viewerFile) { - NS_ENSURE_SUCCESS(viewerFile->Print(PR_FALSE, nsnull, (nsIWebProgressListener*)nsnull), NS_ERROR_FAILURE); + nsCOMPtr webBrowserPrint = do_QueryInterface(viewer); + if (webBrowserPrint) { + NS_ENSURE_SUCCESS(webBrowserPrint->Print(nsnull, (nsIWebProgressListener*)nsnull), NS_ERROR_FAILURE); } } return NS_OK; diff --git a/embedding/browser/activex/src/control/MozillaBrowser.cpp b/embedding/browser/activex/src/control/MozillaBrowser.cpp index 42bd6bf9b2f..7bdc00c0430 100644 --- a/embedding/browser/activex/src/control/MozillaBrowser.cpp +++ b/embedding/browser/activex/src/control/MozillaBrowser.cpp @@ -1446,16 +1446,11 @@ HRESULT CMozillaBrowser::PrintDocument(BOOL promptUser) } // Print the contents - nsCOMPtr browserAsPrint = do_QueryInterface(mWebBrowser); - nsCOMPtr window; - mWebBrowser->GetContentDOMWindow(getter_AddRefs(window)); - if (window) - { - PrintListener *listener = new PrintListener; - nsCOMPtr printListener = do_QueryInterface(listener); - browserAsPrint->Print(window, nsnull, nsnull); - listener->WaitForComplete(); - } + nsCOMPtr browserAsPrint = do_GetInterface(mWebBrowser); + PrintListener *listener = new PrintListener; + nsCOMPtr printListener = do_QueryInterface(listener); + browserAsPrint->Print(nsnull, nsnull); + listener->WaitForComplete(); if (printService) { diff --git a/embedding/browser/photon/src/EmbedPrivate.cpp b/embedding/browser/photon/src/EmbedPrivate.cpp index a56b835737b..5a3bfd36d61 100644 --- a/embedding/browser/photon/src/EmbedPrivate.cpp +++ b/embedding/browser/photon/src/EmbedPrivate.cpp @@ -64,7 +64,6 @@ // for profiles #include -#include "nsIWebBrowserPrint.h" #include "nsIPrintOptions.h" // all of our local includes @@ -235,7 +234,7 @@ EmbedPrivate::Setup() uriListener = do_QueryInterface(mContentListenerGuard); webBrowser->SetParentURIContentListener(uriListener); - nsCOMPtr print(do_GetInterface(webBrowser)); + nsCOMPtr print(do_GetInterface(webBrowser)); if (print) print->GetPrintSettings(getter_AddRefs(m_PrintSettings)); @@ -522,12 +521,11 @@ EmbedPrivate::Clear() void EmbedPrivate::Print(PpPrintContext_t *pc) { - nsCOMPtr window; - mWindow->mWebBrowser->GetContentDOMWindow(getter_AddRefs(window)); - nsCOMPtr print( do_GetInterface( mWindow->mWebBrowser ) ); - - m_PrintSettings->SetEndPageRange((PRInt32) pc); - print->Print(window, m_PrintSettings, mPrint); + nsCOMPtr print = do_GetInterface(mWindow->mWebBrowser); + if (print) { + m_PrintSettings->SetEndPageRange((PRInt32) pc); + print->Print(m_PrintSettings, mPrint); + } } nsresult diff --git a/embedding/browser/photon/src/PtMozilla.cpp b/embedding/browser/photon/src/PtMozilla.cpp index bab0befdb90..070e1b1135b 100644 --- a/embedding/browser/photon/src/PtMozilla.cpp +++ b/embedding/browser/photon/src/PtMozilla.cpp @@ -35,7 +35,6 @@ #include "nsILoadGroup.h" #include "nsIHistoryEntry.h" -#include "nsIWebBrowserPrint.h" #include "nsIPrintOptions.h" #include "nsIDOMEventReceiver.h" diff --git a/embedding/browser/webBrowser/nsIWebBrowserPrint.idl b/embedding/browser/webBrowser/nsIWebBrowserPrint.idl index 5c061ae29c1..65d4858c260 100644 --- a/embedding/browser/webBrowser/nsIWebBrowserPrint.idl +++ b/embedding/browser/webBrowser/nsIWebBrowserPrint.idl @@ -33,41 +33,105 @@ interface nsIWebProgressListener; interface nsIWebBrowserPrint : nsISupports { /** - * Returns a PrintSettings object - * Creates a new the first time, if one doesn't exist. - * then returns the same object each time after that - * unless a different object was set into it. + * PrintPreview Navigation Constants */ - attribute nsIPrintSettings printSettings; + const short PRINTPREVIEW_GOTO_PAGENUM = 0; + const short PRINTPREVIEW_PREV_PAGE = 1; + const short PRINTPREVIEW_NEXT_PAGE = 2; + const short PRINTPREVIEW_HOME = 3; + const short PRINTPREVIEW_END = 4; /** - * This returns the current settings that was last used for printing - * or page setup. For peinring, the print engine always sets the PrintSettings - * from whoever is printing into the global settings - * for page setup it is the responsibilitity of those implementing page setup - * to set their setting into the global settings + * Returns a new, unique PrintSettings object each time. + * + * For example, if each browser was to have its own unique + * PrintSettings, then each brower window would call this to + * create its own unique PrintSettings object. + * + * If each browse window was to use the same PrintSettings object + * then it should use "globalPrintSettings" + * */ - attribute nsIPrintSettings globalPrintSettings; + readonly attribute nsIPrintSettings newPrintSettings; + + /** + * Returns a "global" PrintSettings object + * Creates a new the first time, if one doesn't exist. + * + * Then returns the same object each time after that. + */ + readonly attribute nsIPrintSettings globalPrintSettings; + + /** + * Returns whether it is in Print Preview mode + */ + readonly attribute boolean doingPrintPreview; + + /** + * Use this to Set and Get the current values of the last print invocation + * of "print" or "printpreview". The print engine always sets the PrintSettings + * from whoever is printing (or printpreview'ing) into the global settings. + * + * It is the responsibilitity of those implementing page setup + * to set their setting into the global settings if they want those new value + * to avilable to other callers of "globalPrintSettingsValues" + */ + attribute nsIPrintSettings globalPrintSettingsValues; + + /** + * This returns whether the current document is a frameset document + */ + readonly attribute boolean isFramesetDocument; /** * Print the specified DOM window * - * aDOMWindow - The DOM window to print * aThePrintOptions - Printer Settings for the print job + * nsIWebProgressListener - is updated during the print + * @return void */ - void print(in nsIDOMWindow aDOMWindow, - in nsIPrintSettings aThePrintSettings, + void print(in nsIPrintSettings aThePrintSettings, in nsIWebProgressListener aWPListener); /** * Print Preview the specified DOM window * - * aDOMWindow - The DOM window to print preview * aThePrintOptions - Printer Settings for the print preview + * @return void */ - void printPreview(in nsIDOMWindow aDOMWindow, - in nsIPrintSettings aThePrintSettings); + void printPreview(in nsIPrintSettings aThePrintSettings); + /** + * Print Preview - Navigates within the window + * + * aNavType - navigation enum + * aPageNum - page num to navigate to when aNavType = ePrintPreviewGoToPageNum + * @return void + */ + void printPreviewNavigate(in short aNavType, in long aPageNum); + + /** + * Cancel - Cancels the current print + * @return void + */ void cancel(); + /** + * Returns an array of the names of all documents names (Title or URL) + * and sub-documents. This will return a single item if the attr "isFramesetDocument" is false + * and may return any number of items is "isFramesetDocument" is true + * + * @param aCount - returns number of printers returned + * @param aResult - returns array of names + * @return void + */ + void enumerateDocumentNames(out PRUint32 aCount,[retval, array, size_is(aCount)] out wstring aResult); + + /** + * This exists PrintPreview mode and returns browser window to galley mode + * @return void + */ + void exitPrintPreview(); + }; + diff --git a/embedding/browser/webBrowser/nsWebBrowser.cpp b/embedding/browser/webBrowser/nsWebBrowser.cpp index 499ffd0aaa2..9eb97c822c6 100644 --- a/embedding/browser/webBrowser/nsWebBrowser.cpp +++ b/embedding/browser/webBrowser/nsWebBrowser.cpp @@ -53,7 +53,8 @@ #include "nsIURI.h" #include "nsIWebBrowserPersist.h" #include "nsCWebBrowserPersist.h" -#include "nsIPrintSettings.h" +#include "nsIWebBrowserPrint.h" +#include "nsIServiceManager.h" // for painting the background window #include "nsIRenderingContext.h" @@ -61,12 +62,6 @@ // Printing Includes #include "nsIContentViewer.h" -#include "nsIContentViewerFile.h" - -// Print Options -#include "nsIPrintOptions.h" -#include "nsGfxCIID.h" -#include "nsIServiceManager.h" // PSM2 includes #include "nsISecureBrowserUI.h" @@ -159,7 +154,6 @@ NS_INTERFACE_MAP_BEGIN(nsWebBrowser) NS_INTERFACE_MAP_ENTRY(nsIWebBrowserSetup) NS_INTERFACE_MAP_ENTRY(nsIWebBrowserPersist) NS_INTERFACE_MAP_ENTRY(nsIWebBrowserFocus) - NS_INTERFACE_MAP_ENTRY(nsIWebBrowserPrint) NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_END @@ -175,8 +169,22 @@ NS_IMETHODIMP nsWebBrowser::GetInterface(const nsIID& aIID, void** aSink) if(NS_SUCCEEDED(QueryInterface(aIID, aSink))) return NS_OK; - if(mDocShell) - return mDocShellAsReq->GetInterface(aIID, aSink); + if (mDocShell) { + if (aIID.Equals(NS_GET_IID(nsIWebBrowserPrint))) { + nsCOMPtr viewer; + mDocShell->GetContentViewer(getter_AddRefs(viewer)); + if (viewer) { + nsCOMPtr webBrowserPrint(do_QueryInterface(viewer)); + nsIWebBrowserPrint* print = (nsIWebBrowserPrint*)webBrowserPrint.get(); + NS_ASSERTION(print, "This MUST support this interface!"); + NS_ADDREF(print); + *aSink = print; + return NS_OK; + } + } else { + return mDocShellAsReq->GetInterface(aIID, aSink); + } + } return NS_NOINTERFACE; } @@ -1761,149 +1769,3 @@ NS_IMETHODIMP nsWebBrowser::SetFocusedElement(nsIDOMElement * aFocusedElement) return NS_OK; } - -/* helper function */ -nsresult nsWebBrowser::DoPrintOrPrintPreview(nsIDOMWindow *aDOMWindow, - nsIPrintSettings *aThePrintSettings, - nsIWebProgressListener *aProgressListener, - PRBool aDoPrinting) -{ - // this is if we want to have the ability to switch between having - // each window have their own PrintSettings, or having them all share it. -#ifdef ENABLE_GLOBAL_PRINTSETTINGS - PRBool useGlobalPrintSettings = PR_FALSE; - nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv) && printService) { - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); - if (pref) { - pref->GetBoolPref(&useGlobalPrintSettings); - if (useGlobalPrintSettings && aThePrintSettings != nsnull) { - printService->GetPrintSettingsValues("print.use_global_printsettings", aThePrintSettings); - } - } - } -#endif - - nsresult rv = NS_ERROR_FAILURE; - // XXX this next line may need to be changed - // it is unclear what the correct way is to get the document. - nsCOMPtr thisDOMWin; - GetContentDOMWindow(getter_AddRefs(thisDOMWin)); - if (aDOMWindow == thisDOMWin.get()) { - nsCOMPtr contentViewer; - mDocShell->GetContentViewer(getter_AddRefs(contentViewer)); - if (contentViewer) { - nsCOMPtr contentViewerFile(do_QueryInterface(contentViewer)); - if (contentViewerFile) { - if (aDoPrinting) { - // should we print silent? - PRBool printSilent = PR_FALSE; - if (aThePrintSettings) { - aThePrintSettings->GetPrintSilent(&printSilent); - } - rv = contentViewerFile->Print(printSilent, aThePrintSettings, aProgressListener); - } else { - rv = contentViewerFile->PrintPreview(aThePrintSettings); - } - } - } - } - -#ifdef ENABLE_GLOBAL_PRINTSETTINGS - if (useGlobalPrintSettings && aThePrintSettings != nsnull && printService) { - printService->SetPrintSettingsValues(aThePrintSettings); - } -#endif - - return rv; -} - -//***************************************************************************** -// nsWebBrowser::nsIWebBrowserPrint -//***************************************************************************** - -/* void Print (in nsIDOMWindow aDOMWindow, in nsIPrintSettings aThePrintSettings); */ -NS_IMETHODIMP nsWebBrowser::Print(nsIDOMWindow *aDOMWindow, - nsIPrintSettings *aThePrintSettings, - nsIWebProgressListener * aProgressListener) -{ - return DoPrintOrPrintPreview(aDOMWindow, aThePrintSettings, aProgressListener, PR_TRUE); -} - -/* void PrintPreview (in nsIPrintSettings aThePrintSettings); */ -NS_IMETHODIMP nsWebBrowser::PrintPreview(nsIDOMWindow *aDOMWindow, - nsIPrintSettings *aThePrintSettings) -{ - return DoPrintOrPrintPreview(aDOMWindow, aThePrintSettings, nsnull, PR_FALSE); -} - - /* void Cancel (); */ -NS_IMETHODIMP nsWebBrowser::Cancel(void) -{ - nsresult rv; - nsCOMPtr printService = - do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv) && printService) { - return printService->SetIsCancelled(PR_TRUE); - } - return NS_OK; -} - -/* attribute nsIPrintSettings printSettings; */ -/** - * Creates a PrintSettings Object to be used for Printing - */ -NS_IMETHODIMP nsWebBrowser::GetPrintSettings(nsIPrintSettings * *aPrintSettings) -{ - nsresult rv = NS_OK; - if (!mPrintSettings) { - nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv)) { - printService->CreatePrintSettings(getter_AddRefs(mPrintSettings)); - } - } - *aPrintSettings = mPrintSettings; - NS_IF_ADDREF(*aPrintSettings); - return rv; -} - -NS_IMETHODIMP nsWebBrowser::SetPrintSettings(nsIPrintSettings * aPrintSettings) -{ - mPrintSettings = aPrintSettings; - return NS_OK; -} - - -/* attribute nsIPrintSettings globalPrintSettings; */ -/** - * gets/set the PS into the the PrintOptions - */ -NS_IMETHODIMP nsWebBrowser::GetGlobalPrintSettings(nsIPrintSettings * *aPrintSettings) -{ - NS_ENSURE_ARG_POINTER(aPrintSettings); - NS_ENSURE_ARG_POINTER(*aPrintSettings); - - nsresult rv = NS_OK; - if (aPrintSettings != nsnull && *aPrintSettings != nsnull) { - nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv)) { - printService->GetPrintSettingsValues(aPrintSettings); - } - } - *aPrintSettings = mPrintSettings; - NS_IF_ADDREF(*aPrintSettings); - return rv; -} - -NS_IMETHODIMP nsWebBrowser::SetGlobalPrintSettings(nsIPrintSettings * aPrintSettings) -{ - NS_ENSURE_ARG_POINTER(aPrintSettings); - nsresult rv = NS_OK; - nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv)) { - printService->SetPrintSettingsValues(aPrintSettings); - } - return NS_OK; -} - diff --git a/embedding/browser/webBrowser/nsWebBrowser.h b/embedding/browser/webBrowser/nsWebBrowser.h index 0acf81a21d0..8b9e26d5b24 100644 --- a/embedding/browser/webBrowser/nsWebBrowser.h +++ b/embedding/browser/webBrowser/nsWebBrowser.h @@ -47,13 +47,13 @@ #include "nsIWebBrowserSetup.h" #include "nsIWebBrowserPersist.h" #include "nsIWebBrowserFocus.h" -#include "nsIWebBrowserPrint.h" #include "nsIWindowWatcher.h" #include "nsIPrintSettings.h" #include "nsVoidArray.h" #include "nsWeakPtr.h" +class nsIContentViewerFile; class nsWebBrowserInitInfo { @@ -90,7 +90,6 @@ class nsWebBrowser : public nsIWebBrowser, public nsIInterfaceRequestor, public nsIWebBrowserPersist, public nsIWebBrowserFocus, - public nsIWebBrowserPrint, public nsIWebProgressListener, public nsSupportsWeakReference { @@ -110,7 +109,6 @@ public: NS_DECL_NSIWEBBROWSERSETUP NS_DECL_NSIWEBBROWSERPERSIST NS_DECL_NSIWEBBROWSERFOCUS - NS_DECL_NSIWEBBROWSERPRINT NS_DECL_NSIWEBPROGRESSLISTENER protected: @@ -124,12 +122,6 @@ protected: NS_IMETHOD UnBindListener(nsISupports *aListener, const nsIID& aIID); NS_IMETHOD EnableGlobalHistory(PRBool aEnable); - // helper function for Printing and Print Preview - nsresult DoPrintOrPrintPreview(nsIDOMWindow *aDOMWindow, - nsIPrintSettings *aThePrintSettings, - nsIWebProgressListener* aPrgressListener, - PRBool aDoPrinting); - static nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent); protected: diff --git a/embedding/qa/testembed/BrowserView.cpp b/embedding/qa/testembed/BrowserView.cpp index cab82e2d620..93632b36364 100644 --- a/embedding/qa/testembed/BrowserView.cpp +++ b/embedding/qa/testembed/BrowserView.cpp @@ -982,10 +982,10 @@ void CBrowserView::OnFilePrint() nsCOMPtr domWindow; mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); if(domWindow) { - nsCOMPtr print(do_GetInterface(mWebBrowser)); + nsCOMPtr print(do_GetInterface(mWebBrowser)); if(print) { - CPrintProgressDialog dlg(mWebBrowser, domWindow, m_PrintSettings); + CPrintProgressDialog dlg(mWebBrowser, m_PrintSettings); nsCOMPtr currentURI; nsresult rv = mWebNav->GetCurrentURI(getter_AddRefs(currentURI)); diff --git a/embedding/qa/testembed/PrintProgressDialog.cpp b/embedding/qa/testembed/PrintProgressDialog.cpp index 21872c18319..49ed72f9019 100644 --- a/embedding/qa/testembed/PrintProgressDialog.cpp +++ b/embedding/qa/testembed/PrintProgressDialog.cpp @@ -102,12 +102,10 @@ CDlgPrintListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aR CPrintProgressDialog::CPrintProgressDialog(nsIWebBrowser* aWebBrowser, - nsIDOMWindow* aDOMWin, nsIPrintSettings* aPrintSettings, CWnd* pParent /*=NULL*/) : CDialog(CPrintProgressDialog::IDD, pParent), m_WebBrowser(aWebBrowser), - m_DOMWin(aDOMWin), m_PrintListener(nsnull), m_PrintSettings(aPrintSettings), m_InModalMode(PR_FALSE) @@ -199,7 +197,7 @@ int CPrintProgressDialog::DoModal( ) if (m_PrintListener) { // doModal will be set to false if the print job was cancelled nsIWebProgressListener * wpl = NS_STATIC_CAST(nsIWebProgressListener*, m_PrintListener); - doModal = NS_SUCCEEDED(print->Print(m_DOMWin, m_PrintSettings, wpl)) == PR_TRUE; + doModal = NS_SUCCEEDED(print->Print(m_PrintSettings, wpl)) == PR_TRUE; } } diff --git a/embedding/qa/testembed/PrintProgressDialog.h b/embedding/qa/testembed/PrintProgressDialog.h index 52e4ed409e4..c010d2d6977 100644 --- a/embedding/qa/testembed/PrintProgressDialog.h +++ b/embedding/qa/testembed/PrintProgressDialog.h @@ -19,7 +19,6 @@ class CPrintProgressDialog : public CDialog // Construction public: CPrintProgressDialog(nsIWebBrowser* aWebBrowser, - nsIDOMWindow* aDOMWin, nsIPrintSettings* aPrintSettings, CWnd* pParent = NULL); virtual ~CPrintProgressDialog(); diff --git a/embedding/tests/mfcembed/BrowserView.cpp b/embedding/tests/mfcembed/BrowserView.cpp index d15180c0dc6..b6ac39ecc5d 100644 --- a/embedding/tests/mfcembed/BrowserView.cpp +++ b/embedding/tests/mfcembed/BrowserView.cpp @@ -268,9 +268,9 @@ HRESULT CBrowserView::CreateBrowser() // Finally, show the web browser window mBaseWindow->SetVisibility(PR_TRUE); - nsCOMPtr print(do_GetInterface(mWebBrowser)); + nsCOMPtr print(do_GetInterface(mWebBrowser)); if (print) { - print->GetPrintSettings(getter_AddRefs(m_PrintSettings)); + print->GetNewPrintSettings(getter_AddRefs(m_PrintSettings)); } return S_OK; @@ -994,39 +994,31 @@ void CBrowserView::OnFilePrint() else NS_ASSERTION(PR_FALSE, "Could not get preferences service"); - nsCOMPtr domWindow; - mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - if(domWindow) { - nsCOMPtr print(do_GetInterface(mWebBrowser)); - if(print) - { - CPrintProgressDialog dlg(mWebBrowser, domWindow, m_PrintSettings); + nsCOMPtr print(do_GetInterface(mWebBrowser)); + if(print) + { + CPrintProgressDialog dlg(mWebBrowser, m_PrintSettings); - nsCOMPtr currentURI; - nsresult rv = mWebNav->GetCurrentURI(getter_AddRefs(currentURI)); - if(NS_SUCCEEDED(rv) || currentURI) - { - nsXPIDLCString path; - currentURI->GetPath(getter_Copies(path)); - dlg.SetURI(path.get()); - } - m_bCurrentlyPrinting = TRUE; - dlg.DoModal(); - m_bCurrentlyPrinting = FALSE; + nsCOMPtr currentURI; + nsresult rv = mWebNav->GetCurrentURI(getter_AddRefs(currentURI)); + if(NS_SUCCEEDED(rv) || currentURI) + { + nsXPIDLCString path; + currentURI->GetPath(getter_Copies(path)); + dlg.SetURI(path.get()); } + m_bCurrentlyPrinting = TRUE; + dlg.DoModal(); + m_bCurrentlyPrinting = FALSE; } } void CBrowserView::OnFilePrintPreview() { - nsCOMPtr domWindow; - mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - if(domWindow) { - nsCOMPtr print(do_GetInterface(mWebBrowser)); - if(print) - { - print->PrintPreview(domWindow, m_PrintSettings); - } + nsCOMPtr print(do_GetInterface(mWebBrowser)); + if(print) + { + print->PrintPreview(m_PrintSettings); } } diff --git a/embedding/tests/mfcembed/PrintProgressDialog.cpp b/embedding/tests/mfcembed/PrintProgressDialog.cpp index 5c830be0fc3..6440f0f4c54 100644 --- a/embedding/tests/mfcembed/PrintProgressDialog.cpp +++ b/embedding/tests/mfcembed/PrintProgressDialog.cpp @@ -101,12 +101,10 @@ CDlgPrintListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aR CPrintProgressDialog::CPrintProgressDialog(nsIWebBrowser* aWebBrowser, - nsIDOMWindow* aDOMWin, nsIPrintSettings* aPrintSettings, CWnd* pParent /*=NULL*/) : CDialog(CPrintProgressDialog::IDD, pParent), m_WebBrowser(aWebBrowser), - m_DOMWin(aDOMWin), m_PrintListener(nsnull), m_PrintSettings(aPrintSettings), m_InModalMode(PR_FALSE) @@ -191,14 +189,14 @@ BOOL CPrintProgressDialog::OnInitDialog() int CPrintProgressDialog::DoModal( ) { PRBool doModal = PR_FALSE; - nsCOMPtr print(do_GetInterface(m_WebBrowser)); + nsCOMPtr print(do_GetInterface(m_WebBrowser)); if(print) { m_PrintListener = new CDlgPrintListener(this); // constructor addrefs if (m_PrintListener) { // doModal will be set to false if the print job was cancelled nsIWebProgressListener * wpl = NS_STATIC_CAST(nsIWebProgressListener*, m_PrintListener); - doModal = NS_SUCCEEDED(print->Print(m_DOMWin, m_PrintSettings, wpl)) == PR_TRUE; + doModal = NS_SUCCEEDED(print->Print(m_PrintSettings, wpl)) == PR_TRUE; } } diff --git a/embedding/tests/mfcembed/PrintProgressDialog.h b/embedding/tests/mfcembed/PrintProgressDialog.h index 52e4ed409e4..47d77b1a567 100644 --- a/embedding/tests/mfcembed/PrintProgressDialog.h +++ b/embedding/tests/mfcembed/PrintProgressDialog.h @@ -9,7 +9,6 @@ #include "nsIWebProgressListener.h" class nsIWebBrowser; -class nsIDOMWindow; ///////////////////////////////////////////////////////////////////////////// // CPrintProgressDialog dialog @@ -19,7 +18,6 @@ class CPrintProgressDialog : public CDialog // Construction public: CPrintProgressDialog(nsIWebBrowser* aWebBrowser, - nsIDOMWindow* aDOMWin, nsIPrintSettings* aPrintSettings, CWnd* pParent = NULL); virtual ~CPrintProgressDialog(); @@ -51,7 +49,6 @@ protected: CProgressCtrl m_wndProgress; CString m_URL; nsIWebBrowser* m_WebBrowser; - nsIDOMWindow* m_DOMWin; nsCOMPtr m_PrintListener; nsIPrintSettings* m_PrintSettings; BOOL m_InModalMode; diff --git a/embedding/tests/winEmbed/winEmbed.cpp b/embedding/tests/winEmbed/winEmbed.cpp index 5cc3bc8c917..31fbb0045b7 100644 --- a/embedding/tests/winEmbed/winEmbed.cpp +++ b/embedding/tests/winEmbed/winEmbed.cpp @@ -61,6 +61,7 @@ #include "nsIProfileChangeStatus.h" #include "nsIURI.h" #include "plstr.h" +#include "nsIInterfaceRequestor.h" // Local header files #include "winEmbed.h" @@ -68,6 +69,11 @@ #include "WindowCreator.h" #include "resource.h" +// Printing header files +#include "nsIPrintSettings.h" +#include "nsIWebBrowserPrint.h" + + #define MAX_LOADSTRING 100 const TCHAR *szWindowClass = _T("WINEMBED"); @@ -592,10 +598,12 @@ BOOL CALLBACK BrowserDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar } nsCOMPtr webBrowser; nsCOMPtr webNavigation; + nsCOMPtr webBrowserPrint; if (chrome) { chrome->GetWebBrowser(getter_AddRefs(webBrowser)); webNavigation = do_QueryInterface(webBrowser); + webBrowserPrint = do_GetInterface(webBrowser); } // Test the message @@ -680,16 +688,17 @@ BOOL CALLBACK BrowserDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar // contentviewer AT ALL. This code below will break one // day but will have to do until the embedding API has // a cleaner way to do the same thing. - - nsCOMPtr rootDocShell = do_GetInterface(webBrowser); - nsCOMPtr pContentViewer; - nsresult res = rootDocShell->GetContentViewer(getter_AddRefs(pContentViewer)); - - if (NS_SUCCEEDED(res)) - { - nsCOMPtr spContentViewerFile = do_QueryInterface(pContentViewer); - spContentViewerFile->Print(PR_TRUE, nsnull, (nsIWebProgressListener*)nsnull); - } + if (webBrowserPrint) + { + nsCOMPtr printSettings; + webBrowserPrint->GetGlobalPrintSettings(getter_AddRefs(printSettings)); + NS_ASSERTION(printSettings, "You can't PrintPreview without a PrintSettings!"); + if (printSettings) + { + printSettings->SetPrintSilent(PR_TRUE); + webBrowserPrint->Print(printSettings, (nsIWebProgressListener*)nsnull); + } + } } break; diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 7e327c50156..1eb62126307 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -133,6 +133,7 @@ static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); #include "nsIEventQueueService.h" // Printing +#include "nsIWebBrowserPrint.h" #include "nsIDOMHTMLFrameElement.h" #include "nsIDOMHTMLFrameSetElement.h" #include "nsIDOMHTMLIFrameElement.h" @@ -140,6 +141,8 @@ static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); // Print Preview #include "nsIPrintPreviewContext.h" #include "imgIContainer.h" // image animation mode constants +#include "nsIScrollableView.h" +#include "nsIWebBrowserPrint.h" // needed for PrintPreview Navigation constants // Print Progress #include "nsPrintProgress.h" @@ -409,7 +412,8 @@ private: class DocumentViewerImpl : public nsIDocumentViewer, public nsIContentViewerEdit, public nsIContentViewerFile, - public nsIMarkupDocumentViewer + public nsIMarkupDocumentViewer, + public nsIWebBrowserPrint { friend class nsDocViewerSelectionListener; friend class nsPagePrintTimer; @@ -445,6 +449,9 @@ public: // nsIMarkupDocumentViewer NS_DECL_NSIMARKUPDOCUMENTVIEWER + // nsIWebBrowserPrint + NS_DECL_NSIWEBBROWSERPRINT + typedef void (*CallChildFunc)(nsIMarkupDocumentViewer* aViewer, void* aClosure); nsresult CallChildren(CallChildFunc aFunc, void* aClosure); @@ -513,6 +520,7 @@ private: nsIPrintSettings* aPrintSettings, PRUint32 aErrorCode, PRBool aIsPrinting); + void CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount); // get the currently infocus frame for the document viewer nsIDOMWindowInternal * FindFocusedDOMWindowInternal(); @@ -602,6 +610,7 @@ protected: PRBool mIsDoingPrintPreview; // per DocumentViewer nsIWidget* mParentWidget; // purposely won't be ref counted PrintData* mPrtPreview; + PrintData* mOldPrtPreview; #endif #ifdef NS_DEBUG @@ -886,6 +895,7 @@ static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); PRBool DocumentViewerImpl::mIsCreatingPrintPreview = PR_FALSE; PRBool DocumentViewerImpl::mIsDoingPrinting = PR_FALSE; +//------------------------------------------------------------------ nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult) { @@ -922,6 +932,7 @@ void DocumentViewerImpl::PrepareToStartLoad() { #ifdef NS_PRINT_PREVIEW mIsDoingPrintPreview = PR_FALSE; mPrtPreview = nsnull; + mOldPrtPreview = nsnull; #endif #ifdef NS_DEBUG @@ -938,12 +949,13 @@ DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext) PrepareToStartLoad(); } -NS_IMPL_ISUPPORTS5(DocumentViewerImpl, +NS_IMPL_ISUPPORTS6(DocumentViewerImpl, nsIContentViewer, nsIDocumentViewer, nsIMarkupDocumentViewer, nsIContentViewerFile, - nsIContentViewerEdit) + nsIContentViewerEdit, + nsIWebBrowserPrint) DocumentViewerImpl::~DocumentViewerImpl() { @@ -1362,6 +1374,12 @@ DocumentViewerImpl::Destroy() delete mPrtPreview; mPrtPreview = nsnull; } + + // This is insruance + if (mOldPrtPreview) { + delete mOldPrtPreview; + mOldPrtPreview = nsnull; + } #endif // Avoid leaking the old viewer. @@ -1906,7 +1924,7 @@ static void DumpPrintObjectsList(nsVoidArray * aDocList, FILE* aFD = nsnull) po->mPresShell->GetRootFrame(&rootFrame); while (rootFrame != nsnull) { nsIPageSequenceFrame * sqf = nsnull; - if (NS_SUCCEEDED(CallQueryInterface(rootFrame, &sqf)) && sqf) { + if (NS_SUCCEEDED(CallQueryInterface(rootFrame, &sqf))) { break; } rootFrame->FirstChild(po->mPresContext, nsnull, &rootFrame); @@ -3314,21 +3332,6 @@ DocumentViewerImpl::FindPrintObjectByDOMWin(PrintObject* aPO, nsIDOMWindowIntern return nsnull; } - -//------------------------------------------------------- -nsresult -DocumentViewerImpl::PrintContent(nsIWebShell * aParent, - nsIDeviceContext * aDContext, - nsIDOMWindow * aDOMWin, - PRBool aIsSubDoc) -{ - // XXX Once we get printing for plugins going we will - // have to revist this method. - NS_ASSERTION(0, "Still may be needed for plugins"); - - return NS_ERROR_FAILURE; -} - //------------------------------------------------------- // return the DOMWindowInternal for a WebShell nsIDOMWindowInternal * @@ -4470,23 +4473,6 @@ NS_IMETHODIMP DocumentViewerImpl::GetPasteable(PRBool *aPasteable) #pragma mark - #endif -/* ======================================================================================== - * nsIContentViewerFile - * ======================================================================================== */ -NS_IMETHODIMP -DocumentViewerImpl::Save() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -DocumentViewerImpl::GetSaveable(PRBool *aSaveable) -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID); nsresult DocumentViewerImpl::GetSelectionDocument(nsIDeviceContextSpec * aDevSpec, nsIDocument ** aNewDoc) @@ -4660,6 +4646,143 @@ DocumentViewerImpl::TurnScriptingOn(PRBool aDoTurnOn) scx->SetScriptsEnabled(aDoTurnOn); } +//---------------------------------------------------------------------- +NS_IMETHODIMP +DocumentViewerImpl::PrintPreviewNavigate(PRInt16 aType, PRInt32 aPageNum) +{ + nsIScrollableView* scrollableView; + mViewManager->GetRootScrollableView(&scrollableView); + if (scrollableView == nsnull) return NS_OK; + + // Check to see if we can short circut scrolling to the top + if (aType == nsIWebBrowserPrint::PRINTPREVIEW_HOME || + (aType == nsIWebBrowserPrint::PRINTPREVIEW_GOTO_PAGENUM && aPageNum == 1)) { + scrollableView->ScrollTo(0, 0, PR_TRUE); + return NS_OK; + } + + // Finds the SimplePageSequencer frame + // in PP mPrtPreview->mPrintObject->mSeqFrame is null + nsIFrame* rootFrame; + nsIFrame* seqFrame = nsnull; + mPrtPreview->mPrintObject->mPresShell->GetRootFrame(&rootFrame); + while (rootFrame != nsnull) { + nsIPageSequenceFrame * sqf = nsnull; + if (NS_SUCCEEDED(CallQueryInterface(rootFrame, &sqf)) && sqf) { + seqFrame = rootFrame; + break; + } + rootFrame->FirstChild(mPrtPreview->mPrintObject->mPresContext, nsnull, &rootFrame); + } + if (seqFrame == nsnull) return NS_OK; + + // Figure where we are currently scrolled to + const nsIView * clippedView; + scrollableView->GetClipView(&clippedView); + nscoord x; + nscoord y; + scrollableView->GetScrollPosition(x, y); + + PRInt32 pageNum = 1; + nsIFrame * pageFrame; + nsIFrame * fndPageFrame = nsnull; + nsIFrame * currentPage = nsnull; + + // first count the total number of pages + PRInt32 pageCount = 0; + seqFrame->FirstChild(mPresContext, nsnull, &pageFrame); + while (pageFrame != nsnull) { + pageCount++; + pageFrame->GetNextSibling(&pageFrame); + } + + // If it is "End" then just do a "goto" to the last page + if (aType == nsIWebBrowserPrint::PRINTPREVIEW_END) { + aType = nsIWebBrowserPrint::PRINTPREVIEW_GOTO_PAGENUM; + aPageNum = pageCount; + } + + // Now, locate the current page we are on and + // and the page of the page number + nscoord gap = 0; + seqFrame->FirstChild(mPresContext, nsnull, &pageFrame); + while (pageFrame != nsnull) { + nsRect pageRect; + pageFrame->GetRect(pageRect); + if (pageNum == 1) { + gap = pageRect.y; + } + pageRect.y -= gap; + if (pageRect.Contains(pageRect.x, y)) { + currentPage = pageFrame; + } + if (pageNum == aPageNum) { + fndPageFrame = pageFrame; + break; + } + pageNum++; + pageFrame->GetNextSibling(&pageFrame); + } + + if (aType == nsIWebBrowserPrint::PRINTPREVIEW_PREV_PAGE) { + if (currentPage) { + currentPage->GetPrevInFlow(&fndPageFrame); + if (!fndPageFrame) { + return NS_OK; + } + } else { + return NS_OK; + } + } else if (aType == nsIWebBrowserPrint::PRINTPREVIEW_NEXT_PAGE) { + if (currentPage) { + currentPage->GetNextInFlow(&fndPageFrame); + if (!fndPageFrame) { + return NS_OK; + } + } else { + return NS_OK; + } + } else { // If we get here we are doing "GoTo" + if (aPageNum < 0 || aPageNum > pageCount) { + return NS_OK; + } + } + + if (fndPageFrame && scrollableView) { + // get the child rect + nsRect fRect; + fndPageFrame->GetRect(fRect); + // find offset from view + nsPoint pnt; + nsIView * view; + fndPageFrame->GetOffsetFromView(mPresContext, pnt, &view); + + // scroll so that top of page is at the top of the scroll area + scrollableView->ScrollTo(pnt.x, fRect.y, PR_TRUE); + } + return NS_OK; +} + +/* readonly attribute boolean isFramesetDocument; */ +NS_IMETHODIMP +DocumentViewerImpl::GetIsFramesetDocument(PRBool *aIsFramesetDocument) +{ + nsCOMPtr webContainer(do_QueryInterface(mContainer)); + *aIsFramesetDocument = IsParentAFrameSet(webContainer); + return NS_OK; +} + +/* void exitPrintPreview (); */ +NS_IMETHODIMP +DocumentViewerImpl::ExitPrintPreview() +{ + if (mIsDoingPrintPreview) { + ReturnToGalleyPresentation(); + } + return NS_OK; +} + + void DocumentViewerImpl::InstallNewPresentation() { @@ -4713,14 +4836,66 @@ DocumentViewerImpl::InstallNewPresentation() mViewManager = nsnull; mWindow = nsnull; - // Install the new Presentation - PrintObject * po = mPrt->mPrintObject; - mPresShell = po->mPresShell; - mPresContext = po->mPresContext; - mViewManager = po->mViewManager; - mWindow = po->mWindow; + // Default to the main Print Object + PrintObject * prtObjToDisplay = mPrt->mPrintObject; - po->mSharedPresShell = PR_TRUE; + // This is the new code for selecting the appropriate Frame of a Frameset + // for Print Preview. But it can't be turned on yet +#if 0 + // If it is a Frameset then choose the selected one + // or select the one with the largest area + if (mPrt->mPrintObject->mFrameType == eFrameSet) { + if (mPrt->mCurrentFocusWin) { + PRInt32 cnt = mPrt->mPrintObject->mKids.Count(); + // Start at "1" and skip the FrameSet document itself + for (PRInt32 i=1;imPrintObject->mKids[i]; + nsCOMPtr domWin(getter_AddRefs(GetDOMWinForWebShell(po->mWebShell))); + if (domWin.get() == mPrt->mCurrentFocusWin.get()) { + prtObjToDisplay = po; + break; + } + } + } else { + PrintObject* largestPO = nsnull; + nscoord area = 0; + PRInt32 cnt = mPrt->mPrintObject->mKids.Count(); + // Start at "1" and skip the FrameSet document itself + for (PRInt32 i=1;imPrintObject->mKids[i]; + nsCOMPtr domWin(getter_AddRefs(GetDOMWinForWebShell(po->mWebShell))); + if (domWin.get() == mPrt->mCurrentFocusWin.get()) { + nscoord width; + nscoord height; + domWin->GetInnerWidth(&width); + domWin->GetInnerHeight(&height); + nscoord newArea = width * height; + if (newArea > area) { + largestPO = po; + area = newArea; + } + } + } + // make sure we got one + if (largestPO) { + prtObjToDisplay = largestPO; + } + } + } +#endif + + // Install the new Presentation + mPresShell = prtObjToDisplay->mPresShell; + mPresContext = prtObjToDisplay->mPresContext; + mViewManager = prtObjToDisplay->mViewManager; + mWindow = prtObjToDisplay->mWindow; + + if (mIsDoingPrintPreview) { + delete mOldPrtPreview; + mOldPrtPreview = nsnull; + } + + prtObjToDisplay->mSharedPresShell = PR_TRUE; mPresShell->BeginObservingDocument(); nscoord width = bounds.width; @@ -4889,6 +5064,9 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) #ifdef NS_PRINT_PREVIEW + // Use the "else" case when the UI is checked in + // and remove "if-then" part +#if 1 // if we are printing another URL, then exit // the reason we check here is because this method can be called while // another is still in here (the printing dialog is a good example). @@ -4897,6 +5075,12 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) ReturnToGalleyPresentation(); return NS_OK; } +#else + if (mIsDoingPrintPreview) { + mOldPrtPreview = mPrtPreview; + mPrtPreview = nsnull; + } +#endif mPrt = new PrintData(); if (mPrt == nsnull) { @@ -4904,6 +5088,12 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) return NS_ERROR_OUT_OF_MEMORY; } + // You have to have both a PrintOptions and a PrintSetting to call CheckForPrinters. + // The user can pass in a null PrintSettings, + // but you can only create one if you have a PrintOptions. + // So we we might as check to if we have a PrintOptions first, + // because we can't do anything below without it + // then inside we check to se if the printSettings is null to know if we need to create on. mPrt->mPrintSettings = aPrintSettings; mPrt->mPrintOptions = do_GetService(kPrintOptionsCID, &rv); if (NS_SUCCEEDED(rv) && mPrt->mPrintOptions) { @@ -5160,7 +5350,9 @@ DocumentViewerImpl::DoPrintProgress(PRBool aIsForPrinting) } } -#ifdef NS_DEBUG +/* ======================================================================================== + * nsIContentViewerFile + * ======================================================================================== */ /** --------------------------------------------------- * See documentation above in the nsIContentViewerfile class definition * @update 01/24/00 dwc @@ -5170,18 +5362,33 @@ DocumentViewerImpl::Print(PRBool aSilent, FILE * aDebugFile, nsIPrintSettings* aPrintSettings) { + nsCOMPtr printSettings; +#ifdef NS_DEBUG + nsresult rv = NS_ERROR_FAILURE; + mDebugFile = aDebugFile; - return Print(aSilent, aPrintSettings, nsnull); -} + // if they don't pass in a PrintSettings, then make one + // it will have all the default values + printSettings = aPrintSettings; + nsCOMPtr printOptions = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv)) { + // if they don't pass in a PrintSettings, then make one + if (printSettings == nsnull) { + printOptions->CreatePrintSettings(getter_AddRefs(printSettings)); + } + NS_ASSERTION(printSettings, "You can't PrintPreview without a PrintSettings!"); + } + if (printSettings) printSettings->SetPrintSilent(aSilent); #endif + return Print(printSettings, nsnull); +} + /** --------------------------------------------------- - * See documentation above in the nsIContentViewerfile class definition - * @update 01/24/00 dwc + * From nsIWebBrowserPrint */ NS_IMETHODIMP -DocumentViewerImpl::Print(PRBool aSilent, - nsIPrintSettings* aPrintSettings, +DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, nsIWebProgressListener* aWebProgressListener) { #ifdef DEBUG_PRINTING @@ -5190,7 +5397,7 @@ DocumentViewerImpl::Print(PRBool aSilent, gDumpLOFileNameCnt = 0; #endif - nsresult rv; + nsresult rv = NS_ERROR_FAILURE; if (mIsDoingPrintPreview) { PRBool okToPrint = PR_FALSE; @@ -5238,7 +5445,6 @@ DocumentViewerImpl::Print(PRBool aSilent, return NS_ERROR_FAILURE; } } - mPrt->mPrintSettings->SetPrintSilent(aSilent); // Let's print ... mIsDoingPrinting = PR_TRUE; @@ -5525,8 +5731,9 @@ DocumentViewerImpl::Print(PRBool aSilent, /* cleanup done, let's fire-up an error dialog to notify the user * what went wrong... */ - if (rv != NS_ERROR_ABORT) + if (rv != NS_ERROR_ABORT) { ShowPrintErrorDialog(rv); + } } return rv; @@ -5616,7 +5823,7 @@ DocumentViewerImpl::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrintin } } - +// nsIContentViewerFile interface NS_IMETHODIMP DocumentViewerImpl::GetPrintable(PRBool *aPrintable) { @@ -6498,6 +6705,147 @@ DocumentViewerImpl::IsWindowsInOurSubTree(nsIDOMWindowInternal * aDOMWindow) return found; } + +//---------------------------------------------------------------------------------- +void +DocumentViewerImpl::CleanupDocTitleArray(PRUnichar**& aArray, PRInt32& aCount) +{ + for (PRInt32 i = aCount - 1; i >= 0; i--) { + nsMemory::Free(aArray[i]); + } + nsMemory::Free(aArray); + aArray = NULL; + aCount = 0; +} + +//---------------------------------------------------------------------------------- +// Enumerate all the documents for their titles +NS_IMETHODIMP +DocumentViewerImpl::EnumerateDocumentNames(PRUint32* aCount, + PRUnichar*** aResult) +{ + NS_ENSURE_ARG(aCount); + NS_ENSURE_ARG_POINTER(aResult); + + *aCount = 0; + *aResult = nsnull; + + PRInt32 numDocs = mPrt->mPrintDocList->Count(); + PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numDocs * sizeof(PRUnichar*)); + if (!array) + return NS_ERROR_OUT_OF_MEMORY; + + for (PRInt32 i=0;imPrintDocList->ElementAt(i); + NS_ASSERTION(po, "PrintObject can't be null!"); + PRUnichar * docTitleStr; + PRUnichar * docURLStr; + GetWebShellTitleAndURL(po->mWebShell, nsnull, &docTitleStr, &docURLStr); + + // Use the URL if the doc is empty + if (!docTitleStr || !*docTitleStr) { + if (docURLStr && nsCRT::strlen(docURLStr) > 0) { + nsMemory::Free(docTitleStr); + docTitleStr = docURLStr; + } else { + nsMemory::Free(docURLStr); + } + docURLStr = nsnull; + if (!docTitleStr || !*docTitleStr) { + CleanupDocTitleArray(array, i); + return NS_ERROR_OUT_OF_MEMORY; + } + } + array[i] = docTitleStr; + if (docURLStr) nsMemory::Free(docURLStr); + } + *aCount = numDocs; + *aResult = array; + + return NS_OK; + +} + +/* readonly attribute nsIPrintSettings newPrintSettings; */ +NS_IMETHODIMP +DocumentViewerImpl::GetNewPrintSettings(nsIPrintSettings * *aNewPrintSettings) +{ + NS_ENSURE_ARG_POINTER(aNewPrintSettings); + + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = printService->CreatePrintSettings(aNewPrintSettings); + } + return rv; +} + +/* readonly attribute nsIPrintSettings globalPrintSettings; */ +NS_IMETHODIMP +DocumentViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSettings) +{ + NS_ENSURE_ARG_POINTER(aGlobalPrintSettings); + + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = printService->GetGlobalPrintSettings(aGlobalPrintSettings); + } + return rv; +} + +/* readonly attribute boolean doingPrintPreview; */ +NS_IMETHODIMP +DocumentViewerImpl::GetDoingPrintPreview(PRBool *aDoingPrintPreview) +{ + NS_ENSURE_ARG_POINTER(aDoingPrintPreview); + *aDoingPrintPreview = mIsDoingPrintPreview; + return NS_OK; +} + +/* attribute nsIPrintSettings globalPrintSettingsValues; */ +NS_IMETHODIMP +DocumentViewerImpl::GetGlobalPrintSettingsValues(nsIPrintSettings * *aGlobalPrintSettingsValues) +{ + NS_ENSURE_ARG_POINTER(aGlobalPrintSettingsValues); + NS_ENSURE_ARG_POINTER(*aGlobalPrintSettingsValues); + + nsresult rv = NS_ERROR_FAILURE; + if (aGlobalPrintSettingsValues && *aGlobalPrintSettingsValues) { + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = printService->GetPrintSettingsValues(aGlobalPrintSettingsValues); + } + } + return rv; +} + +NS_IMETHODIMP +DocumentViewerImpl::SetGlobalPrintSettingsValues(nsIPrintSettings * aGlobalPrintSettingsValues) +{ + NS_ENSURE_ARG_POINTER(aGlobalPrintSettingsValues); + + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = printService->SetPrintSettingsValues(aGlobalPrintSettingsValues); + } + return rv; +} + +/* void cancel (); */ +NS_IMETHODIMP +DocumentViewerImpl::Cancel() +{ + nsresult rv; + nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); + if (NS_SUCCEEDED(rv) && printService) { + return printService->SetIsCancelled(PR_TRUE); + } + return NS_OK; +} + + /** --------------------------------------------------- * Get the Focused Frame for a documentviewer * diff --git a/mailnews/addrbook/src/nsAddressBook.cpp b/mailnews/addrbook/src/nsAddressBook.cpp index b58f4f5f52a..5f5842b5608 100644 --- a/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mailnews/addrbook/src/nsAddressBook.cpp @@ -64,7 +64,6 @@ #include "nsIAppShellService.h" #include "nsIDOMWindowInternal.h" #include "nsIContentViewer.h" -#include "nsIContentViewerFile.h" #include "nsIDocShell.h" #include "nsXPIDLString.h" #include "nsReadableUtils.h" diff --git a/mailnews/base/build/Makefile.in b/mailnews/base/build/Makefile.in index 5a41c5d1054..09dde856d33 100644 --- a/mailnews/base/build/Makefile.in +++ b/mailnews/base/build/Makefile.in @@ -62,6 +62,7 @@ REQUIRES = xpcom \ msgnews \ msgimap \ gfx \ + webBrowser_core \ $(NULL) ifeq ($(USE_SHORT_LIBNAME),1) diff --git a/mailnews/base/build/makefile.win b/mailnews/base/build/makefile.win index b81d86f71a2..e69de29bb2d 100644 --- a/mailnews/base/build/makefile.win +++ b/mailnews/base/build/makefile.win @@ -1,91 +0,0 @@ -# The contents of this file are subject to the Netscape Public -# License Version 1.1 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.mozilla.org/NPL/ -# -# Software distributed under the License is distributed on an "AS -# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or -# implied. See the License for the specific language governing -# rights and limitations under the License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is Netscape -# Communications Corporation. Portions created by Netscape are -# Copyright (C) 1998 Netscape Communications Corporation. All -# Rights Reserved. -# -# Contributor(s): - -DEPTH=..\..\.. -MODULE=msgbase -LIBRARY_NAME=msgbase -META_COMPONENT=mail -MODULE_NAME=nsMsgBaseModule -REQUIRES = xpcom \ - string \ - necko \ - intl \ - locale \ - rdf \ - dom \ - docshell \ - widget \ - layout \ - webshell \ - mime \ - uriloader \ - mailnews \ - mork \ - txmgr \ - pref \ - msgcompo \ - msgbaseutil \ - appcomps \ - msgdb \ - msgsearch \ - editor \ - appshell \ - msgnews \ - msgimap \ - layout_xul \ - gfx \ - $(NULL) - -################################################################################ -## exports - -EXPORTS = \ - nsMsgBaseCID.h \ - $(NULL) - -################################################################################ -## library - -RESFILE = mail.res - -CPP_OBJS= \ - .\$(OBJDIR)\nsMsgFactory.obj \ - $(NULL) - -LINCS= -I$(DEPTH)\mailnews\base\src \ - $(NULL) - -SUB_LIBRARIES= \ - $(DIST)\lib\msgbase_s.lib \ - $(DIST)\lib\msgsearch_s.lib \ - $(NULL) - -LLIBS= \ - $(DIST)\lib\xpcom.lib \ - $(DIST)\lib\msgbsutl.lib \ - $(DIST)\lib\rdfutil_s.lib \ - $(DIST)\lib\unicharutil_s.lib \ - $(LIBNSPR) \ - $(NULL) - -WIN_LIBS= \ - shell32.lib \ - $(NULL) - -include <$(DEPTH)/config/rules.mak> diff --git a/mailnews/base/src/Makefile.in b/mailnews/base/src/Makefile.in index cedc3569bc3..64c384833ee 100644 --- a/mailnews/base/src/Makefile.in +++ b/mailnews/base/src/Makefile.in @@ -66,6 +66,7 @@ REQUIRES = xpcom \ mimetype \ windowwatcher \ profile \ + webBrowser_core \ $(NULL) CPPSRCS = \ diff --git a/mailnews/base/src/makefile.win b/mailnews/base/src/makefile.win index 7d6e850b0fa..e450d8b4a18 100644 --- a/mailnews/base/src/makefile.win +++ b/mailnews/base/src/makefile.win @@ -60,6 +60,7 @@ REQUIRES = xpcom \ msgsearch \ layout_xul \ profile \ + webBrowser_core \ $(NULL) include <$(DEPTH)\config\config.mak> diff --git a/mailnews/base/src/nsMessenger.cpp b/mailnews/base/src/nsMessenger.cpp index 6342848910f..0e1857e6851 100644 --- a/mailnews/base/src/nsMessenger.cpp +++ b/mailnews/base/src/nsMessenger.cpp @@ -69,8 +69,11 @@ // gecko #include "nsLayoutCID.h" #include "nsIMarkupDocumentViewer.h" -#include "nsIContentViewerFile.h" #include "nsIContentViewer.h" +#include "nsIWebShell.h" + +// embedding +#include "nsIWebBrowserPrint.h" /* for access to docshell */ #include "nsIDOMWindowInternal.h" @@ -1485,9 +1488,9 @@ NS_IMETHODIMP nsMessenger::DoPrint() if (viewer) { - nsCOMPtr viewerFile = do_QueryInterface(viewer); - if (viewerFile) { - rv = viewerFile->Print(PR_FALSE, nsnull, (nsIWebProgressListener*)nsnull); + nsCOMPtr webBrowserPrint = do_QueryInterface(viewer); + if (webBrowserPrint) { + rv = webBrowserPrint->Print(nsnull, (nsIWebProgressListener*)nsnull); } #ifdef DEBUG_MESSENGER else { diff --git a/mailnews/base/src/nsMsgPrintEngine.cpp b/mailnews/base/src/nsMsgPrintEngine.cpp index c7606f52eb1..96bce1b1e87 100644 --- a/mailnews/base/src/nsMsgPrintEngine.cpp +++ b/mailnews/base/src/nsMsgPrintEngine.cpp @@ -143,24 +143,24 @@ nsMsgPrintEngine::OnStateChange(nsIWebProgress* aWebProgress, mDocShell->GetContentViewer(getter_AddRefs(mContentViewer)); if (mContentViewer) { - mViewerFile = do_QueryInterface(mContentViewer); - if (mViewerFile) + mWebBrowserPrint = do_QueryInterface(mContentViewer); + if (mWebBrowserPrint) { - if (!mPrintSettings) { + if (!mPrintSettings) + { nsCOMPtr printService = do_GetService(kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv)) { - if (mPrintSettings == nsnull) { - printService->CreatePrintSettings(getter_AddRefs(mPrintSettings)); - } + if (NS_SUCCEEDED(rv)) + { + printService->CreatePrintSettings(getter_AddRefs(mPrintSettings)); NS_ASSERTION(mPrintSettings, "You can't PrintPreview without a PrintSettings!"); } } - - rv = mViewerFile->Print((mCurrentlyPrintingURI != 0), mPrintSettings, (nsIWebProgressListener *)this); + mPrintSettings->SetPrintSilent(mCurrentlyPrintingURI != 0); + rv = mWebBrowserPrint->Print(mPrintSettings, (nsIWebProgressListener *)this); if (NS_FAILED(rv)) { - mViewerFile = nsnull; + mWebBrowserPrint = nsnull; mContentViewer = nsnull; PRBool isPrintingCancelled = PR_FALSE; if (mPrintSettings) diff --git a/mailnews/base/src/nsMsgPrintEngine.h b/mailnews/base/src/nsMsgPrintEngine.h index e4c856d2fad..9faa3782ab1 100644 --- a/mailnews/base/src/nsMsgPrintEngine.h +++ b/mailnews/base/src/nsMsgPrintEngine.h @@ -35,7 +35,7 @@ #include "nsIWebProgressListener.h" #include "nsIMsgStatusFeedback.h" #include "nsIStringBundle.h" -#include "nsIContentViewerFile.h" +#include "nsIWebBrowserPrint.h" #include "nsIWebProgressListener.h" #include "nsWeakReference.h" #include "nsIPrintSettings.h" @@ -75,6 +75,6 @@ protected: nsCOMPtr mContentViewer; nsCOMPtr mStringBundle; // String bundles... nsCOMPtr mFeedback; // Tell the user something why don't ya' - nsCOMPtr mViewerFile; + nsCOMPtr mWebBrowserPrint; nsCOMPtr mPrintSettings; }; diff --git a/modules/plugin/base/src/nsPluginViewer.cpp b/modules/plugin/base/src/nsPluginViewer.cpp index 2e091444423..fb052f888bd 100644 --- a/modules/plugin/base/src/nsPluginViewer.cpp +++ b/modules/plugin/base/src/nsPluginViewer.cpp @@ -51,7 +51,7 @@ #include "nsILinkHandler.h" #include "nsIWebShell.h" #include "nsIContentViewerEdit.h" -#include "nsIContentViewerFile.h" +#include "nsIWebBrowserPrint.h" #include "nsIWidget.h" #include "nsIContent.h" #include "nsIDocument.h" @@ -70,6 +70,7 @@ #include "nsITimerCallback.h" class nsIPrintSettings; +class nsIDOMWindow; // Class IDs static NS_DEFINE_IID(kChildWindowCID, NS_CHILD_CID); @@ -175,7 +176,7 @@ private: class PluginViewerImpl : public nsIPluginViewer, public nsIContentViewer, public nsIContentViewerEdit, - public nsIContentViewerFile + public nsIWebBrowserPrint { public: PluginViewerImpl(const char* aCommand); @@ -195,8 +196,8 @@ public: // nsIContentViewerEdit NS_DECL_NSICONTENTVIEWEREDIT - // nsIContentViewerFile - NS_DECL_NSICONTENTVIEWERFILE + // nsIWebBrowserPrint + NS_DECL_NSIWEBBROWSERPRINT virtual ~PluginViewerImpl(); @@ -266,7 +267,7 @@ NS_IMPL_QUERY_INTERFACE4(PluginViewerImpl, nsIPluginViewer, nsIContentViewer, nsIContentViewerEdit, - nsIContentViewerFile) + nsIWebBrowserPrint) PluginViewerImpl::~PluginViewerImpl() @@ -717,7 +718,7 @@ NS_IMETHODIMP pluginInstanceOwner::GetValue(nsPluginInstancePeerVariable variabl return NS_ERROR_NOT_IMPLEMENTED; } /* ======================================================================================== - * nsIContentViewerFile + * nsIContentViewerEdit * ======================================================================================== */ NS_IMETHODIMP PluginViewerImpl::Search() @@ -781,35 +782,10 @@ NS_IMETHODIMP PluginViewerImpl::GetPasteable(PRBool *aPasteable) } /* ======================================================================================== - * nsIContentViewerEdit + * nsIWebBrowserPrint * ======================================================================================== */ NS_IMETHODIMP -PluginViewerImpl::Save() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -PluginViewerImpl::GetSaveable(PRBool *aSaveable) -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -#ifdef NS_DEBUG -NS_IMETHODIMP -PluginViewerImpl::Print(PRBool aSilent, - FILE * aDebugFile, - nsIPrintSettings* aPrintSettings) -{ - return NS_ERROR_FAILURE; -} -#endif - -NS_IMETHODIMP -PluginViewerImpl::Print(PRBool aSilent, - nsIPrintSettings* aPrintSettings, +PluginViewerImpl::Print(nsIPrintSettings* aPrintSettings, nsIWebProgressListener* aWebProgressListener) { nsPluginPrint npprint; @@ -827,32 +803,78 @@ PluginViewerImpl::Print(PRBool aSilent, } -NS_IMETHODIMP -PluginViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings) +NS_IMETHODIMP +PluginViewerImpl::GetNewPrintSettings(nsIPrintSettings * *aNewPrintSettings) { - return NS_OK; // XXX: hey, plug in guys! implement me! + return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP -PluginViewerImpl::GetPrintable(PRBool *aPrintable) +/* readonly attribute nsIPrintSettings globalPrintSettings; */ +NS_IMETHODIMP +PluginViewerImpl::GetGlobalPrintSettings(nsIPrintSettings * *aGlobalPrintSettings) { - NS_ENSURE_ARG_POINTER(aPrintable); - - *aPrintable = PR_FALSE; // XXX: hey, plug in guys! implement me! - return NS_OK; + return NS_ERROR_NOT_IMPLEMENTED; } - -NS_IMETHODIMP -PluginViewerImpl::PrintContent(nsIWebShell * aParent, - nsIDeviceContext * aDContext, - nsIDOMWindow * aDOMWin, - PRBool aIsSubDoc) +/* attribute nsIPrintSettings globalPrintSettingsValues; */ +NS_IMETHODIMP +PluginViewerImpl::GetGlobalPrintSettingsValues(nsIPrintSettings * *aGlobalPrintSettingsValues) { - NS_ENSURE_ARG_POINTER(aParent); - NS_ENSURE_ARG_POINTER(aDContext); + return NS_ERROR_NOT_IMPLEMENTED; +} - return NS_OK; +NS_IMETHODIMP +PluginViewerImpl::SetGlobalPrintSettingsValues(nsIPrintSettings * aGlobalPrintSettingsValues) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} +/* void printPreview (in nsIPrintSettings aThePrintSettings); */ +NS_IMETHODIMP +PluginViewerImpl::PrintPreview(nsIPrintSettings *aThePrintSettings) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void printPreviewNavigate (in short aNavType, in long aPageNum); */ +NS_IMETHODIMP +PluginViewerImpl::PrintPreviewNavigate(PRInt16 aNavType, PRInt32 aPageNum) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* readonly attribute boolean doingPrintPreview; */ +NS_IMETHODIMP +PluginViewerImpl::GetDoingPrintPreview(PRBool *aDoingPrintPreview) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void cancel (); */ +NS_IMETHODIMP +PluginViewerImpl::Cancel() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void enumerateDocumentNames (out PRUint32 aCount, [array, size_is (aCount), retval] out wstring aResult); */ +NS_IMETHODIMP +PluginViewerImpl::EnumerateDocumentNames(PRUint32 *aCount, PRUnichar ***aResult) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* readonly attribute boolean isFramesetDocument; */ +NS_IMETHODIMP +PluginViewerImpl::GetIsFramesetDocument(PRBool *aIsFramesetDocument) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* void exitPrintPreview (); */ +NS_IMETHODIMP +PluginViewerImpl::ExitPrintPreview() +{ + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP diff --git a/webshell/public/MANIFEST b/webshell/public/MANIFEST index 78f7557a8bf..e69de29bb2d 100644 --- a/webshell/public/MANIFEST +++ b/webshell/public/MANIFEST @@ -1,9 +0,0 @@ -# -# This is a list of local files which get copied to the mozilla:dist:webshell directory -# - -nsIDocStreamLoaderFactory.h -nsILinkHandler.h -nsIWebShell.h -nsIContentViewerFile.h -nsIWebShellServices.h diff --git a/webshell/public/Makefile.in b/webshell/public/Makefile.in index ee3552b57b4..8892c1f57b1 100644 --- a/webshell/public/Makefile.in +++ b/webshell/public/Makefile.in @@ -40,7 +40,6 @@ EXPORTS = \ nsIDocStreamLoaderFactory.h \ nsILinkHandler.h \ nsIWebShell.h \ - nsIContentViewerFile.h \ nsIWebShellServices.h \ $(NULL) diff --git a/webshell/public/makefile.win b/webshell/public/makefile.win index edcb7ed2a1a..e69de29bb2d 100644 --- a/webshell/public/makefile.win +++ b/webshell/public/makefile.win @@ -1,45 +0,0 @@ -#!nmake -# -# The contents of this file are subject to the Netscape Public -# License Version 1.1 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.mozilla.org/NPL/ -# -# Software distributed under the License is distributed on an "AS -# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or -# implied. See the License for the specific language governing -# rights and limitations under the License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is Netscape -# Communications Corporation. Portions created by Netscape are -# Copyright (C) 1998 Netscape Communications Corporation. All -# Rights Reserved. -# -# Contributor(s): - -DEPTH=..\.. - -MODULE=webshell -XPIDL_MODULE=webshell_idls - -include <$(DEPTH)\config\config.mak> - -XPIDLSRCS = \ - .\nsIRefreshURI.idl \ - .\nsIClipboardCommands.idl \ - .\nsIContentViewerContainer.idl \ - .\nsIDocumentLoaderFactory.idl \ - $(NULL) - -EXPORTS = \ - nsIDocStreamLoaderFactory.h \ - nsILinkHandler.h \ - nsIWebShell.h \ - nsIContentViewerFile.h \ - nsIWebShellServices.h \ - $(NULL) - -include <$(DEPTH)\config\rules.mak> - diff --git a/webshell/public/nsIContentViewerFile.h b/webshell/public/nsIContentViewerFile.h deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/webshell/tests/viewer/nsBrowserWindow.cpp b/webshell/tests/viewer/nsBrowserWindow.cpp index 25e3a2c82b9..42bc794db2f 100644 --- a/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/webshell/tests/viewer/nsBrowserWindow.cpp @@ -2185,7 +2185,7 @@ nsBrowserWindow::ShowPrintPreview(PRInt32 aID) { nsCOMPtr viewerFile = do_QueryInterface(viewer); if (viewerFile) { - viewerFile->PrintPreview(nsnull); + //viewerFile->PrintPreview(nsnull); } } } @@ -2200,7 +2200,7 @@ void nsBrowserWindow::DoPrint(void) { nsCOMPtr viewerFile = do_QueryInterface(viewer); if (viewerFile) { - viewerFile->Print(PR_FALSE, nsnull, (nsIWebProgressListener*)nsnull); + //viewerFile->Print(PR_FALSE, nsnull, (nsIWebProgressListener*)nsnull); } } } diff --git a/webshell/tests/viewer/nsWebCrawler.cpp b/webshell/tests/viewer/nsWebCrawler.cpp index 17758d7986c..958db6ff3c5 100644 --- a/webshell/tests/viewer/nsWebCrawler.cpp +++ b/webshell/tests/viewer/nsWebCrawler.cpp @@ -245,15 +245,15 @@ nsWebCrawler::DumpRegressionData() switch (mPrinterTestType) { case 1: // dump print data to a file for regression testing - viewerFile->Print(PR_TRUE, fp); + viewerFile->Print(PR_TRUE, fp, nsnull); break; case 2: // visual printing tests, all go to the printer, no printer dialog - viewerFile->Print(PR_TRUE, nsnull); + viewerFile->Print(PR_TRUE, nsnull, nsnull); break; case 3: // visual printing tests, all go to the printer, with a printer dialog - viewerFile->Print(PR_FALSE, nsnull); + viewerFile->Print(PR_FALSE, nsnull, nsnull); break; default: break; diff --git a/xpfe/browser/resources/content/browser.js b/xpfe/browser/resources/content/browser.js index 9c35a95613d..91af2e0b005 100644 --- a/xpfe/browser/resources/content/browser.js +++ b/xpfe/browser/resources/content/browser.js @@ -39,7 +39,6 @@ const nsIWebNavigation = Components.interfaces.nsIWebNavigation; var gPrintSettings = null; -var gUseGlobalPrintSettings = false; function getWebNavigation() { @@ -72,23 +71,46 @@ function BrowserReloadWithFlags(reloadFlags) } } + +function GetPrintSettings(webBrowserPrint) +{ + try { + if (gPrintSettings == null) { + var useGlobalPrintSettings = true; + var pref = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch); + if (pref) { + useGlobalPrintSettings = pref.getBoolPref("print.use_global_printsettings", false); + } + + if (useGlobalPrintSettings) { + gPrintSettings = webBrowserPrint.newPrintSettings; + } else { + gPrintSettings = webBrowserPrint.globalPrintSettings; + } + } + } catch (e) { + alert("GetPrintSettings "+e); + } + return gPrintSettings; +} + function BrowserPrintPreview() { - var printOptionsService = Components.classes["@mozilla.org/gfx/printoptions;1"] - .getService(Components.interfaces.nsIPrintOptions); - if (gPrintSettings == null) { - gPrintSettings = printOptionsService.CreatePrintSettings(); - } - // using _content.printPreview() until printing becomes scriptable on docShell try { - _content.printPreview(gPrintSettings); - + var ifreq = _content.QueryInterface(Components.interfaces.nsIInterfaceRequestor); + var webBrowserPrint = ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint); + if (webBrowserPrint) { + gPrintSettings = GetPrintSettings(webBrowserPrint); + webBrowserPrint.printPreview(gPrintSettings); + } } catch (e) { - // Pressing cancel is expressed as an NS_ERROR_FAILURE return value, + // Pressing cancel is expressed as an NS_ERROR_ABORT return value, // causing an exception to be thrown which we catch here. // Unfortunately this will also consume helpful failures, so add a // dump(e); // if you need to debug } + } @@ -96,33 +118,20 @@ function BrowserPrintSetup() { try { - var pref = Components.classes["@mozilla.org/preferences-service;1"] - .getService(Components.interfaces.nsIPrefBranch); - if (pref) { - gUseGlobalPrintSettings = pref.getBoolPref("print.use_global_printsettings", false); - } - - var printOptionsService = Components.classes["@mozilla.org/gfx/printoptions;1"] - .getService(Components.interfaces.nsIPrintOptions); - - // create our own local copy of the print settings - if (gPrintSettings == null) { - gPrintSettings = printOptionsService.CreatePrintSettings(); - } - - // if we are using the global settings then get them - // before calling page setup - if (gUseGlobalPrintSettings) { - gPrintSettings = printOptionsService.printSettingsValues; + var ifreq = _content.QueryInterface(Components.interfaces.nsIInterfaceRequestor); + var webBrowserPrint = ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint); + if (webBrowserPrint) { + gPrintSettings = GetPrintSettings(webBrowserPrint); } goPageSetup(gPrintSettings); // from utilityOverlay.js - // now set our setting into the global settings - // after the changes were made - if (gUseGlobalPrintSettings) { - printOptionsService.printSettingsValues = gPrintSettings; + if (webBrowserPrint) { + if (webBrowserPrint.doingPrintPreview) { + webBrowserPrint.printPreview(gPrintSettings); + } } + } catch (e) { alert("BrowserPrintSetup "+e); } @@ -131,32 +140,12 @@ function BrowserPrintSetup() function BrowserPrint() { try { - var pref = Components.classes["@mozilla.org/preferences-service;1"] - .getService(Components.interfaces.nsIPrefBranch); - if (pref) { - gUseGlobalPrintSettings = pref.getBoolPref("print.use_global_printsettings"); + var ifreq = _content.QueryInterface(Components.interfaces.nsIInterfaceRequestor); + var webBrowserPrint = ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint); + if (webBrowserPrint) { + gPrintSettings = GetPrintSettings(webBrowserPrint); + webBrowserPrint.print(gPrintSettings, null); } - var printOptionsService = Components.classes["@mozilla.org/gfx/printoptions;1"] - .getService(Components.interfaces.nsIPrintOptions); - if (gPrintSettings == null) { - gPrintSettings = printOptionsService.CreatePrintSettings(); - } - - // if we are using the global settings then get them - // before calling print - if (gUseGlobalPrintSettings) { - gPrintSettings = printOptionsService.printSettingsValues; - } - - // using _content.print() until printing becomes scriptable on docShell - _content.printWithSettings(gPrintSettings); - - // now set our setting into the global settings - // after the changes were made - if (gUseGlobalPrintSettings) { - printOptionsService.printSettingsValues = gPrintSettings; - } - } catch (e) { // Pressing cancel is expressed as an NS_ERROR_ABORT return value, // causing an exception to be thrown which we catch here.