michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsScreenWin.h" michael@0: #include "nsCoord.h" michael@0: #include "gfxWindowsPlatform.h" michael@0: #include "nsIWidget.h" michael@0: michael@0: michael@0: nsScreenWin :: nsScreenWin ( HMONITOR inScreen ) michael@0: : mScreen(inScreen) michael@0: { michael@0: #ifdef DEBUG michael@0: HDC hDCScreen = ::GetDC(nullptr); michael@0: NS_ASSERTION(hDCScreen,"GetDC Failure"); michael@0: NS_ASSERTION ( ::GetDeviceCaps(hDCScreen, TECHNOLOGY) == DT_RASDISPLAY, "Not a display screen"); michael@0: ::ReleaseDC(nullptr,hDCScreen); michael@0: #endif michael@0: michael@0: // nothing else to do. I guess we could cache a bunch of information michael@0: // here, but we want to ask the device at runtime in case anything michael@0: // has changed. michael@0: } michael@0: michael@0: michael@0: nsScreenWin :: ~nsScreenWin() michael@0: { michael@0: // nothing to see here. michael@0: } michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenWin :: GetRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight) michael@0: { michael@0: BOOL success = FALSE; michael@0: if ( mScreen ) { michael@0: MONITORINFO info; michael@0: info.cbSize = sizeof(MONITORINFO); michael@0: success = ::GetMonitorInfoW( mScreen, &info ); michael@0: if ( success ) { michael@0: *outLeft = info.rcMonitor.left; michael@0: *outTop = info.rcMonitor.top; michael@0: *outWidth = info.rcMonitor.right - info.rcMonitor.left; michael@0: *outHeight = info.rcMonitor.bottom - info.rcMonitor.top; michael@0: } michael@0: } michael@0: if (!success) { michael@0: HDC hDCScreen = ::GetDC(nullptr); michael@0: NS_ASSERTION(hDCScreen,"GetDC Failure"); michael@0: michael@0: *outTop = *outLeft = 0; michael@0: *outWidth = ::GetDeviceCaps(hDCScreen, HORZRES); michael@0: *outHeight = ::GetDeviceCaps(hDCScreen, VERTRES); michael@0: michael@0: ::ReleaseDC(nullptr, hDCScreen); michael@0: } michael@0: return NS_OK; michael@0: michael@0: } // GetRect michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenWin :: GetAvailRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight) michael@0: { michael@0: BOOL success = FALSE; michael@0: michael@0: if ( mScreen ) { michael@0: MONITORINFO info; michael@0: info.cbSize = sizeof(MONITORINFO); michael@0: success = ::GetMonitorInfoW( mScreen, &info ); michael@0: if ( success ) { michael@0: *outLeft = info.rcWork.left; michael@0: *outTop = info.rcWork.top; michael@0: *outWidth = info.rcWork.right - info.rcWork.left; michael@0: *outHeight = info.rcWork.bottom - info.rcWork.top; michael@0: } michael@0: } michael@0: if (!success) { michael@0: RECT workArea; michael@0: ::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0); michael@0: *outLeft = workArea.left; michael@0: *outTop = workArea.top; michael@0: *outWidth = workArea.right - workArea.left; michael@0: *outHeight = workArea.bottom - workArea.top; michael@0: } michael@0: michael@0: return NS_OK; michael@0: michael@0: } // GetAvailRect michael@0: michael@0: static double michael@0: GetDPIScale() michael@0: { michael@0: double dpiScale= nsIWidget::DefaultScaleOverride(); michael@0: if (dpiScale <= 0.0) { michael@0: dpiScale = gfxWindowsPlatform::GetPlatform()->GetDPIScale(); michael@0: } michael@0: return dpiScale; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenWin::GetRectDisplayPix(int32_t *outLeft, int32_t *outTop, michael@0: int32_t *outWidth, int32_t *outHeight) michael@0: { michael@0: int32_t left, top, width, height; michael@0: nsresult rv = GetRect(&left, &top, &width, &height); michael@0: if (NS_FAILED(rv)) { michael@0: return rv; michael@0: } michael@0: double scaleFactor = 1.0 / GetDPIScale(); michael@0: *outLeft = NSToIntRound(left * scaleFactor); michael@0: *outTop = NSToIntRound(top * scaleFactor); michael@0: *outWidth = NSToIntRound(width * scaleFactor); michael@0: *outHeight = NSToIntRound(height * scaleFactor); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenWin::GetAvailRectDisplayPix(int32_t *outLeft, int32_t *outTop, michael@0: int32_t *outWidth, int32_t *outHeight) michael@0: { michael@0: int32_t left, top, width, height; michael@0: nsresult rv = GetAvailRect(&left, &top, &width, &height); michael@0: if (NS_FAILED(rv)) { michael@0: return rv; michael@0: } michael@0: double scaleFactor = 1.0 / GetDPIScale(); michael@0: *outLeft = NSToIntRound(left * scaleFactor); michael@0: *outTop = NSToIntRound(top * scaleFactor); michael@0: *outWidth = NSToIntRound(width * scaleFactor); michael@0: *outHeight = NSToIntRound(height * scaleFactor); michael@0: return NS_OK; michael@0: } michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenWin :: GetPixelDepth(int32_t *aPixelDepth) michael@0: { michael@0: //XXX not sure how to get this info for multiple monitors, this might be ok... michael@0: HDC hDCScreen = ::GetDC(nullptr); michael@0: NS_ASSERTION(hDCScreen,"GetDC Failure"); michael@0: michael@0: int32_t depth = ::GetDeviceCaps(hDCScreen, BITSPIXEL); michael@0: if (depth == 32) { michael@0: // If a device uses 32 bits per pixel, it's still only using 8 bits michael@0: // per color component, which is what our callers want to know. michael@0: // (Some devices report 32 and some devices report 24.) michael@0: depth = 24; michael@0: } michael@0: *aPixelDepth = depth; michael@0: michael@0: ::ReleaseDC(nullptr, hDCScreen); michael@0: return NS_OK; michael@0: michael@0: } // GetPixelDepth michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenWin :: GetColorDepth(int32_t *aColorDepth) michael@0: { michael@0: return GetPixelDepth(aColorDepth); michael@0: michael@0: } // GetColorDepth michael@0: michael@0: