bug 824386 - (win-hidpi) nsScreenWin needs to account for logical dpi (resolution scale factor). r=jimm

This commit is contained in:
Jonathan Kew 2013-03-19 17:24:25 +00:00
parent 1fbabdf367
commit 3c12543a8e
3 changed files with 58 additions and 7 deletions

View File

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsScreenWin.h"
#include "nsCoord.h"
nsScreenWin :: nsScreenWin ( HMONITOR inScreen )
@ -87,6 +88,43 @@ nsScreenWin :: GetAvailRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth
} // GetAvailRect
NS_IMETHODIMP
nsScreenWin::GetRectDisplayPix(int32_t *outLeft, int32_t *outTop,
int32_t *outWidth, int32_t *outHeight)
{
int32_t left, top, width, height;
nsresult rv = GetRect(&left, &top, &width, &height);
if (NS_FAILED(rv)) {
return rv;
}
HDC dc = ::GetDC(nullptr);
double scaleFactor = 96.0 / GetDeviceCaps(dc, LOGPIXELSY);
::ReleaseDC(nullptr, dc);
*outLeft = NSToIntRound(left * scaleFactor);
*outTop = NSToIntRound(top * scaleFactor);
*outWidth = NSToIntRound(width * scaleFactor);
*outHeight = NSToIntRound(height * scaleFactor);
return NS_OK;
}
NS_IMETHODIMP
nsScreenWin::GetAvailRectDisplayPix(int32_t *outLeft, int32_t *outTop,
int32_t *outWidth, int32_t *outHeight)
{
int32_t left, top, width, height;
nsresult rv = GetAvailRect(&left, &top, &width, &height);
if (NS_FAILED(rv)) {
return rv;
}
HDC dc = ::GetDC(nullptr);
double scaleFactor = 96.0 / GetDeviceCaps(dc, LOGPIXELSY);
::ReleaseDC(nullptr, dc);
*outLeft = NSToIntRound(left * scaleFactor);
*outTop = NSToIntRound(top * scaleFactor);
*outWidth = NSToIntRound(width * scaleFactor);
*outHeight = NSToIntRound(height * scaleFactor);
return NS_OK;
}
NS_IMETHODIMP

View File

@ -17,8 +17,17 @@ public:
nsScreenWin ( HMONITOR inScreen );
~nsScreenWin();
// These methods return the size in device (physical) pixels
NS_IMETHOD GetRect(int32_t* aLeft, int32_t* aTop, int32_t* aWidth, int32_t* aHeight);
NS_IMETHOD GetAvailRect(int32_t* aLeft, int32_t* aTop, int32_t* aWidth, int32_t* aHeight);
// And these methods get the screen size in 'display pixels' (AKA 'logical pixels')
// that are dependent on the logical DPI setting in windows
NS_IMETHOD GetRectDisplayPix(int32_t *outLeft, int32_t *outTop,
int32_t *outWidth, int32_t *outHeight);
NS_IMETHOD GetAvailRectDisplayPix(int32_t *outLeft, int32_t *outTop,
int32_t *outWidth, int32_t *outHeight);
NS_IMETHOD GetPixelDepth(int32_t* aPixelDepth);
NS_IMETHOD GetColorDepth(int32_t* aColorDepth);

View File

@ -701,6 +701,12 @@ NS_IMETHODIMP nsBaseWidget::MakeFullScreen(bool aFullScreen)
if (!mOriginalBounds)
mOriginalBounds = new nsIntRect();
GetScreenBounds(*mOriginalBounds);
// convert dev pix to display pix for window manipulation
double scale = GetDefaultScale();
mOriginalBounds->x = NSToIntRound(mOriginalBounds->x / scale);
mOriginalBounds->y = NSToIntRound(mOriginalBounds->y / scale);
mOriginalBounds->width = NSToIntRound(mOriginalBounds->width / scale);
mOriginalBounds->height = NSToIntRound(mOriginalBounds->height / scale);
// Move to top-left corner of screen and size to the screen dimensions
nsCOMPtr<nsIScreenManager> screenManager;
@ -708,16 +714,14 @@ NS_IMETHODIMP nsBaseWidget::MakeFullScreen(bool aFullScreen)
NS_ASSERTION(screenManager, "Unable to grab screenManager.");
if (screenManager) {
nsCOMPtr<nsIScreen> screen;
// convert dev pix to display/CSS pix for ScreenForRect
double scale = GetDefaultScale();
screenManager->ScreenForRect(mOriginalBounds->x / scale,
mOriginalBounds->y / scale,
mOriginalBounds->width / scale,
mOriginalBounds->height / scale,
screenManager->ScreenForRect(mOriginalBounds->x,
mOriginalBounds->y,
mOriginalBounds->width,
mOriginalBounds->height,
getter_AddRefs(screen));
if (screen) {
int32_t left, top, width, height;
if (NS_SUCCEEDED(screen->GetRect(&left, &top, &width, &height))) {
if (NS_SUCCEEDED(screen->GetRectDisplayPix(&left, &top, &width, &height))) {
Resize(left, top, width, height, true);
}
}