1 /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 2; -*- */
2 /* vim: set sw=2 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/. */
9 #include "mozilla/dom/DOMTypes.h"
10 #include "mozilla/StaticPrefs_layout.h"
15 NS_IMPL_ISUPPORTS(Screen
, nsIScreen
)
17 Screen::Screen(LayoutDeviceIntRect aRect
, LayoutDeviceIntRect aAvailRect
,
18 uint32_t aPixelDepth
, uint32_t aColorDepth
,
19 DesktopToLayoutDeviceScale aContentsScale
,
20 CSSToLayoutDeviceScale aDefaultCssScale
, float aDPI
)
22 mAvailRect(aAvailRect
),
23 mRectDisplayPix(RoundedToInt(aRect
/ aContentsScale
)),
24 mAvailRectDisplayPix(RoundedToInt(aAvailRect
/ aContentsScale
)),
25 mPixelDepth(aPixelDepth
),
26 mColorDepth(aColorDepth
),
27 mContentsScale(aContentsScale
),
28 mDefaultCssScale(aDefaultCssScale
),
31 Screen::Screen(const mozilla::dom::ScreenDetails
& aScreen
)
32 : mRect(aScreen
.rect()),
33 mAvailRect(aScreen
.availRect()),
34 mRectDisplayPix(aScreen
.rectDisplayPix()),
35 mAvailRectDisplayPix(aScreen
.availRectDisplayPix()),
36 mPixelDepth(aScreen
.pixelDepth()),
37 mColorDepth(aScreen
.colorDepth()),
38 mContentsScale(aScreen
.contentsScaleFactor()),
39 mDefaultCssScale(aScreen
.defaultCSSScaleFactor()),
40 mDPI(aScreen
.dpi()) {}
42 Screen::Screen(const Screen
& aOther
)
43 : mRect(aOther
.mRect
),
44 mAvailRect(aOther
.mAvailRect
),
45 mRectDisplayPix(aOther
.mRectDisplayPix
),
46 mAvailRectDisplayPix(aOther
.mAvailRectDisplayPix
),
47 mPixelDepth(aOther
.mPixelDepth
),
48 mColorDepth(aOther
.mColorDepth
),
49 mContentsScale(aOther
.mContentsScale
),
50 mDefaultCssScale(aOther
.mDefaultCssScale
),
53 mozilla::dom::ScreenDetails
Screen::ToScreenDetails() {
54 return mozilla::dom::ScreenDetails(
55 mRect
, mRectDisplayPix
, mAvailRect
, mAvailRectDisplayPix
, mPixelDepth
,
56 mColorDepth
, mContentsScale
, mDefaultCssScale
, mDPI
);
60 Screen::GetRect(int32_t* aOutLeft
, int32_t* aOutTop
, int32_t* aOutWidth
,
61 int32_t* aOutHeight
) {
62 mRect
.GetRect(aOutLeft
, aOutTop
, aOutWidth
, aOutHeight
);
67 Screen::GetRectDisplayPix(int32_t* aOutLeft
, int32_t* aOutTop
,
68 int32_t* aOutWidth
, int32_t* aOutHeight
) {
69 mRectDisplayPix
.GetRect(aOutLeft
, aOutTop
, aOutWidth
, aOutHeight
);
74 Screen::GetAvailRect(int32_t* aOutLeft
, int32_t* aOutTop
, int32_t* aOutWidth
,
75 int32_t* aOutHeight
) {
76 mAvailRect
.GetRect(aOutLeft
, aOutTop
, aOutWidth
, aOutHeight
);
81 Screen::GetAvailRectDisplayPix(int32_t* aOutLeft
, int32_t* aOutTop
,
82 int32_t* aOutWidth
, int32_t* aOutHeight
) {
83 mAvailRectDisplayPix
.GetRect(aOutLeft
, aOutTop
, aOutWidth
, aOutHeight
);
88 Screen::GetPixelDepth(int32_t* aPixelDepth
) {
89 *aPixelDepth
= mPixelDepth
;
94 Screen::GetColorDepth(int32_t* aColorDepth
) {
95 *aColorDepth
= mColorDepth
;
100 Screen::GetContentsScaleFactor(double* aOutScale
) {
101 *aOutScale
= mContentsScale
.scale
;
106 Screen::GetDefaultCSSScaleFactor(double* aOutScale
) {
107 double scale
= StaticPrefs::layout_css_devPixelsPerPx();
111 *aOutScale
= mDefaultCssScale
.scale
;
117 Screen::GetDpi(float* aDPI
) {
122 } // namespace widget
123 } // namespace mozilla