8038919: Requesting focus to a modeless dialog doesn't work on Safari
Reviewed-by: ant, serb
--- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Fri Oct 10 09:09:06 2014 -0700
+++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Fri Oct 10 20:14:42 2014 +0400
@@ -676,6 +676,13 @@
@Override // PlatformWindow
public void toFront() {
final long nsWindowPtr = getNSWindowPtr();
+ LWCToolkit lwcToolkit = (LWCToolkit) Toolkit.getDefaultToolkit();
+ Window w = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
+ if( w != null
+ && ((LWWindowPeer)w.getPeer()).getPeerType() == LWWindowPeer.PeerType.EMBEDDED_FRAME
+ && !lwcToolkit.isApplicationActive()) {
+ lwcToolkit.activateApplicationIgnoringOtherApps();
+ }
updateFocusabilityForAutoRequestFocus(false);
nativePushNSWindowToFront(nsWindowPtr);
updateFocusabilityForAutoRequestFocus(true);
--- a/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Fri Oct 10 09:09:06 2014 -0700
+++ b/jdk/src/java.desktop/macosx/classes/sun/lwawt/macosx/LWCToolkit.java Fri Oct 10 20:14:42 2014 +0400
@@ -811,6 +811,11 @@
*/
public static native boolean isEmbedded();
+ /*
+ * Activates application ignoring other apps.
+ */
+ public native void activateApplicationIgnoringOtherApps();
+
/************************
* Native methods section
************************/
--- a/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m Fri Oct 10 09:09:06 2014 -0700
+++ b/jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/LWCToolkit.m Fri Oct 10 20:14:42 2014 +0400
@@ -606,6 +606,23 @@
return active;
}
+/*
+ * Class: sun_lwawt_macosx_LWCToolkit
+ * Method: activateApplicationIgnoringOtherApps
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_sun_lwawt_macosx_LWCToolkit_activateApplicationIgnoringOtherApps
+(JNIEnv *env, jclass clazz)
+{
+ JNF_COCOA_ENTER(env);
+ [ThreadUtilities performOnMainThreadWaiting:NO block:^(){
+ if(![NSApp isActive]){
+ [NSApp activateIgnoringOtherApps:YES];
+ }
+ }];
+ JNF_COCOA_EXIT(env);
+}
+
/*
* Class: sun_awt_SunToolkit