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>
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]; }
18 UIKitScreen::GetRect(int32_t* outX, int32_t* outY, int32_t* outWidth,
20 return GetRectDisplayPix(outX, outY, outWidth, outHeight);
24 UIKitScreen::GetAvailRect(int32_t* outX, int32_t* outY, int32_t* outWidth,
26 return GetAvailRectDisplayPix(outX, outY, outWidth, outHeight);
30 UIKitScreen::GetRectDisplayPix(int32_t* outX, int32_t* outY, int32_t* outWidth,
32 nsIntRect rect = UIKitScreenManager::GetBounds();
35 *outWidth = rect.width;
36 *outHeight = rect.height;
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;
56 UIKitScreen::GetPixelDepth(int32_t* aPixelDepth) {
63 UIKitScreen::GetColorDepth(int32_t* aColorDepth) {
64 return GetPixelDepth(aColorDepth);
68 UIKitScreen::GetContentsScaleFactor(double* aContentsScaleFactor) {
69 *aContentsScaleFactor = [mScreen scale];
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;
88 printf("UIKitScreenManager::GetBounds: %d %d %d %d\n", gScreenBounds.x,
89 gScreenBounds.y, gScreenBounds.width, gScreenBounds.height);
94 UIKitScreenManager::GetPrimaryScreen(nsIScreen** outScreen) {
95 NS_IF_ADDREF(*outScreen = mScreen.get());
100 UIKitScreenManager::ScreenForRect(int32_t inLeft, int32_t inTop,
101 int32_t inWidth, int32_t inHeight,
102 nsIScreen** outScreen) {
103 return GetPrimaryScreen(outScreen);