diff --git a/web/src/components/HostChrome.vue b/web/src/components/HostChrome.vue index e406bd3..8bd7d35 100644 --- a/web/src/components/HostChrome.vue +++ b/web/src/components/HostChrome.vue @@ -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" diff --git a/web/src/services/host-floating-placement.test.ts b/web/src/services/host-floating-placement.test.ts index e3bb944..3761ba9 100644 --- a/web/src/services/host-floating-placement.test.ts +++ b/web/src/services/host-floating-placement.test.ts @@ -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); diff --git a/web/src/services/host-floating-placement.ts b/web/src/services/host-floating-placement.ts index 3499677..746c99e 100644 --- a/web/src/services/host-floating-placement.ts +++ b/web/src/services/host-floating-placement.ts @@ -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); diff --git a/web/test/fixtures/host-recovery-toolbar-plugin-panel.html b/web/test/fixtures/host-recovery-toolbar-plugin-panel.html index a0de218..44828e9 100644 --- a/web/test/fixtures/host-recovery-toolbar-plugin-panel.html +++ b/web/test/fixtures/host-recovery-toolbar-plugin-panel.html @@ -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; }
@@ -35,6 +38,9 @@