diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 4e2b6c293a6f..aaf765102d68 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -326,6 +326,13 @@ public: // nsIDocumentViewer interface... NS_IMETHOD GetPresShell(nsIPresShell** aResult); NS_IMETHOD GetPresContext(nsPresContext** aResult); + /** + * Find the view to use as the container view for MakeWindow. Returns + * null if this will be the root of a view manager hierarchy. In that + * case, if mParentWidget is null then this document should not even + * be displayed. + */ + virtual nsIView* FindContainerView(); // nsIContentViewerEdit NS_DECL_NSICONTENTVIEWEREDIT @@ -361,14 +368,6 @@ private: */ nsresult MakeWindow(const nsSize& aSize, nsIView* aContainerView); - /** - * Find the view to use as the container view for MakeWindow. Returns - * null if this will be the root of a view manager hierarchy. In that - * case, if mParentWidget is null then this document should not even - * be displayed. - */ - nsIView* FindContainerView(); - /** * Create our device context */ @@ -382,7 +381,6 @@ private: nsISupports *aState, const nsIntRect& aBounds, PRBool aDoCreation, - PRBool aInPrintPreview, PRBool aNeedMakeCX = PR_TRUE); /** * @param aDoInitialReflow set to true if you want to kick off the initial @@ -691,7 +689,7 @@ NS_IMETHODIMP DocumentViewerImpl::Init(nsIWidget* aParentWidget, const nsIntRect& aBounds) { - return InitInternal(aParentWidget, nsnull, aBounds, PR_TRUE, PR_FALSE); + return InitInternal(aParentWidget, nsnull, aBounds, PR_TRUE); } nsresult @@ -833,7 +831,6 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, nsISupports *aState, const nsIntRect& aBounds, PRBool aDoCreation, - PRBool aInPrintPreview, PRBool aNeedMakeCX /*= PR_TRUE*/) { // We don't want any scripts to run here. That can cause flushing, @@ -945,20 +942,18 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, mPresContext->SetLinkHandler(linkHandler); } - if (!aInPrintPreview) { - // Set script-context-owner in the document + // Set script-context-owner in the document - nsCOMPtr window; - requestor->GetInterface(NS_GET_IID(nsPIDOMWindow), - getter_AddRefs(window)); + nsCOMPtr window; + requestor->GetInterface(NS_GET_IID(nsPIDOMWindow), + getter_AddRefs(window)); - if (window) { - nsCOMPtr curDoc = - do_QueryInterface(window->GetExtantDocument()); - if (!mIsPageMode || curDoc != mDocument) { - window->SetNewDocument(mDocument, aState); - nsJSContext::LoadStart(); - } + if (window) { + nsCOMPtr curDoc = + do_QueryInterface(window->GetExtantDocument()); + if (!mIsPageMode || curDoc != mDocument) { + window->SetNewDocument(mDocument, aState); + nsJSContext::LoadStart(); } } } @@ -1360,7 +1355,7 @@ DocumentViewerImpl::Open(nsISupports *aState, nsISHEntry *aSHEntry) if (mDocument) mDocument->SetContainer(nsCOMPtr(do_QueryReferent(mContainer))); - nsresult rv = InitInternal(mParentWidget, aState, mBounds, PR_FALSE, PR_FALSE); + nsresult rv = InitInternal(mParentWidget, aState, mBounds, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); if (mPresShell) @@ -1884,13 +1879,6 @@ DocumentViewerImpl::SetBounds(const nsIntRect& aBounds) if (mPreviousViewer) mPreviousViewer->SetBounds(aBounds); -#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW) - if (GetIsPrintPreview() && !mPrintEngine->GetIsCreatingPrintPreview()) { - mPrintEngine->GetPrintPreviewWindow()->Resize(aBounds.x, aBounds.y, - aBounds.width, aBounds.height, - PR_FALSE); - } -#endif return NS_OK; } @@ -3657,7 +3645,6 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings, float(mDeviceContext->AppUnitsPerCSSInch()) / float(mDeviceContext->AppUnitsPerDevPixel()) / mPageZoom, - mParentWidget, #ifdef NS_DEBUG mDebugFile #else @@ -3707,8 +3694,8 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings, nsCOMPtr docShell(do_QueryReferent(mContainer)); NS_ASSERTION(docShell, "This has to be a docshell"); - if (!docShell ||! mDeviceContext || !mParentWidget) { - PR_PL(("Can't Print Preview without device context, docshell etc")); + if (!docShell || !mDeviceContext) { + PR_PL(("Can't Print Preview without device context and docshell")); return NS_ERROR_FAILURE; } @@ -3725,7 +3712,6 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings, float(mDeviceContext->AppUnitsPerCSSInch()) / float(mDeviceContext->AppUnitsPerDevPixel()) / mPageZoom, - mParentWidget, #ifdef NS_DEBUG mDebugFile #else @@ -4283,7 +4269,7 @@ NS_IMETHODIMP DocumentViewerImpl::SetPageMode(PRBool aPageMode, nsIPrintSettings nsresult rv = mPresContext->Init(mDeviceContext); NS_ENSURE_SUCCESS(rv, rv); } - InitInternal(mParentWidget, nsnull, mBounds, PR_TRUE, PR_FALSE, PR_FALSE); + InitInternal(mParentWidget, nsnull, mBounds, PR_TRUE, PR_FALSE); Show(); return NS_OK; @@ -4326,8 +4312,7 @@ DocumentViewerImpl::InitializeForPrintPreview() } void -DocumentViewerImpl::SetPrintPreviewPresentation(nsIWidget* aWidget, - nsIViewManager* aViewManager, +DocumentViewerImpl::SetPrintPreviewPresentation(nsIViewManager* aViewManager, nsPresContext* aPresContext, nsIPresShell* aPresShell) { @@ -4335,7 +4320,7 @@ DocumentViewerImpl::SetPrintPreviewPresentation(nsIWidget* aWidget, DestroyPresShell(); } - mWindow = aWidget; + mWindow = nsnull; mViewManager = aViewManager; mPresContext = aPresContext; mPresShell = aPresShell; diff --git a/layout/base/nsIDocumentViewer.h b/layout/base/nsIDocumentViewer.h index d62bee850765..ffc247e22062 100644 --- a/layout/base/nsIDocumentViewer.h +++ b/layout/base/nsIDocumentViewer.h @@ -46,10 +46,12 @@ class nsIDocument; class nsPresContext; class nsIPresShell; class nsIStyleSheet; +class nsIView; #define NS_IDOCUMENT_VIEWER_IID \ - { 0xf29e5537, 0x0763, 0x4977, \ - { 0x83, 0xc2, 0x3c, 0x93, 0x6c, 0x66, 0xa9, 0xfc } } + { 0x79c0bdbf, 0xf508, 0x4970, \ + { 0x94, 0x65, 0x03, 0x5e, 0xda, 0x2c, 0x02, 0x72 } } + /** * A document viewer is a kind of content viewer that uses NGLayout * to manage the presentation of the content. @@ -62,6 +64,8 @@ public: NS_IMETHOD GetPresShell(nsIPresShell** aResult) = 0; NS_IMETHOD GetPresContext(nsPresContext** aResult) = 0; + + virtual nsIView* FindContainerView() = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentViewer, NS_IDOCUMENT_VIEWER_IID) diff --git a/layout/base/nsIDocumentViewerPrint.h b/layout/base/nsIDocumentViewerPrint.h index 0f5ddb35cba7..2e400435634e 100644 --- a/layout/base/nsIDocumentViewerPrint.h +++ b/layout/base/nsIDocumentViewerPrint.h @@ -90,8 +90,7 @@ public: /** * Replaces the current presentation with print preview presentation. */ - virtual void SetPrintPreviewPresentation(nsIWidget* aWidget, - nsIViewManager* aViewManager, + virtual void SetPrintPreviewPresentation(nsIViewManager* aViewManager, nsPresContext* aPresContext, nsIPresShell* aPresShell) = 0; }; @@ -111,8 +110,7 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentViewerPrint, virtual void OnDonePrinting(); \ virtual PRBool IsInitializedForPrintPreview(); \ virtual void InitializeForPrintPreview(); \ - virtual void SetPrintPreviewPresentation(nsIWidget* aWidget, \ - nsIViewManager* aViewManager, \ + virtual void SetPrintPreviewPresentation(nsIViewManager* aViewManager, \ nsPresContext* aPresContext, \ nsIPresShell* aPresShell); diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index 32afa2500826..c4943cbd3e8b 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -155,6 +155,7 @@ static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingpro #include "nsIDOMHTMLImageElement.h" #include "nsIContentViewerContainer.h" #include "nsIContentViewer.h" +#include "nsIDocumentViewer.h" #include "nsIDocumentViewerPrint.h" #include "nsPIDOMWindow.h" @@ -265,7 +266,6 @@ nsPrintEngine::nsPrintEngine() : mPrt(nsnull), mPagePrintTimer(nsnull), mPageSeqFrame(nsnull), - mParentWidget(nsnull), mPrtPreview(nsnull), mOldPrtPreview(nsnull), mDebugFile(nsnull) @@ -320,7 +320,6 @@ nsresult nsPrintEngine::Initialize(nsIDocumentViewerPrint* aDocViewerPrint, nsISupports* aContainer, nsIDocument* aDocument, float aScreenDPI, - nsIWidget* aParentWidget, FILE* aDebugFile) { NS_ENSURE_ARG_POINTER(aDocViewerPrint); @@ -331,7 +330,6 @@ nsresult nsPrintEngine::Initialize(nsIDocumentViewerPrint* aDocViewerPrint, mContainer = aContainer; // weak reference mDocument = aDocument; mScreenDPI = aScreenDPI; - mParentWidget = aParentWidget; mDebugFile = aDebugFile; // ok to be NULL @@ -1884,12 +1882,14 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO) nsSize adjSize; PRBool documentIsTopLevel; - nsIFrame* frame = nsnull; if (!aPO->IsPrintable()) return NS_OK; + PRBool canCreateScrollbars = PR_TRUE; + nsIView* parentView = nsnull; + if (aPO->mParent && aPO->mParent->IsPrintable()) { - frame = aPO->mContent->GetPrimaryFrame(); + nsIFrame* frame = aPO->mContent->GetPrimaryFrame(); // Without a frame, this document can't be displayed; therefore, there is no // point to reflowing it if (!frame) { @@ -1903,6 +1903,16 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO) adjSize = frame->GetContentRect().Size(); documentIsTopLevel = PR_FALSE; // presshell exists because parent is printable + + // the top nsPrintObject's widget will always have scrollbars + if (frame && frame->GetType() == nsGkAtoms::subDocumentFrame) { + nsIView* view = frame->GetView(); + NS_ENSURE_TRUE(view, NS_ERROR_FAILURE); + view = view->GetFirstChild(); + NS_ENSURE_TRUE(view, NS_ERROR_FAILURE); + parentView = view; + canCreateScrollbars = PR_FALSE; + } } else { nscoord pageWidth, pageHeight; mPrt->mPrintDC->GetDeviceSurfaceDimensions(pageWidth, pageHeight); @@ -1921,31 +1931,17 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO) adjSize = nsSize(pageWidth, pageHeight); #endif // XP_UNIX && !XP_MACOSX documentIsTopLevel = PR_TRUE; - } - // Here we decide whether we need scrollbars and - // what the parent will be of the widget - // How this logic presently works: Print Preview is always as-is (as far - // as I can tell; not sure how it would work in other cases); only the root - // is not eIFrame or eFrame. The child documents get a parent widget from - // logic in nsFrameFrame. In any case, a child widget is created for the root - // view of the document. - PRBool canCreateScrollbars = PR_TRUE; - nsIView* parentView = nsnull; - // the top nsPrintObject's widget will always have scrollbars - if (frame && frame->GetType() == nsGkAtoms::subDocumentFrame) { - nsIView* view = frame->GetView(); - NS_ENSURE_TRUE(view, NS_ERROR_FAILURE); - view = view->GetFirstChild(); - NS_ENSURE_TRUE(view, NS_ERROR_FAILURE); - parentView = view; - canCreateScrollbars = PR_FALSE; + nsCOMPtr dv = do_QueryInterface(mDocViewerPrint); + if (dv) { + parentView = dv->FindContainerView(); + } } NS_ASSERTION(!aPO->mPresContext, "Recreating prescontext"); // create the PresContext - aPO->mPresContext = new nsRootPresContext(aPO->mDocument, + aPO->mPresContext = new nsPresContext(aPO->mDocument, mIsCreatingPrintPreview ? nsPresContext::eContext_PrintPreview: nsPresContext::eContext_Print); NS_ENSURE_TRUE(aPO->mPresContext, NS_ERROR_OUT_OF_MEMORY); @@ -1991,21 +1987,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO) nsIView* rootView = aPO->mViewManager->CreateView(tbounds, parentView); NS_ENSURE_TRUE(rootView, NS_ERROR_OUT_OF_MEMORY); - // Only create a widget for print preview; when printing, a widget is - // unnecessary and unexpected - // Also, no widget should be needed except for the top-level document if (mIsCreatingPrintPreview && documentIsTopLevel) { - nsIWidget* widget = nsnull; - if (!frame) - widget = mParentWidget; - rv = widget ? rootView->CreateWidgetForParent(widget, nsnull, - PR_TRUE, PR_TRUE, - eContentTypeContent) - : rootView->CreateWidget(nsnull, - PR_TRUE, PR_TRUE, - eContentTypeContent); - NS_ENSURE_SUCCESS(rv, rv); - aPO->mWindow = rootView->GetWidget(); aPO->mPresContext->SetPaginatedScrolling(canCreateScrollbars); } @@ -2028,8 +2010,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO) aPO->mPresContext->SetPrintPreviewScale(mScreenDPI / printDPI); if (mIsCreatingPrintPreview && documentIsTopLevel) { - mDocViewerPrint->SetPrintPreviewPresentation(aPO->mWindow, - aPO->mViewManager, + mDocViewerPrint->SetPrintPreviewPresentation(aPO->mViewManager, aPO->mPresContext, aPO->mPresShell); } diff --git a/layout/printing/nsPrintEngine.h b/layout/printing/nsPrintEngine.h index 6c08d1e72149..b379378a68ac 100644 --- a/layout/printing/nsPrintEngine.h +++ b/layout/printing/nsPrintEngine.h @@ -105,7 +105,6 @@ public: nsISupports* aContainer, nsIDocument* aDocument, float aScreenDPI, - nsIWidget* aParentWidget, FILE* aDebugFile); nsresult GetSeqFrameAndCountPages(nsIFrame*& aSeqFrame, PRInt32& aCount); @@ -195,8 +194,6 @@ public: PRBool CheckBeforeDestroy(); nsresult Cancelled(); - nsIWidget* GetPrintPreviewWindow() {return mPrtPreview->mPrintObject->mWindow;} - nsIPresShell* GetPrintPreviewPresShell() {return mPrtPreview->mPrintObject->mPresShell;} float GetPrintPreviewScale() { return mPrtPreview->mPrintObject-> @@ -291,7 +288,6 @@ protected: nsIPageSequenceFrame* mPageSeqFrame; // Print Preview - nsCOMPtr mParentWidget; nsPrintData* mPrtPreview; nsPrintData* mOldPrtPreview; diff --git a/layout/printing/nsPrintObject.cpp b/layout/printing/nsPrintObject.cpp index 5bc41d0ec690..4b9662132080 100644 --- a/layout/printing/nsPrintObject.cpp +++ b/layout/printing/nsPrintObject.cpp @@ -122,7 +122,6 @@ nsPrintObject::Init(nsIDocShell* aDocShell, nsIDOMDocument* aDoc, void nsPrintObject::DestroyPresentation() { - mWindow = nsnull; mPresContext = nsnull; if (mPresShell) { mPresShell->EndObservingDocument(); diff --git a/layout/printing/nsPrintObject.h b/layout/printing/nsPrintObject.h index 4582fcd2e81d..f00b61ed2213 100644 --- a/layout/printing/nsPrintObject.h +++ b/layout/printing/nsPrintObject.h @@ -45,7 +45,6 @@ #include "nsIViewManager.h" #include "nsIDocShell.h" #include "nsIDocument.h" -#include "nsIWidget.h" class nsPresContext; @@ -76,7 +75,6 @@ public: nsRefPtr mPresContext; nsCOMPtr mPresShell; nsCOMPtr mViewManager; - nsCOMPtr mWindow; nsCOMPtr mContent; PrintObjectType mFrameType;