Bug 1643246 - Don't use attribute selectors for determining if a select is a drop...
[gecko.git] / widget / Screen.cpp
blob4fb196fe877629da8223f3e38aad1d0e1604e41c
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/. */
7 #include "Screen.h"
9 #include "mozilla/dom/DOMTypes.h"
10 #include "mozilla/StaticPrefs_layout.h"
12 namespace mozilla {
13 namespace widget {
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)
21 : mRect(aRect),
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),
29 mDPI(aDPI) {}
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),
51 mDPI(aOther.mDPI) {}
53 mozilla::dom::ScreenDetails Screen::ToScreenDetails() {
54 return mozilla::dom::ScreenDetails(
55 mRect, mRectDisplayPix, mAvailRect, mAvailRectDisplayPix, mPixelDepth,
56 mColorDepth, mContentsScale, mDefaultCssScale, mDPI);
59 NS_IMETHODIMP
60 Screen::GetRect(int32_t* aOutLeft, int32_t* aOutTop, int32_t* aOutWidth,
61 int32_t* aOutHeight) {
62 mRect.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
63 return NS_OK;
66 NS_IMETHODIMP
67 Screen::GetRectDisplayPix(int32_t* aOutLeft, int32_t* aOutTop,
68 int32_t* aOutWidth, int32_t* aOutHeight) {
69 mRectDisplayPix.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
70 return NS_OK;
73 NS_IMETHODIMP
74 Screen::GetAvailRect(int32_t* aOutLeft, int32_t* aOutTop, int32_t* aOutWidth,
75 int32_t* aOutHeight) {
76 mAvailRect.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
77 return NS_OK;
80 NS_IMETHODIMP
81 Screen::GetAvailRectDisplayPix(int32_t* aOutLeft, int32_t* aOutTop,
82 int32_t* aOutWidth, int32_t* aOutHeight) {
83 mAvailRectDisplayPix.GetRect(aOutLeft, aOutTop, aOutWidth, aOutHeight);
84 return NS_OK;
87 NS_IMETHODIMP
88 Screen::GetPixelDepth(int32_t* aPixelDepth) {
89 *aPixelDepth = mPixelDepth;
90 return NS_OK;
93 NS_IMETHODIMP
94 Screen::GetColorDepth(int32_t* aColorDepth) {
95 *aColorDepth = mColorDepth;
96 return NS_OK;
99 NS_IMETHODIMP
100 Screen::GetContentsScaleFactor(double* aOutScale) {
101 *aOutScale = mContentsScale.scale;
102 return NS_OK;
105 NS_IMETHODIMP
106 Screen::GetDefaultCSSScaleFactor(double* aOutScale) {
107 double scale = StaticPrefs::layout_css_devPixelsPerPx();
108 if (scale > 0.0) {
109 *aOutScale = scale;
110 } else {
111 *aOutScale = mDefaultCssScale.scale;
113 return NS_OK;
116 NS_IMETHODIMP
117 Screen::GetDpi(float* aDPI) {
118 *aDPI = mDPI;
119 return NS_OK;
122 } // namespace widget
123 } // namespace mozilla