mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Need to translate from Cocoa to Gecko coordinates in nsScreen[Manager]Cocoa. Original patch by Sylvain Pasche. b=370106 r=josh sr=pav
This commit is contained in:
parent
28377178b5
commit
b9495cf989
@ -100,6 +100,7 @@ CMMSRCS = \
|
||||
nsDragService.mm \
|
||||
nsToolkit.mm \
|
||||
nsAppShell.mm \
|
||||
nsCocoaUtils.mm \
|
||||
nsCocoaWindow.mm \
|
||||
nsChildView.mm \
|
||||
nsWindowMap.mm \
|
||||
|
@ -63,6 +63,7 @@
|
||||
#include "nsDragService.h"
|
||||
#include "nsCursorManager.h"
|
||||
#include "nsWindowMap.h"
|
||||
#include "nsCocoaUtils.h"
|
||||
|
||||
#include "gfxContext.h"
|
||||
#include "gfxQuartzSurface.h"
|
||||
@ -183,14 +184,9 @@ ConvertGeckoRectToMacRect(const nsRect& aRect, Rect& outMacRect)
|
||||
// Flips a screen coordinate from a point in the cocoa coordinate system (bottom-left rect) to a point
|
||||
// that is a "flipped" cocoa coordinate system (starts in the top-left).
|
||||
static inline void
|
||||
FlipCocoaScreenCoordinate (NSPoint &inPoint) {
|
||||
// need to flip the point relative to the main screen
|
||||
if ([[NSScreen screens] count] > 0) { // paranoia
|
||||
// "global" coords are relative to the upper left of the main screen,
|
||||
// which is the first screen in the array (not [NSScreen mainScreen]).
|
||||
NSRect topLeftScreenFrame = [[[NSScreen screens] objectAtIndex:0] frame];
|
||||
inPoint.y = NSMaxY(topLeftScreenFrame) - inPoint.y;
|
||||
}
|
||||
FlipCocoaScreenCoordinate (NSPoint &inPoint)
|
||||
{
|
||||
inPoint.y = HighestPointOnAnyScreen() - inPoint.y;
|
||||
}
|
||||
|
||||
|
||||
|
64
widget/src/cocoa/nsCocoaUtils.h
Normal file
64
widget/src/cocoa/nsCocoaUtils.h
Normal file
@ -0,0 +1,64 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** 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
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Josh Aas <josh@mozilla.com>
|
||||
* Sylvain Pasche <sylvain.pasche@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either 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 nsCocoaUtils_h_
|
||||
#define nsCocoaUtils_h_
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "nsRect.h"
|
||||
|
||||
// get the highest point on any screen
|
||||
float HighestPointOnAnyScreen();
|
||||
|
||||
/*
|
||||
* Gecko rects (nsRect) contain an origin (x,y) in a coordinate
|
||||
* system with (0,0) in the top-left of the screen. Cocoa rects
|
||||
* (NSRect) contain an origin (x,y) in a coordinate system with
|
||||
* (0,0) in the bottom-left of the screen. Both nsRect and NSRect
|
||||
* contain width/height info, with no difference in their use.
|
||||
*/
|
||||
NSRect geckoRectToCocoaRect(const nsRect &geckoRect);
|
||||
|
||||
//
|
||||
// See explanation for geckoRectToCocoaRect, guess what this does...
|
||||
//
|
||||
nsRect cocoaRectToGeckoRect(const NSRect &cocoaRect);
|
||||
|
||||
#endif // nsCocoaUtils_h_
|
76
widget/src/cocoa/nsCocoaUtils.mm
Normal file
76
widget/src/cocoa/nsCocoaUtils.mm
Normal file
@ -0,0 +1,76 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** 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
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Josh Aas <josh@mozilla.com>
|
||||
* Sylvain Pasche <sylvain.pasche@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either 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 "nsCocoaUtils.h"
|
||||
|
||||
float HighestPointOnAnyScreen()
|
||||
{
|
||||
float highestScreenPoint = 0.0;
|
||||
NSArray* allScreens = [NSScreen screens];
|
||||
for (unsigned int i = 0; i < [allScreens count]; i++) {
|
||||
NSRect currScreenFrame = [[allScreens objectAtIndex:i] frame];
|
||||
float currScreenHighestPoint = currScreenFrame.origin.y + currScreenFrame.size.height;
|
||||
if (currScreenHighestPoint > highestScreenPoint)
|
||||
highestScreenPoint = currScreenHighestPoint;
|
||||
}
|
||||
return highestScreenPoint;
|
||||
}
|
||||
|
||||
|
||||
NSRect geckoRectToCocoaRect(const nsRect &geckoRect)
|
||||
{
|
||||
// We only need to change the Y coordinate by starting with the screen
|
||||
// height, subtracting the gecko Y coordinate, and subtracting the height.
|
||||
return NSMakeRect(geckoRect.x,
|
||||
HighestPointOnAnyScreen() - geckoRect.y - geckoRect.height,
|
||||
geckoRect.width,
|
||||
geckoRect.height);
|
||||
}
|
||||
|
||||
|
||||
nsRect cocoaRectToGeckoRect(const NSRect &cocoaRect)
|
||||
{
|
||||
// We only need to change the Y coordinate by starting with the screen
|
||||
// height and subtracting both the cocoa y origin and the height of the
|
||||
// cocoa rect.
|
||||
return nsRect((nscoord)cocoaRect.origin.x,
|
||||
(nscoord)(HighestPointOnAnyScreen() - (cocoaRect.origin.y + cocoaRect.size.height)),
|
||||
(nscoord)cocoaRect.size.width,
|
||||
(nscoord)cocoaRect.size.height);
|
||||
}
|
@ -42,6 +42,7 @@
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsIRollupListener.h"
|
||||
#include "nsCocoaUtils.h"
|
||||
#include "nsChildView.h"
|
||||
#include "nsIAppShell.h"
|
||||
#include "nsIAppShellService.h"
|
||||
@ -62,55 +63,6 @@ extern BOOL gSomeMenuBarPainted;
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsCocoaWindow, Inherited, nsPIWidgetCocoa)
|
||||
|
||||
|
||||
// get the highest point on any screen
|
||||
static float HighestPointOnAnyScreen()
|
||||
{
|
||||
float highestScreenPoint = 0.0;
|
||||
NSArray* allScreens = [NSScreen screens];
|
||||
for (unsigned int i = 0; i < [allScreens count]; i++) {
|
||||
NSRect currScreenFrame = [[allScreens objectAtIndex:i] frame];
|
||||
float currScreenHighestPoint = currScreenFrame.origin.y + currScreenFrame.size.height;
|
||||
if (currScreenHighestPoint > highestScreenPoint)
|
||||
highestScreenPoint = currScreenHighestPoint;
|
||||
}
|
||||
return highestScreenPoint;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Gecko rects (nsRect) contain an origin (x,y) in a coordinate
|
||||
* system with (0,0) in the top-left of the screen. Cocoa rects
|
||||
* (NSRect) contain an origin (x,y) in a coordinate system with
|
||||
* (0,0) in the bottom-left of the screen. Both nsRect and NSRect
|
||||
* contain width/height info, with no difference in their use.
|
||||
*/
|
||||
static NSRect geckoRectToCocoaRect(const nsRect &geckoRect)
|
||||
{
|
||||
// We only need to change the Y coordinate by starting with the screen
|
||||
// height, subtracting the gecko Y coordinate, and subtracting the
|
||||
// height.
|
||||
return NSMakeRect(geckoRect.x,
|
||||
HighestPointOnAnyScreen() - geckoRect.y - geckoRect.height,
|
||||
geckoRect.width,
|
||||
geckoRect.height);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// See explanation for geckoRectToCocoaRect, guess what this does...
|
||||
//
|
||||
static nsRect cocoaRectToGeckoRect(const NSRect &cocoaRect)
|
||||
{
|
||||
// We only need to change the Y coordinate by starting with the screen
|
||||
// height, subtracting the gecko Y coordinate, and subtracting the
|
||||
// height.
|
||||
return nsRect((nscoord)cocoaRect.origin.x,
|
||||
(nscoord)(HighestPointOnAnyScreen() - (cocoaRect.origin.y + cocoaRect.size.height)),
|
||||
(nscoord)cocoaRect.size.width,
|
||||
(nscoord)cocoaRect.size.height);
|
||||
}
|
||||
|
||||
|
||||
// returns the height of the title bar for a given cocoa NSWindow
|
||||
static float titleBarHeightForWindow(NSWindow* aWindow)
|
||||
{
|
||||
@ -687,13 +639,10 @@ NS_IMETHODIMP nsCocoaWindow::Move(PRInt32 aX, PRInt32 aY)
|
||||
}
|
||||
}
|
||||
|
||||
NSPoint coord = {aX, aY};
|
||||
|
||||
// the point we have assumes that the screen origin is the top-left. Well,
|
||||
// it's not. Use the screen object to convert.
|
||||
//FIXME -- doesn't work on monitors other than primary
|
||||
NSRect screenRect = [[NSScreen mainScreen] frame];
|
||||
coord.y = (screenRect.origin.y + screenRect.size.height) - coord.y;
|
||||
// the point we have is in Gecko coordinates (origin top-left). Convert
|
||||
// it to Cocoa ones (origin bottom-left).
|
||||
NSPoint coord = {aX, HighestPointOnAnyScreen() - aY};
|
||||
|
||||
//printf("final coords %f %f\n", coord.x, coord.y);
|
||||
//printf("- window coords before %f %f\n", [mWindow frame].origin.x, [mWindow frame].origin.y);
|
||||
[mWindow setFrameTopLeftPoint:coord];
|
||||
|
@ -271,7 +271,7 @@ NS_IMETHODIMP nsDeviceContextSpecX::GetSurfaceForPrinter(gfxASurface **surface)
|
||||
if (context)
|
||||
newSurface = new gfxQuartzSurface(context, PR_FALSE, gfxSize(width, height));
|
||||
else
|
||||
newSurface = new gfxImageSurface(gfxIntSize(width, height), gfxASurface::ImageFormatARGB32);
|
||||
newSurface = new gfxImageSurface(gfxIntSize((PRInt32)width, (PRInt32)height), gfxASurface::ImageFormatARGB32);
|
||||
|
||||
if (!newSurface)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -159,8 +159,8 @@ protected:
|
||||
PRPackedBool mDestroyHandlerCalled;
|
||||
PRPackedBool mNeedsRebuild;
|
||||
PRPackedBool mConstructed;
|
||||
PRPackedBool mXBLAttached;
|
||||
PRPackedBool mVisible; // are we visible to the user?
|
||||
PRPackedBool mXBLAttached;
|
||||
};
|
||||
|
||||
#endif // nsMenuX_h_
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "nsUnitConversion.h"
|
||||
|
||||
#include "nsScreenCocoa.h"
|
||||
#include "nsCocoaUtils.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsScreenCocoa, nsIScreen)
|
||||
|
||||
@ -55,12 +56,12 @@ nsScreenCocoa::~nsScreenCocoa ()
|
||||
NS_IMETHODIMP
|
||||
nsScreenCocoa::GetRect(PRInt32 *outX, PRInt32 *outY, PRInt32 *outWidth, PRInt32 *outHeight)
|
||||
{
|
||||
NSRect r = [mScreen frame];
|
||||
nsRect r = cocoaRectToGeckoRect([mScreen frame]);
|
||||
|
||||
*outX = NSToIntFloor(r.origin.x);
|
||||
*outY = NSToIntFloor(r.origin.y);
|
||||
*outWidth = NSToIntFloor(r.size.width);
|
||||
*outHeight = NSToIntFloor(r.size.height);
|
||||
*outX = r.x;
|
||||
*outY = r.y;
|
||||
*outWidth = r.width;
|
||||
*outHeight = r.height;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -68,12 +69,12 @@ nsScreenCocoa::GetRect(PRInt32 *outX, PRInt32 *outY, PRInt32 *outWidth, PRInt32
|
||||
NS_IMETHODIMP
|
||||
nsScreenCocoa::GetAvailRect(PRInt32 *outX, PRInt32 *outY, PRInt32 *outWidth, PRInt32 *outHeight)
|
||||
{
|
||||
NSRect r = [mScreen visibleFrame];
|
||||
nsRect r = cocoaRectToGeckoRect([mScreen visibleFrame]);
|
||||
|
||||
*outX = NSToIntFloor(r.origin.x);
|
||||
*outY = NSToIntFloor(r.origin.y);
|
||||
*outWidth = NSToIntFloor(r.size.width);
|
||||
*outHeight = NSToIntFloor(r.size.height);
|
||||
*outX = r.x;
|
||||
*outY = r.y;
|
||||
*outWidth = r.width;
|
||||
*outHeight = r.height;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsScreenManagerCocoa.h"
|
||||
#include "nsCocoaUtils.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsScreenManagerCocoa, nsIScreenManager)
|
||||
|
||||
@ -73,7 +74,7 @@ nsScreenManagerCocoa::ScreenForRect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRI
|
||||
nsIScreen **outScreen)
|
||||
{
|
||||
NSEnumerator *screenEnum = [[NSScreen screens] objectEnumerator];
|
||||
NSRect inRect = { { aX, aY }, { aWidth, aHeight } };
|
||||
NSRect inRect = geckoRectToCocoaRect(nsRect(aX, aY, aWidth, aHeight));
|
||||
|
||||
while (NSScreen *screen = [screenEnum nextObject]) {
|
||||
NSDictionary *desc = [screen deviceDescription];
|
||||
|
Loading…
Reference in New Issue
Block a user