@astryxdesign/core 0.7.6 → 0.7.7-canary.1d04d40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AppShell/AppShell.d.ts.map +1 -1
- package/dist/AppShell/AppShell.js +23 -3
- package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheetPanel.js +16 -9
- package/dist/Chat/ChatComposerInput.d.ts +9 -0
- package/dist/Chat/ChatComposerInput.d.ts.map +1 -1
- package/dist/Chat/ChatComposerInput.js +2 -0
- package/dist/Chat/ChatMessage.js +2 -2
- package/dist/Chat/chatMessage.vars.stylex.d.ts +8 -8
- package/dist/Chat/chatMessage.vars.stylex.js +8 -8
- package/dist/CommandPalette/CommandPaletteInput.d.ts.map +1 -1
- package/dist/CommandPalette/CommandPaletteInput.js +8 -1
- package/dist/DateInput/MonthScroller.d.ts.map +1 -1
- package/dist/DateInput/MonthScroller.js +72 -2
- package/dist/Drawer/Drawer.d.ts.map +1 -1
- package/dist/Drawer/Drawer.js +6 -0
- package/dist/DropdownMenu/useMenuOverflow.d.ts +13 -3
- package/dist/DropdownMenu/useMenuOverflow.d.ts.map +1 -1
- package/dist/DropdownMenu/useMenuOverflow.js +31 -8
- package/dist/Field/PanelSearchInput.d.ts.map +1 -1
- package/dist/Field/PanelSearchInput.js +8 -1
- package/dist/Field/textEntryTraits.d.ts +6 -6
- package/dist/Field/textEntryTraits.js +6 -6
- package/dist/Layer/layerClickBoundary.d.ts +7 -1
- package/dist/Layer/layerClickBoundary.d.ts.map +1 -1
- package/dist/Layer/layerClickBoundary.js +2 -2
- package/dist/Layer/usePressPin.d.ts +95 -0
- package/dist/Layer/usePressPin.d.ts.map +1 -0
- package/dist/Layer/usePressPin.js +335 -0
- package/dist/Layer/useTouchTrigger.d.ts +23 -1
- package/dist/Layer/useTouchTrigger.d.ts.map +1 -1
- package/dist/Layer/useTouchTrigger.js +29 -2
- package/dist/Link/Link.d.ts.map +1 -1
- package/dist/Link/Link.js +1 -0
- package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
- package/dist/ProgressBar/ProgressBar.js +20 -9
- package/dist/ProgressBar/ProgressBarTouch.d.ts +29 -0
- package/dist/ProgressBar/ProgressBarTouch.d.ts.map +1 -0
- package/dist/ProgressBar/ProgressBarTouch.js +91 -0
- package/dist/Selector/Selector.d.ts.map +1 -1
- package/dist/Selector/Selector.js +25 -13
- package/dist/Slider/Slider.d.ts.map +1 -1
- package/dist/Slider/Slider.js +404 -131
- package/dist/Slider/sliderTouchController.d.ts +189 -0
- package/dist/Slider/sliderTouchController.d.ts.map +1 -0
- package/dist/Slider/sliderTouchController.js +1017 -0
- package/dist/Slider/useSliderTouch.d.ts +22 -0
- package/dist/Slider/useSliderTouch.d.ts.map +1 -0
- package/dist/Slider/useSliderTouch.js +56 -0
- package/dist/Tooltip/Tooltip.d.ts +30 -6
- package/dist/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/Tooltip/Tooltip.js +5 -0
- package/dist/Tooltip/index.d.ts +1 -1
- package/dist/Tooltip/index.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.d.ts +31 -5
- package/dist/Tooltip/useTooltip.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.js +59 -18
- package/dist/Typeahead/BaseTypeahead.d.ts.map +1 -1
- package/dist/Typeahead/BaseTypeahead.js +19 -9
- package/dist/astryx.css +40 -6
- package/dist/gestures/GestureArena.d.ts +21 -2
- package/dist/gestures/GestureArena.d.ts.map +1 -1
- package/dist/gestures/GestureArena.js +23 -3
- package/dist/gestures/GestureHost.d.ts +123 -3
- package/dist/gestures/GestureHost.d.ts.map +1 -1
- package/dist/gestures/GestureHost.js +791 -12
- package/dist/gestures/GestureRecognizer.d.ts +15 -1
- package/dist/gestures/GestureRecognizer.d.ts.map +1 -1
- package/dist/gestures/GestureRecognizer.js +12 -0
- package/dist/gestures/PanGestureRecognizer.d.ts +8 -0
- package/dist/gestures/PanGestureRecognizer.d.ts.map +1 -1
- package/dist/gestures/PinchGestureRecognizer.d.ts +5 -1
- package/dist/gestures/PinchGestureRecognizer.d.ts.map +1 -1
- package/dist/gestures/PinchGestureRecognizer.js +10 -0
- package/dist/gestures/ScreenEdgePanGestureRecognizer.d.ts +3 -3
- package/dist/gestures/ScreenEdgePanGestureRecognizer.d.ts.map +1 -1
- package/dist/gestures/ScreenEdgePanGestureRecognizer.js +7 -5
- package/dist/gestures/nativeScroll.d.ts +16 -2
- package/dist/gestures/nativeScroll.d.ts.map +1 -1
- package/dist/gestures/nativeScroll.js +39 -8
- package/dist/gestures/recognizerInternals.d.ts +4 -2
- package/dist/gestures/recognizerInternals.d.ts.map +1 -1
- package/dist/gestures/types.d.ts +11 -0
- package/dist/gestures/types.d.ts.map +1 -1
- package/dist/gestures/types.js +7 -0
- package/dist/gestures/wheelSegmenter.d.ts +45 -0
- package/dist/gestures/wheelSegmenter.d.ts.map +1 -0
- package/dist/gestures/wheelSegmenter.js +98 -0
- package/dist/motion/animator.d.ts.map +1 -1
- package/dist/motion/animator.js +140 -19
- package/dist/motion/paging.d.ts +58 -0
- package/dist/motion/paging.d.ts.map +1 -0
- package/dist/motion/paging.js +128 -0
- package/dist/motion/uikit/index.d.ts +5 -3
- package/dist/motion/uikit/index.d.ts.map +1 -1
- package/dist/motion/uikit/index.js +5 -3
- package/dist/motion/uikit/paging.d.ts +160 -0
- package/dist/motion/uikit/paging.d.ts.map +1 -0
- package/dist/motion/uikit/paging.js +162 -0
- package/dist/motion/uikit/progressBar.d.ts +59 -0
- package/dist/motion/uikit/progressBar.d.ts.map +1 -0
- package/dist/motion/uikit/progressBar.js +82 -0
- package/dist/motion/uikit/scroll.d.ts +0 -19
- package/dist/motion/uikit/scroll.d.ts.map +1 -1
- package/dist/motion/uikit/scroll.js +2 -21
- package/dist/motion/uikit/slider.d.ts +97 -0
- package/dist/motion/uikit/slider.d.ts.map +1 -0
- package/dist/motion/uikit/slider.js +111 -0
- package/dist/motion/uikit/springs.d.ts +46 -1
- package/dist/motion/uikit/springs.d.ts.map +1 -1
- package/dist/motion/uikit/springs.js +48 -4
- package/dist/utils/selectionLock.d.ts +43 -0
- package/dist/utils/selectionLock.d.ts.map +1 -1
- package/dist/utils/selectionLock.js +394 -6
- package/package.json +5 -5
- package/src/AppShell/AppShell.doc.mjs +10 -0
- package/src/AppShell/AppShell.tsx +48 -2
- package/src/BottomSheet/BottomSheetPanel.tsx +16 -9
- package/src/Chat/Chat.doc.mjs +1 -0
- package/src/Chat/ChatComposerInput.doc.mjs +11 -0
- package/src/Chat/ChatComposerInput.tsx +11 -0
- package/src/Chat/ChatMessage.tsx +2 -2
- package/src/Chat/chatMessage.vars.stylex.ts +8 -8
- package/src/CommandPalette/CommandPaletteInput.tsx +6 -0
- package/src/DateInput/MonthScroller.tsx +63 -5
- package/src/Drawer/Drawer.tsx +6 -0
- package/src/DropdownMenu/useMenuOverflow.ts +44 -8
- package/src/Field/PanelSearchInput.tsx +6 -0
- package/src/Field/textEntryTraits.ts +6 -6
- package/src/Layer/layerClickBoundary.ts +2 -2
- package/src/Layer/usePressPin.ts +481 -0
- package/src/Layer/useTouchTrigger.ts +37 -1
- package/src/Link/Link.tsx +3 -0
- package/src/ProgressBar/ProgressBar.doc.mjs +3 -3
- package/src/ProgressBar/ProgressBar.tsx +82 -11
- package/src/ProgressBar/ProgressBarTouch.ts +109 -0
- package/src/Selector/Selector.tsx +29 -2
- package/src/Slider/Slider.doc.mjs +11 -7
- package/src/Slider/Slider.tsx +539 -132
- package/src/Slider/sliderTouchController.ts +1209 -0
- package/src/Slider/useSliderTouch.ts +78 -0
- package/src/Tooltip/Tooltip.doc.mjs +21 -6
- package/src/Tooltip/Tooltip.tsx +42 -5
- package/src/Tooltip/index.ts +1 -0
- package/src/Tooltip/useTooltip.doc.mjs +4 -2
- package/src/Tooltip/useTooltip.tsx +84 -21
- package/src/Typeahead/BaseTypeahead.tsx +16 -8
- package/src/gestures/GestureArena.ts +45 -4
- package/src/gestures/GestureHost.ts +949 -12
- package/src/gestures/GestureRecognizer.ts +28 -0
- package/src/gestures/PanGestureRecognizer.ts +8 -0
- package/src/gestures/PinchGestureRecognizer.ts +16 -1
- package/src/gestures/README.md +82 -3
- package/src/gestures/ScreenEdgePanGestureRecognizer.ts +7 -5
- package/src/gestures/nativeScroll.ts +49 -9
- package/src/gestures/recognizerInternals.ts +9 -2
- package/src/gestures/types.ts +12 -0
- package/src/gestures/wheelSegmenter.ts +114 -0
- package/src/motion/MEASUREMENTS.md +8 -1
- package/src/motion/README.md +6 -3
- package/src/motion/animator.ts +193 -25
- package/src/motion/paging.ts +138 -0
- package/src/motion/uikit/index.ts +5 -3
- package/src/motion/uikit/paging.ts +162 -0
- package/src/motion/uikit/progressBar.ts +82 -0
- package/src/motion/uikit/scroll.ts +2 -18
- package/src/motion/uikit/slider.ts +105 -0
- package/src/motion/uikit/springs.ts +37 -2
- package/src/utils/selectionLock.ts +501 -6
- package/dist/motion/selectPage.d.ts +0 -26
- package/dist/motion/selectPage.d.ts.map +0 -1
- package/dist/motion/selectPage.js +0 -55
- package/src/motion/selectPage.ts +0 -55
|
@@ -140,9 +140,14 @@ import {
|
|
|
140
140
|
import type {GestureRecognizer, SelectionLock} from './GestureRecognizer';
|
|
141
141
|
import type {PressBounds} from './PressTracker';
|
|
142
142
|
import type {PanGestureRecognizer} from './PanGestureRecognizer';
|
|
143
|
-
import {
|
|
143
|
+
import {
|
|
144
|
+
canElementScroll,
|
|
145
|
+
createNativeScrollProbe,
|
|
146
|
+
parentAcrossShadow,
|
|
147
|
+
} from './nativeScroll';
|
|
144
148
|
import {containsAlongFlatTree} from '../utils/flatTree';
|
|
145
149
|
import {isIosWebKit} from '../utils/touchQueries';
|
|
150
|
+
import {type WheelSegment, WheelSegmenter} from './wheelSegmenter';
|
|
146
151
|
import {
|
|
147
152
|
gestureHostStyle,
|
|
148
153
|
type GestureHostStyle,
|
|
@@ -158,6 +163,7 @@ import type {
|
|
|
158
163
|
GestureEnvironment,
|
|
159
164
|
GestureTouch,
|
|
160
165
|
PointerKind,
|
|
166
|
+
ScrollType,
|
|
161
167
|
TouchBeganInput,
|
|
162
168
|
TouchConsumer,
|
|
163
169
|
TouchInput,
|
|
@@ -171,7 +177,13 @@ import {
|
|
|
171
177
|
} from '../utils/clickGuard';
|
|
172
178
|
import {subscribeInput} from '../utils/inputStream';
|
|
173
179
|
import {isPrimaryClick} from '../utils/primaryClick';
|
|
174
|
-
import {
|
|
180
|
+
import {
|
|
181
|
+
type DragSelectionReleaseOptions,
|
|
182
|
+
lockDragSelection,
|
|
183
|
+
locksSelectionFor,
|
|
184
|
+
selectionRangesOf,
|
|
185
|
+
startsOnSelectableText,
|
|
186
|
+
} from '../utils/selectionLock';
|
|
175
187
|
import {isCoarsePointer, watchCoarsePointer} from '../utils/coarsePointer';
|
|
176
188
|
import {gestureHosts} from './hostRegistry';
|
|
177
189
|
|
|
@@ -186,6 +198,8 @@ interface Registration {
|
|
|
186
198
|
hasTouchEndListener: boolean;
|
|
187
199
|
/** Whether the element carries the host's shared blocking touchmove handler. */
|
|
188
200
|
hasTouchMoveListener: boolean;
|
|
201
|
+
/** Whether the element carries the host's wheel handler. */
|
|
202
|
+
hasWheelListener: boolean;
|
|
189
203
|
/** Inline values the host replaced, to restore on detach. */
|
|
190
204
|
readonly savedStyle: Map<string, string>;
|
|
191
205
|
/**
|
|
@@ -305,6 +319,16 @@ function claimsWhileMoving(recognizer: GestureRecognizer): boolean {
|
|
|
305
319
|
);
|
|
306
320
|
}
|
|
307
321
|
|
|
322
|
+
/**
|
|
323
|
+
* Whether a recognizer takes a contact that comes with Touch Events and a
|
|
324
|
+
* long press's contextmenu: a finger's or a pen's. A scroll-only recognizer
|
|
325
|
+
* (`allowedPointerTypes: []`) and a mouse-only one take neither.
|
|
326
|
+
*/
|
|
327
|
+
function takesTouchContacts(recognizer: GestureRecognizer): boolean {
|
|
328
|
+
const types = recognizer.allowedPointerTypes;
|
|
329
|
+
return types == null || types.has('touch') || types.has('pen');
|
|
330
|
+
}
|
|
331
|
+
|
|
308
332
|
/**
|
|
309
333
|
* A pan (or a pan subclass), told apart by its family rather than its class,
|
|
310
334
|
* so a page that constructs no pan never ships PanGestureRecognizer.
|
|
@@ -381,6 +405,207 @@ function landedOn(
|
|
|
381
405
|
return event.composedPath()[0] ?? retargeted;
|
|
382
406
|
}
|
|
383
407
|
|
|
408
|
+
/**
|
|
409
|
+
* How long after its last event a pinch or a mouse wheel's notches end, ms.
|
|
410
|
+
* The web reports no wheel phases, so a quiet wheel is a lifted one.
|
|
411
|
+
*/
|
|
412
|
+
const WHEEL_END_MS = 100;
|
|
413
|
+
/**
|
|
414
|
+
* How long after its last event a vertical trackpad scroll ends, ms (a
|
|
415
|
+
* sheet's pull), whoever keeps it. A slow drag's stream pauses longer than
|
|
416
|
+
* WHEEL_END_MS between events.
|
|
417
|
+
*/
|
|
418
|
+
const WHEEL_FOLLOW_END_V_MS = 180;
|
|
419
|
+
/**
|
|
420
|
+
* The same horizontally, ms (a pager's or a row's swipe), whose slow
|
|
421
|
+
* swipes pause longer still.
|
|
422
|
+
*/
|
|
423
|
+
const WHEEL_FOLLOW_END_MS = 220;
|
|
424
|
+
/** A line-mode wheel's line, px, as the platforms scroll it. */
|
|
425
|
+
const WHEEL_LINE_PX = 40;
|
|
426
|
+
/** The span a ctrl-wheel pinch's two contacts start at, px. */
|
|
427
|
+
const WHEEL_PINCH_SPAN = 100;
|
|
428
|
+
|
|
429
|
+
/** A wheel gesture: the contacts it drives in the arena, or none where the page keeps it. */
|
|
430
|
+
interface WheelGesture {
|
|
431
|
+
readonly kind: 'pan' | 'pinch';
|
|
432
|
+
/** A mouse wheel's notches, or a trackpad's continuous scroll. */
|
|
433
|
+
readonly scrollType: ScrollType;
|
|
434
|
+
readonly ids: ReadonlyArray<number>;
|
|
435
|
+
/** A pan's contact, or a pinch's center. */
|
|
436
|
+
x: number;
|
|
437
|
+
y: number;
|
|
438
|
+
/** A pinch's span between its two contacts. */
|
|
439
|
+
span: number;
|
|
440
|
+
/** The latest wheel's time. */
|
|
441
|
+
last: number;
|
|
442
|
+
/**
|
|
443
|
+
* How long after its last wheel it ends, ms. A trackpad pan stream waits
|
|
444
|
+
* out its axis's pause bound, whoever keeps it. A pinch or a mouse wheel's
|
|
445
|
+
* notches wait 100 ms.
|
|
446
|
+
*/
|
|
447
|
+
readonly endMs: number;
|
|
448
|
+
timer: unknown;
|
|
449
|
+
/** The recognizers that took it; none where the page keeps it. */
|
|
450
|
+
readonly takers: ReadonlyArray<GestureRecognizer>;
|
|
451
|
+
/** A trackpad scroll a pan follows, until its fingers lift. */
|
|
452
|
+
follow?: WheelFollow;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** A trackpad scroll a pan follows: where its fingers lift, and what waits until then. */
|
|
456
|
+
interface WheelFollow {
|
|
457
|
+
/** The fingers lifted: the momentum after them never moves the pan. */
|
|
458
|
+
lifted: boolean;
|
|
459
|
+
/**
|
|
460
|
+
* Shrinking deltas held until the splitter decides. They are the fingers'
|
|
461
|
+
* when larger ones follow, and the start of momentum when it reads the
|
|
462
|
+
* lift.
|
|
463
|
+
*/
|
|
464
|
+
heldX: number;
|
|
465
|
+
heldY: number;
|
|
466
|
+
/** The time of the fingers' last move the pan took. */
|
|
467
|
+
lastMove: number;
|
|
468
|
+
/** The fingers' travel as of that move: the contact without any held delta. */
|
|
469
|
+
trueX: number;
|
|
470
|
+
trueY: number;
|
|
471
|
+
/** Where the pan was shown at that move, which the undecided stretch moves on from. */
|
|
472
|
+
baseX: number;
|
|
473
|
+
baseY: number;
|
|
474
|
+
/** The fingers' speed at that move, content px per ms. */
|
|
475
|
+
speedX: number;
|
|
476
|
+
speedY: number;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* How long after its last wheel a wheel gesture ends, ms. A trackpad's
|
|
481
|
+
* two-finger scroll waits out a slow drag's pauses for its axis, whoever
|
|
482
|
+
* keeps the stream. A pinch and a mouse wheel's notches end 100 ms after
|
|
483
|
+
* their last wheel.
|
|
484
|
+
*/
|
|
485
|
+
function wheelEndMs(
|
|
486
|
+
kind: 'pan' | 'pinch',
|
|
487
|
+
scrollType: ScrollType,
|
|
488
|
+
isHorizontal: boolean,
|
|
489
|
+
): number {
|
|
490
|
+
if (kind === 'pinch' || scrollType !== 'continuous') {
|
|
491
|
+
return WHEEL_END_MS;
|
|
492
|
+
}
|
|
493
|
+
return isHorizontal ? WHEEL_FOLLOW_END_MS : WHEEL_FOLLOW_END_V_MS;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* A provisional lead `debt` after a move of `moved`. The debt is what a
|
|
498
|
+
* followed pan shows past the fingers' travel, or short of it. Half the move
|
|
499
|
+
* is absorbed, so the pan keeps moving the way the fingers do.
|
|
500
|
+
*/
|
|
501
|
+
function absorbedDebt(debt: number, moved: number): number {
|
|
502
|
+
return Math.sign(debt) * Math.max(0, Math.abs(debt) - Math.abs(moved) / 2);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* `target` where it is ahead of `shown` in the direction of `speed`, else
|
|
507
|
+
* `shown`: a reconcile that never steps back.
|
|
508
|
+
*/
|
|
509
|
+
function ahead(shown: number, target: number, speed: number): number {
|
|
510
|
+
return speed === 0 || (target - shown) * Math.sign(speed) > 0
|
|
511
|
+
? target
|
|
512
|
+
: shown;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* A wheel's deltas in CSS px: a line is `WHEEL_LINE_PX`, a page the
|
|
517
|
+
* viewport.
|
|
518
|
+
*/
|
|
519
|
+
function wheelPixels(
|
|
520
|
+
wheel: WheelEvent,
|
|
521
|
+
view: Window | null,
|
|
522
|
+
): {dx: number; dy: number} {
|
|
523
|
+
if (wheel.deltaMode === 1) {
|
|
524
|
+
return {dx: wheel.deltaX * WHEEL_LINE_PX, dy: wheel.deltaY * WHEEL_LINE_PX};
|
|
525
|
+
}
|
|
526
|
+
if (wheel.deltaMode === 2) {
|
|
527
|
+
return {
|
|
528
|
+
dx: wheel.deltaX * (view?.innerWidth ?? 0),
|
|
529
|
+
dy: wheel.deltaY * (view?.innerHeight ?? 0),
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
return {dx: wheel.deltaX, dy: wheel.deltaY};
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* The web's best reading of what scrolled: a mouse wheel's notches
|
|
537
|
+
* (`discrete`) or a trackpad's scroll (`continuous`). Input it cannot tell
|
|
538
|
+
* apart counts as a mouse wheel's, which a pan that takes only a trackpad's
|
|
539
|
+
* scroll leaves to the page. These read as a mouse wheel's:
|
|
540
|
+
* - a line- or page-mode delta;
|
|
541
|
+
* - a scroll with Shift held (Shift+wheel);
|
|
542
|
+
* - a pixel delta a hair off a whole pixel (a mouse wheel on Windows);
|
|
543
|
+
* - a scroll with no legacy `wheelDelta` (an engine that sends none);
|
|
544
|
+
* - a delta that is not a third of its legacy `wheelDelta`;
|
|
545
|
+
* - a 120 tick over a 40 px delta.
|
|
546
|
+
* A trackpad's precise deltas, a third of their legacy `wheelDelta` in
|
|
547
|
+
* Chromium and WebKit, read as a trackpad's.
|
|
548
|
+
*/
|
|
549
|
+
function scrollTypeOf(wheel: WheelEvent): ScrollType {
|
|
550
|
+
if (wheel.deltaMode !== 0 || wheel.shiftKey) {
|
|
551
|
+
return 'discrete';
|
|
552
|
+
}
|
|
553
|
+
const remainder = (value: number) => {
|
|
554
|
+
const fraction = Math.abs(value - Math.round(value));
|
|
555
|
+
return fraction > 0 && fraction < 0.01;
|
|
556
|
+
};
|
|
557
|
+
if (remainder(wheel.deltaX) || remainder(wheel.deltaY)) {
|
|
558
|
+
return 'discrete';
|
|
559
|
+
}
|
|
560
|
+
const legacy = wheel as WheelEvent & {
|
|
561
|
+
wheelDeltaX?: number;
|
|
562
|
+
wheelDeltaY?: number;
|
|
563
|
+
};
|
|
564
|
+
if (
|
|
565
|
+
typeof legacy.wheelDeltaY !== 'number' ||
|
|
566
|
+
typeof legacy.wheelDeltaX !== 'number'
|
|
567
|
+
) {
|
|
568
|
+
return 'discrete';
|
|
569
|
+
}
|
|
570
|
+
const precise = (delta: number, legacyDelta: number) =>
|
|
571
|
+
delta === 0
|
|
572
|
+
? legacyDelta === 0
|
|
573
|
+
: Math.abs(Math.abs(legacyDelta) - 3 * Math.abs(delta)) <=
|
|
574
|
+
Math.max(1.5, 0.05 * Math.abs(delta) * 3);
|
|
575
|
+
if (
|
|
576
|
+
!precise(wheel.deltaY, legacy.wheelDeltaY) ||
|
|
577
|
+
!precise(wheel.deltaX, legacy.wheelDeltaX)
|
|
578
|
+
) {
|
|
579
|
+
return 'discrete';
|
|
580
|
+
}
|
|
581
|
+
const tick = (delta: number, legacyDelta: number) =>
|
|
582
|
+
legacyDelta !== 0 && legacyDelta % 120 === 0 && delta % 40 === 0;
|
|
583
|
+
return tick(wheel.deltaY, legacy.wheelDeltaY) ||
|
|
584
|
+
tick(wheel.deltaX, legacy.wheelDeltaX)
|
|
585
|
+
? 'discrete'
|
|
586
|
+
: 'continuous';
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/** Read without the pan class, which a page with no pan never ships. */
|
|
590
|
+
function isScrollEdgePan(recognizer: GestureRecognizer): boolean {
|
|
591
|
+
return (recognizer as {scrollEdge?: boolean}).scrollEdge === true;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Whether a pan takes a contact moving by (cx, cy), by its own direction
|
|
596
|
+
* rule, `axisRatio` included. A move its rule leaves undecided stays the
|
|
597
|
+
* page's.
|
|
598
|
+
*/
|
|
599
|
+
function panTakesMove(
|
|
600
|
+
recognizer: GestureRecognizer,
|
|
601
|
+
cx: number,
|
|
602
|
+
cy: number,
|
|
603
|
+
): boolean {
|
|
604
|
+
return (
|
|
605
|
+
(internals(recognizer).classify?.({x: cx, y: cy}) ?? 'begin') === 'begin'
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
|
|
384
609
|
/**
|
|
385
610
|
* An event's time on the arena's clock (`performance.now()`). Some engines
|
|
386
611
|
* and DOM emulators stamp events in epoch milliseconds instead.
|
|
@@ -416,7 +641,35 @@ export class GestureHost {
|
|
|
416
641
|
/** Cancels the scheduled next-frame read (readCallerTouchActionInNextFrame). */
|
|
417
642
|
private cancelCallerRead: (() => void) | null = null;
|
|
418
643
|
/** The selection lock each contact holds, by host contact id. */
|
|
419
|
-
private readonly lockedBy = new Map<
|
|
644
|
+
private readonly lockedBy = new Map<
|
|
645
|
+
number,
|
|
646
|
+
(options?: DragSelectionReleaseOptions) => void
|
|
647
|
+
>();
|
|
648
|
+
/**
|
|
649
|
+
* The page's selection when each mouse or pen press began: a drag a
|
|
650
|
+
* recognizer claims keeps it.
|
|
651
|
+
*/
|
|
652
|
+
private readonly pressSelections = new Map<
|
|
653
|
+
number,
|
|
654
|
+
ReadonlyArray<AbstractRange>
|
|
655
|
+
>();
|
|
656
|
+
/**
|
|
657
|
+
* Mouse and pen contacts that began on selectable text. Once one moves, the
|
|
658
|
+
* browser keeps the drag for a selection, and no recognizer claims it.
|
|
659
|
+
*/
|
|
660
|
+
private readonly selectingContacts = new Set<number>();
|
|
661
|
+
/**
|
|
662
|
+
* Drag selection holds until their last task ends, a task after their lift
|
|
663
|
+
* (lockDragSelection); the last detach ends them at once.
|
|
664
|
+
*/
|
|
665
|
+
private readonly dragHolds = new Set<
|
|
666
|
+
(options?: DragSelectionReleaseOptions) => void
|
|
667
|
+
>();
|
|
668
|
+
/** Each claimed contact's drag hold, until its lift or a give-back. */
|
|
669
|
+
private readonly claimHolds = new Map<
|
|
670
|
+
number,
|
|
671
|
+
(options?: DragSelectionReleaseOptions) => void
|
|
672
|
+
>();
|
|
420
673
|
private readonly presentedHitTesting: 'auto' | 'always' | 'never';
|
|
421
674
|
/**
|
|
422
675
|
* Contacts sent to what is drawn instead of what the engine hit, by host
|
|
@@ -530,6 +783,16 @@ export class GestureHost {
|
|
|
530
783
|
*/
|
|
531
784
|
private fingerTargets: ReadonlyArray<Node> = [];
|
|
532
785
|
private nextId = 1;
|
|
786
|
+
/** The wheel gesture in progress. */
|
|
787
|
+
private wheel: WheelGesture | null = null;
|
|
788
|
+
/** The wheel latch's input-stream subscription, while a gesture is latched. */
|
|
789
|
+
private stopWheelLatch: (() => void) | null = null;
|
|
790
|
+
/** Splits the wheel stream into gestures and reads a trackpad's lift. */
|
|
791
|
+
private readonly segmenter = new WheelSegmenter();
|
|
792
|
+
/** The latest wheel's segment. */
|
|
793
|
+
private wheelSegment: WheelSegment | null = null;
|
|
794
|
+
/** Wheels already taken: each element on the path with a listener hears one. */
|
|
795
|
+
private readonly wheelsSeen = new WeakSet<Event>();
|
|
533
796
|
private isInstalled = false;
|
|
534
797
|
/**
|
|
535
798
|
* Whether the primary pointer is coarse (`spec:AST-094` FR19), read when
|
|
@@ -587,6 +850,11 @@ export class GestureHost {
|
|
|
587
850
|
// tap) ends here: an armed press stops listening (FR24).
|
|
588
851
|
onIdle: () => this.releaseArmedPress(),
|
|
589
852
|
onTransition: options.onTransition,
|
|
853
|
+
onClaim: (ids, claimer) => this.lockClaimedDrags(ids, claimer),
|
|
854
|
+
onRelease: ids => this.releaseClaimedDrags(ids),
|
|
855
|
+
refusesClaim: touch =>
|
|
856
|
+
this.selectingContacts.has(touch.id) &&
|
|
857
|
+
(touch.x !== touch.startX || touch.y !== touch.startY),
|
|
590
858
|
});
|
|
591
859
|
const view = doc.defaultView;
|
|
592
860
|
// A test may pass its own read; otherwise the one coarse-pointer gate,
|
|
@@ -648,6 +916,16 @@ export class GestureHost {
|
|
|
648
916
|
if (recognizer.state !== 'possible' || recognizer.isInvolved()) {
|
|
649
917
|
recognizer.cancel();
|
|
650
918
|
}
|
|
919
|
+
const wheel = this.wheel;
|
|
920
|
+
if (
|
|
921
|
+
wheel != null &&
|
|
922
|
+
wheel.takers.includes(recognizer) &&
|
|
923
|
+
!this.wheelHasTaker(wheel)
|
|
924
|
+
) {
|
|
925
|
+
// At its last wheel: a later stamp would move the arena's clock past
|
|
926
|
+
// the next input's own time.
|
|
927
|
+
this.endWheel(wheel.last);
|
|
928
|
+
}
|
|
651
929
|
this.refresh(element, registration);
|
|
652
930
|
// Even when the element keeps other attachments: one left disabled
|
|
653
931
|
// keeps no listener or observer (FR24).
|
|
@@ -1055,6 +1333,7 @@ export class GestureHost {
|
|
|
1055
1333
|
consumer: null,
|
|
1056
1334
|
hasTouchEndListener: false,
|
|
1057
1335
|
hasTouchMoveListener: false,
|
|
1336
|
+
hasWheelListener: false,
|
|
1058
1337
|
savedStyle: new Map(),
|
|
1059
1338
|
authorTouchAction: null,
|
|
1060
1339
|
manageStyle: true,
|
|
@@ -1135,6 +1414,26 @@ export class GestureHost {
|
|
|
1135
1414
|
element.removeEventListener('touchmove', this.onBlockingTouchMove);
|
|
1136
1415
|
registration.hasTouchMoveListener = false;
|
|
1137
1416
|
}
|
|
1417
|
+
// Wheel and trackpad input, only where an enabled recognizer takes it. A
|
|
1418
|
+
// non-passive wheel listener makes the browser's scrolling over the
|
|
1419
|
+
// element wait for the main thread.
|
|
1420
|
+
const needsWheel = registration.recognizers.some(
|
|
1421
|
+
recognizer =>
|
|
1422
|
+
recognizer.isEnabled &&
|
|
1423
|
+
// A watcher never takes the wheel: the page keeps it.
|
|
1424
|
+
recognizer.claimsTouches &&
|
|
1425
|
+
recognizer.allowedScrollTypes.size > 0 &&
|
|
1426
|
+
// A wheel drives a pan or a pinch only.
|
|
1427
|
+
(internals(recognizer).family === 'pan' ||
|
|
1428
|
+
internals(recognizer).family === 'pinch'),
|
|
1429
|
+
);
|
|
1430
|
+
if (needsWheel && !registration.hasWheelListener) {
|
|
1431
|
+
element.addEventListener('wheel', this.onWheel, {passive: false});
|
|
1432
|
+
registration.hasWheelListener = true;
|
|
1433
|
+
} else if (!needsWheel && registration.hasWheelListener) {
|
|
1434
|
+
element.removeEventListener('wheel', this.onWheel);
|
|
1435
|
+
registration.hasWheelListener = false;
|
|
1436
|
+
}
|
|
1138
1437
|
}
|
|
1139
1438
|
|
|
1140
1439
|
private applyStyle(element: HTMLElement, registration: Registration): void {
|
|
@@ -1290,6 +1589,9 @@ export class GestureHost {
|
|
|
1290
1589
|
if (registration.hasTouchMoveListener) {
|
|
1291
1590
|
element.removeEventListener('touchmove', this.onBlockingTouchMove);
|
|
1292
1591
|
}
|
|
1592
|
+
if (registration.hasWheelListener) {
|
|
1593
|
+
element.removeEventListener('wheel', this.onWheel);
|
|
1594
|
+
}
|
|
1293
1595
|
this.registry.delete(element);
|
|
1294
1596
|
this.uninstallIfIdle();
|
|
1295
1597
|
}
|
|
@@ -1394,7 +1696,13 @@ export class GestureHost {
|
|
|
1394
1696
|
for (const [element, registration] of this.registry) {
|
|
1395
1697
|
const consumer = registration.consumer;
|
|
1396
1698
|
if (
|
|
1397
|
-
registration.recognizers.some(
|
|
1699
|
+
registration.recognizers.some(
|
|
1700
|
+
recognizer =>
|
|
1701
|
+
recognizer.isEnabled &&
|
|
1702
|
+
// One that takes only scroll input has no press to arm.
|
|
1703
|
+
(recognizer.allowedPointerTypes == null ||
|
|
1704
|
+
recognizer.allowedPointerTypes.size > 0),
|
|
1705
|
+
) ||
|
|
1398
1706
|
(consumer != null && consumer.isEnabled?.() !== false)
|
|
1399
1707
|
) {
|
|
1400
1708
|
wanted.add(element);
|
|
@@ -1510,6 +1818,13 @@ export class GestureHost {
|
|
|
1510
1818
|
}
|
|
1511
1819
|
this.ownScrollFrames.clear();
|
|
1512
1820
|
this.ownedScrolls.clear();
|
|
1821
|
+
// A drag's hold whose press lifted in this task ends now, not a task
|
|
1822
|
+
// later: nothing is attached to meet its mouseup or click.
|
|
1823
|
+
for (const release of [...this.dragHolds]) {
|
|
1824
|
+
release({isCancel: true});
|
|
1825
|
+
}
|
|
1826
|
+
this.pressSelections.clear();
|
|
1827
|
+
this.selectingContacts.clear();
|
|
1513
1828
|
});
|
|
1514
1829
|
}
|
|
1515
1830
|
|
|
@@ -1545,8 +1860,9 @@ export class GestureHost {
|
|
|
1545
1860
|
|
|
1546
1861
|
/**
|
|
1547
1862
|
* Whether an enabled participant could claim a touch or cancel a lift: a
|
|
1548
|
-
* consumer, or a recognizer that claims touches
|
|
1549
|
-
*
|
|
1863
|
+
* consumer, or a recognizer that claims touches and takes a finger or a
|
|
1864
|
+
* pen. With only watchers, or only scroll-only recognizers
|
|
1865
|
+
* (`allowedPointerTypes: []`), the host's listeners are all passive.
|
|
1550
1866
|
*/
|
|
1551
1867
|
private hasClaimer(): boolean {
|
|
1552
1868
|
for (const registration of this.registry.values()) {
|
|
@@ -1554,7 +1870,10 @@ export class GestureHost {
|
|
|
1554
1870
|
if (
|
|
1555
1871
|
(consumer != null && consumer.isEnabled?.() !== false) ||
|
|
1556
1872
|
registration.recognizers.some(
|
|
1557
|
-
recognizer =>
|
|
1873
|
+
recognizer =>
|
|
1874
|
+
recognizer.isEnabled &&
|
|
1875
|
+
recognizer.claimsTouches &&
|
|
1876
|
+
takesTouchContacts(recognizer),
|
|
1558
1877
|
)
|
|
1559
1878
|
) {
|
|
1560
1879
|
return true;
|
|
@@ -1827,10 +2146,615 @@ export class GestureHost {
|
|
|
1827
2146
|
}
|
|
1828
2147
|
}
|
|
1829
2148
|
|
|
1830
|
-
/**
|
|
1831
|
-
|
|
1832
|
-
|
|
2149
|
+
/**
|
|
2150
|
+
* Wheel and trackpad input. A wheel gesture drives the recognizers that
|
|
2151
|
+
* allow its scroll type, as a contact that moves with the content. A pan
|
|
2152
|
+
* takes it along its own axis, once no scroller between the pointer and
|
|
2153
|
+
* the pan's element can scroll that way. The gesture's first wheel decides
|
|
2154
|
+
* this. A pinch takes a ctrl-wheel, as a trackpad pinches, as two contacts
|
|
2155
|
+
* whose span follows exp(-deltaY / 100). A wheel the page keeps is never
|
|
2156
|
+
* prevented, and a wheel a recognizer takes always is. A gesture ends its
|
|
2157
|
+
* end window after its last wheel (wheelEndMs), at that wheel's time, so
|
|
2158
|
+
* its release keeps its velocity. A gesture a recognizer took is latched
|
|
2159
|
+
* to it, as a browser latches a scroller. While the gesture lasts, the
|
|
2160
|
+
* shared input stream hands this every wheel first, wherever it lands. So
|
|
2161
|
+
* a pan whose element moves from under a still pointer keeps the gesture.
|
|
2162
|
+
* The page listener exists only during a gesture.
|
|
2163
|
+
*/
|
|
2164
|
+
private readonly onWheel = (event: Event): void => {
|
|
2165
|
+
const wheel = event as WheelEvent;
|
|
2166
|
+
if (this.wheelsSeen.has(wheel)) {
|
|
2167
|
+
return;
|
|
2168
|
+
}
|
|
2169
|
+
this.wheelsSeen.add(wheel);
|
|
2170
|
+
const time = eventTime(wheel);
|
|
2171
|
+
const kind = wheel.ctrlKey ? 'pinch' : 'pan';
|
|
2172
|
+
let gesture = this.wheel;
|
|
2173
|
+
if (
|
|
2174
|
+
gesture != null &&
|
|
2175
|
+
(gesture.kind !== kind || time - gesture.last >= gesture.endMs)
|
|
2176
|
+
) {
|
|
2177
|
+
this.endWheel(time);
|
|
2178
|
+
gesture = null;
|
|
2179
|
+
}
|
|
2180
|
+
if (
|
|
2181
|
+
gesture != null &&
|
|
2182
|
+
gesture.ids.length > 0 &&
|
|
2183
|
+
gesture.follow?.lifted !== true &&
|
|
2184
|
+
!this.wheelHasTaker(gesture)
|
|
2185
|
+
) {
|
|
2186
|
+
// Every recognizer that took it has left (detached, disabled or
|
|
2187
|
+
// cancelled), so the rest of the gesture is the page's. A followed
|
|
2188
|
+
// pan's own lift does not count. Its momentum stays latched and
|
|
2189
|
+
// prevented until the splitter's next gesture or the end timer, and
|
|
2190
|
+
// moves nothing. The release is stamped at its last wheel.
|
|
2191
|
+
this.endWheel(gesture.last);
|
|
2192
|
+
const left = wheelPixels(wheel, this.doc.defaultView);
|
|
2193
|
+
gesture = {
|
|
2194
|
+
kind,
|
|
2195
|
+
scrollType: scrollTypeOf(wheel),
|
|
2196
|
+
ids: [],
|
|
2197
|
+
x: wheel.clientX,
|
|
2198
|
+
y: wheel.clientY,
|
|
2199
|
+
span: WHEEL_PINCH_SPAN,
|
|
2200
|
+
last: time,
|
|
2201
|
+
endMs: wheelEndMs(
|
|
2202
|
+
kind,
|
|
2203
|
+
scrollTypeOf(wheel),
|
|
2204
|
+
Math.abs(left.dx) > Math.abs(left.dy),
|
|
2205
|
+
),
|
|
2206
|
+
timer: null,
|
|
2207
|
+
takers: [],
|
|
2208
|
+
};
|
|
2209
|
+
this.wheel = gesture;
|
|
2210
|
+
}
|
|
2211
|
+
const {dx, dy} = wheelPixels(wheel, this.doc.defaultView);
|
|
2212
|
+
const horizontal = Math.abs(dx) > Math.abs(dy);
|
|
2213
|
+
// The splitter reads a pan's stream only. A ctrl-wheel pinch has no
|
|
2214
|
+
// fingers' phase or momentum to tell apart, and ends 100 ms after its
|
|
2215
|
+
// last wheel.
|
|
2216
|
+
let seg: WheelSegment | null = null;
|
|
2217
|
+
if (kind === 'pan') {
|
|
2218
|
+
seg = this.segmenter.push(
|
|
2219
|
+
time,
|
|
2220
|
+
horizontal ? dx : dy,
|
|
2221
|
+
horizontal ? WHEEL_FOLLOW_END_MS : WHEEL_FOLLOW_END_V_MS,
|
|
2222
|
+
);
|
|
2223
|
+
} else {
|
|
2224
|
+
this.segmenter.end();
|
|
2225
|
+
}
|
|
2226
|
+
this.wheelSegment = seg;
|
|
2227
|
+
if (seg?.boundary != null) {
|
|
2228
|
+
if (gesture != null) {
|
|
2229
|
+
this.endWheel(time);
|
|
2230
|
+
gesture = null;
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
if (gesture == null) {
|
|
2234
|
+
gesture = this.beginWheel(wheel, kind, dx, dy, time);
|
|
2235
|
+
this.wheel = gesture;
|
|
2236
|
+
if (gesture.ids.length > 0) {
|
|
2237
|
+
this.latchWheel();
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
gesture.last = time;
|
|
2241
|
+
if (gesture.timer != null) {
|
|
2242
|
+
this.clock.clearTimeout(gesture.timer);
|
|
2243
|
+
}
|
|
2244
|
+
// A trackpad scroll waits out a slow drag's pauses, whoever
|
|
2245
|
+
// keeps it; a pinch or a mouse wheel's notches 100 ms.
|
|
2246
|
+
gesture.timer = this.clock.setTimeout(() => {
|
|
2247
|
+
this.segmenter.end();
|
|
2248
|
+
this.endWheel();
|
|
2249
|
+
}, gesture.endMs);
|
|
2250
|
+
if (gesture.ids.length === 0) {
|
|
2251
|
+
return;
|
|
2252
|
+
}
|
|
2253
|
+
wheel.preventDefault();
|
|
2254
|
+
if (gesture.kind === 'pan' && gesture.follow) {
|
|
2255
|
+
const f = gesture.follow;
|
|
2256
|
+
if (f.lifted) {
|
|
2257
|
+
return;
|
|
2258
|
+
}
|
|
2259
|
+
if (this.wheelSegment?.liftNow === true) {
|
|
2260
|
+
// Momentum began: the fingers lifted before the held deltas. The pan
|
|
2261
|
+
// keeps the travel it showed through the undecided stretch. It lets
|
|
2262
|
+
// go here, still moving at the fingers' speed, so its release carries
|
|
2263
|
+
// on from it. The rest of the momentum never moves the pan.
|
|
2264
|
+
this.followProvisionally(gesture, f, time);
|
|
2265
|
+
f.lifted = true;
|
|
2266
|
+
this.arena.ended([
|
|
2267
|
+
{id: gesture.ids[0], x: gesture.x, y: gesture.y, time},
|
|
2268
|
+
]);
|
|
2269
|
+
return;
|
|
2270
|
+
}
|
|
2271
|
+
if (this.wheelSegment?.decaying === true) {
|
|
2272
|
+
// Undecided: the real deltas wait for the splitter while the
|
|
2273
|
+
// fingers' last speed carries the pan on.
|
|
2274
|
+
f.heldX += dx;
|
|
2275
|
+
f.heldY += dy;
|
|
2276
|
+
this.followProvisionally(gesture, f, time);
|
|
2277
|
+
return;
|
|
2278
|
+
}
|
|
2279
|
+
// The fingers' own delta; the held ones were theirs too. Their moves
|
|
2280
|
+
// absorb what the pan shows ahead of their travel, or behind it, half a
|
|
2281
|
+
// move at a time. So the pan never steps back, and ends on their travel.
|
|
2282
|
+
const beforeX = f.trueX - f.heldX;
|
|
2283
|
+
const beforeY = f.trueY - f.heldY;
|
|
2284
|
+
const debtX = absorbedDebt(gesture.x - beforeX, dx);
|
|
2285
|
+
const debtY = absorbedDebt(gesture.y - beforeY, dy);
|
|
2286
|
+
const trueX = beforeX - dx;
|
|
2287
|
+
const trueY = beforeY - dy;
|
|
2288
|
+
const elapsed = time - f.lastMove;
|
|
2289
|
+
if (elapsed > 0) {
|
|
2290
|
+
f.speedX = (trueX - f.trueX) / elapsed;
|
|
2291
|
+
f.speedY = (trueY - f.trueY) / elapsed;
|
|
2292
|
+
}
|
|
2293
|
+
f.trueX = trueX;
|
|
2294
|
+
f.trueY = trueY;
|
|
2295
|
+
f.heldX = 0;
|
|
2296
|
+
f.heldY = 0;
|
|
2297
|
+
f.lastMove = time;
|
|
2298
|
+
gesture.x = trueX + debtX;
|
|
2299
|
+
gesture.y = trueY + debtY;
|
|
2300
|
+
f.baseX = gesture.x;
|
|
2301
|
+
f.baseY = gesture.y;
|
|
2302
|
+
this.arena.moved([
|
|
2303
|
+
{id: gesture.ids[0], x: gesture.x, y: gesture.y, time},
|
|
2304
|
+
]);
|
|
2305
|
+
return;
|
|
2306
|
+
}
|
|
2307
|
+
if (gesture.kind === 'pan') {
|
|
2308
|
+
gesture.x -= dx;
|
|
2309
|
+
gesture.y -= dy;
|
|
2310
|
+
this.arena.moved([
|
|
2311
|
+
{id: gesture.ids[0], x: gesture.x, y: gesture.y, time},
|
|
2312
|
+
]);
|
|
2313
|
+
} else {
|
|
2314
|
+
gesture.span *= Math.exp(-dy / 100);
|
|
2315
|
+
this.arena.moved(this.pinchContacts(gesture, time));
|
|
2316
|
+
}
|
|
2317
|
+
};
|
|
2318
|
+
|
|
2319
|
+
/**
|
|
2320
|
+
* Move a followed pan through the splitter's undecided stretch. It moves on
|
|
2321
|
+
* from where it was shown at the fingers' last move, at their last speed.
|
|
2322
|
+
* It never passes what that speed projects for the time since.
|
|
2323
|
+
*/
|
|
2324
|
+
private followProvisionally(
|
|
2325
|
+
gesture: WheelGesture,
|
|
2326
|
+
f: WheelFollow,
|
|
2327
|
+
time: number,
|
|
2328
|
+
): void {
|
|
2329
|
+
const elapsed = Math.max(0, time - f.lastMove);
|
|
2330
|
+
const x = f.baseX + f.speedX * elapsed;
|
|
2331
|
+
const y = f.baseY + f.speedY * elapsed;
|
|
2332
|
+
if (x === gesture.x && y === gesture.y) {
|
|
2333
|
+
return;
|
|
2334
|
+
}
|
|
2335
|
+
gesture.x = x;
|
|
2336
|
+
gesture.y = y;
|
|
2337
|
+
this.arena.moved([{id: gesture.ids[0], x, y, time}]);
|
|
2338
|
+
}
|
|
2339
|
+
|
|
2340
|
+
/** Start a wheel gesture: who takes it, decided once, or nobody. */
|
|
2341
|
+
private beginWheel(
|
|
2342
|
+
wheel: WheelEvent,
|
|
2343
|
+
kind: 'pan' | 'pinch',
|
|
2344
|
+
dx: number,
|
|
2345
|
+
dy: number,
|
|
2346
|
+
time: number,
|
|
2347
|
+
): WheelGesture {
|
|
2348
|
+
const type = scrollTypeOf(wheel);
|
|
2349
|
+
const isHorizontal = Math.abs(dx) > Math.abs(dy);
|
|
2350
|
+
const kept: WheelGesture = {
|
|
2351
|
+
kind,
|
|
2352
|
+
scrollType: type,
|
|
2353
|
+
ids: [],
|
|
2354
|
+
x: wheel.clientX,
|
|
2355
|
+
y: wheel.clientY,
|
|
2356
|
+
span: WHEEL_PINCH_SPAN,
|
|
2357
|
+
last: time,
|
|
2358
|
+
endMs: wheelEndMs(kind, type, isHorizontal),
|
|
2359
|
+
timer: null,
|
|
2360
|
+
takers: [],
|
|
2361
|
+
};
|
|
2362
|
+
// A contact already down keeps its gesture; the wheel stays the page's.
|
|
2363
|
+
// So does a first wheel another handler already prevented, or one that
|
|
2364
|
+
// cannot be cancelled: no recognizer could take it from the page.
|
|
2365
|
+
if (
|
|
2366
|
+
this.arena.touches.length > 0 ||
|
|
2367
|
+
(dx === 0 && dy === 0) ||
|
|
2368
|
+
wheel.defaultPrevented ||
|
|
2369
|
+
!wheel.cancelable
|
|
2370
|
+
) {
|
|
2371
|
+
return kept;
|
|
2372
|
+
}
|
|
2373
|
+
// Every scroller under the pointer, the page included, as a finger's
|
|
2374
|
+
// probe reads them, without touch-action, which a wheel ignores.
|
|
2375
|
+
// What the wheel landed on: at a shadow host's listener the event's
|
|
2376
|
+
// target is the host, and a scroller inside its tree must count.
|
|
2377
|
+
const target = landedOn(wheel);
|
|
2378
|
+
const scroll = createNativeScrollProbe(target, {
|
|
2379
|
+
readsTouchAction: false,
|
|
2380
|
+
});
|
|
2381
|
+
const takers: GestureRecognizer[] = [];
|
|
2382
|
+
for (
|
|
2383
|
+
let node: Node | null = target instanceof Node ? target : null;
|
|
2384
|
+
node != null;
|
|
2385
|
+
node = parentAcrossShadow(node)
|
|
2386
|
+
) {
|
|
2387
|
+
if (!(node instanceof Element)) {
|
|
2388
|
+
continue;
|
|
2389
|
+
}
|
|
2390
|
+
for (const recognizer of this.registry.get(node)?.recognizers ?? []) {
|
|
2391
|
+
// A pan follows a trackpad, never a mouse wheel's notches, which
|
|
2392
|
+
// scroll what is under the pointer.
|
|
2393
|
+
if (
|
|
2394
|
+
!recognizer.isEnabled ||
|
|
2395
|
+
!recognizer.claimsTouches ||
|
|
2396
|
+
!recognizer.allowedScrollTypes.has(type) ||
|
|
2397
|
+
internals(recognizer).family !== kind ||
|
|
2398
|
+
(kind === 'pan' && type !== 'continuous')
|
|
2399
|
+
) {
|
|
2400
|
+
continue;
|
|
2401
|
+
}
|
|
2402
|
+
if (
|
|
2403
|
+
kind === 'pan' &&
|
|
2404
|
+
(!panTakesMove(recognizer, -dx, -dy) ||
|
|
2405
|
+
this.scrollerTakes(target, node, dx, dy, isHorizontal) ||
|
|
2406
|
+
// A scroll-edge pan only past every scroller's edge.
|
|
2407
|
+
(isScrollEdgePan(recognizer) && scroll.canScroll(-dx, -dy)))
|
|
2408
|
+
) {
|
|
2409
|
+
continue;
|
|
2410
|
+
}
|
|
2411
|
+
takers.push(recognizer);
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
if (takers.length === 0) {
|
|
2415
|
+
return kept;
|
|
2416
|
+
}
|
|
2417
|
+
const base = {
|
|
2418
|
+
pointerType: 'mouse' as const,
|
|
2419
|
+
target,
|
|
2420
|
+
scroll,
|
|
2421
|
+
scrollType: type,
|
|
2422
|
+
recognizers: takers,
|
|
2423
|
+
consumer: null,
|
|
2424
|
+
};
|
|
2425
|
+
const ids =
|
|
2426
|
+
kind === 'pan' ? [this.nextId++] : [this.nextId++, this.nextId++];
|
|
2427
|
+
const gesture: WheelGesture = {...kept, ids, takers};
|
|
2428
|
+
if (kind === 'pan' && type === 'continuous') {
|
|
2429
|
+
gesture.follow = {
|
|
2430
|
+
lifted: false,
|
|
2431
|
+
heldX: 0,
|
|
2432
|
+
heldY: 0,
|
|
2433
|
+
lastMove: time,
|
|
2434
|
+
trueX: kept.x,
|
|
2435
|
+
trueY: kept.y,
|
|
2436
|
+
baseX: kept.x,
|
|
2437
|
+
baseY: kept.y,
|
|
2438
|
+
speedX: 0,
|
|
2439
|
+
speedY: 0,
|
|
2440
|
+
};
|
|
2441
|
+
}
|
|
2442
|
+
this.arena.began(
|
|
2443
|
+
kind === 'pan'
|
|
2444
|
+
? [{...base, id: ids[0], x: wheel.clientX, y: wheel.clientY, time}]
|
|
2445
|
+
: this.pinchContacts(gesture, time).map(input => ({
|
|
2446
|
+
...base,
|
|
2447
|
+
...input,
|
|
2448
|
+
})),
|
|
2449
|
+
);
|
|
2450
|
+
// Every recognizer it was offered to may decline it (its own
|
|
2451
|
+
// shouldReceiveTouch). Then nobody took the wheel, and it scrolls the
|
|
2452
|
+
// page from its first step, as with no gesture system.
|
|
2453
|
+
if (ids.every(id => this.arena.participantsOf(id).length === 0)) {
|
|
2454
|
+
this.arena.cancelled(ids, time);
|
|
2455
|
+
return kept;
|
|
2456
|
+
}
|
|
2457
|
+
return gesture;
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
/**
|
|
2461
|
+
* Whether a scroller between `target` and `boundary` (both included)
|
|
2462
|
+
* scrolls this wheel now, along the wheel's major axis. It uses the edge
|
|
2463
|
+
* test a finger's probe uses (canElementScroll).
|
|
2464
|
+
*/
|
|
2465
|
+
private scrollerTakes(
|
|
2466
|
+
target: unknown,
|
|
2467
|
+
boundary: Element,
|
|
2468
|
+
dx: number,
|
|
2469
|
+
dy: number,
|
|
2470
|
+
isHorizontal: boolean,
|
|
2471
|
+
): boolean {
|
|
2472
|
+
for (
|
|
2473
|
+
let node: Node | null = target instanceof Node ? target : null;
|
|
2474
|
+
node != null;
|
|
2475
|
+
node = parentAcrossShadow(node)
|
|
2476
|
+
) {
|
|
2477
|
+
if (
|
|
2478
|
+
node instanceof Element &&
|
|
2479
|
+
canElementScroll(node, isHorizontal ? -dx : 0, isHorizontal ? 0 : -dy)
|
|
2480
|
+
) {
|
|
2481
|
+
return true;
|
|
2482
|
+
}
|
|
2483
|
+
if (node === boundary) {
|
|
2484
|
+
break;
|
|
2485
|
+
}
|
|
2486
|
+
}
|
|
2487
|
+
return false;
|
|
2488
|
+
}
|
|
2489
|
+
|
|
2490
|
+
/** A ctrl-wheel pinch's two contacts, `span` apart around its center. */
|
|
2491
|
+
private pinchContacts(
|
|
2492
|
+
gesture: WheelGesture,
|
|
2493
|
+
time: number,
|
|
2494
|
+
): {id: number; x: number; y: number; time: number}[] {
|
|
2495
|
+
return [
|
|
2496
|
+
{id: gesture.ids[0], x: gesture.x - gesture.span / 2, y: gesture.y, time},
|
|
2497
|
+
{id: gesture.ids[1], x: gesture.x + gesture.span / 2, y: gesture.y, time},
|
|
2498
|
+
];
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
/** Whether a recognizer that took this wheel gesture still takes part in it. */
|
|
2502
|
+
private wheelHasTaker(gesture: WheelGesture): boolean {
|
|
2503
|
+
// A cancelled or failed recognizer keeps that state until its contacts
|
|
2504
|
+
// end, which a wheel gesture's do only here.
|
|
2505
|
+
return gesture.takers.some(recognizer => {
|
|
2506
|
+
const {state} = recognizer;
|
|
2507
|
+
return (
|
|
2508
|
+
recognizer.isEnabled &&
|
|
2509
|
+
(state === 'began' ||
|
|
2510
|
+
state === 'changed' ||
|
|
2511
|
+
(state === 'possible' && recognizer.isInvolved()))
|
|
2512
|
+
);
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
/**
|
|
2517
|
+
* Route every wheel on the page to the live wheel gesture, from its claim.
|
|
2518
|
+
* The route is the shared input stream's capture listener on the window,
|
|
2519
|
+
* which runs before any document listener. It is non-passive only while it
|
|
2520
|
+
* is subscribed.
|
|
2521
|
+
*/
|
|
2522
|
+
private latchWheel(): void {
|
|
2523
|
+
const view = this.doc.defaultView;
|
|
2524
|
+
if (this.stopWheelLatch == null && view != null) {
|
|
2525
|
+
const cancelWheel = () => {
|
|
2526
|
+
const ids = this.dropDrivenWheel();
|
|
2527
|
+
if (ids.length > 0) {
|
|
2528
|
+
this.arena.cancelled(ids, this.arena.now());
|
|
2529
|
+
}
|
|
2530
|
+
};
|
|
2531
|
+
const stops = [
|
|
2532
|
+
subscribeInput(view, 'wheel', this.onWheel, {cancels: true}),
|
|
2533
|
+
// A page that loses focus or hides ends a trackpad pan, as it ends
|
|
2534
|
+
// every touch. An element's blur reaches the window's capture phase
|
|
2535
|
+
// too and means nothing here.
|
|
2536
|
+
subscribeInput(view, 'blur', event => {
|
|
2537
|
+
if (!(event.target instanceof view.Node)) {
|
|
2538
|
+
cancelWheel();
|
|
2539
|
+
}
|
|
2540
|
+
}),
|
|
2541
|
+
subscribeInput(view, 'visibilitychange', () => {
|
|
2542
|
+
if (this.doc.visibilityState === 'hidden') {
|
|
2543
|
+
cancelWheel();
|
|
2544
|
+
}
|
|
2545
|
+
}),
|
|
2546
|
+
];
|
|
2547
|
+
this.stopWheelLatch = () => {
|
|
2548
|
+
for (const stop of stops) {
|
|
2549
|
+
stop();
|
|
2550
|
+
}
|
|
2551
|
+
};
|
|
2552
|
+
}
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2555
|
+
/**
|
|
2556
|
+
* Hold the page's selection for a mouse or pen contact that a recognizer
|
|
2557
|
+
* claims. Examples are a pan's drag and a press a group claims at its own
|
|
2558
|
+
* pointerdown. While the contact is down, the claiming recognizers'
|
|
2559
|
+
* elements refuse a new selection. The selection the page had at the press
|
|
2560
|
+
* is put back over anything that replaced it. That includes the press's own
|
|
2561
|
+
* collapse and a selection the drag made before its claim. The claiming
|
|
2562
|
+
* recognizer's element holds from its claim, in any state: a waiting
|
|
2563
|
+
* recognizer claims while possible, and a swipe claims as ended. The
|
|
2564
|
+
* participants that already recognize hold too. A claim given back to the
|
|
2565
|
+
* browser lets its hold go (releaseClaimedDrags). A drag that starts on
|
|
2566
|
+
* selectable text never gets here, because no recognizer claims it
|
|
2567
|
+
* (`selectingContacts`). A tap claims only at its lift, so a click keeps
|
|
2568
|
+
* the selection it made. A finger keeps the touch-down lock alone.
|
|
2569
|
+
*/
|
|
2570
|
+
private lockClaimedDrags(
|
|
2571
|
+
ids: ReadonlyArray<number>,
|
|
2572
|
+
claimer: GestureRecognizer,
|
|
2573
|
+
): void {
|
|
2574
|
+
for (const id of ids) {
|
|
2575
|
+
if (this.claimHolds.has(id)) {
|
|
2576
|
+
continue;
|
|
2577
|
+
}
|
|
2578
|
+
const touch = this.arena.touches.find(each => each.id === id);
|
|
2579
|
+
// A claim made at the contact's own lift (a tap's) holds nothing: the
|
|
2580
|
+
// drag is over, and a click keeps the selection it made. A wheel's
|
|
2581
|
+
// contact keeps the page's selection, as a scroll does.
|
|
2582
|
+
if (
|
|
2583
|
+
touch == null ||
|
|
2584
|
+
touch.pointerType === 'touch' ||
|
|
2585
|
+
touch.scrollType != null ||
|
|
2586
|
+
touch.phase === 'ended' ||
|
|
2587
|
+
touch.phase === 'cancelled'
|
|
2588
|
+
) {
|
|
2589
|
+
continue;
|
|
2590
|
+
}
|
|
2591
|
+
const elements = new Set<Element>();
|
|
2592
|
+
for (const recognizer of this.arena.participantsOf(id)) {
|
|
2593
|
+
if (
|
|
2594
|
+
(recognizer.state === 'began' || recognizer.state === 'changed') &&
|
|
2595
|
+
(recognizer.view as Node | null)?.nodeType === 1
|
|
2596
|
+
) {
|
|
2597
|
+
elements.add(recognizer.view as Element);
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
if ((claimer.view as Node | null)?.nodeType === 1) {
|
|
2601
|
+
elements.add(claimer.view as Element);
|
|
2602
|
+
}
|
|
2603
|
+
if (elements.size === 0) {
|
|
2604
|
+
continue;
|
|
2605
|
+
}
|
|
2606
|
+
const release = lockDragSelection(
|
|
2607
|
+
elements,
|
|
2608
|
+
this.doc.defaultView,
|
|
2609
|
+
this.pressSelections.get(id) ?? [],
|
|
2610
|
+
() => {
|
|
2611
|
+
this.dragHolds.delete(release);
|
|
2612
|
+
},
|
|
2613
|
+
);
|
|
2614
|
+
this.dragHolds.add(release);
|
|
2615
|
+
// A press lock the contact took at its press stays in `lockedBy`. The
|
|
2616
|
+
// hold sits beside it, and the contact's end releases both.
|
|
2617
|
+
if (!this.lockedBy.has(id)) {
|
|
2618
|
+
this.lockedBy.set(id, release);
|
|
2619
|
+
}
|
|
2620
|
+
this.claimHolds.set(id, release);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
/**
|
|
2625
|
+
* Claimed contacts the arena gave back. Their drag holds end at once, so
|
|
2626
|
+
* the browser's drag selects again. A contact's press lock (lockSelection)
|
|
2627
|
+
* is not a drag hold and stays.
|
|
2628
|
+
*/
|
|
2629
|
+
private releaseClaimedDrags(ids: ReadonlyArray<number>): void {
|
|
2630
|
+
for (const id of ids) {
|
|
2631
|
+
const release = this.claimHolds.get(id);
|
|
2632
|
+
if (release == null) {
|
|
2633
|
+
continue;
|
|
2634
|
+
}
|
|
2635
|
+
this.claimHolds.delete(id);
|
|
2636
|
+
if (this.lockedBy.get(id) === release) {
|
|
2637
|
+
this.lockedBy.delete(id);
|
|
2638
|
+
}
|
|
2639
|
+
release({isCancel: true});
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
|
|
2643
|
+
/**
|
|
2644
|
+
* End the trackpad pan a recognizer still drives, when the page loses focus
|
|
2645
|
+
* or hides, and return its contacts to cancel. The rest of its stream is
|
|
2646
|
+
* the page's until the stream ends, as a touch the browser takes is. A
|
|
2647
|
+
* ctrl-wheel pinch keeps its stream, so the page never zooms for it. A
|
|
2648
|
+
* gesture the page keeps stays as it is. So does a pan its lift released:
|
|
2649
|
+
* its momentum stays latched and prevented until the stream ends.
|
|
2650
|
+
*/
|
|
2651
|
+
private dropDrivenWheel(): ReadonlyArray<number> {
|
|
2652
|
+
const gesture = this.wheel;
|
|
2653
|
+
if (
|
|
2654
|
+
gesture == null ||
|
|
2655
|
+
gesture.kind !== 'pan' ||
|
|
2656
|
+
gesture.ids.length === 0 ||
|
|
2657
|
+
gesture.follow?.lifted === true
|
|
2658
|
+
) {
|
|
2659
|
+
return [];
|
|
2660
|
+
}
|
|
2661
|
+
const kept: WheelGesture = {...gesture, ids: [], takers: []};
|
|
2662
|
+
delete kept.follow;
|
|
2663
|
+
this.wheel = kept;
|
|
2664
|
+
this.stopWheelLatch?.();
|
|
2665
|
+
this.stopWheelLatch = null;
|
|
2666
|
+
return gesture.ids;
|
|
2667
|
+
}
|
|
2668
|
+
|
|
2669
|
+
/**
|
|
2670
|
+
* End the wheel gesture in progress. On its own timer, it ends its end
|
|
2671
|
+
* window after its last wheel. A taker that leaves (a detach, a disable)
|
|
2672
|
+
* passes that last wheel's time. An input that ends it sooner (a press,
|
|
2673
|
+
* the next gesture's first wheel) passes its own time. Both times are on
|
|
2674
|
+
* the wheels' time base (eventTime), never the host's clock, which need
|
|
2675
|
+
* not share it.
|
|
2676
|
+
*/
|
|
2677
|
+
private endWheel(endTime?: number): void {
|
|
2678
|
+
const gesture = this.wheel;
|
|
2679
|
+
this.stopWheelLatch?.();
|
|
2680
|
+
this.stopWheelLatch = null;
|
|
2681
|
+
if (gesture == null) {
|
|
2682
|
+
return;
|
|
2683
|
+
}
|
|
2684
|
+
this.wheel = null;
|
|
2685
|
+
if (gesture.timer != null) {
|
|
2686
|
+
this.clock.clearTimeout(gesture.timer);
|
|
2687
|
+
}
|
|
2688
|
+
if (gesture.ids.length === 0 || gesture.follow?.lifted) {
|
|
2689
|
+
return;
|
|
2690
|
+
}
|
|
2691
|
+
// Fingers that stop without a lift end on their travel, where it runs
|
|
2692
|
+
// ahead of what the pan shows. What the undecided stretch showed past it
|
|
2693
|
+
// stays, as a step back would show.
|
|
2694
|
+
if (gesture.follow != null) {
|
|
2695
|
+
const f = gesture.follow;
|
|
2696
|
+
const x = ahead(gesture.x, f.trueX - f.heldX, f.speedX);
|
|
2697
|
+
const y = ahead(gesture.y, f.trueY - f.heldY, f.speedY);
|
|
2698
|
+
if (x !== gesture.x || y !== gesture.y) {
|
|
2699
|
+
gesture.x = x;
|
|
2700
|
+
gesture.y = y;
|
|
2701
|
+
this.arena.moved([{id: gesture.ids[0], x, y, time: gesture.last}]);
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
// A trackpad scroll whose fingers stop releases still, past the
|
|
2705
|
+
// velocity's stillness interval. A pinch releases 100 ms after its last
|
|
2706
|
+
// wheel, and a lift released the pan already. The release is never later
|
|
2707
|
+
// than the input that ends it (a press, the next gesture's first wheel).
|
|
2708
|
+
// The arena's clock only moves forward, so a later stamp would move that
|
|
2709
|
+
// input's times too.
|
|
2710
|
+
const end = gesture.last + gesture.endMs;
|
|
2711
|
+
const time =
|
|
2712
|
+
endTime == null ? end : Math.max(gesture.last, Math.min(end, endTime));
|
|
2713
|
+
this.arena.ended(
|
|
2714
|
+
gesture.kind === 'pan'
|
|
2715
|
+
? [{id: gesture.ids[0], x: gesture.x, y: gesture.y, time}]
|
|
2716
|
+
: this.pinchContacts(gesture, time),
|
|
2717
|
+
);
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
/**
|
|
2721
|
+
* At a mouse or pen press, mark one that lands on selectable text: once it
|
|
2722
|
+
* moves, it is the browser's drag, and selects text.
|
|
2723
|
+
* Text whose hold does something is locked at this press already
|
|
2724
|
+
* (lockSelection), so it is not selectable text.
|
|
2725
|
+
*/
|
|
2726
|
+
private noteSelectingPress(
|
|
2727
|
+
id: number,
|
|
2728
|
+
x: number,
|
|
2729
|
+
y: number,
|
|
2730
|
+
target: EventTarget | null,
|
|
2731
|
+
): void {
|
|
2732
|
+
if (
|
|
2733
|
+
!this.lockedBy.has(id) &&
|
|
2734
|
+
startsOnSelectableText(this.doc, x, y, target)
|
|
2735
|
+
) {
|
|
2736
|
+
this.selectingContacts.add(id);
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
|
|
2740
|
+
/**
|
|
2741
|
+
* Undo a contact's selection locks, its press lock and its drag hold, at
|
|
2742
|
+
* once for a cancel, and forget its press's selection; idempotent. A
|
|
2743
|
+
* drag's hold keeps its last task after a lift (lockDragSelection).
|
|
2744
|
+
*/
|
|
2745
|
+
private unlockSelection(id: number, isCancel = false): void {
|
|
2746
|
+
const lock = this.lockedBy.get(id);
|
|
2747
|
+
lock?.({isCancel});
|
|
2748
|
+
// A press lock keeps `lockedBy` when the contact also has a drag hold.
|
|
2749
|
+
// Release the hold too.
|
|
2750
|
+
const hold = this.claimHolds.get(id);
|
|
2751
|
+
if (hold != null && hold !== lock) {
|
|
2752
|
+
hold({isCancel});
|
|
2753
|
+
}
|
|
1833
2754
|
this.lockedBy.delete(id);
|
|
2755
|
+
this.claimHolds.delete(id);
|
|
2756
|
+
this.pressSelections.delete(id);
|
|
2757
|
+
this.selectingContacts.delete(id);
|
|
1834
2758
|
}
|
|
1835
2759
|
|
|
1836
2760
|
// --- Touch events ----------------------------------------------------------
|
|
@@ -1869,6 +2793,7 @@ export class GestureHost {
|
|
|
1869
2793
|
}
|
|
1870
2794
|
|
|
1871
2795
|
private readonly onTouchStart = (event: TouchEvent): void => {
|
|
2796
|
+
this.endWheel(eventTime(event));
|
|
1872
2797
|
this.noteFingersDown(event);
|
|
1873
2798
|
// Where the host reads a finger from its pointer events (no ontouchstart,
|
|
1874
2799
|
// as after touch emulation turns on), its Touch Events would track it twice.
|
|
@@ -2554,6 +3479,7 @@ export class GestureHost {
|
|
|
2554
3479
|
// --- Pointer events --------------------------------------------------------
|
|
2555
3480
|
|
|
2556
3481
|
private readonly onPointerDown = (event: PointerEvent): void => {
|
|
3482
|
+
this.endWheel(eventTime(event));
|
|
2557
3483
|
// A new press: whatever click is still owed to the last one is not this.
|
|
2558
3484
|
disarmClickGuard(this.doc);
|
|
2559
3485
|
if (!isPointerKind(event.pointerType)) {
|
|
@@ -2591,6 +3517,11 @@ export class GestureHost {
|
|
|
2591
3517
|
if (target !== landed && target != null) {
|
|
2592
3518
|
this.retargeted.set(id, {x: event.clientX, y: event.clientY, target});
|
|
2593
3519
|
}
|
|
3520
|
+
// Before the arena admits it: a press a group claims at its own
|
|
3521
|
+
// pointerdown keeps the selection the page has now.
|
|
3522
|
+
if (event.pointerType !== 'touch') {
|
|
3523
|
+
this.pressSelections.set(id, selectionRangesOf(this.doc.defaultView));
|
|
3524
|
+
}
|
|
2594
3525
|
this.arena.began([
|
|
2595
3526
|
{
|
|
2596
3527
|
id,
|
|
@@ -2615,6 +3546,10 @@ export class GestureHost {
|
|
|
2615
3546
|
consumerElement,
|
|
2616
3547
|
);
|
|
2617
3548
|
}
|
|
3549
|
+
if (event.pointerType !== 'touch') {
|
|
3550
|
+
// The engine's own hit: the text its caret query and a drag select.
|
|
3551
|
+
this.noteSelectingPress(id, event.clientX, event.clientY, landed);
|
|
3552
|
+
}
|
|
2618
3553
|
};
|
|
2619
3554
|
|
|
2620
3555
|
private readonly onPointerMove = (event: PointerEvent): void => {
|
|
@@ -2766,7 +3701,7 @@ export class GestureHost {
|
|
|
2766
3701
|
const id = this.pointerIds.get(event.pointerId);
|
|
2767
3702
|
if (id != null) {
|
|
2768
3703
|
this.pointerIds.delete(event.pointerId);
|
|
2769
|
-
this.unlockSelection(id);
|
|
3704
|
+
this.unlockSelection(id, true);
|
|
2770
3705
|
this.retargeted.delete(id);
|
|
2771
3706
|
this.arena.cancelled([id], eventTime(event));
|
|
2772
3707
|
}
|
|
@@ -3007,7 +3942,7 @@ export class GestureHost {
|
|
|
3007
3942
|
private cancelEverything(time: number): void {
|
|
3008
3943
|
const ids = [...this.pointerIds.values()];
|
|
3009
3944
|
for (const id of ids) {
|
|
3010
|
-
this.unlockSelection(id);
|
|
3945
|
+
this.unlockSelection(id, true);
|
|
3011
3946
|
}
|
|
3012
3947
|
for (const identifier of [...this.touchIds.keys()]) {
|
|
3013
3948
|
// The browser may keep the touch alive: its lift must not click.
|
|
@@ -3024,6 +3959,8 @@ export class GestureHost {
|
|
|
3024
3959
|
this.unpairedTouches.clear();
|
|
3025
3960
|
this.lastFed.clear();
|
|
3026
3961
|
this.pointerFed.clear();
|
|
3962
|
+
// A trackpad pan a recognizer still drives is cancelled with them.
|
|
3963
|
+
ids.push(...this.dropDrivenWheel());
|
|
3027
3964
|
if (ids.length > 0) {
|
|
3028
3965
|
this.arena.cancelled(ids, time);
|
|
3029
3966
|
}
|