diff --git a/mozilla/gfx/src/thebes/nsThebesDeviceContext.cpp b/mozilla/gfx/src/thebes/nsThebesDeviceContext.cpp index 0a2fb15692f..488de1b3ecb 100644 --- a/mozilla/gfx/src/thebes/nsThebesDeviceContext.cpp +++ b/mozilla/gfx/src/thebes/nsThebesDeviceContext.cpp @@ -693,40 +693,8 @@ nsThebesDeviceContext::ComputeFullAreaUsingScreen(nsRect* outRect) void nsThebesDeviceContext::FindScreen(nsIScreen** outScreen) { - // now then, if we have more than one screen, we need to find which screen this - // window is on. -#ifdef XP_WIN - HWND window = NS_REINTERPRET_CAST(HWND, mWidget); - if (window) { - RECT globalPosition; - ::GetWindowRect(window, &globalPosition); - if (mScreenManager) { - mScreenManager->ScreenForRect(globalPosition.left, globalPosition.top, - globalPosition.right - globalPosition.left, - globalPosition.bottom - globalPosition.top, - outScreen); - return; - } - } -#endif - -#ifdef MOZ_ENABLE_GTK2 - gint x, y, width, height, depth; - x = y = width = height = 0; - - gdk_window_get_geometry(GDK_WINDOW(mWidget), &x, &y, &width, &height, - &depth); - gdk_window_get_origin(GDK_WINDOW(mWidget), &x, &y); - if (mScreenManager) { - mScreenManager->ScreenForRect(x, y, width, height, outScreen); - return; - } - -#endif - -#ifdef XP_MACOSX - // ??? -#endif - - mScreenManager->GetPrimaryScreen(outScreen); + if (mWidget) + mScreenManager->ScreenForNativeWidget(mWidget, outScreen); + else + mScreenManager->GetPrimaryScreen(outScreen); } diff --git a/mozilla/widget/public/nsIScreenManager.idl b/mozilla/widget/public/nsIScreenManager.idl index 5691d1b29be..7c218e2f9f0 100644 --- a/mozilla/widget/public/nsIScreenManager.idl +++ b/mozilla/widget/public/nsIScreenManager.idl @@ -39,8 +39,7 @@ #include "nsISupports.idl" #include "nsIScreen.idl" - -[scriptable, uuid(662e7b78-1dd2-11b2-a3d3-fc1e5f5fb9d4)] +[scriptable, uuid(e224bd44-252b-4b66-b869-99738250904a)] interface nsIScreenManager : nsISupports { // @@ -57,7 +56,11 @@ interface nsIScreenManager : nsISupports // Holds the number of screens that are available readonly attribute unsigned long numberOfScreens; - + + // Returns the nsIScreen instance for the given native widget pointer; + // the pointer is specific to the particular widget implementation, + // and is generally of the same type that NS_NATIVE_WIDGET is. + [noscript] nsIScreen screenForNativeWidget ( in voidPtr nativeWidget ); }; diff --git a/mozilla/widget/src/cocoa/Makefile.in b/mozilla/widget/src/cocoa/Makefile.in index a377bf95028..3caf4c6d871 100644 --- a/mozilla/widget/src/cocoa/Makefile.in +++ b/mozilla/widget/src/cocoa/Makefile.in @@ -101,8 +101,6 @@ MAC_LCPPSRCS = \ nsMimeMapper.cpp \ nsStylClipboardUtils.cpp \ nsToolkitBase.cpp \ - nsScreenMac.cpp \ - nsScreenManagerMac.cpp \ nsDeviceContextSpecFactoryM.cpp \ nsDeviceContextSpecX.cpp \ nsPrintOptionsX.cpp \ @@ -139,6 +137,8 @@ CMMSRCS = \ nsNativeScrollbar.mm \ nsCursorManager.mm \ nsMacCursor.mm \ + nsScreenCocoa.mm \ + nsScreenManagerCocoa.mm \ $(NULL) XPIDLSRCS += \ diff --git a/mozilla/widget/src/cocoa/nsScreenCocoa.h b/mozilla/widget/src/cocoa/nsScreenCocoa.h new file mode 100644 index 00000000000..73ed7418a3b --- /dev/null +++ b/mozilla/widget/src/cocoa/nsScreenCocoa.h @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Mozilla Corporation + * Portions created by the Initial Developer are Copyright (C) 2006 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Vladimir Vukicevic + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef NS_SCREEN_COCOA_H_ +#define NS_SCREEN_COCOA_H_ + +#import + +#include "nsIScreen.h" + +class nsScreenCocoa : public nsIScreen +{ +public: + nsScreenCocoa (NSScreen *screen); + ~nsScreenCocoa (); + + NS_DECL_ISUPPORTS + + NS_DECL_NSISCREEN + + NSScreen *CocoaScreen() { return mScreen; } + +private: + NSScreen *mScreen; +}; + +#endif diff --git a/mozilla/widget/src/cocoa/nsScreenCocoa.mm b/mozilla/widget/src/cocoa/nsScreenCocoa.mm new file mode 100644 index 00000000000..a04b7aa096a --- /dev/null +++ b/mozilla/widget/src/cocoa/nsScreenCocoa.mm @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Mozilla Corporation + * Portions created by the Initial Developer are Copyright (C) 2006 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Vladimir Vukicevic + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsUnitConversion.h" + +#include "nsScreenCocoa.h" + +NS_IMPL_ISUPPORTS1(nsScreenCocoa, nsIScreen) + +nsScreenCocoa::nsScreenCocoa (NSScreen *screen) +{ + mScreen = [screen retain]; +} + +nsScreenCocoa::~nsScreenCocoa () +{ + [mScreen release]; +} + +NS_IMETHODIMP +nsScreenCocoa::GetRect(PRInt32 *outX, PRInt32 *outY, PRInt32 *outWidth, PRInt32 *outHeight) +{ + NSRect r = [mScreen frame]; + + *outX = NSToIntFloor(r.origin.x); + *outY = NSToIntFloor(r.origin.y); + *outWidth = NSToIntFloor(r.size.width); + *outHeight = NSToIntFloor(r.size.height); + + return NS_OK; +} + +NS_IMETHODIMP +nsScreenCocoa::GetAvailRect(PRInt32 *outX, PRInt32 *outY, PRInt32 *outWidth, PRInt32 *outHeight) +{ + NSRect r = [mScreen visibleFrame]; + + *outX = NSToIntFloor(r.origin.x); + *outY = NSToIntFloor(r.origin.y); + *outWidth = NSToIntFloor(r.size.width); + *outHeight = NSToIntFloor(r.size.height); + + return NS_OK; +} + +NS_IMETHODIMP +nsScreenCocoa::GetPixelDepth(PRInt32 *aPixelDepth) +{ + NSWindowDepth depth = [mScreen depth]; + int bpp = NSBitsPerPixelFromDepth (depth); + + *aPixelDepth = bpp; + return NS_OK; +} + +NS_IMETHODIMP +nsScreenCocoa::GetColorDepth(PRInt32 *aColorDepth) +{ + NSWindowDepth depth = [mScreen depth]; + int bpp = NSBitsPerPixelFromDepth (depth); + + *aColorDepth = bpp; + return NS_OK; +} diff --git a/mozilla/widget/src/cocoa/nsScreenManagerCocoa.h b/mozilla/widget/src/cocoa/nsScreenManagerCocoa.h new file mode 100644 index 00000000000..3e141a9c2be --- /dev/null +++ b/mozilla/widget/src/cocoa/nsScreenManagerCocoa.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Mozilla Corporation + * Portions created by the Initial Developer are Copyright (C) 2006 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Vladimir Vukicevic + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef NS_SCREEN_MANAGER_COCOA_H_ +#define NS_SCREEN_MANAGER_COCOA_H_ + +#import + +#include "nsCOMArray.h" + +#include "nsIScreenManager.h" + +#include "nsScreenCocoa.h" + +class nsScreenManagerCocoa : public nsIScreenManager +{ +public: + nsScreenManagerCocoa (); + ~nsScreenManagerCocoa (); + + NS_DECL_ISUPPORTS + + NS_DECL_NSISCREENMANAGER + +private: + + nsScreenCocoa *ScreenForCocoaScreen (NSScreen *screen); + + nsCOMArray mScreenList; +}; + +#endif diff --git a/mozilla/widget/src/cocoa/nsScreenManagerCocoa.mm b/mozilla/widget/src/cocoa/nsScreenManagerCocoa.mm new file mode 100644 index 00000000000..b10eb018001 --- /dev/null +++ b/mozilla/widget/src/cocoa/nsScreenManagerCocoa.mm @@ -0,0 +1,132 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Mozilla Corporation + * Portions created by the Initial Developer are Copyright (C) 2006 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Vladimir Vukicevic + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsCOMPtr.h" + +#include "nsScreenManagerCocoa.h" + +NS_IMPL_ISUPPORTS1(nsScreenManagerCocoa, nsIScreenManager) + +nsScreenManagerCocoa::nsScreenManagerCocoa() +{ +} + +nsScreenManagerCocoa::~nsScreenManagerCocoa() +{ +} + +nsScreenCocoa* +nsScreenManagerCocoa::ScreenForCocoaScreen (NSScreen *screen) +{ + for (PRInt32 i = 0; i < mScreenList.Count(); i++) { + nsScreenCocoa* sc = NS_STATIC_CAST(nsScreenCocoa*, mScreenList.ObjectAt(i)); + + if (sc->CocoaScreen() == screen) { + // doesn't addref + return sc; + } + } + + // didn't find it; create and insert + nsCOMPtr sc = new nsScreenCocoa(screen); + mScreenList.AppendObject(sc); + return sc.get(); +} + +NS_IMETHODIMP +nsScreenManagerCocoa::ScreenForRect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, + nsIScreen **outScreen) +{ + NSEnumerator *screenEnum = [[NSScreen screens] objectEnumerator]; + NSRect inRect = { { aX, aY }, { aWidth, aHeight } }; + + while (NSScreen *screen = [screenEnum nextObject]) { + NSDictionary *desc = [screen deviceDescription]; + if ([desc objectForKey:NSDeviceIsScreen] == nil) + continue; + + if (NSContainsRect ([screen frame], inRect)) { + nsScreenCocoa *sc = ScreenForCocoaScreen (screen); + *outScreen = sc; + NS_ADDREF(*outScreen); + return NS_OK; + } + } + + *outScreen = nsnull; + return NS_OK; +} + +NS_IMETHODIMP +nsScreenManagerCocoa::GetPrimaryScreen (nsIScreen **outScreen) +{ + // 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; +} + +NS_IMETHODIMP +nsScreenManagerCocoa::GetNumberOfScreens (PRUint32 *aNumberOfScreens) +{ + NSArray *ss = [NSScreen screens]; + + *aNumberOfScreens = [ss count]; + + return NS_OK; +} + +NS_IMETHODIMP +nsScreenManagerCocoa::ScreenForNativeWidget (void *nativeWidget, nsIScreen **outScreen) +{ + NSView *view = (NSView*) nativeWidget; + + NSWindow *window = [view window]; + if (window) { + nsIScreen *screen = ScreenForCocoaScreen([window screen]); + *outScreen = screen; + NS_ADDREF(*outScreen); + return NS_OK; + } + + *outScreen = nsnull; + return NS_OK; +} diff --git a/mozilla/widget/src/cocoa/nsWidgetFactory.mm b/mozilla/widget/src/cocoa/nsWidgetFactory.mm index 2c600cda3df..f4711c4ddce 100644 --- a/mozilla/widget/src/cocoa/nsWidgetFactory.mm +++ b/mozilla/widget/src/cocoa/nsWidgetFactory.mm @@ -65,7 +65,7 @@ #include "nsSound.h" #include "nsNativeScrollbar.h" -#include "nsScreenManagerMac.h" +#include "nsScreenManagerCocoa.h" #include "nsDeviceContextSpecX.h" #include "nsDeviceContextSpecFactoryM.h" #include "nsPrintOptionsX.h" @@ -87,7 +87,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard) NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper) NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService) NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragHelperService) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerMac) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerCocoa) NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecX) NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecFactoryMac) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsX, Init) @@ -198,7 +198,7 @@ static const nsModuleComponentInfo gComponents[] = { "nsScreenManager", NS_SCREENMANAGER_CID, "@mozilla.org/gfx/screenmanager;1", - nsScreenManagerMacConstructor }, + nsScreenManagerCocoaConstructor }, { "nsDeviceContextSpec", NS_DEVICE_CONTEXT_SPEC_CID, "@mozilla.org/gfx/devicecontextspec;1", diff --git a/mozilla/widget/src/gtk2/nsScreenManagerGtk.cpp b/mozilla/widget/src/gtk2/nsScreenManagerGtk.cpp index cf1d9cc5f62..2fade9a95b9 100644 --- a/mozilla/widget/src/gtk2/nsScreenManagerGtk.cpp +++ b/mozilla/widget/src/gtk2/nsScreenManagerGtk.cpp @@ -235,3 +235,16 @@ nsScreenManagerGtk :: GetNumberOfScreens(PRUint32 *aNumberOfScreens) } // GetNumberOfScreens +NS_IMETHODIMP +nsScreenManagerGtk :: ScreenForNativeWidget (void *aWidget, nsIScreen **outScreen) +{ + // I don't know how to go from GtkWindow to nsIScreen, especially + // given xinerama and stuff, so let's just do this + gint x, y, width, height, depth; + x = y = width = height = 0; + + gdk_window_get_geometry(GDK_WINDOW(aWidget), &x, &y, &width, &height, + &depth); + gdk_window_get_origin(GDK_WINDOW(aWidget), &x, &y); + return ScreenForRect(x, y, width, height, outScreen); +} diff --git a/mozilla/widget/src/mac/nsScreenManagerMac.cpp b/mozilla/widget/src/mac/nsScreenManagerMac.cpp index e2f1a06d695..6a73e9b3cc4 100644 --- a/mozilla/widget/src/mac/nsScreenManagerMac.cpp +++ b/mozilla/widget/src/mac/nsScreenManagerMac.cpp @@ -182,3 +182,8 @@ nsScreenManagerMac :: GetNumberOfScreens(PRUint32 *aNumberOfScreens) } // GetNumberOfScreens +NS_IMETHODIMP +nsScreenManagerMac :: ScreenForNativeWidget(void *nativeWidget, nsIScreen **aScreen) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} diff --git a/mozilla/widget/src/windows/nsScreenManagerWin.cpp b/mozilla/widget/src/windows/nsScreenManagerWin.cpp index a801a99fc80..f6159a7e9cc 100644 --- a/mozilla/widget/src/windows/nsScreenManagerWin.cpp +++ b/mozilla/widget/src/windows/nsScreenManagerWin.cpp @@ -201,3 +201,11 @@ nsScreenManagerWin :: GetNumberOfScreens(PRUint32 *aNumberOfScreens) return NS_OK; } // GetNumberOfScreens + +NS_IMETHODIMP +nsScreenManagerWin :: ScreenForNativeWidget(void *aWidget, nsIScreen **outScreen) +{ + HMONITOR mon = MonitorFromWindow ((HWND) aWidget, MONITOR_DEFAULTTOPRIMARY); + *outScreen = CreateNewScreenObject (mon); + return NS_OK; +}