Line data Source code
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 :
14 289 : NS_IMPL_ISUPPORTS(Screen, nsIScreen)
15 :
16 1 : Screen::Screen(LayoutDeviceIntRect aRect, LayoutDeviceIntRect aAvailRect,
17 : uint32_t aPixelDepth, uint32_t aColorDepth,
18 : DesktopToLayoutDeviceScale aContentsScale,
19 1 : CSSToLayoutDeviceScale aDefaultCssScale)
20 : : mRect(aRect)
21 : , mAvailRect(aAvailRect)
22 2 : , mRectDisplayPix(RoundedToInt(aRect / aContentsScale))
23 2 : , mAvailRectDisplayPix(RoundedToInt(aAvailRect / aContentsScale))
24 : , mPixelDepth(aPixelDepth)
25 : , mColorDepth(aColorDepth)
26 : , mContentsScale(aContentsScale)
27 4 : , mDefaultCssScale(aDefaultCssScale)
28 : {
29 1 : }
30 :
31 2 : Screen::Screen(const mozilla::dom::ScreenDetails& aScreen)
32 2 : : mRect(aScreen.rect())
33 2 : , mAvailRect(aScreen.availRect())
34 2 : , mRectDisplayPix(aScreen.rectDisplayPix())
35 2 : , mAvailRectDisplayPix(aScreen.availRectDisplayPix())
36 2 : , mPixelDepth(aScreen.pixelDepth())
37 2 : , mColorDepth(aScreen.colorDepth())
38 2 : , mContentsScale(aScreen.contentsScaleFactor())
39 16 : , mDefaultCssScale(aScreen.defaultCSSScaleFactor())
40 : {
41 2 : }
42 :
43 0 : Screen::Screen(const Screen& aOther)
44 : : mRect(aOther.mRect)
45 : , mAvailRect(aOther.mAvailRect)
46 : , mRectDisplayPix(aOther.mRectDisplayPix)
47 : , mAvailRectDisplayPix(aOther.mAvailRectDisplayPix)
48 0 : , mPixelDepth(aOther.mPixelDepth)
49 0 : , mColorDepth(aOther.mColorDepth)
50 : , mContentsScale(aOther.mContentsScale)
51 0 : , mDefaultCssScale(aOther.mDefaultCssScale)
52 : {
53 0 : }
54 :
55 : mozilla::dom::ScreenDetails
56 3 : Screen::ToScreenDetails()
57 : {
58 : return mozilla::dom::ScreenDetails(
59 : mRect, mRectDisplayPix, mAvailRect, mAvailRectDisplayPix,
60 3 : mPixelDepth, mColorDepth, mContentsScale, mDefaultCssScale);
61 : }
62 :
63 : NS_IMETHODIMP
64 14 : Screen::GetRect(int32_t* aOutLeft,
65 : int32_t* aOutTop,
66 : int32_t* aOutWidth,
67 : int32_t* aOutHeight)
68 : {
69 14 : *aOutLeft = mRect.x;
70 14 : *aOutTop = mRect.y;
71 14 : *aOutWidth = mRect.width;
72 14 : *aOutHeight = mRect.height;
73 14 : return NS_OK;
74 : }
75 :
76 : NS_IMETHODIMP
77 0 : Screen::GetRectDisplayPix(int32_t* aOutLeft,
78 : int32_t* aOutTop,
79 : int32_t* aOutWidth,
80 : int32_t* aOutHeight)
81 : {
82 0 : *aOutLeft = mRectDisplayPix.x;
83 0 : *aOutTop = mRectDisplayPix.y;
84 0 : *aOutWidth = mRectDisplayPix.width;
85 0 : *aOutHeight = mRectDisplayPix.height;
86 0 : return NS_OK;
87 : }
88 :
89 : NS_IMETHODIMP
90 4 : Screen::GetAvailRect(int32_t* aOutLeft,
91 : int32_t* aOutTop,
92 : int32_t* aOutWidth,
93 : int32_t* aOutHeight)
94 : {
95 4 : *aOutLeft = mAvailRect.x;
96 4 : *aOutTop = mAvailRect.y;
97 4 : *aOutWidth = mAvailRect.width;
98 4 : *aOutHeight = mAvailRect.height;
99 4 : return NS_OK;
100 : }
101 :
102 : NS_IMETHODIMP
103 0 : Screen::GetAvailRectDisplayPix(int32_t* aOutLeft,
104 : int32_t* aOutTop,
105 : int32_t* aOutWidth,
106 : int32_t* aOutHeight)
107 : {
108 0 : *aOutLeft = mAvailRectDisplayPix.x;
109 0 : *aOutTop = mAvailRectDisplayPix.y;
110 0 : *aOutWidth = mAvailRectDisplayPix.width;
111 0 : *aOutHeight = mAvailRectDisplayPix.height;
112 0 : return NS_OK;
113 : }
114 :
115 : NS_IMETHODIMP
116 1 : Screen::GetPixelDepth(int32_t* aPixelDepth)
117 : {
118 1 : *aPixelDepth = mPixelDepth;
119 1 : return NS_OK;
120 : }
121 :
122 : NS_IMETHODIMP
123 4 : Screen::GetColorDepth(int32_t* aColorDepth)
124 : {
125 4 : *aColorDepth = mColorDepth;
126 4 : return NS_OK;
127 : }
128 :
129 : NS_IMETHODIMP
130 10 : Screen::GetContentsScaleFactor(double *aOutScale)
131 : {
132 10 : *aOutScale = mContentsScale.scale;
133 10 : return NS_OK;
134 : }
135 :
136 : NS_IMETHODIMP
137 0 : Screen::GetDefaultCSSScaleFactor(double *aOutScale)
138 : {
139 0 : double scale = nsIWidget::DefaultScaleOverride();
140 0 : if (scale > 0.0) {
141 0 : *aOutScale = scale;
142 : } else {
143 0 : *aOutScale = mDefaultCssScale.scale;
144 : }
145 0 : return NS_OK;
146 : }
147 :
148 : } // namespace widget
149 : } // namespace mozilla
|