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 "nsScreenManagerCocoa.h"
|
2008-02-21 02:47:05 +03:00
|
|
|
#include "nsObjCExceptions.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2007-02-23 00:56:50 +03:00
|
|
|
#include "nsCocoaUtils.h"
|
2006-09-21 01:08:24 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsScreenManagerCocoa, nsIScreenManager)
|
2006-09-21 01:08:24 +04:00
|
|
|
|
|
|
|
nsScreenManagerCocoa::nsScreenManagerCocoa()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsScreenManagerCocoa::~nsScreenManagerCocoa()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsScreenCocoa*
|
2011-03-23 21:46:57 +03:00
|
|
|
nsScreenManagerCocoa::ScreenForCocoaScreen(NSScreen *screen)
|
2006-09-21 01:08:24 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mScreenList.Length(); ++i) {
|
2009-09-10 23:05:50 +04:00
|
|
|
nsScreenCocoa* sc = mScreenList[i];
|
2006-09-21 01:08:24 +04:00
|
|
|
if (sc->CocoaScreen() == screen) {
|
|
|
|
// doesn't addref
|
|
|
|
return sc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// didn't find it; create and insert
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsScreenCocoa> sc = new nsScreenCocoa(screen);
|
2009-09-10 23:05:50 +04:00
|
|
|
mScreenList.AppendElement(sc);
|
2006-09-21 01:08:24 +04:00
|
|
|
return sc.get();
|
|
|
|
}
|
|
|
|
|
2014-07-14 21:22:26 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerCocoa::ScreenForId (uint32_t aId, nsIScreen **outScreen)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT
|
|
|
|
|
|
|
|
*outScreen = nullptr;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mScreenList.Length(); ++i) {
|
|
|
|
nsScreenCocoa* sc = mScreenList[i];
|
|
|
|
uint32_t id;
|
|
|
|
nsresult rv = sc->GetId(&id);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && id == aId) {
|
|
|
|
*outScreen = sc;
|
|
|
|
NS_ADDREF(*outScreen);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
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
|
|
|
nsScreenManagerCocoa::ScreenForRect (int32_t aX, int32_t aY, int32_t aWidth, int32_t aHeight,
|
2006-09-21 01:08:24 +04:00
|
|
|
nsIScreen **outScreen)
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2006-09-21 01:08:24 +04:00
|
|
|
NSEnumerator *screenEnum = [[NSScreen screens] objectEnumerator];
|
2009-01-15 06:27:09 +03:00
|
|
|
NSRect inRect = nsCocoaUtils::GeckoRectToCocoaRect(nsIntRect(aX, aY, aWidth, aHeight));
|
2007-02-23 06:35:59 +03:00
|
|
|
NSScreen *screenWindowIsOn = [NSScreen mainScreen];
|
|
|
|
float greatestArea = 0;
|
2006-09-21 01:08:24 +04:00
|
|
|
|
|
|
|
while (NSScreen *screen = [screenEnum nextObject]) {
|
|
|
|
NSDictionary *desc = [screen deviceDescription];
|
|
|
|
if ([desc objectForKey:NSDeviceIsScreen] == nil)
|
|
|
|
continue;
|
|
|
|
|
2007-02-23 06:35:59 +03:00
|
|
|
NSRect r = NSIntersectionRect([screen frame], inRect);
|
|
|
|
float area = r.size.width * r.size.height;
|
|
|
|
if (area > greatestArea) {
|
|
|
|
greatestArea = area;
|
|
|
|
screenWindowIsOn = screen;
|
2006-09-21 01:08:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-23 06:35:59 +03:00
|
|
|
*outScreen = ScreenForCocoaScreen(screenWindowIsOn);
|
|
|
|
NS_ADDREF(*outScreen);
|
2006-09-21 01:08:24 +04:00
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2006-09-21 01:08:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerCocoa::GetPrimaryScreen (nsIScreen **outScreen)
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2006-09-21 01:08:24 +04:00
|
|
|
// the mainScreen is the screen with the "key window" (focus, I assume?)
|
|
|
|
NSScreen *sc = [[NSScreen screens] objectAtIndex:0];
|
|
|
|
|
|
|
|
*outScreen = ScreenForCocoaScreen(sc);
|
|
|
|
NS_ADDREF(*outScreen);
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
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
|
|
|
nsScreenManagerCocoa::GetNumberOfScreens (uint32_t *aNumberOfScreens)
|
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
|
|
|
NSArray *ss = [NSScreen screens];
|
|
|
|
|
|
|
|
*aNumberOfScreens = [ss count];
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2006-09-21 01:08:24 +04:00
|
|
|
}
|
|
|
|
|
2013-04-10 01:07:02 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerCocoa::GetSystemDefaultScale(float *aDefaultScale)
|
|
|
|
{
|
|
|
|
*aDefaultScale = 1.0f;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-09-21 01:08:24 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerCocoa::ScreenForNativeWidget (void *nativeWidget, nsIScreen **outScreen)
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2009-04-10 14:43:19 +04:00
|
|
|
NSWindow *window = static_cast<NSWindow*>(nativeWidget);
|
2006-09-21 01:08:24 +04:00
|
|
|
if (window) {
|
|
|
|
nsIScreen *screen = ScreenForCocoaScreen([window screen]);
|
|
|
|
*outScreen = screen;
|
|
|
|
NS_ADDREF(*outScreen);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*outScreen = nullptr;
|
2006-09-21 01:08:24 +04:00
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2006-09-21 01:08:24 +04:00
|
|
|
}
|