8205479: OS X: requestFocus() does not work properly for embedded frame
authordmarkov
Fri, 17 Aug 2018 09:31:13 +0100
changeset 51910 4b492ccc0b71
parent 51909 8f12ff1c0555
child 51911 57fa2c1c98d4
8205479: OS X: requestFocus() does not work properly for embedded frame Reviewed-by: serb, aivanov
src/java.desktop/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java
src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java
--- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java	Thu Aug 16 19:20:20 2018 +0100
+++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java	Fri Aug 17 09:31:13 2018 +0100
@@ -165,8 +165,6 @@
                         : this;
             }
         }
-        // ignore focus "lost" native request as it may mistakenly
-        // deactivate active window (see 8001161)
         if (globalFocusedWindow == this) {
             responder.handleWindowFocusEvent(parentWindowActive, null);
         }
@@ -181,4 +179,19 @@
         // another window.
         return globalFocusedWindow != null ? !globalFocusedWindow.isParentWindowActive() : true;
     }
+
+    @Override
+    public void synthesizeWindowActivation(boolean doActivate) {
+        if (isParentWindowActive() != doActivate) {
+            handleWindowFocusEvent(doActivate);
+        }
+    }
+
+    public static void updateGlobalFocusedWindow(CEmbeddedFrame newGlobalFocusedWindow) {
+        synchronized (classLock) {
+            if (newGlobalFocusedWindow.isParentWindowActive()) {
+                globalFocusedWindow = newGlobalFocusedWindow;
+            }
+        }
+    }
 }
--- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java	Thu Aug 16 19:20:20 2018 +0100
+++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPlatformEmbeddedFrame.java	Fri Aug 17 09:31:13 2018 +0100
@@ -147,6 +147,8 @@
 
     @Override
     public boolean requestWindowFocus() {
+        CEmbeddedFrame.updateGlobalFocusedWindow(target);
+        target.synthesizeWindowActivation(true);
         return true;
     }