fix: look through toasts when placing floating host controls

A toast passing over a skin control hid it from the hit test, so its corner
looked free: with 854a488's return-home rule the application-library launcher
jumped back to its default bottom-right corner on open-voice-surface desktop,
flapped as toasts came and went, and the flap freeze then parked it on
"Share accompaniment" for 10 s.

- Obstacle hit tests look through transient overlays (app.toast) and the other
  host floating control (elementsFromPoint); a modal backdrop or skin layer
  still hides a control.
- While frozen by the anti-flap guard, a control parked on a skin control may
  step off it once per freeze (confirm delay and 1 s interval still apply),
  then holds still.
- Tests: reachableThrough unit test; browser fixture replaying the toast
  sequence and the freeze escape (both fail on 854a488).
This commit is contained in:
OddTurtleHead committed 2026-11-16 00:24:20 +08:00
1 parent 99d7b86d09
commit 8ca33fd77d
5 files changed
+280 -8

No files matched your search

@@ -9,6 +9,7 @@ import {
floatingRect,
shouldFold,
floatingScore,
reachableThrough,
type FloatingObstacle,
} from "./host-floating-placement.js";
import type { HostPartRect } from "./host-chrome-visibility.js";
@@ -142,3 +143,38 @@ test("with every spot taken, the capsule covers a dialog button before a protect
const footprint = floatingRect(choice.position, wide, mobile, margins);
assert.equal(floatingScore(footprint, [obstacles[0]]), 0, choice.position);
});
test("a toast or the other host control passing over a control does not hide it from the obstacle check", () => {
// Stand-ins for elementsFromPoint() results, topmost first.
const button = { id: "accompaniment" } as unknown as Element;
const icon = { id: "accompaniment-icon" } as unknown as Element;
const toast = { id: "toast" } as unknown as Element;
const toastText = { id: "toast-text" } as unknown as Element;
const otherHost = { id: "library-launcher" } as unknown as Element;
const skinLayer = { id: "skin-panel" } as unknown as Element;
const backdrop = { id: "modal-backdrop" } as unknown as Element;
const isTarget = (element: Element) => element === button || element === icon;
const isTransparent = (element: Element) => element === toast || element === toastText || element === otherHost;
assert.equal(reachableThrough([icon, button], isTarget, isTransparent), true);
// The toast is on top for a moment: the control under it still counts.
assert.equal(reachableThrough([toastText, toast, icon, button], isTarget, isTransparent), true);
assert.equal(reachableThrough([otherHost, toast, button], isTarget, isTransparent), true);
// A skin layer or modal backdrop really hides it (even under a toast).
assert.equal(reachableThrough([skinLayer, button], isTarget, isTransparent), false);
assert.equal(reachableThrough([toast, backdrop, button], isTarget, isTransparent), false);
assert.equal(reachableThrough([toast], isTarget, isTransparent), false);
assert.equal(reachableThrough([], isTarget, isTransparent), false);
});
test("a corner whose control is counted (not hidden by a toast) is never chosen as the free default corner", () => {
// Library launcher: default bottom-right, parked top-left because the skin's
// accompaniment button sits in the bottom-right corner.
const launcher = { width: 34, height: 34 };
const launcherMargins = { top: 16, right: 16, bottom: 16, left: 16 };
const accompaniment = { rect: rect(1218, 738, 34, 34), weight: FLOATING_WEIGHT_PROTECTED };
const counted = chooseFloatingPosition({ current: "top-left", size: launcher, viewport, margins: launcherMargins, obstacles: [accompaniment], home: "bottom-right" });
assert.equal(counted.position, "top-left");
// What 854a488 did while a toast hid the button: the corner looked free.
const hidden = chooseFloatingPosition({ current: "top-left", size: launcher, viewport, margins: launcherMargins, obstacles: [], home: "bottom-right" });
assert.equal(hidden.position, "bottom-right");
});