From a35664dabe7930f0e5f33a2ef35acfce642de320 Mon Sep 17 00:00:00 2001 From: Konrad Neitzel Date: Mon, 16 Nov 2026 01:28:32 +0100 Subject: [PATCH] Fix overlay drop ordering and qualify native docking test setup Hit-test expanded overlays before the docked content they cover. Share tab detachment and group-settings capture across lifecycle paths. Native fixtures establish their initial OS focus with one client click. Geometry setup waits for the requested client width before creating the split, avoiding a ratio constrained by the previous native size. Transfer assertions remain unchanged. Verified 329 fx tests and 34 example tests with all five native test options enabled. --- fx/docs/docking-drag.md | 6 ++ fx/docs/docking-floating.md | 6 ++ fx/docs/docking-workspace.md | 24 ++++++++ .../fx/docking/DockDragController.java | 47 ++++++++++------ .../de/neitzel/fx/docking/DockingManager.java | 37 +++++-------- .../fx/view/FloatingNativeFocusTest.java | 1 + .../fx/view/FloatingWindowGeometryTest.java | 18 +++++- .../neitzel/fx/view/NativeDockDragTest.java | 3 + .../neitzel/fx/view/NativeFixtureFocus.java | 52 ++++++++++++++++++ .../neitzel/fx/view/OverlayDockDropTest.java | 55 +++++++++++++++++++ 10 files changed, 205 insertions(+), 44 deletions(-) create mode 100644 fx/src/test/java/de/neitzel/fx/view/NativeFixtureFocus.java diff --git a/fx/docs/docking-drag.md b/fx/docs/docking-drag.md index 067f9a3..572b944 100644 --- a/fx/docs/docking-drag.md +++ b/fx/docs/docking-drag.md @@ -123,3 +123,9 @@ No MVVM setup is required. The buttons are setup/recovery commands; dragging uses the same move checks and live contents. Closing the demonstration's main Stage hides its floating windows; application-wide shutdown coordination is supplied by its own slice. + +The final native fixtures explicitly establish their initial desktop state with +one real click in the initial editor, then restore its selected range. No such +setup helper runs after a tested transfer, invalid drop or cancellation. This +avoids assuming that programmatic Stage display alone established OS focus; it +does not claim a specific operating-system defect. diff --git a/fx/docs/docking-floating.md b/fx/docs/docking-floating.md index 5c24d19..e49112f 100644 --- a/fx/docs/docking-floating.md +++ b/fx/docs/docking-floating.md @@ -129,3 +129,9 @@ exclusive desktop slot: Without that property, the native pointer case is explicitly skipped. Ordinary public initial-bounds verification still runs. The native case includes a watchdog and restores the pointer in `finally`. + +The final native fixtures explicitly establish their initial desktop state with +one real click in the initial editor, then restore its selected range. No such +setup helper runs after a tested transfer, invalid drop or cancellation. This +avoids assuming that programmatic Stage display alone established OS focus; it +does not claim a specific operating-system defect. diff --git a/fx/docs/docking-workspace.md b/fx/docs/docking-workspace.md index fcdc80e..12eaf93 100644 --- a/fx/docs/docking-workspace.md +++ b/fx/docs/docking-workspace.md @@ -101,3 +101,27 @@ independent managers/processes and JavaFX Dragboard interoperability are outside this implementation. Native input has to be qualified on each target desktop; see the [drag](docking-drag.md) and [keyboard](docking-accessibility.md) guides for the executed platform checks. + +## Verified integration + +On 2026-11-16, the complete affected reactor passed `verify` with Java 25, +JavaFX 27.0.1 and macOS 27.2. All 329 `fx` tests and 34 `fx-example` tests ran +without failures or skips. The reference application contributes five +Java/FXML/storage/MVVM workflow cases, three actual file-boundary cases and one +native desktop case. The latter drags Notes into a new window, replaces selected +text, returns it through the real keyboard context menu and types again without +a focus-repair click. It also observes every consent before cleanup, a veto, +a pending/failed save and successful persistence before final closure. + +To rerun that native application case, use an exclusive desktop session: + +```sh +./mvnw -pl fx-example -am -DskipVersions=true -Dversions.skip=true \ + -Dtest=NativeReferenceWorkspaceTest -Dsurefire.failIfNoSpecifiedTests=false \ + -Dneitzellib.nativeWorkspaceTest=true test +``` + +The suite asserts exact text, retained Node identities, visible outcomes and +saved application data. The Changes list is illustrative content, not a file +watcher. Windows/Linux native delivery and full screen-reader behavior are not +established by this macOS qualification. diff --git a/fx/src/main/java/de/neitzel/fx/docking/DockDragController.java b/fx/src/main/java/de/neitzel/fx/docking/DockDragController.java index f6297da..2df1388 100644 --- a/fx/src/main/java/de/neitzel/fx/docking/DockDragController.java +++ b/fx/src/main/java/de/neitzel/fx/docking/DockDragController.java @@ -287,6 +287,12 @@ final class DockDragController { private Proposal proposal(DockableId id, double screenX, double screenY) { List groups = surfaces.get(); + for (GroupSurface group : groups) { + if (group.tabs() instanceof DockGroupPane tabs && tabs.isOverlay() && !tabs.isCollapsed()) { + Proposal overlay = visibleProposal(id, group, screenX, screenY); + if (overlay != null) return overlay; + } + } for (GroupSurface group : groups) { if (hidden(group) && (group.edge() != null || group.tabs().isManaged())) { Proposal empty = emptyProposal(group, screenX, screenY); @@ -294,24 +300,8 @@ final class DockDragController { } } for (GroupSurface group : groups) { - if (hidden(group)) continue; - Bounds bounds = group.tabs().localToScreen(group.tabs().getBoundsInLocal()); - if (bounds == null || !bounds.contains(screenX, screenY)) continue; - Node strip = headerStrip(group.tabs()); - Bounds stripBounds = strip == null ? null : strip.localToScreen(strip.getBoundsInLocal()); - if (stripBounds != null && stripBounds.contains(screenX, screenY)) { - Proposal insertion = insertion(group, screenX, screenY); - if (insertion != null) return insertion; - } - Bounds content = contentBounds(bounds, stripBounds, group.tabs().getSide()); - Side edge = edgeAt(content, screenX, screenY); - if (edge != null) { - DockTarget target = DockTarget.split(group.id(), edge); - MoveCheck split = manager.checkMove(id, target); - if (split instanceof MoveCheck.Allowed) return new Proposal(target, half(content, edge)); - if (split instanceof MoveCheck.NoChange) return new Proposal(target, bounds); - } - return new Proposal(DockTarget.group(group.id()), bounds); + Proposal visible = visibleProposal(id, group, screenX, screenY); + if (visible != null) return visible; } for (GroupSurface group : groups) { if (hidden(group) && group.edge() == null && !group.tabs().isManaged()) { @@ -322,6 +312,27 @@ final class DockDragController { return null; } + private Proposal visibleProposal(DockableId id, GroupSurface group, double screenX, double screenY) { + if (hidden(group)) return null; + Bounds bounds = group.tabs().localToScreen(group.tabs().getBoundsInLocal()); + if (bounds == null || !bounds.contains(screenX, screenY)) return null; + Node strip = headerStrip(group.tabs()); + Bounds stripBounds = strip == null ? null : strip.localToScreen(strip.getBoundsInLocal()); + if (stripBounds != null && stripBounds.contains(screenX, screenY)) { + Proposal insertion = insertion(group, screenX, screenY); + if (insertion != null) return insertion; + } + Bounds content = contentBounds(bounds, stripBounds, group.tabs().getSide()); + Side edge = edgeAt(content, screenX, screenY); + if (edge != null) { + DockTarget target = DockTarget.split(group.id(), edge); + MoveCheck split = manager.checkMove(id, target); + if (split instanceof MoveCheck.Allowed) return new Proposal(target, half(content, edge)); + if (split instanceof MoveCheck.NoChange) return new Proposal(target, bounds); + } + return new Proposal(DockTarget.group(group.id()), bounds); + } + private static boolean hidden(GroupSurface group) { return !group.tabs().isVisible() || !group.tabs().isManaged(); } diff --git a/fx/src/main/java/de/neitzel/fx/docking/DockingManager.java b/fx/src/main/java/de/neitzel/fx/docking/DockingManager.java index ee26d04..66b6d96 100644 --- a/fx/src/main/java/de/neitzel/fx/docking/DockingManager.java +++ b/fx/src/main/java/de/neitzel/fx/docking/DockingManager.java @@ -386,6 +386,15 @@ public final class DockingManager { if (kind == CloseScope.Kind.MAIN_WINDOW && mainWindowCloseMode == MainWindowCloseMode.AUTOMATIC) stage.hide(); } + private void detachTab(Group group, Tab tab) { + dragFor(group).uninstallTab(tab); + DockTabPresentation.unbind(tab); + tab.textProperty().unbind(); + tab.graphicProperty().unbind(); + tab.setGraphic(null); + tab.setContent(null); + } + private void removeDockables(List ids) { Dockable previousActive = active.get(); Group previousGroup = previousActive == null ? null : containing(previousActive.getId()); @@ -395,12 +404,7 @@ public final class DockingManager { Group group = containing(id); if (group == null) continue; Tab tab = group.tabs.getTabs().get(tabIndex(group, id)); - dragFor(group).uninstallTab(tab); - DockTabPresentation.unbind(tab); - tab.textProperty().unbind(); - tab.graphicProperty().unbind(); - tab.setGraphic(null); - tab.setContent(null); + detachTab(group, tab); group.tabs.getTabs().remove(tab); dockables.remove(id); previousFocus.remove(id); @@ -963,12 +967,7 @@ public final class DockingManager { try { for (Group old : groups.values()) { for (Tab tab : List.copyOf(old.tabs.getTabs())) { - dragFor(old).uninstallTab(tab); - DockTabPresentation.unbind(tab); - tab.textProperty().unbind(); - tab.graphicProperty().unbind(); - tab.setGraphic(null); - tab.setContent(null); + detachTab(old, tab); } old.tabs.getTabs().clear(); } @@ -1103,18 +1102,8 @@ public final class DockingManager { } private Group createDetachedGroup(DockGroupId id, DockGroupDefinition definition) { - DockGroupDefinition captured = new DockGroupDefinition(definition.getDestinationId()); - captured.setTabSide(definition.getTabSide()); - captured.setMode(definition.getMode()); - captured.setPreferredWidth(definition.getPreferredWidth()); - captured.setPreferredHeight(definition.getPreferredHeight()); - captured.setMinimumWidth(definition.getMinimumWidth()); - captured.setMinimumHeight(definition.getMinimumHeight()); - captured.setSplitDirections(definition.getSplitDirections()); - captured.setPersistent(definition.isPersistent()); - captured.setCollapsible(definition.isCollapsible()); - captured.setVisibleWhenEmpty(definition.isVisibleWhenEmpty()); - captured.setReleaseSpaceWhenEmpty(definition.isReleaseSpaceWhenEmpty()); + DockGroupDefinition captured = LayoutSnapshot.GroupSettings.capture(definition) + .definition(new DockAreaId(definition.getDestinationId())); TabPane tabs = new DockGroupPane(captured); tabs.setSide(captured.getTabSide()); ((DockGroupPane) tabs).setCollapsed(captured.getMode() == DockGroupMode.OVERLAY); diff --git a/fx/src/test/java/de/neitzel/fx/view/FloatingNativeFocusTest.java b/fx/src/test/java/de/neitzel/fx/view/FloatingNativeFocusTest.java index c86d017..d66f324 100644 --- a/fx/src/test/java/de/neitzel/fx/view/FloatingNativeFocusTest.java +++ b/fx/src/test/java/de/neitzel/fx/view/FloatingNativeFocusTest.java @@ -51,6 +51,7 @@ class FloatingNativeFocusTest { Fixture fixture = fixture(); AtomicReference firstFloating = new AtomicReference<>(); try { + NativeFixtureFocus.establish(robot, fixture.notes); typeIntoFocusedNotes(robot, fixture, KeyEvent.VK_1, "1"); FxThread.onFx(() -> { command(fixture.notes, "Float", null); diff --git a/fx/src/test/java/de/neitzel/fx/view/FloatingWindowGeometryTest.java b/fx/src/test/java/de/neitzel/fx/view/FloatingWindowGeometryTest.java index 27ed7db..af33e45 100644 --- a/fx/src/test/java/de/neitzel/fx/view/FloatingWindowGeometryTest.java +++ b/fx/src/test/java/de/neitzel/fx/view/FloatingWindowGeometryTest.java @@ -147,14 +147,17 @@ class FloatingWindowGeometryTest { AtomicReference ratio = new AtomicReference<>(); AtomicReference start = new AtomicReference<>(); try { + FxThread.onFx(() -> fixture.floating.setWidth(760)); + awaitClientWidth(fixture.floating, 740); FxThread.onFx(() -> { - fixture.floating.setWidth(760); var window = fixture.manager.layout().windows().stream().filter(candidate -> !candidate.main()).findFirst().orElseThrow(); var group = window.areas().getFirst().groups().getFirst().id(); Dockable anchor = new Dockable(new DockableId("anchor"), new TextArea("Anchor")); fixture.manager.open(anchor, DockTarget.group(group)); fixture.manager.move(anchor.getId(), DockTarget.split(group, Side.RIGHT)); - fixture.manager.updateGroup(group, DockGroupChanges.builder().minimumWidth(320).build()); + // Make this minimum active at the starting width as well: even a short native + // shrink must change the live ratio before testing committed publication. + fixture.manager.updateGroup(group, DockGroupChanges.builder().minimumWidth(500).build()); }); Thread.sleep(400); FxThread.onFx(() -> { @@ -200,6 +203,17 @@ class FloatingWindowGeometryTest { } } + private static void awaitClientWidth(Stage stage, double minimum) throws Exception { + long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(3); + AtomicReference ready = new AtomicReference<>(false); + do { + Thread.sleep(25); + FxThread.onFx(() -> ready.set(stage.getScene().getWidth() >= minimum + && stage.getScene().getRoot().getLayoutBounds().getWidth() >= minimum)); + } while (!ready.get() && System.nanoTime() < deadline); + assertTrue(ready.get(), "The native window's client layout must reach the starting width before splitting"); + } + private static DockLayoutView.Split publishedSplit(DockingManager manager) { var area = manager.layout().windows().stream().filter(window -> !window.main()).findFirst().orElseThrow().areas().getFirst(); return assertInstanceOf(DockLayoutView.Split.class, area.root()); diff --git a/fx/src/test/java/de/neitzel/fx/view/NativeDockDragTest.java b/fx/src/test/java/de/neitzel/fx/view/NativeDockDragTest.java index a22a292..d8f413f 100644 --- a/fx/src/test/java/de/neitzel/fx/view/NativeDockDragTest.java +++ b/fx/src/test/java/de/neitzel/fx/view/NativeDockDragTest.java @@ -50,6 +50,7 @@ class NativeDockDragTest { var watchdog = Executors.newSingleThreadScheduledExecutor(); watchdog.schedule(() -> robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK), 20, TimeUnit.SECONDS); try { + NativeFixtureFocus.establish(robot, f.notes); await(() -> f.main.isFocused(), "Initial main window must be focused"); Point outside = onFx(() -> { var screen = Screen.getPrimary().getVisualBounds(); @@ -131,6 +132,7 @@ class NativeDockDragTest { var watchdog = Executors.newSingleThreadScheduledExecutor(); watchdog.schedule(() -> robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK), 25, TimeUnit.SECONDS); try { + NativeFixtureFocus.establish(robot, f.notes); await(() -> source.get().isFocused(), "The initial source window must have focus"); var before = onFx(f.manager::layout); drag(robot, onFx(() -> headerPoint(f.notes)), onFx(() -> center(readme.get())), () -> FxThread.onFx(() -> { @@ -190,6 +192,7 @@ class NativeDockDragTest { var watchdog = Executors.newSingleThreadScheduledExecutor(); watchdog.schedule(() -> robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK), 20, TimeUnit.SECONDS); try { + NativeFixtureFocus.establish(robot, f.notes); await(() -> source.get().isFocused(), "The initial floating source must be focused"); var initial = onFx(f.manager::layout); drag(robot, onFx(() -> headerPoint(f.notes)), onFx(() -> headerPoint(project.get())), () -> FxThread.onFx(() -> { diff --git a/fx/src/test/java/de/neitzel/fx/view/NativeFixtureFocus.java b/fx/src/test/java/de/neitzel/fx/view/NativeFixtureFocus.java new file mode 100644 index 0000000..c37b5a5 --- /dev/null +++ b/fx/src/test/java/de/neitzel/fx/view/NativeFixtureFocus.java @@ -0,0 +1,52 @@ +package de.neitzel.fx.view; + +import javafx.geometry.Bounds; +import javafx.scene.control.IndexRange; +import javafx.scene.control.TextArea; +import javafx.stage.Stage; + +import java.awt.MouseInfo; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.InputEvent; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** Establishes the starting desktop state once; never used to repair focus after a tested operation. */ +final class NativeFixtureFocus { + private NativeFixtureFocus() { } + + static void establish(Robot robot, TextArea editor) throws Exception { + Point original = MouseInfo.getPointerInfo().getLocation(); + AtomicReference client = new AtomicReference<>(); + AtomicReference selection = new AtomicReference<>(); + FxThread.onFx(() -> { + Stage stage = (Stage) editor.getScene().getWindow(); + stage.toFront(); + editor.getScene().getRoot().applyCss(); + editor.getScene().getRoot().layout(); + selection.set(editor.getSelection()); + Bounds bounds = editor.localToScreen(editor.getBoundsInLocal()); + client.set(new Point((int) bounds.getCenterX(), (int) bounds.getCenterY())); + }); + try { + robot.mouseMove(client.get().x, client.get().y); + try { robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); } + finally { robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); } + long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(3); + AtomicReference focused = new AtomicReference<>(false); + do { + Thread.sleep(25); + FxThread.onFx(() -> focused.set(editor.getScene().getWindow().isFocused() + && editor.getScene().getFocusOwner() == editor)); + } while (!focused.get() && System.nanoTime() < deadline); + assertTrue(focused.get(), "The initial editor click must establish native window and content focus"); + FxThread.onFx(() -> editor.selectRange(selection.get().getStart(), selection.get().getEnd())); + } finally { + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseMove(original.x, original.y); + } + } +} diff --git a/fx/src/test/java/de/neitzel/fx/view/OverlayDockDropTest.java b/fx/src/test/java/de/neitzel/fx/view/OverlayDockDropTest.java index 2558dc7..e980356 100644 --- a/fx/src/test/java/de/neitzel/fx/view/OverlayDockDropTest.java +++ b/fx/src/test/java/de/neitzel/fx/view/OverlayDockDropTest.java @@ -133,6 +133,61 @@ class OverlayDockDropTest { }); } + @ParameterizedTest + @EnumSource(Side.class) + void expandedOverlayContentReceivesDropsAboveTheUnderlyingEditor(Side side) throws Exception { + FxThread.onFx(() -> { + DockLayout initial = new DockLayout(); + initial.setCenter(new DockGroupDefinition("editors")); + DockGroupDefinition tools = new DockGroupDefinition("tools"); + tools.setCollapsible(true); + tools.setMode(DockGroupMode.OVERLAY); + tools.setTabSide(side); + tools.setPreferredWidth(240); + tools.setPreferredHeight(190); + tools.setSplitDirections(de.neitzel.fx.docking.SplitDirections.NONE); + edge(initial, side, tools); + DockPane pane = new DockPane(); + pane.setInitialLayout(initial); + Stage stage = new Stage(); + stage.setScene(new Scene(pane, 900, 600)); + DockingManager manager = DockingManager.attach(stage, pane, new DockingOptions()); + Dockable editor = new Dockable(new DockableId("editor"), new TextArea("Editor")); + Dockable first = new Dockable(new DockableId("first"), new TextArea("Unsaved first")); + first.setTitle("First"); + Dockable second = new Dockable(new DockableId("second"), new TextArea("Second")); + second.setTitle("Second"); + manager.open(editor, DockTarget.area("editors")); + manager.open(first, DockTarget.area("tools")); + manager.open(second, DockTarget.area("tools")); + stage.show(); + try { + pane.applyCss(); + pane.layout(); + TabPane overlay = tabs(pane, first.getId()); + Bounds into = second.getContent().localToScreen(second.getContent().getBoundsInLocal()); + double x = into.getCenterX(); + double y = into.getCenterY(); + Bounds underneath = tabs(pane, editor.getId()).localToScreen( + tabs(pane, editor.getId()).getBoundsInLocal()); + assertTrue(underneath.contains(x, y), "The visible overlay content covers the editor drop surface"); + assertFalse(group(manager).collapsed()); + Node sourceHeader = header(overlay, first.getId()); + Bounds from = sourceHeader.localToScreen(sourceHeader.getBoundsInLocal()); + mouse(sourceHeader, MouseEvent.MOUSE_PRESSED, from.getCenterX(), from.getCenterY(), true); + mouse(sourceHeader, MouseEvent.MOUSE_DRAGGED, x, y, true); + assertTrue(pane.lookup(".dock-drop-indicator").isVisible()); + mouse(sourceHeader, MouseEvent.MOUSE_RELEASED, x, y, false); + assertEquals(java.util.List.of(second.getId(), first.getId()), group(manager).dockableIds(), + "A drop on overlay content appends within that visible group"); + assertEquals(java.util.List.of(editor.getId()), group(manager, "editors").dockableIds()); + assertSame(first, manager.activeDockable()); + assertSame(first.getContent(), overlay.getSelectionModel().getSelectedItem().getContent()); + assertFalse(group(manager).collapsed()); + } finally { stage.hide(); } + }); + } + private static void edge(DockLayout layout, Side side, DockGroupDefinition group) { switch (side) { case LEFT -> layout.setLeft(group);