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:
@@ -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,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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user