changeset 6519:c7aa16d3a823

8020811: [macosx] Merge fault 7u25-7u40: Missed focus fix JDK-8012330 Reviewed-by: serb, art
author alexsch
date Tue, 23 Jul 2013 16:33:35 +0400
parents d41a1959df12
children 961894dbe220
files src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java
diffstat 1 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java	Mon Jul 22 17:02:01 2013 -0700
+++ b/src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java	Tue Jul 23 16:33:35 2013 +0400
@@ -38,7 +38,8 @@
 public class CEmbeddedFrame extends EmbeddedFrame {
 
     private CPlatformResponder responder;
-    private boolean focused = true;
+    private static final Object classLock = new Object();
+    private static volatile CEmbeddedFrame focusedWindow;
     private boolean parentWindowActive = true;
 
     public CEmbeddedFrame() {
@@ -110,9 +111,16 @@
         responder.handleInputEvent(text);
     }
 
+    // handleFocusEvent is called when the applet becames focused/unfocused.
+    // This method can be called from different threads.
     public void handleFocusEvent(boolean focused) {
-        this.focused = focused;
-        if (focused) {
+        synchronized (classLock) {
+            // In some cases an applet may not receive the focus lost event
+            // from the parent window (see 8012330)
+            focusedWindow = (focused) ? this
+                    : ((focusedWindow == this) ? null : focusedWindow);
+        }
+        if (focusedWindow == this) {
             // see bug 8010925
             // we can't put this to handleWindowFocusEvent because
             // it won't be invoced if focuse is moved to a html element
@@ -126,6 +134,10 @@
     }
 
     /**
+     * handleWindowFocusEvent is called for all applets, when the browser
+     * becames active/inactive. This event should be filtered out for
+     * non-focused applet. This method can be called from different threads.
+     *
      * When the window is activated and had focus before the deactivation
      * calling this method triggers focus events in the following order:
      *  1. WINDOW_ACTIVATED for this EmbeddedFrame
@@ -140,7 +152,7 @@
         this.parentWindowActive = parentWindowActive;
         // ignore focus "lost" native request as it may mistakenly
         // deactivate active window (see 8001161)
-        if (focused && parentWindowActive) {
+        if (focusedWindow == this && parentWindowActive) {
             responder.handleWindowFocusEvent(parentWindowActive, null);
         }
     }