|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
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/. */ |
|
5 |
|
6 #include "nsScreenCocoa.h" |
|
7 #include "nsObjCExceptions.h" |
|
8 #include "nsCocoaUtils.h" |
|
9 |
|
10 nsScreenCocoa::nsScreenCocoa (NSScreen *screen) |
|
11 { |
|
12 NS_OBJC_BEGIN_TRY_ABORT_BLOCK; |
|
13 |
|
14 mScreen = [screen retain]; |
|
15 |
|
16 NS_OBJC_END_TRY_ABORT_BLOCK; |
|
17 } |
|
18 |
|
19 nsScreenCocoa::~nsScreenCocoa () |
|
20 { |
|
21 NS_OBJC_BEGIN_TRY_ABORT_BLOCK; |
|
22 |
|
23 [mScreen release]; |
|
24 |
|
25 NS_OBJC_END_TRY_ABORT_BLOCK; |
|
26 } |
|
27 |
|
28 NS_IMETHODIMP |
|
29 nsScreenCocoa::GetRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) |
|
30 { |
|
31 NSRect frame = [mScreen frame]; |
|
32 |
|
33 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor()); |
|
34 |
|
35 *outX = r.x; |
|
36 *outY = r.y; |
|
37 *outWidth = r.width; |
|
38 *outHeight = r.height; |
|
39 |
|
40 return NS_OK; |
|
41 } |
|
42 |
|
43 NS_IMETHODIMP |
|
44 nsScreenCocoa::GetAvailRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) |
|
45 { |
|
46 NSRect frame = [mScreen visibleFrame]; |
|
47 |
|
48 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor()); |
|
49 |
|
50 *outX = r.x; |
|
51 *outY = r.y; |
|
52 *outWidth = r.width; |
|
53 *outHeight = r.height; |
|
54 |
|
55 return NS_OK; |
|
56 } |
|
57 |
|
58 NS_IMETHODIMP |
|
59 nsScreenCocoa::GetRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) |
|
60 { |
|
61 NSRect frame = [mScreen frame]; |
|
62 |
|
63 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame); |
|
64 |
|
65 *outX = r.x; |
|
66 *outY = r.y; |
|
67 *outWidth = r.width; |
|
68 *outHeight = r.height; |
|
69 |
|
70 return NS_OK; |
|
71 } |
|
72 |
|
73 NS_IMETHODIMP |
|
74 nsScreenCocoa::GetAvailRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) |
|
75 { |
|
76 NSRect frame = [mScreen visibleFrame]; |
|
77 |
|
78 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame); |
|
79 |
|
80 *outX = r.x; |
|
81 *outY = r.y; |
|
82 *outWidth = r.width; |
|
83 *outHeight = r.height; |
|
84 |
|
85 return NS_OK; |
|
86 } |
|
87 |
|
88 NS_IMETHODIMP |
|
89 nsScreenCocoa::GetPixelDepth(int32_t *aPixelDepth) |
|
90 { |
|
91 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; |
|
92 |
|
93 NSWindowDepth depth = [mScreen depth]; |
|
94 int bpp = NSBitsPerPixelFromDepth(depth); |
|
95 |
|
96 *aPixelDepth = bpp; |
|
97 return NS_OK; |
|
98 |
|
99 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; |
|
100 } |
|
101 |
|
102 NS_IMETHODIMP |
|
103 nsScreenCocoa::GetColorDepth(int32_t *aColorDepth) |
|
104 { |
|
105 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; |
|
106 |
|
107 NSWindowDepth depth = [mScreen depth]; |
|
108 int bpp = NSBitsPerPixelFromDepth (depth); |
|
109 |
|
110 *aColorDepth = bpp; |
|
111 return NS_OK; |
|
112 |
|
113 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; |
|
114 } |
|
115 |
|
116 NS_IMETHODIMP |
|
117 nsScreenCocoa::GetContentsScaleFactor(double *aContentsScaleFactor) |
|
118 { |
|
119 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; |
|
120 |
|
121 *aContentsScaleFactor = (double) BackingScaleFactor(); |
|
122 return NS_OK; |
|
123 |
|
124 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; |
|
125 } |
|
126 |
|
127 CGFloat |
|
128 nsScreenCocoa::BackingScaleFactor() |
|
129 { |
|
130 return nsCocoaUtils::GetBackingScaleFactor(mScreen); |
|
131 } |