JRE-953 Focus goes behind 'Replace in Path' / "Find in path" dialogs
diff --git a/src/macosx/classes/sun/lwawt/LWWindowPeer.java b/src/macosx/classes/sun/lwawt/LWWindowPeer.java
index d5d062a..4d1e307 100644
--- a/src/macosx/classes/sun/lwawt/LWWindowPeer.java
+++ b/src/macosx/classes/sun/lwawt/LWWindowPeer.java
@@ -1277,7 +1277,7 @@
private boolean isOneOfOwnersOf(LWWindowPeer peer) {
Window owner = (peer != null ? peer.getTarget().getOwner() : null);
while (owner != null) {
- if ((LWWindowPeer)owner.getPeer() == this) {
+ if (owner.getPeer() == this) {
return true;
}
owner = owner.getOwner();
@@ -1325,11 +1325,28 @@
grabbingWindow.ungrab();
}
+ Window eventWindow = getTarget();
+
+ Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
+ // 1. Every time we are loosing focus, we check if the current focused window is a Simple Window.
+ if (!becomesFocused && focusedWindow != null && ((LWWindowPeer)focusedWindow.getPeer()).isSimpleWindow()) {
+ // 2. Save the window as a previously focused
+ previouslyFocusedWindow = focusedWindow;
+ } else if (previouslyFocusedWindow != null) {
+ if (previouslyFocusedWindow.isShowing()) {
+ // 3. Use the previous focused window
+ eventWindow = previouslyFocusedWindow;
+ }
+ // 4. Reset the previously focused window
+ previouslyFocusedWindow = null;
+ }
+
KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
- kfmPeer.setCurrentFocusedWindow(becomesFocused ? getTarget() : null);
+ kfmPeer.setCurrentFocusedWindow(becomesFocused ? eventWindow : null);
int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
- WindowEvent windowEvent = new TimedWindowEvent(getTarget(), eventID, opposite, System.currentTimeMillis());
+
+ WindowEvent windowEvent = new TimedWindowEvent(eventWindow, eventID, opposite, System.currentTimeMillis());
SunToolkit.setSystemGenerated(windowEvent);
AWTAccessor.getAWTEventAccessor().setPosted(windowEvent);
@@ -1344,6 +1361,8 @@
postEvent(pe);
}
+ private Window previouslyFocusedWindow = null;
+
/*
* Retrieves the owner of the peer.
* Note: this method returns the owner which can be activated, (i.e. the instance