Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
6 #include "nsScreenCocoa.h"
7 #include "nsObjCExceptions.h"
8 #include "nsCocoaUtils.h"
10 nsScreenCocoa::nsScreenCocoa (NSScreen *screen)
11 {
12 NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
14 mScreen = [screen retain];
16 NS_OBJC_END_TRY_ABORT_BLOCK;
17 }
19 nsScreenCocoa::~nsScreenCocoa ()
20 {
21 NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
23 [mScreen release];
25 NS_OBJC_END_TRY_ABORT_BLOCK;
26 }
28 NS_IMETHODIMP
29 nsScreenCocoa::GetRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
30 {
31 NSRect frame = [mScreen frame];
33 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor());
35 *outX = r.x;
36 *outY = r.y;
37 *outWidth = r.width;
38 *outHeight = r.height;
40 return NS_OK;
41 }
43 NS_IMETHODIMP
44 nsScreenCocoa::GetAvailRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
45 {
46 NSRect frame = [mScreen visibleFrame];
48 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor());
50 *outX = r.x;
51 *outY = r.y;
52 *outWidth = r.width;
53 *outHeight = r.height;
55 return NS_OK;
56 }
58 NS_IMETHODIMP
59 nsScreenCocoa::GetRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
60 {
61 NSRect frame = [mScreen frame];
63 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame);
65 *outX = r.x;
66 *outY = r.y;
67 *outWidth = r.width;
68 *outHeight = r.height;
70 return NS_OK;
71 }
73 NS_IMETHODIMP
74 nsScreenCocoa::GetAvailRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
75 {
76 NSRect frame = [mScreen visibleFrame];
78 nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame);
80 *outX = r.x;
81 *outY = r.y;
82 *outWidth = r.width;
83 *outHeight = r.height;
85 return NS_OK;
86 }
88 NS_IMETHODIMP
89 nsScreenCocoa::GetPixelDepth(int32_t *aPixelDepth)
90 {
91 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
93 NSWindowDepth depth = [mScreen depth];
94 int bpp = NSBitsPerPixelFromDepth(depth);
96 *aPixelDepth = bpp;
97 return NS_OK;
99 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
100 }
102 NS_IMETHODIMP
103 nsScreenCocoa::GetColorDepth(int32_t *aColorDepth)
104 {
105 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
107 NSWindowDepth depth = [mScreen depth];
108 int bpp = NSBitsPerPixelFromDepth (depth);
110 *aColorDepth = bpp;
111 return NS_OK;
113 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
114 }
116 NS_IMETHODIMP
117 nsScreenCocoa::GetContentsScaleFactor(double *aContentsScaleFactor)
118 {
119 NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
121 *aContentsScaleFactor = (double) BackingScaleFactor();
122 return NS_OK;
124 NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
125 }
127 CGFloat
128 nsScreenCocoa::BackingScaleFactor()
129 {
130 return nsCocoaUtils::GetBackingScaleFactor(mScreen);
131 }