--- old/src/java.desktop/macosx/classes/sun/lwawt/LWLightweightFramePeer.java 2017-09-21 15:24:07.000000000 +0530 +++ new/src/java.desktop/macosx/classes/sun/lwawt/LWLightweightFramePeer.java 2017-09-21 15:24:07.000000000 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,10 +34,11 @@ import java.awt.event.FocusEvent; import sun.awt.LightweightFrame; +import sun.awt.OverrideNativeWindowHandle; import sun.swing.JLightweightFrame; import sun.swing.SwingAccessor; -public class LWLightweightFramePeer extends LWWindowPeer { +public class LWLightweightFramePeer extends LWWindowPeer implements OverrideNativeWindowHandle { public LWLightweightFramePeer(LightweightFrame target, PlatformComponent platformComponent, @@ -116,4 +117,15 @@ public void updateCursorImmediately() { SwingAccessor.getJLightweightFrameAccessor().updateCursor((JLightweightFrame)getLwTarget()); } + + private long overridenWindowHandle = 0L; + + @Override + public void overrideWindowHandle(final long handle) { + this.overridenWindowHandle = handle; + } + + public long getOverridenWindowHandle() { + return overridenWindowHandle; + } } --- old/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java 2017-09-21 15:24:08.000000000 +0530 +++ new/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java 2017-09-21 15:24:08.000000000 +0530 @@ -25,9 +25,6 @@ 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.*; @@ -607,6 +604,20 @@ if (!isKeyWindow) { CWrapper.NSWindow.makeKeyWindow(ptr); } + + if (owner != null + && owner.getPeer() instanceof LWLightweightFramePeer) { + LWLightweightFramePeer peer = + (LWLightweightFramePeer) owner.getPeer(); + + long ownerWindowPtr = peer.getOverridenWindowHandle(); + if (ownerWindowPtr != 0) { + //Place window above JavaFX stage + CWrapper.NSWindow.addChildWindow( + ownerWindowPtr, ptr, + CWrapper.NSWindow.NSWindowAbove); + } + } }); } else { execute(ptr->{ --- old/src/java.desktop/share/classes/sun/swing/JLightweightFrame.java 2017-09-21 15:24:09.000000000 +0530 +++ new/src/java.desktop/share/classes/sun/swing/JLightweightFrame.java 2017-09-21 15:24:09.000000000 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -54,6 +54,7 @@ import sun.awt.AWTAccessor; import sun.awt.DisplayChangedListener; import sun.awt.LightweightFrame; +import sun.awt.OverrideNativeWindowHandle; import sun.security.action.GetPropertyAction; import sun.swing.SwingUtilities2.RepaintListener; @@ -104,6 +105,13 @@ public void updateCursor(JLightweightFrame frame) { frame.updateClientCursor(); } + + @Override + public void overrideNativeWindowHandle(JLightweightFrame frame, long ptr) { + if (frame != null) { + frame.overrideNativeWindowHandle(ptr); + } + } }); copyBufferEnabled = "true".equals(AccessController. doPrivileged(new GetPropertyAction("swing.jlf.copyBufferEnabled", "true"))); @@ -526,6 +534,13 @@ } } + private void overrideNativeWindowHandle(long handle) { + final Object peer = AWTAccessor.getComponentAccessor().getPeer(this); + if (peer instanceof OverrideNativeWindowHandle) { + ((OverrideNativeWindowHandle) peer).overrideWindowHandle(handle); + } + } + public T createDragGestureRecognizer( Class abstractRecognizerClass, DragSource ds, Component c, int srcActions, --- old/src/java.desktop/share/classes/sun/swing/SwingAccessor.java 2017-09-21 15:24:09.000000000 +0530 +++ new/src/java.desktop/share/classes/sun/swing/SwingAccessor.java 2017-09-21 15:24:09.000000000 +0530 @@ -89,6 +89,13 @@ * Notifies the JLightweight frame that it needs to update a cursor */ void updateCursor(JLightweightFrame frame); + + /** + * Notifies the JLightweight frame embed to JavaFX stage about + * its native toplevel window change + */ + + void overrideNativeWindowHandle(JLightweightFrame frame, long ptr); } /** --- old/src/java.desktop/unix/classes/sun/awt/X11/XLightweightFramePeer.java 2017-09-21 15:24:10.000000000 +0530 +++ new/src/java.desktop/unix/classes/sun/awt/X11/XLightweightFramePeer.java 2017-09-21 15:24:10.000000000 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,10 +29,11 @@ import java.awt.dnd.DropTarget; import sun.awt.LightweightFrame; +import sun.awt.OverrideNativeWindowHandle; import sun.swing.JLightweightFrame; import sun.swing.SwingAccessor; -public class XLightweightFramePeer extends XFramePeer { +public class XLightweightFramePeer extends XFramePeer implements OverrideNativeWindowHandle { XLightweightFramePeer(LightweightFrame target) { super(target); @@ -80,4 +81,15 @@ public void removeDropTarget(DropTarget dt) { getLwTarget().removeDropTarget(dt); } + + private long overridenWindowHandle = 0L; + + @Override + public void overrideWindowHandle(long handle) { + overridenWindowHandle = handle; + } + + public long getOverridenWindowHandle() { + return overridenWindowHandle; + } } --- old/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java 2017-09-21 15:24:11.000000000 +0530 +++ new/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java 2017-09-21 15:24:11.000000000 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1689,6 +1689,14 @@ tpw = XlibUtil.getParentWindow(tpw); parent = XToolkit.windowToXWindow(tpw); } + + if (parent instanceof XLightweightFramePeer) { + XLightweightFramePeer peer = (XLightweightFramePeer) parent; + long ownerWindowPtr = peer.getOverridenWindowHandle(); + if (ownerWindowPtr != 0) { + tpw = ownerWindowPtr; + } + } XlibWrapper.XSetTransientFor(XToolkit.getDisplay(), bpw, tpw); window.curRealTransientFor = parent; } --- old/src/java.desktop/windows/classes/sun/awt/windows/WLightweightFramePeer.java 2017-09-21 15:24:12.000000000 +0530 +++ new/src/java.desktop/windows/classes/sun/awt/windows/WLightweightFramePeer.java 2017-09-21 15:24:12.000000000 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,10 +32,11 @@ import java.awt.event.MouseEvent; import sun.awt.LightweightFrame; +import sun.awt.OverrideNativeWindowHandle; import sun.swing.JLightweightFrame; import sun.swing.SwingAccessor; -public class WLightweightFramePeer extends WFramePeer { +public class WLightweightFramePeer extends WFramePeer implements OverrideNativeWindowHandle { public WLightweightFramePeer(LightweightFrame target) { super(target); @@ -50,6 +51,13 @@ return getLwTarget().getGraphics(); } + private native void overrideNativeHandle(long hwnd); + + @Override + public void overrideWindowHandle(final long handle) { + overrideNativeHandle(handle); + } + @Override public void show() { super.show(); --- old/src/java.desktop/windows/native/libawt/windows/awt_Dialog.cpp 2017-09-21 15:24:13.000000000 +0530 +++ new/src/java.desktop/windows/native/libawt/windows/awt_Dialog.cpp 2017-09-21 15:24:12.000000000 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -117,7 +117,8 @@ if (parent != NULL) { JNI_CHECK_PEER_GOTO(parent, done); awtParent = (AwtWindow *)(JNI_GET_PDATA(parent)); - hwndParent = awtParent->GetHWnd(); + HWND oHWnd = awtParent->GetOverridenHWnd(); + hwndParent = oHWnd ? oHWnd : awtParent->GetHWnd(); } else { // There is no way to prevent a parentless dialog from showing on // the taskbar other than to specify an invisible parent and set --- old/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp 2017-09-21 15:24:13.000000000 +0530 +++ new/src/java.desktop/windows/native/libawt/windows/awt_Window.cpp 2017-09-21 15:24:13.000000000 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -164,6 +164,11 @@ jfloat scaleY; }; +struct OverrideHandle { + jobject frame; + HWND handle; +}; + /************************************************************************ * AwtWindow fields */ @@ -242,6 +247,7 @@ prevScaleRec.screen = -1; prevScaleRec.scaleX = -1.0f; prevScaleRec.scaleY = -1.0f; + m_overridenHwnd = NULL; } AwtWindow::~AwtWindow() @@ -2571,6 +2577,24 @@ delete rfs; } +void AwtWindow::_OverrideHandle(void *param) +{ + JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); + + OverrideHandle* oh = (OverrideHandle *) param; + jobject self = oh->frame; + AwtWindow *f = NULL; + + PDATA pData; + JNI_CHECK_PEER_GOTO(self, ret); + f = (AwtWindow *)pData; + f->OverrideHWnd(oh->handle); +ret: + env->DeleteGlobalRef(self); + + delete oh; +} + /* * This is AwtWindow-specific function that is not intended for reusing */ @@ -3949,4 +3973,25 @@ CATCH_BAD_ALLOC; } + +/* + * Class: sun_awt_windows_WLightweightFramePeer + * Method: overrideNativeHandle + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_sun_awt_windows_WLightweightFramePeer_overrideNativeHandle + (JNIEnv *env, jobject self, jlong hwnd) +{ + TRY; + + OverrideHandle *oh = new OverrideHandle; + oh->frame = env->NewGlobalRef(self); + oh->handle = (HWND) hwnd; + + AwtToolkit::GetInstance().SyncCall(AwtFrame::_OverrideHandle, oh); + // global ref and oh are deleted in _OverrideHandle() + + CATCH_BAD_ALLOC; +} + } /* extern "C" */ --- old/src/java.desktop/windows/native/libawt/windows/awt_Window.h 2017-09-21 15:24:14.000000000 +0530 +++ new/src/java.desktop/windows/native/libawt/windows/awt_Window.h 2017-09-21 15:24:14.000000000 +0530 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -245,6 +245,7 @@ static void _SetFullScreenExclusiveModeState(void* param); static void _GetNativeWindowSize(void* param); static void _WindowDPIChange(void* param); + static void _OverrideHandle(void *param); inline static BOOL IsResizing() { return sm_resizing; @@ -260,6 +261,9 @@ static void FocusedWindowChanged(HWND from, HWND to); + inline HWND GetOverridenHWnd() { return m_overridenHwnd; } + inline void OverrideHWnd(HWND hwnd) { m_overridenHwnd = hwnd; } + private: static int ms_instanceCounter; static HHOOK ms_hCBTFilter; @@ -311,6 +315,9 @@ // The tooltip that appears when hovering the icon HWND securityTooltipWindow; + //Allows substitute parent window with JavaFX stage to make it below a dialog + HWND m_overridenHwnd; + UINT warningWindowWidth; UINT warningWindowHeight; void InitSecurityWarningSize(JNIEnv *env); --- /dev/null 2017-09-21 15:24:15.000000000 +0530 +++ new/src/java.desktop/share/classes/sun/awt/OverrideNativeWindowHandle.java 2017-09-21 15:24:15.000000000 +0530 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package sun.awt; + +/** + * Used for replacing window owner with another non-Swing window. + * It is useful in case of JavaFX-Swing interop: + * it helps to keep Swing dialogs above its owner(JavaFX stage). + */ + +public interface OverrideNativeWindowHandle { + + /** + * Replaces owner window with a window with provided handle. + * @param handle native window handle + */ + void overrideWindowHandle(final long handle); +}