2006-09-21 01:08:24 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-09-21 01:08:24 +04:00
|
|
|
|
|
|
|
#include "nsScreenCocoa.h"
|
2008-02-21 02:47:05 +03:00
|
|
|
#include "nsObjCExceptions.h"
|
2007-02-23 00:56:50 +03:00
|
|
|
#include "nsCocoaUtils.h"
|
2006-09-21 01:08:24 +04:00
|
|
|
|
|
|
|
nsScreenCocoa::nsScreenCocoa (NSScreen *screen)
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
mScreen = [screen retain];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2006-09-21 01:08:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsScreenCocoa::~nsScreenCocoa ()
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
[mScreen release];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2006-09-21 01:08:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenCocoa::GetRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
|
2006-09-21 01:08:24 +04:00
|
|
|
{
|
2012-09-29 15:36:09 +04:00
|
|
|
NSRect frame = [mScreen frame];
|
|
|
|
|
|
|
|
nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor());
|
2006-09-21 01:08:24 +04:00
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
*outX = r.x;
|
|
|
|
*outY = r.y;
|
|
|
|
*outWidth = r.width;
|
|
|
|
*outHeight = r.height;
|
2006-09-21 01:08:24 +04:00
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
return NS_OK;
|
2006-09-21 01:08:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenCocoa::GetAvailRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
|
2006-09-21 01:08:24 +04:00
|
|
|
{
|
2012-09-29 15:36:09 +04:00
|
|
|
NSRect frame = [mScreen visibleFrame];
|
|
|
|
|
|
|
|
nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor());
|
2006-09-21 01:08:24 +04:00
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
*outX = r.x;
|
|
|
|
*outY = r.y;
|
|
|
|
*outWidth = r.width;
|
|
|
|
*outHeight = r.height;
|
2006-09-21 01:08:24 +04:00
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
return NS_OK;
|
2006-09-21 01:08:24 +04:00
|
|
|
}
|
|
|
|
|
2012-10-16 23:41:19 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenCocoa::GetRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
|
|
|
|
{
|
|
|
|
NSRect frame = [mScreen frame];
|
|
|
|
|
|
|
|
nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame);
|
|
|
|
|
|
|
|
*outX = r.x;
|
|
|
|
*outY = r.y;
|
|
|
|
*outWidth = r.width;
|
|
|
|
*outHeight = r.height;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenCocoa::GetAvailRectDisplayPix(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
|
|
|
|
{
|
|
|
|
NSRect frame = [mScreen visibleFrame];
|
|
|
|
|
|
|
|
nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRect(frame);
|
|
|
|
|
|
|
|
*outX = r.x;
|
|
|
|
*outY = r.y;
|
|
|
|
*outWidth = r.width;
|
|
|
|
*outHeight = r.height;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-09-21 01:08:24 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenCocoa::GetPixelDepth(int32_t *aPixelDepth)
|
2006-09-21 01:08:24 +04:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
2006-09-21 01:08:24 +04:00
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
NSWindowDepth depth = [mScreen depth];
|
|
|
|
int bpp = NSBitsPerPixelFromDepth(depth);
|
|
|
|
|
|
|
|
*aPixelDepth = bpp;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2006-09-21 01:08:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenCocoa::GetColorDepth(int32_t *aColorDepth)
|
2006-09-21 01:08:24 +04:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
NSWindowDepth depth = [mScreen depth];
|
|
|
|
int bpp = NSBitsPerPixelFromDepth (depth);
|
|
|
|
|
|
|
|
*aColorDepth = bpp;
|
|
|
|
return NS_OK;
|
2006-09-21 01:08:24 +04:00
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2006-09-21 01:08:24 +04:00
|
|
|
}
|
2012-09-29 15:36:09 +04:00
|
|
|
|
2012-10-02 23:48:05 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenCocoa::GetContentsScaleFactor(double *aContentsScaleFactor)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
*aContentsScaleFactor = (double) BackingScaleFactor();
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
2012-09-29 15:36:09 +04:00
|
|
|
CGFloat
|
|
|
|
nsScreenCocoa::BackingScaleFactor()
|
|
|
|
{
|
|
|
|
return nsCocoaUtils::GetBackingScaleFactor(mScreen);
|
|
|
|
}
|