2006-01-11 21:28:25 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-01-11 21:27:48 +00:00
|
|
|
|
|
|
|
#include "nsScreenWin.h"
|
2013-03-19 17:24:25 +00:00
|
|
|
#include "nsCoord.h"
|
2013-04-01 09:10:28 +00:00
|
|
|
#include "gfxWindowsPlatform.h"
|
2013-04-09 08:39:47 +00:00
|
|
|
#include "nsIWidget.h"
|
2006-01-11 21:27:48 +00:00
|
|
|
|
2006-01-11 21:28:03 +00:00
|
|
|
|
2012-01-05 07:52:22 +00:00
|
|
|
nsScreenWin :: nsScreenWin ( HMONITOR inScreen )
|
2006-04-04 20:57:13 +00:00
|
|
|
: mScreen(inScreen)
|
2006-01-11 21:27:48 +00:00
|
|
|
{
|
2006-01-11 21:28:13 +00:00
|
|
|
#ifdef DEBUG
|
2012-07-30 14:20:58 +00:00
|
|
|
HDC hDCScreen = ::GetDC(nullptr);
|
2006-01-11 21:28:13 +00:00
|
|
|
NS_ASSERTION(hDCScreen,"GetDC Failure");
|
|
|
|
NS_ASSERTION ( ::GetDeviceCaps(hDCScreen, TECHNOLOGY) == DT_RASDISPLAY, "Not a display screen");
|
2012-07-30 14:20:58 +00:00
|
|
|
::ReleaseDC(nullptr,hDCScreen);
|
2006-01-11 21:28:13 +00:00
|
|
|
#endif
|
2006-01-11 21:28:03 +00:00
|
|
|
|
2006-01-11 21:27:48 +00:00
|
|
|
// nothing else to do. I guess we could cache a bunch of information
|
|
|
|
// here, but we want to ask the device at runtime in case anything
|
|
|
|
// has changed.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsScreenWin :: ~nsScreenWin()
|
|
|
|
{
|
|
|
|
// nothing to see here.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-11 21:28:07 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsScreenWin :: GetRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight)
|
2006-01-11 21:27:48 +00:00
|
|
|
{
|
2006-01-11 21:28:04 +00:00
|
|
|
BOOL success = FALSE;
|
2006-04-04 20:57:13 +00:00
|
|
|
if ( mScreen ) {
|
2006-01-11 21:28:03 +00:00
|
|
|
MONITORINFO info;
|
|
|
|
info.cbSize = sizeof(MONITORINFO);
|
2012-01-05 07:52:22 +00:00
|
|
|
success = ::GetMonitorInfoW( mScreen, &info );
|
2006-01-11 21:28:07 +00:00
|
|
|
if ( success ) {
|
|
|
|
*outLeft = info.rcMonitor.left;
|
|
|
|
*outTop = info.rcMonitor.top;
|
|
|
|
*outWidth = info.rcMonitor.right - info.rcMonitor.left;
|
|
|
|
*outHeight = info.rcMonitor.bottom - info.rcMonitor.top;
|
|
|
|
}
|
2006-01-11 21:28:03 +00:00
|
|
|
}
|
2006-01-11 21:28:07 +00:00
|
|
|
if (!success) {
|
2012-07-30 14:20:58 +00:00
|
|
|
HDC hDCScreen = ::GetDC(nullptr);
|
2006-01-11 21:28:13 +00:00
|
|
|
NS_ASSERTION(hDCScreen,"GetDC Failure");
|
|
|
|
|
|
|
|
*outTop = *outLeft = 0;
|
|
|
|
*outWidth = ::GetDeviceCaps(hDCScreen, HORZRES);
|
|
|
|
*outHeight = ::GetDeviceCaps(hDCScreen, VERTRES);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
::ReleaseDC(nullptr, hDCScreen);
|
2006-01-11 21:28:07 +00:00
|
|
|
}
|
2006-01-11 21:27:48 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2006-01-11 21:28:07 +00:00
|
|
|
} // GetRect
|
2006-01-11 21:27:48 +00:00
|
|
|
|
|
|
|
|
2006-01-11 21:28:07 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsScreenWin :: GetAvailRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight)
|
2006-01-11 21:27:48 +00:00
|
|
|
{
|
2006-01-11 21:28:04 +00:00
|
|
|
BOOL success = FALSE;
|
2009-04-14 05:27:39 +00:00
|
|
|
|
2006-04-04 20:57:13 +00:00
|
|
|
if ( mScreen ) {
|
2006-01-11 21:28:03 +00:00
|
|
|
MONITORINFO info;
|
|
|
|
info.cbSize = sizeof(MONITORINFO);
|
2012-01-05 07:52:22 +00:00
|
|
|
success = ::GetMonitorInfoW( mScreen, &info );
|
2006-01-11 21:28:07 +00:00
|
|
|
if ( success ) {
|
|
|
|
*outLeft = info.rcWork.left;
|
|
|
|
*outTop = info.rcWork.top;
|
|
|
|
*outWidth = info.rcWork.right - info.rcWork.left;
|
|
|
|
*outHeight = info.rcWork.bottom - info.rcWork.top;
|
|
|
|
}
|
2006-01-11 21:28:03 +00:00
|
|
|
}
|
2006-01-11 21:28:07 +00:00
|
|
|
if (!success) {
|
|
|
|
RECT workArea;
|
|
|
|
::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
|
|
|
|
*outLeft = workArea.left;
|
|
|
|
*outTop = workArea.top;
|
|
|
|
*outWidth = workArea.right - workArea.left;
|
|
|
|
*outHeight = workArea.bottom - workArea.top;
|
|
|
|
}
|
|
|
|
|
2006-01-11 21:27:48 +00:00
|
|
|
return NS_OK;
|
2006-01-11 21:28:07 +00:00
|
|
|
|
|
|
|
} // GetAvailRect
|
2006-01-11 21:27:48 +00:00
|
|
|
|
2013-04-09 08:39:47 +00:00
|
|
|
static double
|
|
|
|
GetDPIScale()
|
|
|
|
{
|
|
|
|
double dpiScale= nsIWidget::DefaultScaleOverride();
|
|
|
|
if (dpiScale <= 0.0) {
|
|
|
|
dpiScale = gfxWindowsPlatform::GetPlatform()->GetDPIScale();
|
|
|
|
}
|
|
|
|
return dpiScale;
|
|
|
|
}
|
|
|
|
|
2013-03-19 17:24:25 +00:00
|
|
|
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;
|
|
|
|
}
|
2013-04-09 08:39:47 +00:00
|
|
|
double scaleFactor = 1.0 / GetDPIScale();
|
2013-03-19 17:24:25 +00:00
|
|
|
*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;
|
|
|
|
}
|
2013-04-09 08:39:47 +00:00
|
|
|
double scaleFactor = 1.0 / GetDPIScale();
|
2013-03-19 17:24:25 +00:00
|
|
|
*outLeft = NSToIntRound(left * scaleFactor);
|
|
|
|
*outTop = NSToIntRound(top * scaleFactor);
|
|
|
|
*outWidth = NSToIntRound(width * scaleFactor);
|
|
|
|
*outHeight = NSToIntRound(height * scaleFactor);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-01-11 21:27:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsScreenWin :: GetPixelDepth(int32_t *aPixelDepth)
|
2006-01-11 21:27:48 +00:00
|
|
|
{
|
2006-01-11 21:28:03 +00:00
|
|
|
//XXX not sure how to get this info for multiple monitors, this might be ok...
|
2012-07-30 14:20:58 +00:00
|
|
|
HDC hDCScreen = ::GetDC(nullptr);
|
2006-01-11 21:28:13 +00:00
|
|
|
NS_ASSERTION(hDCScreen,"GetDC Failure");
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t depth = ::GetDeviceCaps(hDCScreen, BITSPIXEL);
|
2008-12-23 14:06:56 +00:00
|
|
|
if (depth == 32) {
|
|
|
|
// If a device uses 32 bits per pixel, it's still only using 8 bits
|
|
|
|
// per color component, which is what our callers want to know.
|
|
|
|
// (Some devices report 32 and some devices report 24.)
|
|
|
|
depth = 24;
|
|
|
|
}
|
|
|
|
*aPixelDepth = depth;
|
2006-01-11 21:28:13 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
::ReleaseDC(nullptr, hDCScreen);
|
2006-01-11 21:27:48 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
} // GetPixelDepth
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsScreenWin :: GetColorDepth(int32_t *aColorDepth)
|
2006-01-11 21:27:48 +00:00
|
|
|
{
|
2006-01-11 21:27:51 +00:00
|
|
|
return GetPixelDepth(aColorDepth);
|
2006-01-11 21:27:48 +00:00
|
|
|
|
|
|
|
} // GetColorDepth
|
|
|
|
|
|
|
|
|