1 /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 2; -*- */
2 /* vim: set sw=4 ts=8 et tw=80 : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "Screen.h"
8 
9 #include "mozilla/dom/DOMTypes.h"
10 
11 namespace mozilla {
12 namespace widget {
13 
NS_IMPL_ISUPPORTS(Screen,nsIScreen)14 NS_IMPL_ISUPPORTS(Screen, nsIScreen)
15 
16 Screen::Screen(LayoutDeviceIntRect aRect, LayoutDeviceIntRect aAvailRect,
17                uint32_t aPixelDepth, uint32_t aColorDepth,
18                DesktopToLayoutDeviceScale aContentsScale,
19                CSSToLayoutDeviceScale aDefaultCssScale, float aDPI)
20     : mRect(aRect),
21       mAvailRect(aAvailRect),
22       mRectDisplayPix(RoundedToInt(aRect / aContentsScale)),
23       mAvailRectDisplayPix(RoundedToInt(aAvailRect / aContentsScale)),
24       mPixelDepth(aPixelDepth),
25       mColorDepth(aColorDepth),
26       mContentsScale(aContentsScale),
27       mDefaultCssScale(aDefaultCssScale),
28       mDPI(aDPI) {}
29 
Screen(const mozilla::dom::ScreenDetails & aScreen)30 Screen::Screen(const mozilla::dom::ScreenDetails& aScreen)
31     : mRect(aScreen.rect()),
32       mAvailRect(aScreen.availRect()),
33       mRectDisplayPix(aScreen.rectDisplayPix()),
34       mAvailRectDisplayPix(aScreen.availRectDisplayPix()),
35       mPixelDepth(aScreen.pixelDepth()),
36       mColorDepth(aScreen.colorDepth()),
37       mContentsScale(aScreen.contentsScaleFactor()),
38       mDefaultCssScale(aScreen.defaultCSSScaleFactor()),
39       mDPI(aScreen.dpi()) {}
40 
Screen(const Screen & aOther)41 Screen::Screen(const Screen& aOther)
42     : mRect(aOther.mRect),
43       mAvailRect(aOther.mAvailRect),
44       mRectDisplayPix(aOther.mRectDisplayPix),
45       mAvailRectDisplayPix(aOther.mAvailRectDisplayPix),
46       mPixelDepth(aOther.mPixelDepth),
47       mColorDepth(aOther.mColorDepth),
48       mContentsScale(aOther.mContentsScale),
49       mDefaultCssScale(aOther.mDefaultCssScale),
50       mDPI(aOther.mDPI) {}
51 
ToScreenDetails()52 mozilla::dom::ScreenDetails Screen::ToScreenDetails() {
53   return mozilla::dom::ScreenDetails(
54       mRect, mRectDisplayPix, mAvailRect, mAvailRectDisplayPix, mPixelDepth,
55       mColorDepth, mContentsScale, mDefaultCssScale, mDPI);
56 }
57 
58 NS_IMETHODIMP
GetRect(int32_t * aOutLeft,int32_t * aOutTop,int32_t * aOutWidth,int32_t * aOutHeight)59 Screen::GetRect(int32_t* aOutLeft, int32_t* aOutTop, int32_t* aOutWidth,
60                 int32_t* aOutHeight) {
61   mRect.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
62   return NS_OK;
63 }
64 
65 NS_IMETHODIMP
GetRectDisplayPix(int32_t * aOutLeft,int32_t * aOutTop,int32_t * aOutWidth,int32_t * aOutHeight)66 Screen::GetRectDisplayPix(int32_t* aOutLeft, int32_t* aOutTop,
67                           int32_t* aOutWidth, int32_t* aOutHeight) {
68   mRectDisplayPix.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
69   return NS_OK;
70 }
71 
72 NS_IMETHODIMP
GetAvailRect(int32_t * aOutLeft,int32_t * aOutTop,int32_t * aOutWidth,int32_t * aOutHeight)73 Screen::GetAvailRect(int32_t* aOutLeft, int32_t* aOutTop, int32_t* aOutWidth,
74                      int32_t* aOutHeight) {
75   mAvailRect.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
76   return NS_OK;
77 }
78 
79 NS_IMETHODIMP
GetAvailRectDisplayPix(int32_t * aOutLeft,int32_t * aOutTop,int32_t * aOutWidth,int32_t * aOutHeight)80 Screen::GetAvailRectDisplayPix(int32_t* aOutLeft, int32_t* aOutTop,
81                                int32_t* aOutWidth, int32_t* aOutHeight) {
82   mAvailRectDisplayPix.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
83   return NS_OK;
84 }
85 
86 NS_IMETHODIMP
GetPixelDepth(int32_t * aPixelDepth)87 Screen::GetPixelDepth(int32_t* aPixelDepth) {
88   *aPixelDepth = mPixelDepth;
89   return NS_OK;
90 }
91 
92 NS_IMETHODIMP
GetColorDepth(int32_t * aColorDepth)93 Screen::GetColorDepth(int32_t* aColorDepth) {
94   *aColorDepth = mColorDepth;
95   return NS_OK;
96 }
97 
98 NS_IMETHODIMP
GetContentsScaleFactor(double * aOutScale)99 Screen::GetContentsScaleFactor(double* aOutScale) {
100   *aOutScale = mContentsScale.scale;
101   return NS_OK;
102 }
103 
104 NS_IMETHODIMP
GetDefaultCSSScaleFactor(double * aOutScale)105 Screen::GetDefaultCSSScaleFactor(double* aOutScale) {
106   double scale = nsIWidget::DefaultScaleOverride();
107   if (scale > 0.0) {
108     *aOutScale = scale;
109   } else {
110     *aOutScale = mDefaultCssScale.scale;
111   }
112   return NS_OK;
113 }
114 
115 NS_IMETHODIMP
GetDpi(float * aDPI)116 Screen::GetDpi(float* aDPI) {
117   *aDPI = mDPI;
118   return NS_OK;
119 }
120 
121 }  // namespace widget
122 }  // namespace mozilla
123