From 8ae37850019d135f16ea933b24ed5052a605f966 Mon Sep 17 00:00:00 2001 From: Alexander Zvegintsev Date: Thu, 3 Nov 2016 03:49:42 +0300 Subject: [PATCH] 8143914: Provide Mac-specific fullscreen support Reviewed-by: serb, ssadetsky --- .../sun/lwawt/macosx/CPlatformWindow.java | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java index cbbf3b193e9..d93b4bbcf21 100644 --- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java +++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java @@ -25,10 +25,12 @@ package sun.lwawt.macosx; +import com.apple.eawt.FullScreenAdapter; +import com.apple.eawt.FullScreenUtilities; +import com.apple.eawt.event.FullScreenEvent; import java.awt.*; import java.awt.Dialog.ModalityType; import java.awt.event.*; -import java.awt.peer.WindowPeer; import java.beans.*; import java.lang.reflect.InvocationTargetException; @@ -44,6 +46,7 @@ import sun.util.logging.PlatformLogger; import com.apple.laf.*; import com.apple.laf.ClientPropertyApplicator.Property; import com.sun.awt.AWTUtilities; +import sun.lwawt.LWWindowPeer.PeerType; public class CPlatformWindow extends CFRetainedResource implements PlatformWindow { private native long nativeCreateNSWindow(long nsViewPtr,long ownerPtr, long styleBits, double x, double y, double w, double h); @@ -175,10 +178,24 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo c.setStyleBits(CLOSEABLE, Boolean.parseBoolean(value.toString())); }}, new Property(WINDOW_ZOOMABLE) { public void applyProperty(final CPlatformWindow c, final Object value) { - c.setStyleBits(ZOOMABLE, Boolean.parseBoolean(value.toString())); + boolean zoomable = Boolean.parseBoolean(value.toString()); + if (c.target instanceof RootPaneContainer + && c.getPeer().getPeerType() == PeerType.FRAME) { + if (c.isInFullScreen && !zoomable) { + c.toggleFullScreen(); + } + } + c.setStyleBits(ZOOMABLE, zoomable); }}, new Property(WINDOW_FULLSCREENABLE) { public void applyProperty(final CPlatformWindow c, final Object value) { - c.setStyleBits(FULLSCREENABLE, Boolean.parseBoolean(value.toString())); + boolean fullscrenable = Boolean.parseBoolean(value.toString()); + if (c.target instanceof RootPaneContainer + && c.getPeer().getPeerType() == PeerType.FRAME) { + if (c.isInFullScreen && !fullscrenable) { + c.toggleFullScreen(); + } + } + c.setStyleBits(FULLSCREENABLE, fullscrenable); }}, new Property(WINDOW_SHADOW_REVALIDATE_NOW) { public void applyProperty(final CPlatformWindow c, final Object value) { nativeRevalidateNSWindowShadow(c.getNSWindowPtr()); @@ -210,6 +227,8 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo private volatile boolean isFullScreenMode; private boolean isFullScreenAnimationOn; + private volatile boolean isInFullScreen; + private Window target; private LWWindowPeer peer; protected CPlatformView contentView; @@ -308,6 +327,8 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo styleBits = SET(styleBits, RESIZABLE, resizable); if (!resizable) { styleBits = SET(styleBits, ZOOMABLE, false); + } else { + setCanFullscreen(true); } } @@ -680,9 +701,25 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo updateFocusabilityForAutoRequestFocus(true); } + private void setCanFullscreen(final boolean canFullScreen) { + if (target instanceof RootPaneContainer + && getPeer().getPeerType() == PeerType.FRAME) { + + if (isInFullScreen && !canFullScreen) { + toggleFullScreen(); + } + + final RootPaneContainer rpc = (RootPaneContainer) target; + rpc.getRootPane().putClientProperty( + CPlatformWindow.WINDOW_FULLSCREENABLE, canFullScreen); + } + } + @Override public void setResizable(final boolean resizable) { + setCanFullscreen(resizable); setStyleBits(RESIZABLE, resizable); + setStyleBits(ZOOMABLE, resizable); } @Override @@ -1074,6 +1111,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo } private void windowDidEnterFullScreen() { + isInFullScreen = true; isFullScreenAnimationOn = false; } @@ -1082,6 +1120,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo } private void windowDidExitFullScreen() { + isInFullScreen = false; isFullScreenAnimationOn = false; } }