From 6bb838c1fca64927720b16657034398834a6350f Mon Sep 17 00:00:00 2001 From: "darin%meer.net" Date: Fri, 21 Oct 2005 17:59:30 +0000 Subject: [PATCH] fixes bug 245418 "menus and contextual menus open on wrong screen when using two/dual/multiple screens/monitors/displays" patch by Brett Wilson (brettw@gmail.com) r=darin,pink sr=roc git-svn-id: svn://10.0.0.236/trunk@182714 18797224-902f-48f8-a5cc-f745e15eee43 --- .../gfx/src/windows/nsDeviceContextWin.cpp | 82 +++++++------------ mozilla/gfx/src/windows/nsDeviceContextWin.h | 2 - 2 files changed, 29 insertions(+), 55 deletions(-) diff --git a/mozilla/gfx/src/windows/nsDeviceContextWin.cpp b/mozilla/gfx/src/windows/nsDeviceContextWin.cpp index ec1f3a882ff..36ff7765fd6 100644 --- a/mozilla/gfx/src/windows/nsDeviceContextWin.cpp +++ b/mozilla/gfx/src/windows/nsDeviceContextWin.cpp @@ -53,8 +53,6 @@ #define DOC_TITLE_LENGTH 64 -PRUint32 nsDeviceContextWin::sNumberOfScreens = 0; - #include "prlog.h" #ifdef PR_LOGGING PRLogModuleInfo * kGfxPrintingLogMod = PR_NewLogModule("printing-gfx"); @@ -161,8 +159,6 @@ void nsDeviceContextWin :: CommonInit(HDC aDC) // screen objects. We'll save the result nsresult ignore; mScreenManager = do_GetService("@mozilla.org/gfx/screenmanager;1", &ignore); - if ( !sNumberOfScreens ) - mScreenManager->GetNumberOfScreens(&sNumberOfScreens); } // if this dc is not a print device mTwipsToPixels = 1.0 / mPixelsToTwips; @@ -173,29 +169,25 @@ void nsDeviceContextWin :: CommonInit(HDC aDC) void nsDeviceContextWin :: ComputeClientRectUsingScreen ( nsRect* outRect ) { - // if we have more than one screen, we always need to recompute the clientRect + // we always need to recompute the clientRect // because the window may have moved onto a different screen. In the single // monitor case, we only need to do the computation if we haven't done it // once already, and remember that we have because we're assured it won't change. - if ( sNumberOfScreens > 1 || !mCachedClientRect ) { - nsCOMPtr screen; - FindScreen ( getter_AddRefs(screen) ); - if ( screen ) { - PRInt32 x, y, width, height; - screen->GetAvailRect ( &x, &y, &width, &height ); - - // convert to device units - outRect->y = NSToIntRound(y * mDevUnitsToAppUnits); - outRect->x = NSToIntRound(x * mDevUnitsToAppUnits); - outRect->width = NSToIntRound(width * mDevUnitsToAppUnits); - outRect->height = NSToIntRound(height * mDevUnitsToAppUnits); + nsCOMPtr screen; + FindScreen ( getter_AddRefs(screen) ); + if ( screen ) { + PRInt32 x, y, width, height; + screen->GetAvailRect ( &x, &y, &width, &height ); + + // convert to device units + outRect->y = NSToIntRound(y * mDevUnitsToAppUnits); + outRect->x = NSToIntRound(x * mDevUnitsToAppUnits); + outRect->width = NSToIntRound(width * mDevUnitsToAppUnits); + outRect->height = NSToIntRound(height * mDevUnitsToAppUnits); - mCachedClientRect = PR_TRUE; - mClientRect = *outRect; - } - } // if we need to recompute the client rect - else - *outRect = mClientRect; + mCachedClientRect = PR_TRUE; + mClientRect = *outRect; + } } // ComputeClientRectUsingScreen @@ -207,29 +199,21 @@ nsDeviceContextWin :: ComputeFullAreaUsingScreen ( nsRect* outRect ) // because the window may have moved onto a different screen. In the single // monitor case, we only need to do the computation if we haven't done it // once already, and remember that we have because we're assured it won't change. - if ( sNumberOfScreens > 1 || !mCachedFullRect ) { - nsCOMPtr screen; - FindScreen ( getter_AddRefs(screen) ); - if ( screen ) { - PRInt32 x, y, width, height; - screen->GetRect ( &x, &y, &width, &height ); - - // convert to device units - outRect->y = NSToIntRound(y * mDevUnitsToAppUnits); - outRect->x = NSToIntRound(x * mDevUnitsToAppUnits); - outRect->width = NSToIntRound(width * mDevUnitsToAppUnits); - outRect->height = NSToIntRound(height * mDevUnitsToAppUnits); + nsCOMPtr screen; + FindScreen ( getter_AddRefs(screen) ); + if ( screen ) { + PRInt32 x, y, width, height; + screen->GetRect ( &x, &y, &width, &height ); + + // convert to device units + outRect->y = NSToIntRound(y * mDevUnitsToAppUnits); + outRect->x = NSToIntRound(x * mDevUnitsToAppUnits); + outRect->width = NSToIntRound(width * mDevUnitsToAppUnits); + outRect->height = NSToIntRound(height * mDevUnitsToAppUnits); - mWidth = width; - mHeight = height; - mCachedFullRect = PR_TRUE; - } - } // if we need to recompute the client rect - else { - outRect->y = 0; - outRect->x = 0; - outRect->width = NSToIntRound(mWidth * mDevUnitsToAppUnits); - outRect->height = NSToIntRound(mHeight * mDevUnitsToAppUnits); + mWidth = width; + mHeight = height; + mCachedFullRect = PR_TRUE; } } // ComputeFullRectUsingScreen @@ -243,14 +227,6 @@ nsDeviceContextWin :: ComputeFullAreaUsingScreen ( nsRect* outRect ) void nsDeviceContextWin :: FindScreen ( nsIScreen** outScreen ) { - // optimize for the case where we only have one monitor. - if ( !mPrimaryScreen && mScreenManager ) - mScreenManager->GetPrimaryScreen ( getter_AddRefs(mPrimaryScreen) ); - if ( sNumberOfScreens == 1 ) { - NS_IF_ADDREF(*outScreen = mPrimaryScreen.get()); - return; - } - // now then, if we have more than one screen, we need to find which screen this // window is on. HWND window = NS_REINTERPRET_CAST(HWND, mWidget); diff --git a/mozilla/gfx/src/windows/nsDeviceContextWin.h b/mozilla/gfx/src/windows/nsDeviceContextWin.h index 7c8defa093e..0939e6ad869 100644 --- a/mozilla/gfx/src/windows/nsDeviceContextWin.h +++ b/mozilla/gfx/src/windows/nsDeviceContextWin.h @@ -118,8 +118,6 @@ protected: nsIDeviceContextSpec *mSpec; nsCOMPtr mScreenManager; // cache the screen service - nsCOMPtr mPrimaryScreen; // cache the screen for single-monitor systems - static PRUint32 sNumberOfScreens; public: HDC mDC;