2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsScreenCocoa.h"
|
2008-02-20 15:47:05 -08:00
|
|
|
#include "nsObjCExceptions.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCocoaUtils.h"
|
|
|
|
|
2014-07-14 10:22:26 -07:00
|
|
|
static uint32_t sScreenId = 0;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsScreenCocoa::nsScreenCocoa (NSScreen *screen)
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
mScreen = [screen retain];
|
2014-07-14 10:22:26 -07:00
|
|
|
mId = ++sScreenId;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsScreenCocoa::~nsScreenCocoa ()
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
[mScreen release];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-07-14 10:22:26 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenCocoa::GetId(uint32_t *outId)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
*outId = mId;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsScreenCocoa::GetRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-29 04:36:09 -07:00
|
|
|
NSRect frame = [mScreen frame];
|
|
|
|
|
|
|
|
nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-20 15:47:05 -08:00
|
|
|
*outX = r.x;
|
|
|
|
*outY = r.y;
|
|
|
|
*outWidth = r.width;
|
|
|
|
*outHeight = r.height;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-20 15:47:05 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsScreenCocoa::GetAvailRect(int32_t *outX, int32_t *outY, int32_t *outWidth, int32_t *outHeight)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-29 04:36:09 -07:00
|
|
|
NSRect frame = [mScreen visibleFrame];
|
|
|
|
|
|
|
|
nsIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-20 15:47:05 -08:00
|
|
|
*outX = r.x;
|
|
|
|
*outY = r.y;
|
|
|
|
*outWidth = r.width;
|
|
|
|
*outHeight = r.height;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-20 15:47:05 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-16 12:41:19 -07: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;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsScreenCocoa::GetPixelDepth(int32_t *aPixelDepth)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-20 15:47:05 -08:00
|
|
|
NSWindowDepth depth = [mScreen depth];
|
|
|
|
int bpp = NSBitsPerPixelFromDepth(depth);
|
|
|
|
|
|
|
|
*aPixelDepth = bpp;
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsScreenCocoa::GetColorDepth(int32_t *aColorDepth)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
NSWindowDepth depth = [mScreen depth];
|
|
|
|
int bpp = NSBitsPerPixelFromDepth (depth);
|
|
|
|
|
|
|
|
*aColorDepth = bpp;
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-09-29 04:36:09 -07:00
|
|
|
|
2012-10-02 12:48:05 -07: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 04:36:09 -07:00
|
|
|
CGFloat
|
|
|
|
nsScreenCocoa::BackingScaleFactor()
|
|
|
|
{
|
|
|
|
return nsCocoaUtils::GetBackingScaleFactor(mScreen);
|
|
|
|
}
|