Backed out changeset 3fe07c50c854 (bug 946316) for bustage. a=backout
[gecko.git] / widget / cocoa / nsScreenCocoa.mm
blob5780a4c7eab25d61adbe10831d094d89ee3087bb
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)
12   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
14   mScreen = [screen retain];
16   NS_OBJC_END_TRY_ABORT_BLOCK;
19 nsScreenCocoa::~nsScreenCocoa ()
21   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
23   [mScreen release];
25   NS_OBJC_END_TRY_ABORT_BLOCK;
28 NS_IMETHODIMP
29 nsScreenCocoa::GetRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
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;
43 NS_IMETHODIMP
44 nsScreenCocoa::GetAvailRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
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;
58 NS_IMETHODIMP
59 nsScreenCocoa::GetRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
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;
73 NS_IMETHODIMP
74 nsScreenCocoa::GetAvailRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
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;
88 NS_IMETHODIMP
89 nsScreenCocoa::GetPixelDepth(int32_t *aPixelDepth)
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;
102 NS_IMETHODIMP
103 nsScreenCocoa::GetColorDepth(int32_t *aColorDepth)
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;
116 NS_IMETHODIMP
117 nsScreenCocoa::GetContentsScaleFactor(double *aContentsScaleFactor)
119   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
121   *aContentsScaleFactor = (double) BackingScaleFactor();
122   return NS_OK;
124   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
127 CGFloat
128 nsScreenCocoa::BackingScaleFactor()
130   return nsCocoaUtils::GetBackingScaleFactor(mScreen);