fix(skin): keep split fallback capsule clear of docked toolbars at 320px

The library toolbar falls back to the floating capsule when its docked footprint would cover the built-in toolbar in split mode. The fallback was positioned by light-DOM floating avoidance, which cannot see toolbars inside the closed shadow root, so it could land on the still-docked built-in button and hide/cover the library action (GUI retest at 318/320px). Exclude docked toolbar footprints from floating positions, give the slotted capsule the same sibling guard, and assert real elementFromPoint hit testing plus rect disjointness in the 320px iframe fixture.
This commit is contained in:
OddTurtleHead committed 2026-11-26 23:06:43 +08:00
1 parent e5c891fc94
commit 4131d9c319
5 files changed
+132 -7

No files matched your search

+14
View File
@@ -490,6 +490,13 @@ function rectOf(control: HTMLElement): HostPartRect {
};
}
/** Every recovery toolbar currently docked in the top layer. */
function dockedToolbarRects(): HostPartRect[] {
return [groupToolbarElement.value, builtInToolbarElement.value, libraryToolbarElement.value]
.filter((element): element is HTMLElement => Boolean(element) && isToolbarShown(element))
.map(rectOf);
}
/** 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]
@@ -547,6 +554,8 @@ function syncSlotBindings() {
anchor: capsuleConfig.anchor,
skinId: hostChromeActiveSkinId.value,
align: capsuleConfig.align,
// A slotted capsule must not cover a still-docked split toolbar either.
otherControls: () => dockedToolbarRects(),
onModeChange: change => { slotMode.value = change.mode; },
});
}
@@ -592,6 +601,11 @@ function bindFloating() {
return { width: hit + 10, height: hit + 10 };
},
onCompactChange: next => { floatCompact.value = next; },
// Docked toolbars are inside the closed shadow root, so the light-DOM
// obstacle scan cannot see them. In split mode the library toolbar falls
// back to this capsule while the built-in toolbar stays docked; without
// this exclusion the capsule could cover it (320px GUI failure).
avoidRects: () => dockedToolbarRects(),
// Never move the capsule under the user's pointer or focus, and leave a
// docked capsule to the slot binding.
paused: () => slotMode.value === "slotted"
@@ -6,6 +6,7 @@ import {
FLOATING_WEIGHT_PROTECTED,
FLOATING_WEIGHT_POINTER,
chooseFloatingPosition,
floatingHitsAvoidRect,
floatingRect,
shouldFold,
floatingScore,
@@ -33,6 +34,23 @@ test("floating rects follow the corner margins and stay inside the viewport", ()
assert.ok(narrow.bottom <= 844);
});
test("a docked host toolbar is an excluded floating spot, not just a weighted obstacle", () => {
// 318px stage from the GUI retest: a 218x36 built-in toolbar docked at the
// top-left; the fallback capsule is 169x38. Top corners overlap it, so a
// capsule pushed off the bottom dock must not land there.
const narrow = { width: 318, height: 638 };
const cap = { width: 169, height: 38 };
const dockedToolbar = rect(20, 10, 218, 36);
assert.equal(floatingHitsAvoidRect("top-left", cap, narrow, margins, [dockedToolbar]), true);
assert.equal(floatingHitsAvoidRect("top-right", cap, narrow, margins, [dockedToolbar]), true);
assert.equal(floatingHitsAvoidRect("top-center", cap, narrow, margins, [dockedToolbar]), true);
assert.equal(floatingHitsAvoidRect("middle-left", cap, narrow, margins, [dockedToolbar]), false);
assert.equal(floatingHitsAvoidRect("middle-right", cap, narrow, margins, [dockedToolbar]), false);
assert.equal(floatingHitsAvoidRect("bottom-left", cap, narrow, margins, [dockedToolbar]), false);
// A one-pixel brush against the footprint is not a cover.
assert.equal(floatingHitsAvoidRect("top-left", cap, narrow, margins, [rect(180, 50, 10, 10)]), false);
});
test("score is zero without overlap, ignores 1px brushes and weights dialog and (above all) protected controls", () => {
const footprint = rect(12, 724, 200, 38);
assert.equal(floatingScore(footprint, [{ rect: rect(400, 400, 40, 40), weight: 1 }]), 0);
+45 -6
View File
@@ -228,6 +228,22 @@ function rectsIntersect(first: HostPartRect, second: HostPartRect): boolean {
return first.left < second.right && first.right > second.left && first.top < second.bottom && first.bottom > second.top;
}
/**
* Whether a candidate corner would put the control on top of a docked host
* control. Used to exclude such spots outright; scoring alone can still pick
* one when the other corners cover skin controls.
*/
export function floatingHitsAvoidRect(
position: FloatingPosition,
size: FloatingSize,
viewport: FloatingViewport,
margins: FloatingMargins,
avoidRects: readonly HostPartRect[],
): boolean {
const footprint = floatingRect(position, size, viewport, margins);
return avoidRects.some(rect => rectsIntersect(footprint, rect));
}
/* ------------------------------------------------------------------ *
* DOM binding
* ------------------------------------------------------------------ */
@@ -358,6 +374,14 @@ export interface FloatingAvoidanceOptions {
onCompactChange?: (compact: boolean) => void;
/** Skip re-evaluation (hovered, focused, slotted, drawer open…). */
paused?: () => boolean;
/**
* Footprints of host controls that are docked in the top layer. They are
* invisible to `collectFloatingObstacles` (which scans the light DOM), but a
* floating fallback must never sit on them: a covered button loses its
* label and its click lands on the wrong action. Positions that intersect
* one of these rects are skipped whenever any free position exists.
*/
avoidRects?: () => readonly HostPartRect[];
}
export interface FloatingAvoidance {
@@ -457,13 +481,28 @@ export function bindFloatingAvoidance(options: FloatingAvoidanceOptions): Floati
}
const now = Date.now();
const urgent = now < urgentUntil;
// Return home only after a screen change (see chooseFloatingPosition).
const home = urgent ? defaultPosition : undefined;
const full = chooseFloatingPosition({ current: position, size, viewport, margins, obstacles, moveObstacles, home });
// Docked recovery toolbars live in the closed shadow root, so the light-DOM
// obstacle scan above cannot see them. Exclude their footprints outright:
// scoring alone could still park the fallback where a docked button sits
// (GUI reproduced this at 320px: the library capsule covered the built-in
// toolbar and its centre click hit the built-in action). If every corner
// is docked, fall back to scoring over all positions rather than trapping
// the capsule off-screen.
const avoid = options.avoidRects?.() ?? [];
const forbiddenAt = (candidate: FloatingPosition) =>
floatingHitsAvoidRect(candidate, size, viewport, margins, avoid);
const freePositions = FLOATING_POSITIONS.filter(candidate => !forbiddenAt(candidate));
const positions = freePositions.length ? freePositions : FLOATING_POSITIONS;
const current = forbiddenAt(position) && freePositions.length ? freePositions[0] : position;
const park = forbiddenAt(defaultPosition) && freePositions.length ? freePositions[0] : defaultPosition;
// Return home only after a screen change (see chooseFloatingPosition), and
// only when the default corner is not one of the docked footprints.
const home = urgent && !forbiddenAt(defaultPosition) ? defaultPosition : undefined;
const full = chooseFloatingPosition({ current, size, viewport, margins, obstacles, moveObstacles, positions, home });
let next = full;
let nextCompact = false;
if (full.score > 0 && small && small.width > 0 && small.height > 0) {
const reduced = chooseFloatingPosition({ current: full.position, size: small, viewport, margins, obstacles, moveObstacles });
const reduced = chooseFloatingPosition({ current: full.position, size: small, viewport, margins, obstacles, moveObstacles, positions });
if (shouldFold(full, reduced)) {
next = reduced;
nextCompact = true;
@@ -514,8 +553,8 @@ export function bindFloatingAvoidance(options: FloatingAvoidanceOptions): Floati
moveTimes = [];
frozenUntil = now + HOST_FLOATING_FLAP_FREEZE_MS;
frozenEscaped = false;
if (position !== defaultPosition) {
position = defaultPosition;
if (position !== park) {
position = park;
apply(position);
}
setCompact(false);
@@ -16,6 +16,9 @@
#home-anchor { left: 20px; }
#voice-anchor { left: 20px; display: none; }
#dock { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 8px; }
#dock button { height: 32px; padding: 0 10px; border: 1px solid #47dcc4; border-radius: 8px; background: #102030; color: #fff; font: inherit; }
#output-dock { position: absolute; right: 12px; bottom: 12px; }
#output-dock button { height: 32px; padding: 0 10px; border: 1px solid #47dcc4; border-radius: 8px; background: #102030; color: #fff; font: inherit; }
</style>
</head>
<body>
@@ -35,6 +38,9 @@
<div id="dock" data-ws-part="voice.audio-dock">
<button type="button" data-ws-part="voice.audio-dock.microphone">Mic</button>
</div>
<div id="output-dock" data-ws-part="voice.audio-dock">
<button type="button" data-ws-part="voice.audio-dock.output">Output</button>
</div>
</div>
<div id="app"></div>
<div id="plugin-app"></div>
@@ -75,6 +81,23 @@ const isVisible = (element) => {
const rect = element.getBoundingClientRect();
return style.display !== "none" && style.visibility !== "hidden" && rect.width > 0 && rect.height > 0;
};
// Real hit testing, not element.click(): a fallback capsule can be fully
// covered by a still-docked toolbar while still reporting a visible box. All
// recovery buttons live in the closed shadow root, so elementFromPoint on the
// document retargets to the layer host; scoping it to the shadow root reveals
// which action is actually on top at the button's own centre.
const hitOf = (button, layer) => {
const box = button.getBoundingClientRect();
const x = box.left + box.width / 2;
const y = box.top + box.height / 2;
const docHit = document.elementFromPoint(x, y);
const shadowHit = layer?.shadow.elementFromPoint(x, y);
const hitButton = (shadowHit ?? docHit)?.closest?.("[data-ws-recovery-action]");
return {
docHitIsLayerHost: docHit === layer?.host,
hitAction: hitButton?.getAttribute("data-ws-recovery-action") ?? null,
};
};
// The real PluginPanel calls createPluginAppClient().list() on mount. Keep it
// entirely local and deterministic: no production gateway, no external fetch.
@@ -171,9 +194,12 @@ try {
height: rectOf(button).height,
visible: isVisible(button),
inViewport: withinViewport(rectOf(button)),
...hitOf(button, layer),
})),
capsuleOpen: isOpen(cap),
capsuleVisible: isVisible(cap),
capsuleFloat: cap?.getAttribute("data-ws-float") ?? null,
capsuleRect: cap ? rectOf(cap) : null,
capsuleActions: capActions,
launcherPresent: Boolean(lch),
launcherVisible: isVisible(lch),
@@ -214,6 +240,7 @@ try {
height: rectOf(button).height,
visible: isVisible(button),
inViewport: withinViewport(rectOf(button)),
...hitOf(button, layer),
}));
}
hostLanguage.value = "de";
+28 -1
View File
@@ -55,7 +55,7 @@ const scenarios = [
];
test("host chrome renders recovery and authorization in a closed-shadow top layer", async () => {
const [hostChrome, authorization, ownedLayer, hostChromeService, publicSkin, recoveryNotice, slotPlacement, pluginPanel, presentation, controlTokens] = await Promise.all([
const [hostChrome, authorization, ownedLayer, hostChromeService, publicSkin, recoveryNotice, slotPlacement, floatingPlacement, pluginPanel, presentation, controlTokens] = await Promise.all([
read("../src/components/HostChrome.vue"),
read("../src/components/InstanceAuthorization.vue"),
read("../src/services/host-owned-layer.ts"),
@@ -63,6 +63,7 @@ test("host chrome renders recovery and authorization in a closed-shadow top laye
read("../src/composables/usePublicSkin.ts"),
read("../src/components/SkinLoadRecoveryNotice.vue"),
read("../src/services/host-slot-placement.ts"),
read("../src/services/host-floating-placement.ts"),
read("../src/components/PluginPanel.vue"),
read("../src/services/host-recovery-presentation.ts"),
read("../src/services/host-control-tokens.ts"),
@@ -117,6 +118,13 @@ test("host chrome renders recovery and authorization in a closed-shadow top laye
// Two split recovery toolbars must not cover each other on a narrow screen.
assert.match(slotPlacement, /covers-host-control/);
assert.match(hostChrome, /otherControls:/);
// A fallback capsule must also avoid toolbars that are still docked: they
// live in the closed shadow root and are invisible to the light-DOM obstacle
// scan, so the document scan alone cannot protect their labels/clicks.
assert.match(hostChrome, /avoidRects:/);
assert.match(hostChrome, /dockedToolbarRects\(\)/);
assert.match(floatingPlacement, /avoidRects\?:/);
assert.match(floatingPlacement, /forbiddenAt\(/);
assert.match(hostChromeService, /export function activeHostSlot/);
assert.match(hostChromeService, /HOST_SLOTTABLE_PART_IDS\.has\(part\)/);
assert.match(hostChromeService, /isThirdPartySkinActive\(\)/);
@@ -665,6 +673,10 @@ test("real PluginPanel launcher is de-duplicated by group and split toolbars on
assert.equal(entry.visible, true, `${context}: button is not visible`);
assert.equal(entry.inViewport, true, `${context}: button escaped the viewport: ${JSON.stringify(entry.rect)}`);
assert.ok(entry.height >= 28, `${context}: button fell below the host hit target (${entry.height})`);
// A visible box is not enough: elementFromPoint at the button's own
// centre must resolve to that button, not to a sibling host control.
assert.equal(entry.docHitIsLayerHost, true, `${context}: ${entry.action} is not in the host top layer`);
assert.equal(entry.hitAction, entry.action, `${context}: ${entry.action} centre is covered by ${entry.hitAction}`);
}
};
@@ -764,6 +776,21 @@ test("real PluginPanel launcher is de-duplicated by group and split toolbars on
assert.equal(narrowSplit.initial.launcherPresent, false, "the real launcher reappeared at 320px");
assert.equal(narrowSplit.initial.visibleLibraryEntries, 1, "the narrow fallback added a duplicate library entry");
observableButtons(narrowSplit.initial, "split 320px");
// The pushed-out library toolbar falls back to the capsule while built-in
// stays docked. Both bottom corners of the fixture are occupied, which is
// what drives the capsule toward the top bar (the GUI-retested failure).
// Assert the two footprints are disjoint and each action's centre resolves
// to its own button via elementFromPoint, not a synthetic element.click().
const dockedSplitBar = narrowSplit.initial.toolbars.find((bar) => bar.open);
const dockedSplitButton = narrowSplit.initial.visibleActions.find((entry) => entry.action === "built-in");
const capsuleSplitButton = narrowSplit.initial.visibleActions.find((entry) => entry.action === "library");
assert.ok(dockedSplitBar && dockedSplitButton && capsuleSplitButton, "split 320px did not show one docked and one fallback action");
assert.equal(
overlaps(dockedSplitBar.rect, capsuleSplitButton.rect), false,
`fallback capsule covers the docked toolbar at 320px: ${JSON.stringify({ toolbar: dockedSplitBar.rect, capsule: capsuleSplitButton.rect })}`,
);
assert.equal(dockedSplitButton.hitAction, "built-in", "the docked built-in button is not the hit target at its centre");
assert.equal(capsuleSplitButton.hitAction, "library", "the fallback library button is not the hit target at its centre");
assert.equal(narrowSplit.clicks.builtIn, true, "the docked split button was not clickable at 320px");
assert.equal(narrowSplit.clicks.library, true, "the fallback capsule button was not clickable at 320px");
for (const lang of ["de", "ru", "ja"]) {