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/LookAndFeel.h"
12 #include "mozilla/StaticPrefs_layout.h"
14 namespace mozilla::widget
{
16 NS_IMPL_ISUPPORTS(Screen
, nsIScreen
)
18 static hal::ScreenOrientation
EffectiveOrientation(
19 hal::ScreenOrientation aOrientation
, const LayoutDeviceIntRect
& aRect
) {
20 if (aOrientation
== hal::ScreenOrientation::None
) {
21 return aRect
.Width() >= aRect
.Height()
22 ? hal::ScreenOrientation::LandscapePrimary
23 : hal::ScreenOrientation::PortraitPrimary
;
28 Screen::Screen(LayoutDeviceIntRect aRect
, LayoutDeviceIntRect aAvailRect
,
29 uint32_t aPixelDepth
, uint32_t aColorDepth
,
30 uint32_t aRefreshRate
, DesktopToLayoutDeviceScale aContentsScale
,
31 CSSToLayoutDeviceScale aDefaultCssScale
, float aDPI
,
32 IsPseudoDisplay aIsPseudoDisplay
,
33 hal::ScreenOrientation aOrientation
,
34 OrientationAngle aOrientationAngle
)
36 mAvailRect(aAvailRect
),
37 mRectDisplayPix(RoundedToInt(aRect
/ aContentsScale
)),
38 mAvailRectDisplayPix(RoundedToInt(aAvailRect
/ aContentsScale
)),
39 mPixelDepth(aPixelDepth
),
40 mColorDepth(aColorDepth
),
41 mRefreshRate(aRefreshRate
),
42 mContentsScale(aContentsScale
),
43 mDefaultCssScale(aDefaultCssScale
),
45 mScreenOrientation(EffectiveOrientation(aOrientation
, aRect
)),
46 mOrientationAngle(aOrientationAngle
),
47 mIsPseudoDisplay(aIsPseudoDisplay
== IsPseudoDisplay::Yes
) {}
49 Screen::Screen(const dom::ScreenDetails
& aScreen
)
50 : mRect(aScreen
.rect()),
51 mAvailRect(aScreen
.availRect()),
52 mRectDisplayPix(aScreen
.rectDisplayPix()),
53 mAvailRectDisplayPix(aScreen
.availRectDisplayPix()),
54 mPixelDepth(aScreen
.pixelDepth()),
55 mColorDepth(aScreen
.colorDepth()),
56 mRefreshRate(aScreen
.refreshRate()),
57 mContentsScale(aScreen
.contentsScaleFactor()),
58 mDefaultCssScale(aScreen
.defaultCSSScaleFactor()),
60 mScreenOrientation(aScreen
.orientation()),
61 mOrientationAngle(aScreen
.orientationAngle()),
62 mIsPseudoDisplay(aScreen
.isPseudoDisplay()) {}
64 Screen::Screen(const Screen
& aOther
)
65 : mRect(aOther
.mRect
),
66 mAvailRect(aOther
.mAvailRect
),
67 mRectDisplayPix(aOther
.mRectDisplayPix
),
68 mAvailRectDisplayPix(aOther
.mAvailRectDisplayPix
),
69 mPixelDepth(aOther
.mPixelDepth
),
70 mColorDepth(aOther
.mColorDepth
),
71 mRefreshRate(aOther
.mRefreshRate
),
72 mContentsScale(aOther
.mContentsScale
),
73 mDefaultCssScale(aOther
.mDefaultCssScale
),
75 mScreenOrientation(aOther
.mScreenOrientation
),
76 mOrientationAngle(aOther
.mOrientationAngle
),
77 mIsPseudoDisplay(aOther
.mIsPseudoDisplay
) {}
79 dom::ScreenDetails
Screen::ToScreenDetails() const {
80 return dom::ScreenDetails(
81 mRect
, mRectDisplayPix
, mAvailRect
, mAvailRectDisplayPix
, mPixelDepth
,
82 mColorDepth
, mRefreshRate
, mContentsScale
, mDefaultCssScale
, mDPI
,
83 mScreenOrientation
, mOrientationAngle
, mIsPseudoDisplay
);
87 Screen::GetRect(int32_t* aOutLeft
, int32_t* aOutTop
, int32_t* aOutWidth
,
88 int32_t* aOutHeight
) {
89 mRect
.GetRect(aOutLeft
, aOutTop
, aOutWidth
, aOutHeight
);
94 Screen::GetRectDisplayPix(int32_t* aOutLeft
, int32_t* aOutTop
,
95 int32_t* aOutWidth
, int32_t* aOutHeight
) {
96 mRectDisplayPix
.GetRect(aOutLeft
, aOutTop
, aOutWidth
, aOutHeight
);
101 Screen::GetAvailRect(int32_t* aOutLeft
, int32_t* aOutTop
, int32_t* aOutWidth
,
102 int32_t* aOutHeight
) {
103 mAvailRect
.GetRect(aOutLeft
, aOutTop
, aOutWidth
, aOutHeight
);
108 Screen::GetAvailRectDisplayPix(int32_t* aOutLeft
, int32_t* aOutTop
,
109 int32_t* aOutWidth
, int32_t* aOutHeight
) {
110 mAvailRectDisplayPix
.GetRect(aOutLeft
, aOutTop
, aOutWidth
, aOutHeight
);
115 Screen::GetPixelDepth(int32_t* aPixelDepth
) {
116 *aPixelDepth
= mPixelDepth
;
121 Screen::GetColorDepth(int32_t* aColorDepth
) {
122 *aColorDepth
= mColorDepth
;
127 Screen::GetContentsScaleFactor(double* aOutScale
) {
128 *aOutScale
= mContentsScale
.scale
;
133 Screen::GetDefaultCSSScaleFactor(double* aOutScale
) {
134 double scale
= StaticPrefs::layout_css_devPixelsPerPx();
138 *aOutScale
= mDefaultCssScale
.scale
;
140 *aOutScale
*= LookAndFeel::SystemZoomSettings().mFullZoom
;
145 Screen::GetDpi(float* aDPI
) {
151 Screen::GetRefreshRate(int32_t* aRefreshRate
) {
152 *aRefreshRate
= mRefreshRate
;
157 Screen::GetIsPseudoDisplay(bool* aIsPseudoDisplay
) {
158 *aIsPseudoDisplay
= mIsPseudoDisplay
;
162 } // namespace mozilla::widget