fix(skin): verify real launcher dedup and keep split recovery tappable at 320px

- Fall back an overlapping docked recovery toolbar to the visible capsule so
  split built-in/library buttons never cover each other on narrow screens.
- Add browser fixtures mounting real HostChrome + real PluginPanel for group,
  split and legacy capsule modes, including a genuine 320px iframe viewport.
- Assert the real launcher is suppressed by toolbar slots and never duplicated
  after a bad-anchor fallback, with both split toolbars observable and clickable.
This commit is contained in:
OddTurtleHead committed 2026-11-26 23:06:43 +08:00
1 parent cfbf488f75
commit e5c891fc94
6 files changed
+543 -1

No files matched your search

+26 -1
View File
@@ -161,7 +161,7 @@ import {
type FloatingAvoidance,
type FloatingPosition,
} from "../services/host-floating-placement.js";
import { shouldShowRecovery } from "../services/host-chrome-visibility.js";
import { shouldShowRecovery, type HostPartRect } from "../services/host-chrome-visibility.js";
import { thirdPartyAllowed } from "../services/instance-authorization.js";
import {
RECOVERY_CONTROL_DEFAULTS,
@@ -474,6 +474,30 @@ function syncToolbarPopovers() {
);
}
/** A toolbar that is currently displayed (top layer or display fallback). */
function isToolbarShown(control: HTMLElement | null): boolean {
if (!control) return false;
if (control.matches?.(":popover-open")) return true;
const rect = control.getBoundingClientRect();
return getComputedStyle(control).display !== "none" && rect.width > 0 && rect.height > 0;
}
function rectOf(control: HTMLElement): HostPartRect {
const rect = control.getBoundingClientRect();
return {
left: rect.left, top: rect.top, width: rect.width, height: rect.height,
right: rect.right, bottom: rect.bottom,
};
}
/** Other docked recovery toolbars this entry must not cover on a narrow screen. */
function otherToolbarRects(control: HTMLElement): HostPartRect[] {
return [groupToolbarElement.value, builtInToolbarElement.value, libraryToolbarElement.value]
.filter((element): element is HTMLElement => Boolean(element)
&& element !== control && isToolbarShown(element))
.map(rectOf);
}
function bindToolbarEntry(
control: HTMLElement | null,
config: SkinChromeSlot | undefined,
@@ -487,6 +511,7 @@ function bindToolbarEntry(
skinId: hostChromeActiveSkinId.value,
align: config.align,
presentation: "toolbar",
otherControls: () => otherToolbarRects(control),
// A floating toolbar is a closed popover (display:none). Show it for the
// synchronous measurement/hit test and hide it again unless it docked.
prepare: () => syncRecoveryPopover(control, true),
@@ -161,6 +161,28 @@ test("a slotted capsule that would cover a protected control falls back", () =>
assert.deepEqual(evaluateSlottedControl({ ...baseEvaluation, coversProtected: false }), { ok: true });
});
test("a toolbar that would cover another docked host control falls back", () => {
assert.deepEqual(
evaluateSlottedControl({
...baseEvaluation,
otherControls: [rect(160, 105, 120, 30)],
}),
{ ok: false, reason: "covers-host-control" },
);
// Edge contact is not a collision; both toolbars can still dock side by side.
assert.deepEqual(
evaluateSlottedControl({
...baseEvaluation,
otherControls: [rect(60, 105, 120, 30)],
}),
{ ok: true },
);
assert.deepEqual(
evaluateSlottedControl({ ...baseEvaluation, otherControls: [] }),
{ ok: true },
);
});
test("rect overlap ignores edge contact and sub-pixel slivers", () => {
assert.equal(rectsOverlap(rect(0, 0, 100, 40), rect(50, 10, 100, 40)), true);
assert.equal(rectsOverlap(rect(0, 0, 100, 40), rect(100, 0, 50, 40)), false);
+13
View File
@@ -83,6 +83,7 @@ export type SlotFailureReason =
| "control-too-small"
| "control-offscreen"
| "covers-protected"
| "covers-host-control"
| "hit-test";
export interface SlotAnchorSnapshot {
@@ -109,6 +110,8 @@ export interface SlotEvaluationInput {
* capsule is top layer, so it would block those controls for the pointer.
*/
coversProtected?: boolean;
/** Footprints of other docked host controls this one must not cover. */
otherControls?: readonly HostPartRect[];
}
export type SlotEvaluation = { ok: true } | { ok: false; reason: SlotFailureReason };
@@ -163,6 +166,13 @@ export function evaluateSlottedControl(input: SlotEvaluationInput): SlotEvaluati
return { ok: false, reason: "control-too-small" };
}
if (!fullyInsideViewport(controlRect, viewport)) return { ok: false, reason: "control-offscreen" };
// Two independently anchored recovery toolbars can converge on the same
// narrow anchor (for example at 320px). Covering a sibling host control
// would make one of the buttons unreachable, so that action returns to the
// visible floating capsule instead of pretending to be docked.
if (input.otherControls?.some((rect) => rectsOverlap(controlRect, rect))) {
return { ok: false, reason: "covers-host-control" };
}
if (input.coversProtected) return { ok: false, reason: "covers-protected" };
if (!hitTestOk) return { ok: false, reason: "hit-test" };
return { ok: true };
@@ -332,6 +342,8 @@ export interface HostSlotBindingOptions {
/** Called after each evaluation with the resulting docked state. */
settle?: (slotted: boolean) => void;
resolveAnchor?: (anchor: string | readonly string[]) => HTMLElement | null;
/** Live footprints of other docked host controls; overlaps force a fallback. */
otherControls?: () => readonly HostPartRect[];
onModeChange?: (change: HostSlotModeChange) => void;
}
@@ -512,6 +524,7 @@ export function bindHostSlot(options: HostSlotBindingOptions): HostSlotBinding {
viewport,
minHitTarget: tokens.hitTarget,
coversProtected,
otherControls: options.otherControls?.(),
hitTestOk: placement
? hitTestAt(placement.left, placement.top, { width: controlBox.width, height: controlBox.height })
: false,