1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/cocoa/nsScreenCocoa.mm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,131 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsScreenCocoa.h" 1.10 +#include "nsObjCExceptions.h" 1.11 +#include "nsCocoaUtils.h" 1.12 + 1.13 +nsScreenCocoa::nsScreenCocoa (NSScreen *screen) 1.14 +{ 1.15 + NS_OBJC_BEGIN_TRY_ABORT_BLOCK; 1.16 + 1.17 + mScreen = [screen retain]; 1.18 + 1.19 + NS_OBJC_END_TRY_ABORT_BLOCK; 1.20 +} 1.21 + 1.22 +nsScreenCocoa::~nsScreenCocoa () 1.23 +{ 1.24 + NS_OBJC_BEGIN_TRY_ABORT_BLOCK; 1.25 + 1.26 + [mScreen release]; 1.27 + 1.28 + NS_OBJC_END_TRY_ABORT_BLOCK; 1.29 +} 1.30 + 1.31 +NS_IMETHODIMP 1.32 +nsScreenCocoa::GetRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) 1.33 +{ 1.34 + NSRect frame = [mScreen frame]; 1.35 + 1.36 + nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor()); 1.37 + 1.38 + *outX = r.x; 1.39 + *outY = r.y; 1.40 + *outWidth = r.width; 1.41 + *outHeight = r.height; 1.42 + 1.43 + return NS_OK; 1.44 +} 1.45 + 1.46 +NS_IMETHODIMP 1.47 +nsScreenCocoa::GetAvailRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) 1.48 +{ 1.49 + NSRect frame = [mScreen visibleFrame]; 1.50 + 1.51 + nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor()); 1.52 + 1.53 + *outX = r.x; 1.54 + *outY = r.y; 1.55 + *outWidth = r.width; 1.56 + *outHeight = r.height; 1.57 + 1.58 + return NS_OK; 1.59 +} 1.60 + 1.61 +NS_IMETHODIMP 1.62 +nsScreenCocoa::GetRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) 1.63 +{ 1.64 + NSRect frame = [mScreen frame]; 1.65 + 1.66 + nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame); 1.67 + 1.68 + *outX = r.x; 1.69 + *outY = r.y; 1.70 + *outWidth = r.width; 1.71 + *outHeight = r.height; 1.72 + 1.73 + return NS_OK; 1.74 +} 1.75 + 1.76 +NS_IMETHODIMP 1.77 +nsScreenCocoa::GetAvailRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight) 1.78 +{ 1.79 + NSRect frame = [mScreen visibleFrame]; 1.80 + 1.81 + nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame); 1.82 + 1.83 + *outX = r.x; 1.84 + *outY = r.y; 1.85 + *outWidth = r.width; 1.86 + *outHeight = r.height; 1.87 + 1.88 + return NS_OK; 1.89 +} 1.90 + 1.91 +NS_IMETHODIMP 1.92 +nsScreenCocoa::GetPixelDepth(int32_t *aPixelDepth) 1.93 +{ 1.94 + NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; 1.95 + 1.96 + NSWindowDepth depth = [mScreen depth]; 1.97 + int bpp = NSBitsPerPixelFromDepth(depth); 1.98 + 1.99 + *aPixelDepth = bpp; 1.100 + return NS_OK; 1.101 + 1.102 + NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; 1.103 +} 1.104 + 1.105 +NS_IMETHODIMP 1.106 +nsScreenCocoa::GetColorDepth(int32_t *aColorDepth) 1.107 +{ 1.108 + NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; 1.109 + 1.110 + NSWindowDepth depth = [mScreen depth]; 1.111 + int bpp = NSBitsPerPixelFromDepth (depth); 1.112 + 1.113 + *aColorDepth = bpp; 1.114 + return NS_OK; 1.115 + 1.116 + NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; 1.117 +} 1.118 + 1.119 +NS_IMETHODIMP 1.120 +nsScreenCocoa::GetContentsScaleFactor(double *aContentsScaleFactor) 1.121 +{ 1.122 + NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; 1.123 + 1.124 + *aContentsScaleFactor = (double) BackingScaleFactor(); 1.125 + return NS_OK; 1.126 + 1.127 + NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; 1.128 +} 1.129 + 1.130 +CGFloat 1.131 +nsScreenCocoa::BackingScaleFactor() 1.132 +{ 1.133 + return nsCocoaUtils::GetBackingScaleFactor(mScreen); 1.134 +}