2006-01-12 00:28:25 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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-12 00:27:48 +03:00
|
|
|
|
|
|
|
#include "nsScreenWin.h"
|
2013-03-19 21:24:25 +04:00
|
|
|
#include "nsCoord.h"
|
2013-04-01 13:10:28 +04:00
|
|
|
#include "gfxWindowsPlatform.h"
|
2013-04-09 12:39:47 +04:00
|
|
|
#include "nsIWidget.h"
|
2006-01-12 00:27:48 +03:00
|
|
|
|
2006-01-12 00:28:03 +03:00
|
|
|
|
2012-01-05 11:52:22 +04:00
|
|
|
nsScreenWin :: nsScreenWin ( HMONITOR inScreen )
|
2006-04-05 00:57:13 +04:00
|
|
|
: mScreen(inScreen)
|
2006-01-12 00:27:48 +03:00
|
|
|
{
|
2006-01-12 00:28:13 +03:00
|
|
|
#ifdef DEBUG
|
2012-07-30 18:20:58 +04:00
|
|
|
HDC hDCScreen = ::GetDC(nullptr);
|
2006-01-12 00:28:13 +03:00
|
|
|
NS_ASSERTION(hDCScreen,"GetDC Failure");
|
|
|
|
NS_ASSERTION ( ::GetDeviceCaps(hDCScreen, TECHNOLOGY) == DT_RASDISPLAY, "Not a display screen");
|
2012-07-30 18:20:58 +04:00
|
|
|
::ReleaseDC(nullptr,hDCScreen);
|
2006-01-12 00:28:13 +03:00
|
|
|
#endif
|
2006-01-12 00:28:03 +03:00
|
|
|
|
2006-01-12 00:27:48 +03: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-12 00:28:07 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenWin :: GetRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight)
|
2006-01-12 00:27:48 +03:00
|
|
|
{
|
2006-01-12 00:28:04 +03:00
|
|
|
BOOL success = FALSE;
|
2006-04-05 00:57:13 +04:00
|
|
|
if ( mScreen ) {
|
2006-01-12 00:28:03 +03:00
|
|
|
MONITORINFO info;
|
|
|
|
info.cbSize = sizeof(MONITORINFO);
|
2012-01-05 11:52:22 +04:00
|
|
|
success = ::GetMonitorInfoW( mScreen, &info );
|
2006-01-12 00:28:07 +03: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-12 00:28:03 +03:00
|
|
|
}
|
2006-01-12 00:28:07 +03:00
|
|
|
if (!success) {
|
2012-07-30 18:20:58 +04:00
|
|
|
HDC hDCScreen = ::GetDC(nullptr);
|
2006-01-12 00:28:13 +03:00
|
|
|
NS_ASSERTION(hDCScreen,"GetDC Failure");
|
|
|
|
|
|
|
|
*outTop = *outLeft = 0;
|
|
|
|
*outWidth = ::GetDeviceCaps(hDCScreen, HORZRES);
|
|
|
|
*outHeight = ::GetDeviceCaps(hDCScreen, VERTRES);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
::ReleaseDC(nullptr, hDCScreen);
|
2006-01-12 00:28:07 +03:00
|
|
|
}
|
2006-01-12 00:27:48 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
2006-01-12 00:28:07 +03:00
|
|
|
} // GetRect
|
2006-01-12 00:27:48 +03:00
|
|
|
|
|
|
|
|
2006-01-12 00:28:07 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenWin :: GetAvailRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight)
|
2006-01-12 00:27:48 +03:00
|
|
|
{
|
2006-01-12 00:28:04 +03:00
|
|
|
BOOL success = FALSE;
|
2009-04-14 09:27:39 +04:00
|
|
|
|
2006-04-05 00:57:13 +04:00
|
|
|
if ( mScreen ) {
|
2006-01-12 00:28:03 +03:00
|
|
|
MONITORINFO info;
|
|
|
|
info.cbSize = sizeof(MONITORINFO);
|
2012-01-05 11:52:22 +04:00
|
|
|
success = ::GetMonitorInfoW( mScreen, &info );
|
2006-01-12 00:28:07 +03: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-12 00:28:03 +03:00
|
|
|
}
|
2006-01-12 00:28:07 +03: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-12 00:27:48 +03:00
|
|
|
return NS_OK;
|
2006-01-12 00:28:07 +03:00
|
|
|
|
|
|
|
} // GetAvailRect
|
2006-01-12 00:27:48 +03:00
|
|
|
|
2013-04-09 12:39:47 +04:00
|
|
|
static double
|
|
|
|
GetDPIScale()
|
|
|
|
{
|
|
|
|
double dpiScale= nsIWidget::DefaultScaleOverride();
|
|
|
|
if (dpiScale <= 0.0) {
|
|
|
|
dpiScale = gfxWindowsPlatform::GetPlatform()->GetDPIScale();
|
|
|
|
}
|
|
|
|
return dpiScale;
|
|
|
|
}
|
|
|
|
|
2013-03-19 21:24:25 +04: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 12:39:47 +04:00
|
|
|
double scaleFactor = 1.0 / GetDPIScale();
|
2013-03-19 21:24:25 +04: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 12:39:47 +04:00
|
|
|
double scaleFactor = 1.0 / GetDPIScale();
|
2013-03-19 21:24:25 +04:00
|
|
|
*outLeft = NSToIntRound(left * scaleFactor);
|
|
|
|
*outTop = NSToIntRound(top * scaleFactor);
|
|
|
|
*outWidth = NSToIntRound(width * scaleFactor);
|
|
|
|
*outHeight = NSToIntRound(height * scaleFactor);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-01-12 00:27:48 +03:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenWin :: GetPixelDepth(int32_t *aPixelDepth)
|
2006-01-12 00:27:48 +03:00
|
|
|
{
|
2006-01-12 00:28:03 +03:00
|
|
|
//XXX not sure how to get this info for multiple monitors, this might be ok...
|
2012-07-30 18:20:58 +04:00
|
|
|
HDC hDCScreen = ::GetDC(nullptr);
|
2006-01-12 00:28:13 +03:00
|
|
|
NS_ASSERTION(hDCScreen,"GetDC Failure");
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t depth = ::GetDeviceCaps(hDCScreen, BITSPIXEL);
|
2008-12-23 17:06:56 +03: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-12 00:28:13 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
::ReleaseDC(nullptr, hDCScreen);
|
2006-01-12 00:27:48 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
} // GetPixelDepth
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenWin :: GetColorDepth(int32_t *aColorDepth)
|
2006-01-12 00:27:48 +03:00
|
|
|
{
|
2006-01-12 00:27:51 +03:00
|
|
|
return GetPixelDepth(aColorDepth);
|
2006-01-12 00:27:48 +03:00
|
|
|
|
|
|
|
} // GetColorDepth
|
|
|
|
|
|
|
|
|