Bug 370034: Replace nsIDeviceContext::GetDeviceContextFor with nsIDeviceContext::Init. r+sr=roc

This commit is contained in:
sharparrow1%yahoo.com 2007-02-15 11:08:47 +00:00
Родитель 5b44965fcc
Коммит 5d26b185b1
5 изменённых файлов: 41 добавлений и 69 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -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(mDeviceContextSpec = aDevice);
NS_ADDREF(aDevice);
mPrinter = PR_TRUE;
newDevCon->mDeviceContextSpec = aDevice;
aDevice->GetSurfaceForPrinter(getter_AddRefs(mPrintingSurface));
newDevCon->mPrinter = PR_TRUE;
Init(nsnull);
aDevice->GetSurfaceForPrinter(getter_AddRefs(newDevCon->mPrintingSurface));
newDevCon->Init(nsnull);
newDevCon->CalcPrintingSize();
CalcPrintingSize();
return NS_OK;
}

Просмотреть файл

@ -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);

Просмотреть файл

@ -833,23 +833,18 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget,
#ifdef NS_PRINT_PREVIEW
if (mIsPageMode) {
nsCOMPtr<nsIDeviceContext> devctx;
;
nsCOMPtr<nsIDeviceContextSpec> 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<nsIDeviceContext> 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;

Просмотреть файл

@ -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<nsIDeviceContext> ppDC;
nsCOMPtr<nsIDeviceContextSpec> 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<nsIDeviceContextSpec> 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);
}