# HG changeset patch # User alexsch # Date 1367239578 -14400 # Node ID 3d459273c61bcb9db2921d3986c62beae241797f # Parent 5d5752746305eeb6ad63685413a06684bafeb9c6 8012330: [macosx] Sometimes the applet showing the modal dialog itself loses the ability to gain focus Reviewed-by: serb, ant diff -r 5d5752746305 -r 3d459273c61b src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java --- a/src/macosx/classes/sun/lwawt/macosx/CEmbeddedFrame.java Wed May 01 00:49:21 2013 +0200 +++ 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() { @@ -98,18 +99,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); } }