Fix crash in nsRenderingContextGTK::Init. Bug 156043, patch by

Roland.Mainz@informatik.med.uni-giessen.de (Roland Mainz), r=roc, sr=scc
This commit is contained in:
bzbarsky%mit.edu 2002-08-06 03:27:05 +00:00
parent 4795ff232f
commit 5e0f2971fb
13 changed files with 159 additions and 34 deletions

View File

@ -93,8 +93,8 @@ public:
NS_IMETHOD CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext);
NS_IMETHOD CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext);
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext){return NS_ERROR_NOT_IMPLEMENTED;}
NS_IMETHOD InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWindow);
NS_IMETHOD CreateRenderingContext(nsDrawingSurface aSurface, nsIRenderingContext *&aContext);
NS_IMETHOD CreateRenderingContextInstance(nsIRenderingContext *&aContext);
NS_IMETHOD GetDevUnitsToTwips(float &aDevUnitsToTwips) const;
NS_IMETHOD GetTwipsToDevUnits(float &aTwipsToDevUnits) const;
@ -143,6 +143,11 @@ public:
#endif
private:
/* Helper methods for |CreateRenderingContext|&co. */
nsresult InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWindow);
nsresult InitRenderingContext(nsIRenderingContext *aContext, nsDrawingSurface aSurface);
protected:
virtual ~DeviceContextImpl();

View File

@ -215,6 +215,14 @@ public:
*/
NS_IMETHOD CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext) = 0;
/**
* Create a rendering context and initialize it from an nsDrawingSurface
* @param nsDrawingSurface widget to initialize context from
* @param aContext out parameter for new rendering context
* @return error status
*/
NS_IMETHOD CreateRenderingContext(nsDrawingSurface aSurface, nsIRenderingContext *&aContext) = 0;
/**
* Create a rendering context and initialize it from an nsIWidget
* @param aWidget widget to initialize context from
@ -232,14 +240,11 @@ public:
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext) = 0;
/**
* Initialize a rendering context from a widget. This method is only for use
* when a rendering context was obtained directly from a factory rather than
* through one of the Create* methods above.
* @param aContext rendering context to initialize
* @param aWindow widget to initialize context from
* Create an uninitalised rendering context.
* @param aContext out parameter for new rendering context
* @return error status
*/
NS_IMETHOD InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWindow) = 0;
NS_IMETHOD CreateRenderingContextInstance(nsIRenderingContext *&aContext) = 0;
/**
* Query the device to see if it supports native widgets. If not, then

View File

@ -353,6 +353,18 @@ NS_IMETHODIMP nsDeviceContextGTK::CreateRenderingContext(nsIRenderingContext *&a
return rv;
}
NS_IMETHODIMP nsDeviceContextGTK::CreateRenderingContextInstance(nsIRenderingContext *&aContext)
{
nsCOMPtr<nsIRenderingContext> renderingContext = new nsRenderingContextGTK();
if (!renderingContext)
return NS_ERROR_OUT_OF_MEMORY;
aContext = renderingContext;
NS_ADDREF(aContext);
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextGTK::SupportsNativeWidgets(PRBool &aSupportsWidgets)
{
//XXX it is very critical that this not lie!! MMP

View File

@ -61,6 +61,8 @@ public:
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
NS_IMETHOD CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aView,aContext));}
NS_IMETHOD CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aWidget,aContext));}
NS_IMETHOD CreateRenderingContext(nsDrawingSurface aSurface, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aSurface, aContext));}
NS_IMETHOD CreateRenderingContextInstance(nsIRenderingContext *&aContext);
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);

View File

@ -162,8 +162,6 @@ NS_IMETHODIMP DeviceContextImpl::SetCanonicalPixelScale(float aScale)
return NS_OK;
}
static NS_DEFINE_CID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
NS_IMETHODIMP DeviceContextImpl::CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext)
{
#ifdef NS_PRINT_PREVIEW
@ -173,12 +171,13 @@ NS_IMETHODIMP DeviceContextImpl::CreateRenderingContext(nsIView *aView, nsIRende
}
#endif
nsresult rv;
nsIWidget *win;
aView->GetWidget(win);
nsresult rv;
nsCOMPtr<nsIWidget> win;
aView->GetWidget(*getter_AddRefs(win));
aContext = nsnull;
nsCOMPtr<nsIRenderingContext> pContext = do_CreateInstance(kRenderingContextCID, &rv);
nsCOMPtr<nsIRenderingContext> pContext;
rv = CreateRenderingContextInstance(*getter_AddRefs(pContext));
if (NS_SUCCEEDED(rv)) {
rv = InitRenderingContext(pContext, win);
if (NS_SUCCEEDED(rv)) {
@ -187,7 +186,31 @@ NS_IMETHODIMP DeviceContextImpl::CreateRenderingContext(nsIView *aView, nsIRende
}
}
NS_IF_RELEASE(win);
return rv;
}
NS_IMETHODIMP DeviceContextImpl::CreateRenderingContext(nsDrawingSurface aSurface, nsIRenderingContext *&aContext)
{
#ifdef NS_PRINT_PREVIEW
// AltDC NEVER use widgets to create their DCs
if (mAltDC && (mUseAltDC & kUseAltDCFor_CREATERC_PAINT)) {
return mAltDC->CreateRenderingContext(aContext);
}
#endif /* NS_PRINT_PREVIEW */
nsresult rv;
aContext = nsnull;
nsCOMPtr<nsIRenderingContext> pContext;
rv = CreateRenderingContextInstance(*getter_AddRefs(pContext));
if (NS_SUCCEEDED(rv)) {
rv = InitRenderingContext(pContext, aSurface);
if (NS_SUCCEEDED(rv)) {
aContext = pContext;
NS_ADDREF(aContext);
}
}
return rv;
}
@ -205,7 +228,8 @@ NS_IMETHODIMP DeviceContextImpl::CreateRenderingContext(nsIWidget *aWidget, nsIR
#endif
aContext = nsnull;
nsCOMPtr<nsIRenderingContext> pContext = do_CreateInstance(kRenderingContextCID, &rv);
nsCOMPtr<nsIRenderingContext> pContext;
rv = CreateRenderingContextInstance(*getter_AddRefs(pContext));
if (NS_SUCCEEDED(rv)) {
rv = InitRenderingContext(pContext, aWidget);
if (NS_SUCCEEDED(rv)) {
@ -217,7 +241,20 @@ NS_IMETHODIMP DeviceContextImpl::CreateRenderingContext(nsIWidget *aWidget, nsIR
return rv;
}
NS_IMETHODIMP DeviceContextImpl::InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWin)
NS_IMETHODIMP DeviceContextImpl::CreateRenderingContextInstance(nsIRenderingContext *&aContext)
{
static NS_DEFINE_CID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
nsresult rv;
nsCOMPtr<nsIRenderingContext> pContext = do_CreateInstance(kRenderingContextCID, &rv);
if (NS_SUCCEEDED(rv)) {
aContext = pContext;
NS_ADDREF(aContext);
}
return rv;
}
nsresult DeviceContextImpl::InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWin)
{
#ifdef NS_PRINT_PREVIEW
// there are a couple of cases where the kUseAltDCFor_CREATERC_xxx flag has been turned off
@ -232,6 +269,21 @@ NS_IMETHODIMP DeviceContextImpl::InitRenderingContext(nsIRenderingContext *aCont
#endif
}
nsresult DeviceContextImpl::InitRenderingContext(nsIRenderingContext *aContext, nsDrawingSurface aSurface)
{
#ifdef NS_PRINT_PREVIEW
// there are a couple of cases where the kUseAltDCFor_CREATERC_xxx flag has been turned off
// but we still need to initialize with the Alt DC
if (mAltDC) {
return aContext->Init(mAltDC, aSurface);
} else {
return aContext->Init(this, aSurface);
}
#else
return aContext->Init(this, aSurface);
#endif /* NS_PRINT_PREVIEW */
}
NS_IMETHODIMP DeviceContextImpl::CreateFontCache()
{
mFontCache = new nsFontCache();

View File

@ -207,6 +207,18 @@ NS_IMETHODIMP nsDeviceContextPS::CreateRenderingContext(nsIRenderingContext *&aC
return rv;
}
NS_IMETHODIMP nsDeviceContextPS::CreateRenderingContextInstance(nsIRenderingContext *&aContext)
{
nsCOMPtr<nsIRenderingContext> renderingContext = new nsRenderingContextPS();
if (!renderingContext)
return NS_ERROR_OUT_OF_MEMORY;
aContext = renderingContext;
NS_ADDREF(aContext);
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc

View File

@ -69,7 +69,9 @@ public:
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
NS_IMETHOD CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aView,aContext));}
NS_IMETHOD CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aWidget,aContext));}
/* PostScript module does not support offscreen drawing surfaces */
NS_IMETHOD CreateRenderingContext(nsDrawingSurface aSurface, nsIRenderingContext *&aContext) {return NS_ERROR_NOT_IMPLEMENTED;}
NS_IMETHOD CreateRenderingContextInstance(nsIRenderingContext *&aContext);
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);

View File

@ -234,6 +234,18 @@ NS_IMETHODIMP nsDeviceContextXlib::CreateRenderingContext(nsIRenderingContext *&
return rv;
}
NS_IMETHODIMP nsDeviceContextXlib::CreateRenderingContextInstance(nsIRenderingContext *&aContext)
{
nsCOMPtr<nsIRenderingContext> renderingContext = new nsRenderingContextXlib();
if (!renderingContext)
return NS_ERROR_OUT_OF_MEMORY;
aContext = renderingContext;
NS_ADDREF(aContext);
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextXlib::SupportsNativeWidgets(PRBool &aSupportsWidgets)
{
PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::SupportsNativeWidgets()\n"));

View File

@ -56,6 +56,10 @@ public:
{return (DeviceContextImpl::CreateRenderingContext(aView, aContext)); }
NS_IMETHOD CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext)
{return (DeviceContextImpl::CreateRenderingContext(aWidget, aContext)); }
NS_IMETHOD CreateRenderingContext(nsDrawingSurface aSurface, nsIRenderingContext *&aContext)
{return (DeviceContextImpl::CreateRenderingContext(aSurface, aContext));}
NS_IMETHOD CreateRenderingContextInstance(nsIRenderingContext *&aContext);
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
NS_IMETHOD GetScrollBarDimensions(float &aWidth, float &aHeight) const;

View File

@ -201,6 +201,18 @@ NS_IMETHODIMP nsDeviceContextXp :: CreateRenderingContext(nsIRenderingContext *&
return rv;
}
NS_IMETHODIMP nsDeviceContextXp::CreateRenderingContextInstance(nsIRenderingContext *&aContext)
{
nsCOMPtr<nsIRenderingContext> renderingContext = new nsRenderingContextXp();
if (!renderingContext)
return NS_ERROR_OUT_OF_MEMORY;
aContext = renderingContext;
NS_ADDREF(aContext);
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
*/

View File

@ -63,7 +63,16 @@ public:
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
NS_IMETHOD CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aView,aContext));}
NS_IMETHOD CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aWidget,aContext));}
#ifdef NOT_NOW
/* Xprint API supports offscreen surfaces but Mozilla does not make use of
* them, see bug 124761 ("RFE: Make use of "offpaper" drawing surfaces in
* some printing APIs"))
*/
NS_IMETHOD CreateRenderingContext(nsDrawingSurface aSurface, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aSurface, aContext));}
#else
NS_IMETHOD CreateRenderingContext(nsDrawingSurface aSurface, nsIRenderingContext *&aContext) {return NS_ERROR_NOT_IMPLEMENTED;}
#endif /* NOT_NOW */
NS_IMETHOD CreateRenderingContextInstance(nsIRenderingContext *&aContext);
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
NS_IMETHOD GetScrollBarDimensions(float &aWidth, float &aHeight) const;

View File

@ -20,9 +20,10 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Contributor(s): Patrick C. Beard <beard@netscape.com>
* Kevin McCluskey <kmcclusk@netscape.com>
* Robert O'Callahan <roc+@cs.cmu.edu>
* Patrick C. Beard <beard@netscape.com>
* Kevin McCluskey <kmcclusk@netscape.com>
* Robert O'Callahan <roc+@cs.cmu.edu>
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -311,6 +312,7 @@ nsViewManager::nsViewManager()
}
if (gCleanupContext == nsnull) {
/* XXX: This should use a device to create a matching |nsIRenderingContext| object */
nsComponentManager::CreateInstance(kRenderingContextCID,
nsnull, NS_GET_IID(nsIRenderingContext), (void**)&gCleanupContext);
NS_ASSERTION(gCleanupContext != nsnull, "Wasn't able to create a graphics context for cleanup");
@ -1297,14 +1299,10 @@ inline PRInt32 nextPowerOf2(PRInt32 value)
static nsresult NewOffscreenContext(nsIDeviceContext* deviceContext, nsDrawingSurface surface,
const nsSize& size, nsIRenderingContext* *aResult)
{
nsresult rv;
nsIRenderingContext* context;
rv = nsComponentManager::CreateInstance(kRenderingContextCID, nsnull,
NS_GET_IID(nsIRenderingContext),
(void **)&context);
if (NS_FAILED(rv))
return rv;
rv = context->Init(deviceContext, surface);
nsresult rv;
nsIRenderingContext *context = nsnull;
rv = deviceContext->CreateRenderingContext(surface, context);
if (NS_FAILED(rv))
return rv;

View File

@ -484,10 +484,10 @@ NS_IMETHODIMP nsBaseWidget::HideWindowChrome(PRBool aShouldHide)
//-------------------------------------------------------------------------
nsIRenderingContext* nsBaseWidget::GetRenderingContext()
{
static NS_DEFINE_CID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
nsresult rv;
nsresult rv;
nsCOMPtr<nsIRenderingContext> renderingCtx;
nsCOMPtr<nsIRenderingContext> renderingCtx = do_CreateInstance(kRenderingContextCID, &rv);
rv = mContext->CreateRenderingContextInstance(*getter_AddRefs(renderingCtx));
if (NS_SUCCEEDED(rv)) {
rv = renderingCtx->Init(mContext, this);
if (NS_SUCCEEDED(rv)) {