diff options
author | Sven Gothel <[email protected]> | 2013-10-03 15:19:29 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-10-03 15:19:29 +0200 |
commit | 7f7275834922b9c30aec6520dc5c5f20939a49d8 (patch) | |
tree | 60ba99266d9a869c5f727ecd91c241dce24ca528 /src/nativewindow/classes | |
parent | 60968cdc388b6a7464da3a6b58f25cb61e29f681 (diff) |
Bug 816 (OSX CALayer pos): Fix location on 'inner CALayer' calculation
'inner CALayer' is the outter AWT Window client space (content).
+++
Pseudo-Code:
p0 = c.locationOnScreen();
p0 -= c.getOutterComp.getPos();
p0 -= c.getOutterComp.getInsets();
Where 'locationOnScreen()' is:
p0 = 0/0;
while( null != c ) {
p0 += c.getPos();
}
+++
JAWTWindow.getLocationOnScreenNonBlocking(..) validated against
AWT's Component.getLocationOnScreen() - OK for all use-cases.
(Validation enabled w/ DEBUG)
All unit tests manually validated on OSX 10.7 w/ jdk7u40.
Diffstat (limited to 'src/nativewindow/classes')
3 files changed, 43 insertions, 21 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java index 5b5df7f68..53eb985b2 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java @@ -61,7 +61,6 @@ import javax.media.nativewindow.util.InsetsImmutable; import javax.media.nativewindow.util.Point; import javax.media.nativewindow.util.Rectangle; import javax.media.nativewindow.util.RectangleImmutable; -import javax.swing.JRootPane; import jogamp.nativewindow.SurfaceUpdatedHelper; import jogamp.nativewindow.awt.AWTMisc; @@ -574,23 +573,26 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, protected abstract Point getLocationOnScreenNativeImpl(int x, int y); protected static Component getLocationOnScreenNonBlocking(Point storage, Component comp) { + final java.awt.Insets insets = new java.awt.Insets(0, 0, 0, 0); // DEBUG Component last = null; while(null != comp) { final int dx = comp.getX(); final int dy = comp.getY(); if( DEBUG ) { - final java.awt.Insets ins = AWTMisc.getInsets(comp); - System.err.print("LOS: "+storage+" + "+comp.getClass().getName()+"["+dx+"/"+dy+", vis "+comp.isVisible()+", ins "+ins+"] -> "); + final java.awt.Insets ins = AWTMisc.getInsets(comp, false); + if( null != ins ) { + insets.bottom += ins.bottom; + insets.top += ins.top; + insets.left += ins.left; + insets.right += ins.right; + } + System.err.print("LOS: "+storage+" + "+comp.getClass().getName()+"["+dx+"/"+dy+", vis "+comp.isVisible()+", ins "+ins+" -> "+insets+"] -> "); } storage.translate(dx, dy); if( DEBUG ) { System.err.println(storage); } last = comp; - if( comp instanceof JRootPane ) { - // LW JRootPane is considered a top-level component! - break; - } comp = comp.getParent(); } return last; diff --git a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java index 611c13a22..23c48d20e 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java +++ b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java @@ -82,8 +82,10 @@ public class AWTMisc { * This is due to <i>experience</i> that <i>some</i> JRootPane's * do not expose valid insets value. * </p> + * @param topLevelOnly if true only returns insets of top-level components, i.e. Window and JRootPanel, + * otherwise for JComponent as well. */ - public static Insets getInsets(Component c) { + public static Insets getInsets(Component c, boolean topLevelOnly) { if( c instanceof Window ) { return ((Window)c).getInsets(); } @@ -94,7 +96,7 @@ public class AWTMisc { } return ((JRootPane)c).getInsets(); } - if( c instanceof JComponent ) { + if( !topLevelOnly && c instanceof JComponent ) { return ((JComponent)c).getInsets(); } return null; diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java index 0d81274ca..833e6cd24 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java @@ -113,15 +113,24 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { // See: {@link JAWTWindow#JAWT_OSX_CALAYER_QUIRK_LAYOUT} final Point p0 = new Point(); final Component outterComp = getLocationOnScreenNonBlocking(p0, component); - final java.awt.Insets ins = AWTMisc.getInsets(outterComp); - if(null != ins) { - p0.translate(-ins.left, -ins.top); + final java.awt.Insets outterInsets = AWTMisc.getInsets(outterComp, true); + final Point p1 = (Point)p0.cloneMutable(); + p1.translate(-outterComp.getX(), -outterComp.getY()); + if( null != outterInsets ) { + p1.translate(-outterInsets.left, -outterInsets.top); } + if( DEBUG ) { - final java.awt.Point wP0 = outterComp.getLocationOnScreen(); - System.err.println("JAWTWindow.attachSurfaceHandleImpl: "+toHexString(layerHandle) + ", wP0 "+wP0+"[ins "+ins+"], p0 "+p0+", bounds "+bounds); + final java.awt.Point pA0 = component.getLocationOnScreen(); + final Point pA1 = new Point(pA0.x, pA0.y); + pA1.translate(-outterComp.getX(), -outterComp.getY()); + if( null != outterInsets ) { + pA1.translate(-outterInsets.left, -outterInsets.top); + } + System.err.println("JAWTWindow.attachSurfaceLayerImpl: "+toHexString(layerHandle) + ", [ins "+outterInsets+"], pA "+pA0+" -> "+pA1+ + ", p0 "+p0+" -> "+p1+", bounds "+bounds); } - OSXUtil.AddCASublayer(rootSurfaceLayer, layerHandle, p0.getX(), p0.getY(), getWidth(), getHeight(), JAWTUtil.getOSXCALayerQuirks()); + OSXUtil.AddCASublayer(rootSurfaceLayer, layerHandle, p1.getX(), p1.getY(), getWidth(), getHeight(), JAWTUtil.getOSXCALayerQuirks()); } } ); } @@ -135,15 +144,24 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { // See: {@link JAWTWindow#JAWT_OSX_CALAYER_QUIRK_LAYOUT} final Point p0 = new Point(); final Component outterComp = getLocationOnScreenNonBlocking(p0, component); - final java.awt.Insets ins = AWTMisc.getInsets(outterComp); - if( null != ins ) { - p0.translate(-ins.left, -ins.top); + final java.awt.Insets outterInsets = AWTMisc.getInsets(outterComp, true); + final Point p1 = (Point)p0.cloneMutable(); + p1.translate(-outterComp.getX(), -outterComp.getY()); + if( null != outterInsets ) { + p1.translate(-outterInsets.left, -outterInsets.top); } + if( DEBUG ) { - final java.awt.Point wP0 = outterComp.getLocationOnScreen(); - System.err.println("JAWTWindow.layoutSurfaceLayerImpl: "+toHexString(layerHandle) + ", wP0 "+wP0+"[ins "+ins+"], p0 "+p0+", bounds "+bounds); + final java.awt.Point pA0 = component.getLocationOnScreen(); + final Point pA1 = new Point(pA0.x, pA0.y); + pA1.translate(-outterComp.getX(), -outterComp.getY()); + if( null != outterInsets ) { + pA1.translate(-outterInsets.left, -outterInsets.top); + } + System.err.println("JAWTWindow.layoutSurfaceLayerImpl: "+toHexString(layerHandle) + ", [ins "+outterInsets+"], pA "+pA0+" -> "+pA1+ + ", p0 "+p0+" -> "+p1+", bounds "+bounds); } - OSXUtil.FixCALayerLayout(rootSurfaceLayer, layerHandle, p0.getX(), p0.getY(), getWidth(), getHeight(), caLayerQuirks); + OSXUtil.FixCALayerLayout(rootSurfaceLayer, layerHandle, p1.getX(), p1.getY(), getWidth(), getHeight(), caLayerQuirks); } } |