1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#import <UIKit/UIScreen.h>
#include "gfxPoint.h"
#include "nsScreenManager.h"
#include "nsAppShell.h"
static LayoutDeviceIntRect gScreenBounds;
static bool gScreenBoundsSet = false;
UIKitScreen::UIKitScreen(UIScreen* aScreen) { mScreen = [aScreen retain]; }
NS_IMETHODIMP
UIKitScreen::GetRect(int32_t* outX, int32_t* outY, int32_t* outWidth,
int32_t* outHeight) {
return GetRectDisplayPix(outX, outY, outWidth, outHeight);
}
NS_IMETHODIMP
UIKitScreen::GetAvailRect(int32_t* outX, int32_t* outY, int32_t* outWidth,
int32_t* outHeight) {
return GetAvailRectDisplayPix(outX, outY, outWidth, outHeight);
}
NS_IMETHODIMP
UIKitScreen::GetRectDisplayPix(int32_t* outX, int32_t* outY, int32_t* outWidth,
int32_t* outHeight) {
nsIntRect rect = UIKitScreenManager::GetBounds();
*outX = rect.x;
*outY = rect.y;
*outWidth = rect.width;
*outHeight = rect.height;
return NS_OK;
}
NS_IMETHODIMP
UIKitScreen::GetAvailRectDisplayPix(int32_t* outX, int32_t* outY,
int32_t* outWidth, int32_t* outHeight) {
CGRect rect = [mScreen applicationFrame];
CGFloat scale = [mScreen scale];
*outX = rect.origin.x * scale;
*outY = rect.origin.y * scale;
*outWidth = rect.size.width * scale;
*outHeight = rect.size.height * scale;
return NS_OK;
}
NS_IMETHODIMP
UIKitScreen::GetPixelDepth(int32_t* aPixelDepth) {
// Close enough.
*aPixelDepth = 24;
return NS_OK;
}
NS_IMETHODIMP
UIKitScreen::GetColorDepth(int32_t* aColorDepth) {
return GetPixelDepth(aColorDepth);
}
NS_IMETHODIMP
UIKitScreen::GetContentsScaleFactor(double* aContentsScaleFactor) {
*aContentsScaleFactor = [mScreen scale];
return NS_OK;
}
NS_IMPL_ISUPPORTS(UIKitScreenManager, nsIScreenManager)
UIKitScreenManager::UIKitScreenManager()
: mScreen(new UIKitScreen([UIScreen mainScreen])) {}
LayoutDeviceIntRect UIKitScreenManager::GetBounds() {
if (!gScreenBoundsSet) {
CGRect rect = [[UIScreen mainScreen] bounds];
CGFloat scale = [[UIScreen mainScreen] scale];
gScreenBounds.x = rect.origin.x * scale;
gScreenBounds.y = rect.origin.y * scale;
gScreenBounds.width = rect.size.width * scale;
gScreenBounds.height = rect.size.height * scale;
gScreenBoundsSet = true;
}
printf("UIKitScreenManager::GetBounds: %d %d %d %d\n", gScreenBounds.x,
gScreenBounds.y, gScreenBounds.width, gScreenBounds.height);
return gScreenBounds;
}
NS_IMETHODIMP
UIKitScreenManager::GetPrimaryScreen(nsIScreen** outScreen) {
NS_IF_ADDREF(*outScreen = mScreen.get());
return NS_OK;
}
NS_IMETHODIMP
UIKitScreenManager::ScreenForRect(int32_t inLeft, int32_t inTop,
int32_t inWidth, int32_t inHeight,
nsIScreen** outScreen) {
return GetPrimaryScreen(outScreen);
}
|