提交 09fd1d8c 编写于 作者: A anthony

7124428: [macosx] Frame.setExtendedState() doesn't work for undecorated windows

Summary: Emulate native NSWindow -zoom for undecorated windows
Reviewed-by: art
上级 5aa3d712
...@@ -202,6 +202,8 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -202,6 +202,8 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
private LWWindowPeer peer; private LWWindowPeer peer;
private CPlatformView contentView; private CPlatformView contentView;
private CPlatformWindow owner; private CPlatformWindow owner;
private boolean undecorated; // initialized in getInitialStyleBits()
private Rectangle normalBounds = null; // not-null only for undecorated maximized windows
public CPlatformWindow(final PeerType peerType) { public CPlatformWindow(final PeerType peerType) {
super(0, true); super(0, true);
...@@ -277,8 +279,8 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -277,8 +279,8 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
// Either java.awt.Frame or java.awt.Dialog can be undecorated, however java.awt.Window always is undecorated. // Either java.awt.Frame or java.awt.Dialog can be undecorated, however java.awt.Window always is undecorated.
{ {
final boolean undecorated = isFrame ? ((Frame)target).isUndecorated() : (isDialog ? ((Dialog)target).isUndecorated() : true); this.undecorated = isFrame ? ((Frame)target).isUndecorated() : (isDialog ? ((Dialog)target).isUndecorated() : true);
if (undecorated) styleBits = SET(styleBits, DECORATED, false); if (this.undecorated) styleBits = SET(styleBits, DECORATED, false);
} }
// Either java.awt.Frame or java.awt.Dialog can be resizable, however java.awt.Window is never resizable // Either java.awt.Frame or java.awt.Dialog can be resizable, however java.awt.Window is never resizable
...@@ -466,6 +468,30 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -466,6 +468,30 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h); nativeSetNSWindowBounds(getNSWindowPtr(), x, y, w, h);
} }
private void zoom() {
if (!undecorated) {
CWrapper.NSWindow.zoom(getNSWindowPtr());
} else {
// OS X handles -zoom incorrectly for undecorated windows
final boolean isZoomed = this.normalBounds == null;
deliverZoom(isZoomed);
Rectangle toBounds;
if (isZoomed) {
this.normalBounds = peer.getBounds();
long screen = CWrapper.NSWindow.screen(getNSWindowPtr());
toBounds = CWrapper.NSScreen.visibleFrame(screen).getBounds();
// Flip the y coordinate
Rectangle frame = CWrapper.NSScreen.frame(screen).getBounds();
toBounds.y = frame.height - toBounds.y - toBounds.height;
} else {
toBounds = normalBounds;
this.normalBounds = null;
}
setBounds(toBounds.x, toBounds.y, toBounds.width, toBounds.height);
}
}
@Override // PlatformWindow @Override // PlatformWindow
public void setVisible(boolean visible) { public void setVisible(boolean visible) {
final long nsWindowPtr = getNSWindowPtr(); final long nsWindowPtr = getNSWindowPtr();
...@@ -486,7 +512,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -486,7 +512,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
CWrapper.NSWindow.deminiaturize(nsWindowPtr); CWrapper.NSWindow.deminiaturize(nsWindowPtr);
break; break;
case Frame.MAXIMIZED_BOTH: case Frame.MAXIMIZED_BOTH:
CWrapper.NSWindow.zoom(nsWindowPtr); zoom();
break; break;
} }
} }
...@@ -526,7 +552,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -526,7 +552,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
CWrapper.NSWindow.miniaturize(nsWindowPtr); CWrapper.NSWindow.miniaturize(nsWindowPtr);
break; break;
case Frame.MAXIMIZED_BOTH: case Frame.MAXIMIZED_BOTH:
CWrapper.NSWindow.zoom(nsWindowPtr); zoom();
break; break;
} }
} }
...@@ -692,7 +718,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -692,7 +718,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
if (prevWindowState == Frame.MAXIMIZED_BOTH) { if (prevWindowState == Frame.MAXIMIZED_BOTH) {
// let's return into the normal states first // let's return into the normal states first
// the zoom call toggles between the normal and the max states // the zoom call toggles between the normal and the max states
CWrapper.NSWindow.zoom(nsWindowPtr); zoom();
} }
CWrapper.NSWindow.miniaturize(nsWindowPtr); CWrapper.NSWindow.miniaturize(nsWindowPtr);
break; break;
...@@ -701,14 +727,14 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo ...@@ -701,14 +727,14 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
// let's return into the normal states first // let's return into the normal states first
CWrapper.NSWindow.deminiaturize(nsWindowPtr); CWrapper.NSWindow.deminiaturize(nsWindowPtr);
} }
CWrapper.NSWindow.zoom(nsWindowPtr); zoom();
break; break;
case Frame.NORMAL: case Frame.NORMAL:
if (prevWindowState == Frame.ICONIFIED) { if (prevWindowState == Frame.ICONIFIED) {
CWrapper.NSWindow.deminiaturize(nsWindowPtr); CWrapper.NSWindow.deminiaturize(nsWindowPtr);
} else if (prevWindowState == Frame.MAXIMIZED_BOTH) { } else if (prevWindowState == Frame.MAXIMIZED_BOTH) {
// the zoom call toggles between the normal and the max states // the zoom call toggles between the normal and the max states
CWrapper.NSWindow.zoom(nsWindowPtr); zoom();
} }
break; break;
default: default:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册