### Description

The setup is the following:
Window1
Window2 owner Window1
FileChooser owner Window2

When Window2 is closed,
then Window2 and the FileChooser are closed,
but the nested event loop from the dialog never returns.
Even worse, Window1 is in a broken state: it can't ever get focus again.

### The Fix
The fix has two parts.

### Close FileChooser when owner is closed (GlassDialogs.m)
AppKit does not call the completionHandler of the dialog when the owner window 
is closed, so the nested event loop is never left.
We add a listener to the owner of the FileChooser, ensuring the FileChooser 
gets closed when the owner is closed.
showOpenDialog then returns null, as if the user had cancelled.

### Refocus when disabled window becomes key/focused (GlassWindow.m)
When a window becomes focused while it is disabled, the focus isn't processed.
Therefore we resend the focus event when it gets re-enabled.

### System test
A system test is included which tests both changes at once.

### A note on platform differences
On Windows/Linux, closing the owner of a FileChooser currently doesn't close
the FileChooser at all. For that reason, the test only works on macOS.
But this difference is not introduced by the PR.
It probably would be possible to change that behavior and it would be a good
additional improvement, because in all other cases, closing the owner also 
closes the child windows.

>From the Stage JavaDoc (class doc, showAndWait doc):
 > When a parent window is closed or iconified, then all owned windows will be 
 > affected as well
 > A Stage is hidden (closed) by one of the following means: ... this stage has 
 > a non-null owner window, and its owner is closed

### Close API
A possible follow-up would be to provide an API to close the FileChooser 
programmatically.
This would also make it easier to write tests.

---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK 
Interim AI Policy](https://openjdk.org/legal/ai).

-------------

Commit messages:
 - 8389735

Changes: https://git.openjdk.org/jfx/pull/2242/files
  Webrev: https://webrevs.openjdk.org/?repo=jfx&pr=2242&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8389735
  Stats: 146 lines in 4 files changed: 146 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jfx/pull/2242.diff
  Fetch: git fetch https://git.openjdk.org/jfx.git pull/2242/head:pull/2242

PR: https://git.openjdk.org/jfx/pull/2242

Reply via email to