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.
This commit is contained in:
2026-11-16 01:28:48 +01:00
parent 01af6c6a0c
commit a35664dabe
10 changed files with 205 additions and 44 deletions
+6
View File
@@ -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.
+6
View File
@@ -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.
+24
View File
@@ -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.
@@ -287,6 +287,12 @@ final class DockDragController {
private Proposal proposal(DockableId id, double screenX, double screenY) {
List<GroupSurface> 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,9 +300,22 @@ final class DockDragController {
}
}
for (GroupSurface group : groups) {
if (hidden(group)) continue;
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()) {
Proposal empty = emptyProposal(group, screenX, screenY);
if (empty != null) return empty;
}
}
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)) continue;
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)) {
@@ -313,14 +332,6 @@ final class DockDragController {
}
return new Proposal(DockTarget.group(group.id()), bounds);
}
for (GroupSurface group : groups) {
if (hidden(group) && group.edge() == null && !group.tabs().isManaged()) {
Proposal empty = emptyProposal(group, screenX, screenY);
if (empty != null) return empty;
}
}
return null;
}
private static boolean hidden(GroupSurface group) {
return !group.tabs().isVisible() || !group.tabs().isManaged();
@@ -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<DockableId> 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);
@@ -51,6 +51,7 @@ class FloatingNativeFocusTest {
Fixture fixture = fixture();
AtomicReference<Stage> firstFloating = new AtomicReference<>();
try {
NativeFixtureFocus.establish(robot, fixture.notes);
typeIntoFocusedNotes(robot, fixture, KeyEvent.VK_1, "1");
FxThread.onFx(() -> {
command(fixture.notes, "Float", null);
@@ -147,14 +147,17 @@ class FloatingWindowGeometryTest {
AtomicReference<Double> ratio = new AtomicReference<>();
AtomicReference<Point> 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<Boolean> 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());
@@ -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(() -> {
@@ -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<Point> client = new AtomicReference<>();
AtomicReference<IndexRange> 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<Boolean> 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);
}
}
}
@@ -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);