changeset 6376:2c3fae51b7d6

8012330: [macosx] Sometimes the applet showing the modal dialog itself loses the ability to gain focus Reviewed-by: serb, ant
author alexsch
date Mon, 29 Apr 2013 16:46:18 +0400
parents 64055b403176
children 9f59600aea52
files src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java
diffstat 1 files changed, 26 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java	Fri Apr 26 09:30:54 2013 +0400
+++ b/src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java	Mon Apr 29 16:46:18 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() {
@@ -104,18 +105,38 @@
         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 (parentWindowActive) {
+
+        boolean handleWindowFocusEvent;
+        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);
+            handleWindowFocusEvent = parentWindowActive;
+        }
+
+        if (handleWindowFocusEvent) {
             responder.handleWindowFocusEvent(focused);
         }
     }
 
+    // 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.
     public void handleWindowFocusEvent(boolean parentWindowActive) {
-        this.parentWindowActive = parentWindowActive;
+
+        boolean handleWindowFocusEvent;
+        synchronized (classLock) {
+            this.parentWindowActive = parentWindowActive;
+            handleWindowFocusEvent = focusedWindow == this && parentWindowActive;
+        }
+
         // ignore focus "lost" native request as it may mistakenly
         // deactivate active window (see 8001161)
-        if (focused && parentWindowActive) {
+        if (handleWindowFocusEvent) {
             responder.handleWindowFocusEvent(parentWindowActive);
         }
     }