michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsScreenCocoa.h" michael@0: #include "nsObjCExceptions.h" michael@0: #include "nsCocoaUtils.h" michael@0: michael@0: nsScreenCocoa::nsScreenCocoa (NSScreen *screen) michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK; michael@0: michael@0: mScreen = [screen retain]; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK; michael@0: } michael@0: michael@0: nsScreenCocoa::~nsScreenCocoa () michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK; michael@0: michael@0: [mScreen release]; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenCocoa::GetRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) michael@0: { michael@0: NSRect frame = [mScreen frame]; michael@0: michael@0: nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor()); michael@0: michael@0: *outX = r.x; michael@0: *outY = r.y; michael@0: *outWidth = r.width; michael@0: *outHeight = r.height; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenCocoa::GetAvailRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) michael@0: { michael@0: NSRect frame = [mScreen visibleFrame]; michael@0: michael@0: nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor()); michael@0: michael@0: *outX = r.x; michael@0: *outY = r.y; michael@0: *outWidth = r.width; michael@0: *outHeight = r.height; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenCocoa::GetRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) michael@0: { michael@0: NSRect frame = [mScreen frame]; michael@0: michael@0: nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame); michael@0: michael@0: *outX = r.x; michael@0: *outY = r.y; michael@0: *outWidth = r.width; michael@0: *outHeight = r.height; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenCocoa::GetAvailRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) michael@0: { michael@0: NSRect frame = [mScreen visibleFrame]; michael@0: michael@0: nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame); michael@0: michael@0: *outX = r.x; michael@0: *outY = r.y; michael@0: *outWidth = r.width; michael@0: *outHeight = r.height; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenCocoa::GetPixelDepth(int32_t *aPixelDepth) michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; michael@0: michael@0: NSWindowDepth depth = [mScreen depth]; michael@0: int bpp = NSBitsPerPixelFromDepth(depth); michael@0: michael@0: *aPixelDepth = bpp; michael@0: return NS_OK; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenCocoa::GetColorDepth(int32_t *aColorDepth) michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; michael@0: michael@0: NSWindowDepth depth = [mScreen depth]; michael@0: int bpp = NSBitsPerPixelFromDepth (depth); michael@0: michael@0: *aColorDepth = bpp; michael@0: return NS_OK; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenCocoa::GetContentsScaleFactor(double *aContentsScaleFactor) michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; michael@0: michael@0: *aContentsScaleFactor = (double) BackingScaleFactor(); michael@0: return NS_OK; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; michael@0: } michael@0: michael@0: CGFloat michael@0: nsScreenCocoa::BackingScaleFactor() michael@0: { michael@0: return nsCocoaUtils::GetBackingScaleFactor(mScreen); michael@0: }