Skip to content

Commit 1e9748c

Browse files
committed
fix(snapshot): read toolbar host scroll evidence from the shared scrollable predicate
Keep the full scrollable family, excluding scroll indicators. listedSiblings bails when the node is not listed. Fixture depth walks the parent chain.
1 parent bcc1950 commit 1e9748c

2 files changed

Lines changed: 44 additions & 16 deletions

File tree

‎packages/capture-kit/src/snapshot-occlusion.ts‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import type { RawSnapshotNode, Rect } from '@agent-device/kernel/snapshot';
22
import { centerOfRect } from '@agent-device/kernel/snapshot';
33
import { areRectsApproximatelyEqual, normalizeRect } from '@agent-device/kernel/rect-center';
44
import { containsPoint, rectContains } from '@agent-device/kernel/rect';
5-
import { normalizeType, isViewportRootNode } from '@agent-device/contracts/snapshot';
5+
import {
6+
isScrollableNodeLike,
7+
normalizeType,
8+
isViewportRootNode,
9+
} from '@agent-device/contracts/snapshot';
610

711
const COVERED_PRESENTATION_HINT = 'covered';
812
const OVERLAY_KIND_FRAGMENTS = [
@@ -19,7 +23,7 @@ const OVERLAY_KIND_FRAGMENTS = [
1923
];
2024
const VIEWPORT_CHROME_KIND_FRAGMENTS = ['tabbar', 'toolbar', 'navigationbar'];
2125
const TOOLBAR_HOST_KIND_FRAGMENTS = ['toolbar'];
22-
const SCROLL_CONTAINER_TYPES = new Set(['collectionview', 'table', 'scrollview']);
26+
const SCROLL_INDICATOR_KIND_FRAGMENTS = ['scrollbar', 'scrollindicator'];
2327
const SEMANTIC_TOUCH_KIND_FRAGMENTS = [
2428
'button',
2529
'link',
@@ -321,7 +325,9 @@ function isSiblingSizedChromeContainer(
321325
if (typeof node.parentIndex !== 'number') return false;
322326
const rect = positiveRect(node.rect);
323327
if (!rect) return false;
324-
const { siblings, position } = listedSiblings(node, neighbourhood);
328+
const listed = listedSiblings(node, neighbourhood);
329+
if (!listed) return false;
330+
const { siblings, position } = listed;
325331
return siblings.some(
326332
(sibling, siblingPosition) =>
327333
siblingPosition !== position && areRectsApproximatelyEqual(rect, sibling.rect),
@@ -345,7 +351,9 @@ function isOwnPresentationToolbarHost(
345351
if (!nodeKindIncludesAny(node, TOOLBAR_HOST_KIND_FRAGMENTS)) return false;
346352
const rect = positiveRect(node.rect);
347353
if (!rect) return false;
348-
const { siblings, position } = listedSiblings(node, neighbourhood);
354+
const listed = listedSiblings(node, neighbourhood);
355+
if (!listed) return false;
356+
const { siblings, position } = listed;
349357
const ownStart = ownPresentationStart(siblings, position);
350358
const enclosed = siblings.flatMap((sibling, siblingPosition) =>
351359
siblingPosition !== position && isEnclosedHostedRegion(rect, sibling) ? [siblingPosition] : [],
@@ -366,25 +374,24 @@ function ownPresentationStart(siblings: readonly RawSnapshotNode[], position: nu
366374
return start;
367375
}
368376

369-
/** A bar or a scroll container (by type, so a scroll indicator does not count) inside `rect`. */
377+
/** A bar or a scroll container inside `rect`; a scroll indicator is not a container. */
370378
function isEnclosedHostedRegion(rect: Rect, node: RawSnapshotNode): boolean {
371379
const isHostedRegion =
372380
nodeKindIncludesAny(node, VIEWPORT_CHROME_KIND_FRAGMENTS) ||
373-
SCROLL_CONTAINER_TYPES.has(normalizeType(node.type ?? ''));
381+
(isScrollableNodeLike(node) && !nodeKindIncludesAny(node, SCROLL_INDICATOR_KIND_FRAGMENTS));
374382
const nodeRect = positiveRect(node.rect);
375383
return Boolean(isHostedRegion && nodeRect && rectContains(rect, nodeRect));
376384
}
377385

378-
/** The siblings listed under the node's parent in document order, and the node's position among them. */
386+
/** The siblings listed under the node's parent in document order and the node's position, if listed. */
379387
function listedSiblings(
380388
node: RawSnapshotNode,
381389
neighbourhood: NeighbourhoodIndex,
382-
): { siblings: readonly RawSnapshotNode[]; position: number } {
383-
const siblings =
384-
typeof node.parentIndex === 'number'
385-
? (neighbourhood.childrenByParent.get(node.parentIndex) ?? [])
386-
: [];
387-
return { siblings, position: siblings.findIndex((sibling) => sibling.index === node.index) };
390+
): { siblings: readonly RawSnapshotNode[]; position: number } | undefined {
391+
if (typeof node.parentIndex !== 'number') return undefined;
392+
const siblings = neighbourhood.childrenByParent.get(node.parentIndex) ?? [];
393+
const position = siblings.findIndex((sibling) => sibling.index === node.index);
394+
return position < 0 ? undefined : { siblings, position };
388395
}
389396

390397
function isFullViewportChromeContainer(

‎packages/capture-kit/src/snapshot-sibling-sized-chrome.test.ts‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,13 @@ type CapturedNode = [
440440

441441
/** Builds a tree from rows captured with `snapshot -i --json`, every node hittable as published. */
442442
function capturedTree(rows: CapturedNode[]): RawSnapshotNode[] {
443-
const depthByIndex = new Map<number, number>();
443+
const parentByIndex = new Map(rows.map(([index, parentIndex]) => [index, parentIndex]));
444+
const depthOf = (index: number | undefined): number => {
445+
const parentIndex = index === undefined ? undefined : parentByIndex.get(index);
446+
return parentIndex === undefined ? 0 : depthOf(parentIndex) + 1;
447+
};
444448
return rows.map(([index, parentIndex, type, role, label, [x, y, width, height]]) => {
445-
const depth = parentIndex === undefined ? 0 : (depthByIndex.get(parentIndex) ?? 0) + 1;
446-
depthByIndex.set(index, depth);
449+
const depth = depthOf(index);
447450
return node({
448451
index,
449452
parentIndex,
@@ -688,6 +691,24 @@ test('a toolbar host enclosing only a scroll indicator still covers, so the scro
688691
assert.ok(coveredLabels(nodes).includes('Barless primary'));
689692
});
690693

694+
test.for([
695+
{
696+
name: 'an Android RecyclerView type',
697+
type: 'androidx.recyclerview.widget.RecyclerView',
698+
role: '',
699+
},
700+
{ name: 'a scroll kind published only in role', type: 'Other', role: 'UIScrollView' },
701+
])('a toolbar host enclosing $name reads it as a scroll container', ({ type, role }) => {
702+
const nodes = capturedTree([
703+
[0, undefined, 'Other', 'SwiftUIApplication', 'SheetRepro', [0, 0, 402, 874]],
704+
[1, 0, type, role, undefined, [0, 100, 402, 712]],
705+
[3, 1, 'Button', 'SwiftUI.AccessibilityNode', 'Barless primary', [16, 100, 370, 49]],
706+
[17, 0, 'Toolbar', '_UIFloatingBarContainerView', 'Toolbar', [0, 62, 402, 812]],
707+
]);
708+
709+
assert.deepEqual(coveredLabels(nodes), []);
710+
});
711+
691712
test('a control the exempt toolbar host really hosts still covers the row it overlaps', () => {
692713
// The host is exempt for the list it encloses, but a bar-kind strip it hosts is judged by its own
693714
// rect: it covers the row beneath it and leaves the row above it alone.

0 commit comments

Comments
 (0)