Bug 1857632 [wpt PR 42241] - Start dbus for Chrome, a=testonly
[gecko.git] / widget / uikit / nsScreenManager.mm
blobda37a4199d8829ff6abd029567d1c91f78887a0f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #import <UIKit/UIScreen.h>
8 #include "gfxPoint.h"
9 #include "nsScreenManager.h"
10 #include "nsAppShell.h"
12 static LayoutDeviceIntRect gScreenBounds;
13 static bool gScreenBoundsSet = false;
15 UIKitScreen::UIKitScreen(UIScreen* aScreen) { mScreen = [aScreen retain]; }
17 NS_IMETHODIMP
18 UIKitScreen::GetRect(int32_t* outX, int32_t* outY, int32_t* outWidth,
19                      int32_t* outHeight) {
20   return GetRectDisplayPix(outX, outY, outWidth, outHeight);
23 NS_IMETHODIMP
24 UIKitScreen::GetAvailRect(int32_t* outX, int32_t* outY, int32_t* outWidth,
25                           int32_t* outHeight) {
26   return GetAvailRectDisplayPix(outX, outY, outWidth, outHeight);
29 NS_IMETHODIMP
30 UIKitScreen::GetRectDisplayPix(int32_t* outX, int32_t* outY, int32_t* outWidth,
31                                int32_t* outHeight) {
32   nsIntRect rect = UIKitScreenManager::GetBounds();
33   *outX = rect.x;
34   *outY = rect.y;
35   *outWidth = rect.width;
36   *outHeight = rect.height;
38   return NS_OK;
41 NS_IMETHODIMP
42 UIKitScreen::GetAvailRectDisplayPix(int32_t* outX, int32_t* outY,
43                                     int32_t* outWidth, int32_t* outHeight) {
44   CGRect rect = [mScreen applicationFrame];
45   CGFloat scale = [mScreen scale];
47   *outX = rect.origin.x * scale;
48   *outY = rect.origin.y * scale;
49   *outWidth = rect.size.width * scale;
50   *outHeight = rect.size.height * scale;
52   return NS_OK;
55 NS_IMETHODIMP
56 UIKitScreen::GetPixelDepth(int32_t* aPixelDepth) {
57   // Close enough.
58   *aPixelDepth = 24;
59   return NS_OK;
62 NS_IMETHODIMP
63 UIKitScreen::GetColorDepth(int32_t* aColorDepth) {
64   return GetPixelDepth(aColorDepth);
67 NS_IMETHODIMP
68 UIKitScreen::GetContentsScaleFactor(double* aContentsScaleFactor) {
69   *aContentsScaleFactor = [mScreen scale];
70   return NS_OK;
73 NS_IMPL_ISUPPORTS(UIKitScreenManager, nsIScreenManager)
75 UIKitScreenManager::UIKitScreenManager()
76     : mScreen(new UIKitScreen([UIScreen mainScreen])) {}
78 LayoutDeviceIntRect UIKitScreenManager::GetBounds() {
79   if (!gScreenBoundsSet) {
80     CGRect rect = [[UIScreen mainScreen] bounds];
81     CGFloat scale = [[UIScreen mainScreen] scale];
82     gScreenBounds.x = rect.origin.x * scale;
83     gScreenBounds.y = rect.origin.y * scale;
84     gScreenBounds.width = rect.size.width * scale;
85     gScreenBounds.height = rect.size.height * scale;
86     gScreenBoundsSet = true;
87   }
88   printf("UIKitScreenManager::GetBounds: %d %d %d %d\n", gScreenBounds.x,
89          gScreenBounds.y, gScreenBounds.width, gScreenBounds.height);
90   return gScreenBounds;
93 NS_IMETHODIMP
94 UIKitScreenManager::GetPrimaryScreen(nsIScreen** outScreen) {
95   NS_IF_ADDREF(*outScreen = mScreen.get());
96   return NS_OK;
99 NS_IMETHODIMP
100 UIKitScreenManager::ScreenForRect(int32_t inLeft, int32_t inTop,
101                                   int32_t inWidth, int32_t inHeight,
102                                   nsIScreen** outScreen) {
103   return GetPrimaryScreen(outScreen);