widget/windows/nsScreenWin.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/windows/nsScreenWin.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,167 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsScreenWin.h"
    1.10 +#include "nsCoord.h"
    1.11 +#include "gfxWindowsPlatform.h"
    1.12 +#include "nsIWidget.h"
    1.13 +
    1.14 +
    1.15 +nsScreenWin :: nsScreenWin ( HMONITOR inScreen )
    1.16 +  : mScreen(inScreen)
    1.17 +{
    1.18 +#ifdef DEBUG
    1.19 +  HDC hDCScreen = ::GetDC(nullptr);
    1.20 +  NS_ASSERTION(hDCScreen,"GetDC Failure");
    1.21 +  NS_ASSERTION ( ::GetDeviceCaps(hDCScreen, TECHNOLOGY) == DT_RASDISPLAY, "Not a display screen");
    1.22 +  ::ReleaseDC(nullptr,hDCScreen);
    1.23 +#endif
    1.24 +
    1.25 +  // nothing else to do. I guess we could cache a bunch of information
    1.26 +  // here, but we want to ask the device at runtime in case anything
    1.27 +  // has changed.
    1.28 +}
    1.29 +
    1.30 +
    1.31 +nsScreenWin :: ~nsScreenWin()
    1.32 +{
    1.33 +  // nothing to see here.
    1.34 +}
    1.35 +
    1.36 +
    1.37 +NS_IMETHODIMP
    1.38 +nsScreenWin :: GetRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight)
    1.39 +{
    1.40 +  BOOL success = FALSE;
    1.41 +  if ( mScreen ) {
    1.42 +    MONITORINFO info;
    1.43 +    info.cbSize = sizeof(MONITORINFO);
    1.44 +    success = ::GetMonitorInfoW( mScreen, &info );
    1.45 +    if ( success ) {
    1.46 +      *outLeft = info.rcMonitor.left;
    1.47 +      *outTop = info.rcMonitor.top;
    1.48 +      *outWidth = info.rcMonitor.right - info.rcMonitor.left;
    1.49 +      *outHeight = info.rcMonitor.bottom - info.rcMonitor.top;
    1.50 +    }
    1.51 +  }
    1.52 +  if (!success) {
    1.53 +     HDC hDCScreen = ::GetDC(nullptr);
    1.54 +     NS_ASSERTION(hDCScreen,"GetDC Failure");
    1.55 +    
    1.56 +     *outTop = *outLeft = 0;
    1.57 +     *outWidth = ::GetDeviceCaps(hDCScreen, HORZRES);
    1.58 +     *outHeight = ::GetDeviceCaps(hDCScreen, VERTRES); 
    1.59 +     
    1.60 +     ::ReleaseDC(nullptr, hDCScreen);
    1.61 +  }
    1.62 +  return NS_OK;
    1.63 +
    1.64 +} // GetRect
    1.65 +
    1.66 +
    1.67 +NS_IMETHODIMP
    1.68 +nsScreenWin :: GetAvailRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight)
    1.69 +{
    1.70 +  BOOL success = FALSE;
    1.71 +
    1.72 +  if ( mScreen ) {
    1.73 +    MONITORINFO info;
    1.74 +    info.cbSize = sizeof(MONITORINFO);
    1.75 +    success = ::GetMonitorInfoW( mScreen, &info );
    1.76 +    if ( success ) {
    1.77 +      *outLeft = info.rcWork.left;
    1.78 +      *outTop = info.rcWork.top;
    1.79 +      *outWidth = info.rcWork.right - info.rcWork.left;
    1.80 +      *outHeight = info.rcWork.bottom - info.rcWork.top;
    1.81 +    }
    1.82 +  }
    1.83 +  if (!success) {
    1.84 +    RECT workArea;
    1.85 +    ::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
    1.86 +    *outLeft = workArea.left;
    1.87 +    *outTop = workArea.top;
    1.88 +    *outWidth = workArea.right - workArea.left;
    1.89 +    *outHeight = workArea.bottom - workArea.top;
    1.90 +  }
    1.91 +
    1.92 +  return NS_OK;
    1.93 +  
    1.94 +} // GetAvailRect
    1.95 +
    1.96 +static double
    1.97 +GetDPIScale()
    1.98 +{
    1.99 +  double dpiScale= nsIWidget::DefaultScaleOverride();
   1.100 +  if (dpiScale <= 0.0) {
   1.101 +    dpiScale = gfxWindowsPlatform::GetPlatform()->GetDPIScale(); 
   1.102 +  }
   1.103 +  return dpiScale;
   1.104 +}
   1.105 +
   1.106 +NS_IMETHODIMP
   1.107 +nsScreenWin::GetRectDisplayPix(int32_t *outLeft,  int32_t *outTop,
   1.108 +                               int32_t *outWidth, int32_t *outHeight)
   1.109 +{
   1.110 +  int32_t left, top, width, height;
   1.111 +  nsresult rv = GetRect(&left, &top, &width, &height);
   1.112 +  if (NS_FAILED(rv)) {
   1.113 +    return rv;
   1.114 +  }
   1.115 +  double scaleFactor = 1.0 / GetDPIScale();
   1.116 +  *outLeft = NSToIntRound(left * scaleFactor);
   1.117 +  *outTop = NSToIntRound(top * scaleFactor);
   1.118 +  *outWidth = NSToIntRound(width * scaleFactor);
   1.119 +  *outHeight = NSToIntRound(height * scaleFactor);
   1.120 +  return NS_OK;
   1.121 +}
   1.122 +
   1.123 +NS_IMETHODIMP
   1.124 +nsScreenWin::GetAvailRectDisplayPix(int32_t *outLeft,  int32_t *outTop,
   1.125 +                                    int32_t *outWidth, int32_t *outHeight)
   1.126 +{
   1.127 +  int32_t left, top, width, height;
   1.128 +  nsresult rv = GetAvailRect(&left, &top, &width, &height);
   1.129 +  if (NS_FAILED(rv)) {
   1.130 +    return rv;
   1.131 +  }
   1.132 +  double scaleFactor = 1.0 / GetDPIScale();
   1.133 +  *outLeft = NSToIntRound(left * scaleFactor);
   1.134 +  *outTop = NSToIntRound(top * scaleFactor);
   1.135 +  *outWidth = NSToIntRound(width * scaleFactor);
   1.136 +  *outHeight = NSToIntRound(height * scaleFactor);
   1.137 +  return NS_OK;
   1.138 +}
   1.139 +
   1.140 +
   1.141 +NS_IMETHODIMP 
   1.142 +nsScreenWin :: GetPixelDepth(int32_t *aPixelDepth)
   1.143 +{
   1.144 +  //XXX not sure how to get this info for multiple monitors, this might be ok...
   1.145 +  HDC hDCScreen = ::GetDC(nullptr);
   1.146 +  NS_ASSERTION(hDCScreen,"GetDC Failure");
   1.147 +
   1.148 +  int32_t depth = ::GetDeviceCaps(hDCScreen, BITSPIXEL);
   1.149 +  if (depth == 32) {
   1.150 +    // If a device uses 32 bits per pixel, it's still only using 8 bits
   1.151 +    // per color component, which is what our callers want to know.
   1.152 +    // (Some devices report 32 and some devices report 24.)
   1.153 +    depth = 24;
   1.154 +  }
   1.155 +  *aPixelDepth = depth;
   1.156 +
   1.157 +  ::ReleaseDC(nullptr, hDCScreen);
   1.158 +  return NS_OK;
   1.159 +
   1.160 +} // GetPixelDepth
   1.161 +
   1.162 +
   1.163 +NS_IMETHODIMP 
   1.164 +nsScreenWin :: GetColorDepth(int32_t *aColorDepth)
   1.165 +{
   1.166 +  return GetPixelDepth(aColorDepth);
   1.167 +
   1.168 +} // GetColorDepth
   1.169 +
   1.170 +

mercurial