2017-03-14 13:44:54 +03:00
|
|
|
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 2; -*- */
|
2018-11-30 18:39:55 +03:00
|
|
|
/* vim: set sw=2 ts=8 et tw=80 : */
|
2017-03-14 13:44:54 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "Screen.h"
|
|
|
|
|
2017-03-09 14:30:26 +03:00
|
|
|
#include "mozilla/dom/DOMTypes.h"
|
2021-12-30 08:09:40 +03:00
|
|
|
#include "mozilla/Hal.h"
|
2019-08-27 00:02:43 +03:00
|
|
|
#include "mozilla/StaticPrefs_layout.h"
|
2017-03-09 14:30:26 +03:00
|
|
|
|
2022-02-15 23:22:54 +03:00
|
|
|
namespace mozilla::widget {
|
2017-03-14 13:44:54 +03:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(Screen, nsIScreen)
|
|
|
|
|
2022-02-15 23:22:54 +03:00
|
|
|
static hal::ScreenOrientation EffectiveOrientation(
|
|
|
|
hal::ScreenOrientation aOrientation, const LayoutDeviceIntRect& aRect) {
|
|
|
|
if (aOrientation == hal::ScreenOrientation::None) {
|
|
|
|
return aRect.Width() >= aRect.Height()
|
|
|
|
? hal::ScreenOrientation::LandscapePrimary
|
|
|
|
: hal::ScreenOrientation::PortraitPrimary;
|
|
|
|
}
|
|
|
|
return aOrientation;
|
|
|
|
}
|
|
|
|
|
2017-03-14 13:44:54 +03:00
|
|
|
Screen::Screen(LayoutDeviceIntRect aRect, LayoutDeviceIntRect aAvailRect,
|
|
|
|
uint32_t aPixelDepth, uint32_t aColorDepth,
|
|
|
|
DesktopToLayoutDeviceScale aContentsScale,
|
2022-02-15 23:22:54 +03:00
|
|
|
CSSToLayoutDeviceScale aDefaultCssScale, float aDPI,
|
|
|
|
hal::ScreenOrientation aOrientation,
|
|
|
|
OrientationAngle aOrientationAngle)
|
2017-03-14 13:44:54 +03:00
|
|
|
: mRect(aRect),
|
|
|
|
mAvailRect(aAvailRect),
|
|
|
|
mRectDisplayPix(RoundedToInt(aRect / aContentsScale)),
|
|
|
|
mAvailRectDisplayPix(RoundedToInt(aAvailRect / aContentsScale)),
|
|
|
|
mPixelDepth(aPixelDepth),
|
|
|
|
mColorDepth(aColorDepth),
|
|
|
|
mContentsScale(aContentsScale),
|
|
|
|
mDefaultCssScale(aDefaultCssScale),
|
2022-02-15 23:22:54 +03:00
|
|
|
mDPI(aDPI),
|
|
|
|
mScreenOrientation(EffectiveOrientation(aOrientation, aRect)),
|
|
|
|
mOrientationAngle(aOrientationAngle) {}
|
2017-03-09 14:30:26 +03:00
|
|
|
|
2022-02-15 23:22:54 +03:00
|
|
|
Screen::Screen(const dom::ScreenDetails& aScreen)
|
2017-03-09 14:30:26 +03:00
|
|
|
: mRect(aScreen.rect()),
|
|
|
|
mAvailRect(aScreen.availRect()),
|
|
|
|
mRectDisplayPix(aScreen.rectDisplayPix()),
|
|
|
|
mAvailRectDisplayPix(aScreen.availRectDisplayPix()),
|
|
|
|
mPixelDepth(aScreen.pixelDepth()),
|
|
|
|
mColorDepth(aScreen.colorDepth()),
|
|
|
|
mContentsScale(aScreen.contentsScaleFactor()),
|
|
|
|
mDefaultCssScale(aScreen.defaultCSSScaleFactor()),
|
2022-02-15 23:22:54 +03:00
|
|
|
mDPI(aScreen.dpi()),
|
|
|
|
mScreenOrientation(aScreen.orientation()),
|
|
|
|
mOrientationAngle(aScreen.orientationAngle()) {}
|
2017-03-14 13:44:54 +03:00
|
|
|
|
|
|
|
Screen::Screen(const Screen& aOther)
|
|
|
|
: mRect(aOther.mRect),
|
|
|
|
mAvailRect(aOther.mAvailRect),
|
|
|
|
mRectDisplayPix(aOther.mRectDisplayPix),
|
|
|
|
mAvailRectDisplayPix(aOther.mAvailRectDisplayPix),
|
|
|
|
mPixelDepth(aOther.mPixelDepth),
|
|
|
|
mColorDepth(aOther.mColorDepth),
|
|
|
|
mContentsScale(aOther.mContentsScale),
|
|
|
|
mDefaultCssScale(aOther.mDefaultCssScale),
|
2022-02-15 23:22:54 +03:00
|
|
|
mDPI(aOther.mDPI),
|
|
|
|
mScreenOrientation(aOther.mScreenOrientation),
|
|
|
|
mOrientationAngle(aOther.mOrientationAngle) {}
|
|
|
|
|
|
|
|
dom::ScreenDetails Screen::ToScreenDetails() const {
|
|
|
|
return dom::ScreenDetails(mRect, mRectDisplayPix, mAvailRect,
|
|
|
|
mAvailRectDisplayPix, mPixelDepth, mColorDepth,
|
|
|
|
mContentsScale, mDefaultCssScale, mDPI,
|
|
|
|
mScreenOrientation, mOrientationAngle);
|
2021-12-30 08:09:40 +03:00
|
|
|
}
|
|
|
|
|
2017-03-14 13:44:54 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Screen::GetRect(int32_t* aOutLeft, int32_t* aOutTop, int32_t* aOutWidth,
|
|
|
|
int32_t* aOutHeight) {
|
2018-01-10 19:14:16 +03:00
|
|
|
mRect.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
|
2017-03-14 13:44:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Screen::GetRectDisplayPix(int32_t* aOutLeft, int32_t* aOutTop,
|
|
|
|
int32_t* aOutWidth, int32_t* aOutHeight) {
|
2018-01-10 19:14:16 +03:00
|
|
|
mRectDisplayPix.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
|
2017-03-14 13:44:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Screen::GetAvailRect(int32_t* aOutLeft, int32_t* aOutTop, int32_t* aOutWidth,
|
|
|
|
int32_t* aOutHeight) {
|
2018-01-10 19:14:16 +03:00
|
|
|
mAvailRect.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
|
2017-03-14 13:44:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Screen::GetAvailRectDisplayPix(int32_t* aOutLeft, int32_t* aOutTop,
|
|
|
|
int32_t* aOutWidth, int32_t* aOutHeight) {
|
2018-01-10 19:14:16 +03:00
|
|
|
mAvailRectDisplayPix.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
|
2017-03-14 13:44:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Screen::GetPixelDepth(int32_t* aPixelDepth) {
|
|
|
|
*aPixelDepth = mPixelDepth;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Screen::GetColorDepth(int32_t* aColorDepth) {
|
|
|
|
*aColorDepth = mColorDepth;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Screen::GetContentsScaleFactor(double* aOutScale) {
|
|
|
|
*aOutScale = mContentsScale.scale;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Screen::GetDefaultCSSScaleFactor(double* aOutScale) {
|
2019-08-27 00:02:43 +03:00
|
|
|
double scale = StaticPrefs::layout_css_devPixelsPerPx();
|
2017-04-05 16:11:34 +03:00
|
|
|
if (scale > 0.0) {
|
|
|
|
*aOutScale = scale;
|
|
|
|
} else {
|
|
|
|
*aOutScale = mDefaultCssScale.scale;
|
|
|
|
}
|
2017-03-14 13:44:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-06 13:09:34 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Screen::GetDpi(float* aDPI) {
|
|
|
|
*aDPI = mDPI;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2022-02-15 23:22:54 +03:00
|
|
|
} // namespace mozilla::widget
|