diff --git a/gfx/public/nsIDeviceContext.h b/gfx/public/nsIDeviceContext.h index 9aa867cdaab..4f9d6659ac0 100644 --- a/gfx/public/nsIDeviceContext.h +++ b/gfx/public/nsIDeviceContext.h @@ -222,6 +222,13 @@ public: */ NS_IMETHOD Init(nsNativeWidget aWidget) = 0; + /** + * Initialize the device context from a device context spec + * @param aDevSpec the specification of the printng device (platform-specific) + * @return error status + */ + NS_IMETHOD InitForPrinting(nsIDeviceContextSpec* aDevSpec) = 0; + /** * Create a rendering context and initialize it from an nsIView * @param aView view to initialize context from @@ -393,19 +400,6 @@ public: */ NS_IMETHOD GetClientRect(nsRect &aRect) = 0; - /** - * Returns a new nsIDeviceContext suitable for the device context - * specification passed in. - * @param aDevice a device context specification. this is a platform - * specific structure that only a platform specific device - * context can interpret. - * @param aContext out parameter for new device context. nsnull on - * failure to create new device context. - * @return error status - */ - NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice, - nsIDeviceContext *&aContext) = 0; - /** * This is enables the DeviceContext to anything it needs to do for Printing * before Reflow and BeginDocument is where work can be done after reflow. diff --git a/gfx/src/thebes/nsThebesDeviceContext.cpp b/gfx/src/thebes/nsThebesDeviceContext.cpp index 8e71b31b541..e62344dcc68 100644 --- a/gfx/src/thebes/nsThebesDeviceContext.cpp +++ b/gfx/src/thebes/nsThebesDeviceContext.cpp @@ -461,33 +461,22 @@ nsThebesDeviceContext::PrepareNativeWidget(nsIWidget* aWidget, void** aOut) /* - * below methods are for printing and are not implemented + * below methods are for printing */ NS_IMETHODIMP -nsThebesDeviceContext::GetDeviceContextFor(nsIDeviceContextSpec *aDevice, - nsIDeviceContext *&aContext) +nsThebesDeviceContext::InitForPrinting(nsIDeviceContextSpec *aDevice) { - nsThebesDeviceContext *newDevCon = new nsThebesDeviceContext(); + NS_ENSURE_ARG_POINTER(aDevice); - if (newDevCon) { - // this will ref count it - nsresult rv = newDevCon->QueryInterface(NS_GET_IID(nsIDeviceContext), (void**)&aContext); - NS_ASSERTION(NS_SUCCEEDED(rv), "This has to support nsIDeviceContext"); - } else { - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_ADDREF(aDevice); + NS_ADDREF(mDeviceContextSpec = aDevice); - newDevCon->mDeviceContextSpec = aDevice; + mPrinter = PR_TRUE; - newDevCon->mPrinter = PR_TRUE; + aDevice->GetSurfaceForPrinter(getter_AddRefs(mPrintingSurface)); - aDevice->GetSurfaceForPrinter(getter_AddRefs(newDevCon->mPrintingSurface)); + Init(nsnull); - newDevCon->Init(nsnull); - - newDevCon->CalcPrintingSize(); + CalcPrintingSize(); return NS_OK; } diff --git a/gfx/src/thebes/nsThebesDeviceContext.h b/gfx/src/thebes/nsThebesDeviceContext.h index d8aa2bf644e..51cf7bd5c96 100644 --- a/gfx/src/thebes/nsThebesDeviceContext.h +++ b/gfx/src/thebes/nsThebesDeviceContext.h @@ -68,6 +68,7 @@ public: NS_DECL_ISUPPORTS_INHERITED NS_IMETHOD Init(nsNativeWidget aWidget); + NS_IMETHOD InitForPrinting(nsIDeviceContextSpec* aDevSpec); NS_IMETHOD CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext); NS_IMETHOD CreateRenderingContext(nsIDrawingSurface *aSurface, nsIRenderingContext *&aContext); @@ -93,9 +94,6 @@ public: NS_IMETHOD GetClientRect(nsRect &aRect); /* printing goop */ - NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice, - nsIDeviceContext *&aContext); - NS_IMETHOD PrepareDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName); diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index e5f9da4906f..553a7fe5e7e 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -833,23 +833,18 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, #ifdef NS_PRINT_PREVIEW if (mIsPageMode) { - nsCOMPtr devctx; + ; nsCOMPtr devspec = - do_CreateInstance("@mozilla.org/gfx/devicecontextspec;1"); - // XXX CRASHES ON OOM. YUM. WOULD SOMEONE PLEASE FIX ME. - // PERHAPS SOMEONE SHOULD HAVE REVIEWED THIS CODE. - // XXX I have no idea how critical this code is, so i'm not fixing it. - // In fact I'm just adding a line that makes this block - // get compiled *less* often. + do_CreateInstance("@mozilla.org/gfx/devicecontextspec;1", &rv); + NS_ENSURE_SUCCESS(rv, rv); // mWindow has been initialized by preceding call to MakeWindow - devspec->Init(mWindow, mPresContext->GetPrintSettings(), PR_FALSE); - // XXX CRASHES ON OOM under at least - // nsPrintJobFactoryPS::CreatePrintJob. WOULD SOMEONE PLEASE FIX ME. - // PERHAPS SOMEONE SHOULD HAVE REVIEWED THIS CODE. - // XXX I have no idea how critical this code is, so i'm not fixing it. - // In fact I'm just adding a line that makes this block - // get compiled *less* often. - mDeviceContext->GetDeviceContextFor(devspec, *getter_AddRefs(devctx)); + rv = devspec->Init(mWindow, mPresContext->GetPrintSettings(), PR_FALSE); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr devctx = + do_CreateInstance("@mozilla.org/gfx/devicecontext;1", &rv); + NS_ENSURE_SUCCESS(rv, rv); + rv = devctx->Init(devspec); + NS_ENSURE_SUCCESS(rv, rv); // XXX I'm breaking this code; I'm not sure I really want to mess with // the document viewer at the moment to get the right device context // (this won't break anyone, since page layout mode was never really @@ -4093,6 +4088,9 @@ DocumentViewerImpl::OnDonePrinting() NS_IMETHODIMP DocumentViewerImpl::SetPageMode(PRBool aPageMode, nsIPrintSettings* aPrintSettings) { + // XXX until the print code is in a more stable state, I don't + // want to worry about this code + return NS_ERROR_NOT_IMPLEMENTED; mIsPageMode = aPageMode; // Get the current size of what is being viewed nsRect bounds; diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index f263aac2671..e166d72fd0d 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -641,8 +641,9 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings, } if (NS_SUCCEEDED(rv)) { - rv = mDeviceContext->GetDeviceContextFor(devspec, - *getter_AddRefs(mPrt->mPrintDC)); + mPrt->mPrintDC = do_CreateInstance("@mozilla.org/gfx/devicecontext;1", &rv); + if (NS_SUCCEEDED(rv)) + rv = mPrt->mPrintDC->InitForPrinting(devspec); if (NS_SUCCEEDED(rv)) { if(webContainer) { // Always check and set the print settings first and then fall back @@ -919,15 +920,15 @@ nsPrintEngine::PrintPreview(nsIPrintSettings* aPrintSettings, } #endif - nsCOMPtr ppDC; - nsCOMPtr devspec = - do_CreateInstance("@mozilla.org/gfx/devicecontextspec;1"); - if (devspec) { - rv = devspec->Init(mParentWidget, mPrt->mPrintSettings, PR_TRUE); - if (NS_SUCCEEDED(rv)) { - rv = mDeviceContext->GetDeviceContextFor(devspec, *getter_AddRefs(ppDC)); - } - } + nsCOMPtr devspec + (do_CreateInstance("@mozilla.org/gfx/devicecontextspec;1", &rv)); + NS_ENSURE_SUCCESS(rv, rv); + rv = devspec->Init(mParentWidget, mPrt->mPrintSettings, PR_TRUE); + NS_ENSURE_SUCCESS(rv, rv); + mPrt->mPrintDC = do_CreateInstance("@mozilla.org/gfx/devicecontext;1", &rv); + NS_ENSURE_SUCCESS(rv, rv); + rv = mPrt->mPrintDC->InitForPrinting(devspec); + NS_ENSURE_SUCCESS(rv, rv); mPrt->mPrintSettings->SetPrintFrameType(nsIPrintSettings::kFramesAsIs); @@ -935,14 +936,6 @@ nsPrintEngine::PrintPreview(nsIPrintSettings* aPrintSettings, // we want to view every page in PrintPreview each time mPrt->mPrintSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages); - if (ppDC) - mPrt->mPrintDC = ppDC; - else - mPrt->mPrintDC = mDeviceContext; - - if (!mPrt->mPrintDC) - return NS_ERROR_FAILURE; - if (aWebProgressListener != nsnull) { mPrt->mPrintProgressListeners.AppendObject(aWebProgressListener); }