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/Hal.h"
11 #include "mozilla/StaticPrefs_layout.h"
13 namespace mozilla::widget
{
15 NS_IMPL_ISUPPORTS(Screen
, nsIScreen
)
17 static hal::ScreenOrientation
EffectiveOrientation(
18 hal::ScreenOrientation aOrientation
, const LayoutDeviceIntRect
& aRect
) {
19 if (aOrientation
== hal::ScreenOrientation::None
) {
20 return aRect
.Width() >= aRect
.Height()
21 ? hal::ScreenOrientation::LandscapePrimary
22 : hal::ScreenOrientation::PortraitPrimary
;
27 Screen::Screen(LayoutDeviceIntRect aRect
, LayoutDeviceIntRect aAvailRect
,
28 uint32_t aPixelDepth
, uint32_t aColorDepth
,
29 DesktopToLayoutDeviceScale aContentsScale
,
30 CSSToLayoutDeviceScale aDefaultCssScale
, float aDPI
,
31 hal::ScreenOrientation aOrientation
,
32 OrientationAngle aOrientationAngle
)
34 mAvailRect(aAvailRect
),
35 mRectDisplayPix(RoundedToInt(aRect
/ aContentsScale
)),
36 mAvailRectDisplayPix(RoundedToInt(aAvailRect
/ aContentsScale
)),
37 mPixelDepth(aPixelDepth
),
38 mColorDepth(aColorDepth
),
39 mContentsScale(aContentsScale
),
40 mDefaultCssScale(aDefaultCssScale
),
42 mScreenOrientation(EffectiveOrientation(aOrientation
, aRect
)),
43 mOrientationAngle(aOrientationAngle
) {}
45 Screen::Screen(const dom::ScreenDetails
& aScreen
)
46 : mRect(aScreen
.rect()),
47 mAvailRect(aScreen
.availRect()),
48 mRectDisplayPix(aScreen
.rectDisplayPix()),
49 mAvailRectDisplayPix(aScreen
.availRectDisplayPix()),
50 mPixelDepth(aScreen
.pixelDepth()),
51 mColorDepth(aScreen
.colorDepth()),
52 mContentsScale(aScreen
.contentsScaleFactor()),
53 mDefaultCssScale(aScreen
.defaultCSSScaleFactor()),
55 mScreenOrientation(aScreen
.orientation()),
56 mOrientationAngle(aScreen
.orientationAngle()) {}
58 Screen::Screen(const Screen
& aOther
)
59 : mRect(aOther
.mRect
),
60 mAvailRect(aOther
.mAvailRect
),
61 mRectDisplayPix(aOther
.mRectDisplayPix
),
62 mAvailRectDisplayPix(aOther
.mAvailRectDisplayPix
),
63 mPixelDepth(aOther
.mPixelDepth
),
64 mColorDepth(aOther
.mColorDepth
),
65 mContentsScale(aOther
.mContentsScale
),
66 mDefaultCssScale(aOther
.mDefaultCssScale
),
68 mScreenOrientation(aOther
.mScreenOrientation
),
69 mOrientationAngle(aOther
.mOrientationAngle
) {}
71 dom::ScreenDetails
Screen::ToScreenDetails() const {
72 return dom::ScreenDetails(mRect
, mRectDisplayPix
, mAvailRect
,
73 mAvailRectDisplayPix
, mPixelDepth
, mColorDepth
,
74 mContentsScale
, mDefaultCssScale
, mDPI
,
75 mScreenOrientation
, mOrientationAngle
);
79 Screen::GetRect(int32_t* aOutLeft
, int32_t* aOutTop
, int32_t* aOutWidth
,
80 int32_t* aOutHeight
) {
81 mRect
.GetRect(aOutLeft
, aOutTop
, aOutWidth
, aOutHeight
);
86 Screen::GetRectDisplayPix(int32_t* aOutLeft
, int32_t* aOutTop
,
87 int32_t* aOutWidth
, int32_t* aOutHeight
) {
88 mRectDisplayPix
.GetRect(aOutLeft
, aOutTop
, aOutWidth
, aOutHeight
);
93 Screen::GetAvailRect(int32_t* aOutLeft
, int32_t* aOutTop
, int32_t* aOutWidth
,
94 int32_t* aOutHeight
) {
95 mAvailRect
.GetRect(aOutLeft
, aOutTop
, aOutWidth
, aOutHeight
);
100 Screen::GetAvailRectDisplayPix(int32_t* aOutLeft
, int32_t* aOutTop
,
101 int32_t* aOutWidth
, int32_t* aOutHeight
) {
102 mAvailRectDisplayPix
.GetRect(aOutLeft
, aOutTop
, aOutWidth
, aOutHeight
);
107 Screen::GetPixelDepth(int32_t* aPixelDepth
) {
108 *aPixelDepth
= mPixelDepth
;
113 Screen::GetColorDepth(int32_t* aColorDepth
) {
114 *aColorDepth
= mColorDepth
;
119 Screen::GetContentsScaleFactor(double* aOutScale
) {
120 *aOutScale
= mContentsScale
.scale
;
125 Screen::GetDefaultCSSScaleFactor(double* aOutScale
) {
126 double scale
= StaticPrefs::layout_css_devPixelsPerPx();
130 *aOutScale
= mDefaultCssScale
.scale
;
136 Screen::GetDpi(float* aDPI
) {
141 } // namespace mozilla::widget