From cdb7be5f3bd37f43a94de7c459f39694a07f9270 Mon Sep 17 00:00:00 2001 From: mcherkas Date: Fri, 10 Oct 2014 20:14:42 +0400 Subject: [PATCH] 8038919: Requesting focus to a modeless dialog doesn't work on Safari Reviewed-by: ant, serb --- .../sun/lwawt/macosx/CPlatformWindow.java | 7 +++++++ .../classes/sun/lwawt/macosx/LWCToolkit.java | 5 +++++ src/macosx/native/sun/awt/LWCToolkit.m | 17 +++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java index aa21535d3..57dd241fd 100644 --- a/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java +++ b/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java @@ -674,6 +674,13 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo @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); diff --git a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java index 44f49e081..f13a01cf0 100644 --- a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java +++ b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java @@ -801,6 +801,11 @@ public final class LWCToolkit extends LWToolkit { */ public static native boolean isEmbedded(); + /* + * Activates application ignoring other apps. + */ + public native void activateApplicationIgnoringOtherApps(); + /************************ * Native methods section ************************/ diff --git a/src/macosx/native/sun/awt/LWCToolkit.m b/src/macosx/native/sun/awt/LWCToolkit.m index 1f1d1c414..3dd759ad0 100644 --- a/src/macosx/native/sun/awt/LWCToolkit.m +++ b/src/macosx/native/sun/awt/LWCToolkit.m @@ -413,6 +413,23 @@ JNF_COCOA_EXIT(env); 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 -- GitLab