@@ -4,44 +4,81 @@ import type { Rect } from '@agent-device/kernel/snapshot';
44import { buildScrollGesturePlan , type ScrollDirection } from './scroll-gesture.ts' ;
55
66// The iPhone geometry #2714 was reported on: a 402x874 frame, the default 10% edge padding leaving
7- // y 87..787 for a swipe.
7+ // x 40..362 and y 87..787 for a swipe.
88const FRAME = { referenceWidth : 402 , referenceHeight : 874 } ;
9+ const PADDED_LEFT = 40 ;
910const PADDED_TOP = 87 ;
1011const PADDED_BOTTOM = 787 ;
12+ // Inset under a navigation bar and running to the bottom of the frame.
1113const INSET_CONTAINER : Rect = { x : 18 , y : 178 , width : 366 , height : 662 } ;
14+ // Inset at both ends: a footer sits below it, well above the padded band's bottom.
15+ const FOOTERED_CONTAINER : Rect = { x : 18 , y : 178 , width : 366 , height : 500 } ;
1216const FITTING_CONTAINER : Rect = { x : 18 , y : 62 , width : 366 , height : 729 } ;
1317
14- function endpointsInside (
15- plan : { x1 : number ; y1 : number ; x2 : number ; y2 : number } ,
16- rect : Rect ,
17- ) : boolean {
18+ type Endpoints = { x1 : number ; y1 : number ; x2 : number ; y2 : number } ;
19+
20+ /**
21+ * A container rect is half-open, as Android bounds and View hit-testing are: `y + height` is the
22+ * first row outside it. Strictly inside on both sides also keeps the drag off the edge row.
23+ */
24+ function strictlyInside ( plan : Endpoints , rect : Rect ) : boolean {
1825 const inside = ( x : number , y : number ) =>
19- x >= rect . x && x <= rect . x + rect . width && y >= rect . y && y <= rect . y + rect . height ;
26+ x > rect . x && x < rect . x + rect . width && y > rect . y && y < rect . y + rect . height ;
2027 return inside ( plan . x1 , plan . y1 ) && inside ( plan . x2 , plan . y2 ) ;
2128}
2229
23- test . each < ScrollDirection > ( [ 'up' , 'down' ] ) (
24- 'a %s swipe longer than an inset container shrinks to the container and reports both spans' ,
25- ( direction ) => {
30+ test . each < [ ScrollDirection , string , Rect ] > ( [
31+ [ 'up' , 'inset' , INSET_CONTAINER ] ,
32+ [ 'down' , 'inset' , INSET_CONTAINER ] ,
33+ [ 'up' , 'footered' , FOOTERED_CONTAINER ] ,
34+ [ 'down' , 'footered' , FOOTERED_CONTAINER ] ,
35+ ] ) (
36+ 'a %s swipe longer than an %s container shrinks inside it and reports both spans' ,
37+ ( direction , _ , container ) => {
2638 const unclamped = buildScrollGesturePlan ( { direction, amount : 0.75 , ...FRAME } ) ;
27- const plan = buildScrollGesturePlan ( {
28- direction,
29- amount : 0.75 ,
30- ...FRAME ,
31- container : INSET_CONTAINER ,
32- } ) ;
39+ const plan = buildScrollGesturePlan ( { direction, amount : 0.75 , ...FRAME , container } ) ;
3340
34- assert . ok ( endpointsInside ( plan , INSET_CONTAINER ) , JSON . stringify ( plan ) ) ;
35- assert . deepEqual (
36- [ Math . min ( plan . y1 , plan . y2 ) , Math . max ( plan . y1 , plan . y2 ) ] ,
37- [ INSET_CONTAINER . y , PADDED_BOTTOM ] ,
38- ) ;
39- assert . equal ( plan . pixels , PADDED_BOTTOM - INSET_CONTAINER . y ) ;
41+ assert . ok ( strictlyInside ( plan , container ) , JSON . stringify ( plan ) ) ;
42+ assert . ok ( Math . max ( plan . y1 , plan . y2 ) <= PADDED_BOTTOM , JSON . stringify ( plan ) ) ;
43+ assert . equal ( plan . pixels , Math . abs ( plan . y2 - plan . y1 ) ) ;
44+ assert . ok ( plan . pixels < unclamped . pixels ) ;
4045 assert . equal ( plan . requestedPixels , unclamped . pixels ) ;
4146 assert . equal ( Math . sign ( plan . y2 - plan . y1 ) , Math . sign ( unclamped . y2 - unclamped . y1 ) ) ;
4247 } ,
4348) ;
4449
50+ test . each < ScrollDirection > ( [ 'left' , 'right' ] ) (
51+ 'a %s swipe longer than a narrow container shrinks inside it along x' ,
52+ ( direction ) => {
53+ const column : Rect = { x : 100 , y : 0 , width : 200 , height : 874 } ;
54+ const unclamped = buildScrollGesturePlan ( { direction, ...FRAME } ) ;
55+ const plan = buildScrollGesturePlan ( { direction, ...FRAME , container : column } ) ;
56+
57+ assert . ok ( strictlyInside ( plan , column ) , JSON . stringify ( plan ) ) ;
58+ assert . deepEqual ( [ plan . y1 , plan . y2 ] , [ unclamped . y1 , unclamped . y2 ] ) ;
59+ assert . equal ( plan . pixels , Math . abs ( plan . x2 - plan . x1 ) ) ;
60+ assert . ok ( plan . pixels < unclamped . pixels ) ;
61+ assert . equal ( plan . requestedPixels , unclamped . pixels ) ;
62+ assert . equal ( Math . sign ( plan . x2 - plan . x1 ) , Math . sign ( unclamped . x2 - unclamped . x1 ) ) ;
63+ } ,
64+ ) ;
65+
66+ test ( 'a horizontal swipe that fits an offset container moves into it without shortening' , ( ) => {
67+ const rightPane : Rect = { x : 180 , y : 0 , width : 222 , height : 874 } ;
68+ const unclamped = buildScrollGesturePlan ( { direction : 'left' , pixels : 100 , ...FRAME } ) ;
69+ const plan = buildScrollGesturePlan ( {
70+ direction : 'left' ,
71+ pixels : 100 ,
72+ ...FRAME ,
73+ container : rightPane ,
74+ } ) ;
75+
76+ assert . ok ( strictlyInside ( plan , rightPane ) , JSON . stringify ( plan ) ) ;
77+ assert . equal ( Math . abs ( plan . x2 - plan . x1 ) , Math . abs ( unclamped . x2 - unclamped . x1 ) ) ;
78+ assert . equal ( plan . pixels , unclamped . pixels ) ;
79+ assert . equal ( 'requestedPixels' in plan , false ) ;
80+ } ) ;
81+
4582test . each < ScrollDirection > ( [ 'up' , 'down' , 'left' , 'right' ] ) (
4683 'a %s swipe already inside its container keeps today’s endpoints and distance' ,
4784 ( direction ) => {
@@ -68,24 +105,72 @@ test('a swipe that fits an offset container moves into it without shortening', (
68105 container : lowerContainer ,
69106 } ) ;
70107
71- assert . ok ( endpointsInside ( plan , lowerContainer ) , JSON . stringify ( plan ) ) ;
72- assert . equal ( Math . min ( plan . y1 , plan . y2 ) , lowerContainer . y ) ;
108+ assert . ok ( strictlyInside ( plan , lowerContainer ) , JSON . stringify ( plan ) ) ;
73109 assert . equal ( Math . abs ( plan . y1 - plan . y2 ) , Math . abs ( unclamped . y1 - unclamped . y2 ) ) ;
74110 assert . equal ( plan . pixels , unclamped . pixels ) ;
75111 assert . equal ( 'requestedPixels' in plan , false ) ;
76112} ) ;
77113
78- test ( 'a vertical swipe beside a narrow container runs down its centre line' , ( ) => {
114+ test ( 'an odd span that only loses its rounding pixel is not reported as shortened' , ( ) => {
115+ // On an 875-point axis the padded band is 88..787 (699 points), and a 699-point request centred
116+ // on 438 rounds its halves to a 700-point lane. Fitting it into the band drops that rounding
117+ // pixel, not any of the travel asked for.
118+ const frame = { referenceWidth : 402 , referenceHeight : 875 } ;
119+ const wholeFrame : Rect = { x : 0 , y : 0 , width : 402 , height : 875 } ;
120+ const plan = buildScrollGesturePlan ( {
121+ direction : 'up' ,
122+ pixels : 699 ,
123+ ...frame ,
124+ container : wholeFrame ,
125+ } ) ;
126+
127+ assert . equal ( plan . pixels , 699 ) ;
128+ assert . equal ( Math . abs ( plan . y2 - plan . y1 ) , 699 ) ;
129+ assert . equal ( 'requestedPixels' in plan , false ) ;
130+ } ) ;
131+
132+ test ( 'a vertical swipe beside a narrow container moves across into it' , ( ) => {
79133 const rightColumn : Rect = { x : 250 , y : 0 , width : 152 , height : 874 } ;
80134 const unclamped = buildScrollGesturePlan ( { direction : 'up' , ...FRAME } ) ;
81135 const plan = buildScrollGesturePlan ( { direction : 'up' , ...FRAME , container : rightColumn } ) ;
82136
83- assert . equal ( plan . x1 , rightColumn . x + rightColumn . width / 2 ) ;
137+ assert . ok ( strictlyInside ( plan , rightColumn ) , JSON . stringify ( plan ) ) ;
138+ assert . ok ( plan . x1 <= FRAME . referenceWidth - PADDED_LEFT , `swipe x ${ plan . x1 } is in the padding` ) ;
84139 assert . equal ( plan . x2 , plan . x1 ) ;
85140 assert . deepEqual ( [ plan . y1 , plan . y2 , plan . pixels ] , [ unclamped . y1 , unclamped . y2 , unclamped . pixels ] ) ;
86141} ) ;
87142
88- test ( 'a container lying wholly in the edge padding leaves the padded swipe as it was' , ( ) => {
143+ test ( 'a container reaching into the side padding is swiped in the part the padding leaves' , ( ) => {
144+ const edgeColumn : Rect = { x : 0 , y : 0 , width : 60 , height : 874 } ;
145+ const plan = buildScrollGesturePlan ( { direction : 'up' , ...FRAME , container : edgeColumn } ) ;
146+
147+ assert . ok ( strictlyInside ( plan , edgeColumn ) , JSON . stringify ( plan ) ) ;
148+ assert . ok ( plan . x1 >= PADDED_LEFT , `swipe x ${ plan . x1 } is inside the side padding` ) ;
149+ } ) ;
150+
151+ test . each < [ ScrollDirection , string , Rect ] > ( [
152+ [
153+ 'up' ,
154+ 'a navigation rail along the left edge' ,
155+ { x : 0 , y : 0 , width : PADDED_LEFT - 1 , height : 874 } ,
156+ ] ,
157+ [
158+ 'left' ,
159+ 'a chip row just above the padded band' ,
160+ { x : 0 , y : 60 , width : 402 , height : PADDED_TOP - 61 } ,
161+ ] ,
162+ ] ) (
163+ 'a %s swipe aimed at %s runs inside it when the cross-axis padding leaves none of it' ,
164+ ( direction , _ , container ) => {
165+ const unclamped = buildScrollGesturePlan ( { direction, ...FRAME } ) ;
166+ const plan = buildScrollGesturePlan ( { direction, ...FRAME , container } ) ;
167+
168+ assert . ok ( strictlyInside ( plan , container ) , JSON . stringify ( plan ) ) ;
169+ assert . equal ( plan . pixels , unclamped . pixels ) ;
170+ } ,
171+ ) ;
172+
173+ test ( 'a container lying wholly in the padding of the scrolled axis leaves the padded swipe as it was' , ( ) => {
89174 const statusBand : Rect = { x : 0 , y : 0 , width : 402 , height : PADDED_TOP - 1 } ;
90175 const unclamped = buildScrollGesturePlan ( { direction : 'up' , ...FRAME } ) ;
91176 const plan = buildScrollGesturePlan ( { direction : 'up' , ...FRAME , container : statusBand } ) ;
0 commit comments