bug 859266 - respect devPixelsPerPx preference when calculating screen dimens on Windows. r=roc

This commit is contained in:
Jonathan Kew 2013-04-09 09:39:47 +01:00
parent 9e38d90345
commit 6354f2dfe3
6 changed files with 48 additions and 9 deletions

View File

@ -607,6 +607,19 @@ class nsIWidget : public nsISupports {
*/
double GetDefaultScale();
/**
* Return the Gecko override of the system default scale, if any;
* returns <= 0.0 if the system scale should be used as-is.
* nsIWidget::GetDefaultScale() [above] takes this into account.
* It is exposed here so that code that wants to check for a
* default-scale override without having a widget on hand can
* easily access the same value.
* Note that any scale override is a browser-wide value, whereas
* the default GetDefaultScale value (when no override is present)
* may vary between widgets (or screens).
*/
static double DefaultScaleOverride();
/**
* Return the first child of this widget. Will return null if
* there are no children.

View File

@ -202,7 +202,10 @@ GetGutterSize(HANDLE theme, HDC hdc)
GetThemePartSize(theme, hdc, MENU_POPUPITEM, MPI_NORMAL, NULL, TS_TRUE, &itemSize);
// Figure out how big the menuitem's icon will be (if present) at current DPI
FLOAT scaleFactor = gfxWindowsPlatform::GetPlatform()->GetDPIScale();
double scaleFactor = nsIWidget::DefaultScaleOverride();
if (scaleFactor <= 0.0) {
scaleFactor = gfxWindowsPlatform::GetPlatform()->GetDPIScale();
}
int iconDevicePixels = NSToIntRound(16 * scaleFactor);
SIZE iconSize = {
iconDevicePixels, iconDevicePixels

View File

@ -6,6 +6,7 @@
#include "nsScreenManagerWin.h"
#include "nsScreenWin.h"
#include "gfxWindowsPlatform.h"
#include "nsIWidget.h"
BOOL CALLBACK CountMonitors ( HMONITOR, HDC, LPRECT, LPARAM ioCount ) ;
@ -78,7 +79,10 @@ nsScreenManagerWin :: ScreenForRect ( int32_t inLeft, int32_t inTop, int32_t inW
}
// convert coordinates from logical to device pixels for MonitorFromRect
FLOAT dpiScale = gfxWindowsPlatform::GetPlatform()->GetDPIScale();
double dpiScale = nsIWidget::DefaultScaleOverride();
if (dpiScale <= 0.0) {
dpiScale = gfxWindowsPlatform::GetPlatform()->GetDPIScale();
}
RECT globalWindowBounds = {
NSToIntRound(dpiScale * inLeft),
NSToIntRound(dpiScale * inTop),

View File

@ -6,6 +6,7 @@
#include "nsScreenWin.h"
#include "nsCoord.h"
#include "gfxWindowsPlatform.h"
#include "nsIWidget.h"
nsScreenWin :: nsScreenWin ( HMONITOR inScreen )
@ -89,6 +90,16 @@ nsScreenWin :: GetAvailRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth
} // GetAvailRect
static double
GetDPIScale()
{
double dpiScale= nsIWidget::DefaultScaleOverride();
if (dpiScale <= 0.0) {
dpiScale = gfxWindowsPlatform::GetPlatform()->GetDPIScale();
}
return dpiScale;
}
NS_IMETHODIMP
nsScreenWin::GetRectDisplayPix(int32_t *outLeft, int32_t *outTop,
int32_t *outWidth, int32_t *outHeight)
@ -98,7 +109,7 @@ nsScreenWin::GetRectDisplayPix(int32_t *outLeft, int32_t *outTop,
if (NS_FAILED(rv)) {
return rv;
}
double scaleFactor = 1.0 / gfxWindowsPlatform::GetPlatform()->GetDPIScale();
double scaleFactor = 1.0 / GetDPIScale();
*outLeft = NSToIntRound(left * scaleFactor);
*outTop = NSToIntRound(top * scaleFactor);
*outWidth = NSToIntRound(width * scaleFactor);
@ -115,7 +126,7 @@ nsScreenWin::GetAvailRectDisplayPix(int32_t *outLeft, int32_t *outTop,
if (NS_FAILED(rv)) {
return rv;
}
double scaleFactor = 1.0 / gfxWindowsPlatform::GetPlatform()->GetDPIScale();
double scaleFactor = 1.0 / GetDPIScale();
*outLeft = NSToIntRound(left * scaleFactor);
*outTop = NSToIntRound(top * scaleFactor);
*outWidth = NSToIntRound(width * scaleFactor);

View File

@ -1632,7 +1632,7 @@ NS_METHOD nsWindow::ConstrainPosition(bool aAllowSlop,
if (!mIsTopWidgetWindow) // only a problem for top-level windows
return NS_OK;
float dpiScale = gfxWindowsPlatform::GetPlatform()->GetDPIScale();
double dpiScale = GetDefaultScale();
// we need to use the window size in logical screen pixels
int32_t logWidth = std::max<int32_t>(NSToIntRound(mBounds.width / dpiScale), 1);

View File

@ -380,6 +380,18 @@ float nsBaseWidget::GetDPI()
}
double nsIWidget::GetDefaultScale()
{
double devPixelsPerCSSPixel = DefaultScaleOverride();
if (devPixelsPerCSSPixel <= 0.0) {
devPixelsPerCSSPixel = GetDefaultScaleInternal();
}
return devPixelsPerCSSPixel;
}
/* static */
double nsIWidget::DefaultScaleOverride()
{
// The number of device pixels per CSS pixel. A value <= 0 means choose
// automatically based on the DPI. A positive value is used as-is. This effectively
@ -391,10 +403,6 @@ double nsIWidget::GetDefaultScale()
devPixelsPerCSSPixel = PR_strtod(prefString, nullptr);
}
if (devPixelsPerCSSPixel <= 0.0) {
devPixelsPerCSSPixel = GetDefaultScaleInternal();
}
return devPixelsPerCSSPixel;
}