diff --git a/gfx/src/gtk/nsDeviceContextGTK.cpp b/gfx/src/gtk/nsDeviceContextGTK.cpp index c77ca4d43d31..b3a1a0ec3d14 100644 --- a/gfx/src/gtk/nsDeviceContextGTK.cpp +++ b/gfx/src/gtk/nsDeviceContextGTK.cpp @@ -51,6 +51,11 @@ nsDeviceContextGTK::nsDeviceContextGTK() mPaletteInfo.numReserved = 0; mPaletteInfo.palette = NULL; mNumCells = 0; + + mWidthFloat = 0.0f; + mHeightFloat = 0.0f; + mWidth = -1; + mHeight = -1; } nsDeviceContextGTK::~nsDeviceContextGTK() @@ -134,6 +139,9 @@ NS_IMETHODIMP nsDeviceContextGTK::Init(nsNativeWidget aNativeWidget) gtk_widget_destroy(sb); gtk_widget_unref(sb); + mWidthFloat = (float) gdk_screen_width(); + mHeightFloat = (float) gdk_screen_height(); + #ifdef DEBUG static PRBool once = PR_TRUE; if (once) { @@ -142,6 +150,8 @@ NS_IMETHODIMP nsDeviceContextGTK::Init(nsNativeWidget aNativeWidget) } #endif + DeviceContextImpl::CommonInit(); + return NS_OK; } @@ -182,7 +192,7 @@ NS_IMETHODIMP nsDeviceContextGTK::CreateRenderingContext(nsIRenderingContext *&a w->allocation.width, w->allocation.height, gdk_rgb_get_visual()->depth); - + GdkGC *gc = gdk_gc_new(win); // init the nsDrawingSurfaceGTK @@ -368,10 +378,16 @@ NS_IMETHODIMP nsDeviceContextGTK::CheckFontExistence(const nsString& aFontName) NS_IMETHODIMP nsDeviceContextGTK::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight) { - aWidth = 1; - aHeight = 1; + if (mWidth == -1) + mWidth = NSToIntRound(mWidthFloat * mDevUnitsToAppUnits); - return NS_ERROR_FAILURE; + if (mHeight == -1) + mHeight = NSToIntRound(mHeightFloat * mDevUnitsToAppUnits); + + aWidth = mWidth; + aHeight = mHeight; + + return NS_OK; } NS_IMETHODIMP nsDeviceContextGTK::GetDeviceContextFor(nsIDeviceContextSpec *aDevice, diff --git a/gfx/src/gtk/nsDeviceContextGTK.h b/gfx/src/gtk/nsDeviceContextGTK.h index f20ee7ed2a27..6759631d96c5 100644 --- a/gfx/src/gtk/nsDeviceContextGTK.h +++ b/gfx/src/gtk/nsDeviceContextGTK.h @@ -70,9 +70,14 @@ private: PRUint32 mDepth; PRBool mWriteable; nsPaletteInfo mPaletteInfo; - PRUint32 mNumCells; - PRInt16 mScrollbarHeight; - PRInt16 mScrollbarWidth; + PRUint32 mNumCells; + PRInt16 mScrollbarHeight; + PRInt16 mScrollbarWidth; + + float mWidthFloat; + float mHeightFloat; + PRInt32 mWidth; + PRInt32 mHeight; }; #endif /* nsDeviceContextGTK_h___ */ diff --git a/gfx/src/xlib/nsDeviceContextXlib.cpp b/gfx/src/xlib/nsDeviceContextXlib.cpp index eced8e152b55..8a6718eb70f8 100644 --- a/gfx/src/xlib/nsDeviceContextXlib.cpp +++ b/gfx/src/xlib/nsDeviceContextXlib.cpp @@ -52,6 +52,11 @@ nsDeviceContextXlib::nsDeviceContextXlib() mScreen = nsnull; mVisual = nsnull; mDepth = 0; + + mWidthFloat = 0.0f; + mHeightFloat = 0.0f; + mWidth = -1; + mHeight = -1; } nsDeviceContextXlib::~nsDeviceContextXlib() @@ -127,6 +132,10 @@ nsDeviceContextXlib::CommonInit(void) PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("GFX: dpi=%d t2p=%g p2t=%g\n", dpi, mTwipsToPixels, mPixelsToTwips)); + + mWidthFloat = (float) WidthOfScreen(mScreen); + mHeightFloat = (float) HeightOfScreen(mScreen); + DeviceContextImpl::CommonInit(); } @@ -344,9 +353,15 @@ NS_IMETHODIMP nsDeviceContextXlib::CheckFontExistence(const nsString& aFontName) NS_IMETHODIMP nsDeviceContextXlib::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight) { - PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::GetDeviceSurfaceDimensions()\n")); - aWidth = 1; - aHeight = 1; + if (mWidth == -1) + mWidth = NSToIntRound(mWidthFloat * mDevUnitsToAppUnits); + + if (mHeight == -1) + mHeight = NSToIntRound(mHeightFloat * mDevUnitsToAppUnits); + + aWidth = mWidth; + aHeight = mHeight; + return NS_OK; } diff --git a/gfx/src/xlib/nsDeviceContextXlib.h b/gfx/src/xlib/nsDeviceContextXlib.h index 4fedfdc8f5fe..488182d2643b 100644 --- a/gfx/src/xlib/nsDeviceContextXlib.h +++ b/gfx/src/xlib/nsDeviceContextXlib.h @@ -71,6 +71,11 @@ private: Screen * mScreen; Visual * mVisual; int mDepth; + + float mWidthFloat; + float mHeightFloat; + PRInt32 mWidth; + PRInt32 mHeight; }; #endif