widget/cocoa/nsScreenCocoa.mm

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial