Bug 495920 - nsThebesDeviceContext shouldn't have a reference to a native widget. r=masayuki, sr=roc

This commit is contained in:
Markus Stange 2009-06-11 11:24:41 +02:00
Родитель a0e3fe0bfe
Коммит f64a903399
6 изменённых файлов: 16 добавлений и 25 удалений

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

@ -45,7 +45,6 @@
#include "nsIRenderingContext.h"
// XXX we need only gfxTypes.h, but we cannot include it directly.
#include "gfxPoint.h"
#include "nsNativeWidget.h"
class nsIView;
class nsIFontMetrics;
@ -169,10 +168,10 @@ const PRUint8 kUseAltDCFor_CREATERC_PAINT = 0x04; // Use when creating Renderin
const PRUint8 kUseAltDCFor_SURFACE_DIM = 0x08; // Use it for getting the Surface Dimensions
#endif
// eca27eb2-ef6f-4142-bf77-89c14e595171
// 40aebd88-a82b-48b0-8a44-be51510064a7
#define NS_IDEVICE_CONTEXT_IID \
{ 0xeca27eb2, 0xef6f, 0x4142, \
{ 0xbf, 0x77, 0x89, 0xc1, 0x4e, 0x59, 0x51, 0x71 } }
{ 0x40aebd88, 0xa82b, 0x48b0, \
{ 0x8a, 0x44, 0xbe, 0x51, 0x51, 0x00, 0x64, 0xa7 } }
//a cross platform way of specifying a native palette handle
typedef void * nsPalette;
@ -215,10 +214,10 @@ public:
/**
* Initialize the device context from a widget
* @param aWidget a native widget to initialize the device context from
* @param aWidget a widget to initialize the device context from
* @return error status
*/
NS_IMETHOD Init(nsNativeWidget aWidget) = 0;
NS_IMETHOD Init(nsIWidget* aWidget) = 0;
/**
* Initialize the device context from a device context spec

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

@ -756,7 +756,7 @@ nsThebesDeviceContext::SetDPI()
}
NS_IMETHODIMP
nsThebesDeviceContext::Init(nsNativeWidget aWidget)
nsThebesDeviceContext::Init(nsIWidget *aWidget)
{
mWidget = aWidget;
@ -1185,8 +1185,9 @@ nsThebesDeviceContext::ComputeFullAreaUsingScreen(nsRect* outRect)
void
nsThebesDeviceContext::FindScreen(nsIScreen** outScreen)
{
if (mWidget)
mScreenManager->ScreenForNativeWidget(mWidget, outScreen);
if (mWidget && mWidget->GetNativeData(NS_NATIVE_WINDOW))
mScreenManager->ScreenForNativeWidget(mWidget->GetNativeData(NS_NATIVE_WINDOW),
outScreen);
else
mScreenManager->GetPrimaryScreen(outScreen);
}
@ -1234,12 +1235,12 @@ nsThebesDeviceContext::CalcPrintingSize()
inPoints = PR_FALSE;
HDC dc = GetPrintHDC();
if (!dc)
dc = GetDC((HWND)mWidget);
dc = GetDC((HWND)mWidget->GetNativeData(NS_NATIVE_WIDGET));
size.width = NSFloatPixelsToAppUnits(::GetDeviceCaps(dc, HORZRES)/mPrintingScale, AppUnitsPerDevPixel());
size.height = NSFloatPixelsToAppUnits(::GetDeviceCaps(dc, VERTRES)/mPrintingScale, AppUnitsPerDevPixel());
mDepth = (PRUint32)::GetDeviceCaps(dc, BITSPIXEL);
if (dc != (HDC)GetPrintHDC())
ReleaseDC((HWND)mWidget, dc);
ReleaseDC((HWND)mWidget->GetNativeData(NS_NATIVE_WIDGET), dc);
break;
}
#endif

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

@ -81,7 +81,7 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_IMETHOD Init(nsNativeWidget aWidget);
NS_IMETHOD Init(nsIWidget *aWidget);
NS_IMETHOD InitForPrinting(nsIDeviceContextSpec *aDevSpec);
NS_IMETHOD CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext);
NS_IMETHOD CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext);
@ -145,7 +145,6 @@ public:
PRBool IsPrinterSurface(void);
nsNativeWidget GetWidget() { return mWidget; }
#if defined(XP_WIN) || defined(XP_OS2)
HDC GetPrintHDC();
#endif
@ -167,7 +166,7 @@ protected:
nsFontCache* mFontCache;
nsCOMPtr<nsIAtom> mLocaleLangGroup; // XXX temp fix for performance bug - erik
nsHashtable* mFontAliasTable;
nsNativeWidget mWidget;
nsIWidget* mWidget;
#ifdef NS_DEBUG
PRBool mInitialized;
#endif

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

@ -373,7 +373,7 @@ nsresult CoverageTest(int *argc, char **argv)
if (NS_OK == res)
{
deviceContext->Init(gWindow->GetNativeData(NS_NATIVE_WIDGET));
deviceContext->Init(gWindow);
NS_ADDREF(deviceContext);
}

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

@ -2318,16 +2318,7 @@ DocumentViewerImpl::CreateDeviceContext(nsIWidget* aWidget)
// might have changed.
mDeviceContext = do_CreateInstance(kDeviceContextCID);
NS_ENSURE_TRUE(mDeviceContext, NS_ERROR_FAILURE);
nsNativeWidget nativeWidget = nsnull;
if (aWidget) {
// The device context should store NS_NATIVE_WINDOW of TopLevelWidget,
// because NS_NATIVE_WIDGET and NS_NATIVE_WINDOW of the given widget can be
// destroyed earlier than the device context.
nsIWidget* toplevelWidget = aWidget->GetTopLevelWidget();
NS_ASSERTION(toplevelWidget, "GetTopLevelWidget returns NULL");
nativeWidget = aWidget->GetNativeData(NS_NATIVE_WINDOW);
}
mDeviceContext->Init(nativeWidget);
mDeviceContext->Init(aWidget ? aWidget->GetTopLevelWidget() : nsnull);
return NS_OK;
}

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

@ -39,6 +39,7 @@
#define nsIScrollableView_h___
#include "nsCoord.h"
#include "nsNativeWidget.h"
class nsIView;
class nsIScrollPositionListener;