1616import { AnnotationEditorParamsType , unreachable } from "../../shared/util.js" ;
1717import { noContextMenu , stopEvent } from "../display_utils.js" ;
1818import { AnnotationEditor } from "./editor.js" ;
19+ import { CurrentPointers } from "./tools.js" ;
1920
2021class DrawingOptions {
2122 #svgProperties = Object . create ( null ) ;
@@ -81,14 +82,6 @@ class DrawingEditor extends AnnotationEditor {
8182
8283 static #currentDrawingOptions = null ;
8384
84- static #currentPointerId = NaN ;
85-
86- static #currentPointerType = null ;
87-
88- static #currentPointerIds = null ;
89-
90- static #currentMoveTimestamp = NaN ;
91-
9285 static _INNER_MARGIN = 3 ;
9386
9487 constructor ( params ) {
@@ -678,20 +671,15 @@ class DrawingEditor extends AnnotationEditor {
678671 }
679672
680673 static startDrawing ( parent , uiManager , _isLTR , event ) {
681- // The _currentPointerType is set when the user starts an empty drawing
682- // session. If, in the same drawing session, the user starts using a
674+ // The pointerType of CurrentPointer is set when the user starts an empty
675+ // drawing session. If, in the same drawing session, the user starts using a
683676 // different type of pointer (e.g. a pen and then a finger), we just return.
684677 //
685- // The _currentPointerId and _currentPointerIds are used to keep track of
686- // the pointers with a same type (e.g. two fingers). If the user starts to
687- // draw with a finger and then uses a second finger, we just stop the
688- // current drawing and let the user zoom the document.
678+ // If the user starts to draw with a finger and then uses a second finger,
679+ // we just stop the current drawing and let the user zoom the document.
689680
690681 const { target, offsetX : x , offsetY : y , pointerId, pointerType } = event ;
691- if (
692- DrawingEditor . #currentPointerType &&
693- DrawingEditor . #currentPointerType !== pointerType
694- ) {
682+ if ( CurrentPointers . isInitializedAndDifferentPointerType ( pointerType ) ) {
695683 return ;
696684 }
697685
@@ -704,42 +692,37 @@ class DrawingEditor extends AnnotationEditor {
704692 const ac = ( DrawingEditor . #currentDrawingAC = new AbortController ( ) ) ;
705693 const signal = parent . combinedSignal ( ac ) ;
706694
707- DrawingEditor . #currentPointerId ||= pointerId ;
708- DrawingEditor . #currentPointerType ??= pointerType ;
695+ CurrentPointers . setPointer ( pointerType , pointerId ) ;
709696
710697 window . addEventListener (
711698 "pointerup" ,
712699 e => {
713- if ( DrawingEditor . #currentPointerId === e . pointerId ) {
700+ if ( CurrentPointers . isSamePointerIdOrRemove ( e . pointerId ) ) {
714701 this . _endDraw ( e ) ;
715- } else {
716- DrawingEditor . #currentPointerIds?. delete ( e . pointerId ) ;
717702 }
718703 } ,
719704 { signal }
720705 ) ;
721706 window . addEventListener (
722707 "pointercancel" ,
723708 e => {
724- if ( DrawingEditor . #currentPointerId === e . pointerId ) {
709+ if ( CurrentPointers . isSamePointerIdOrRemove ( e . pointerId ) ) {
725710 this . _currentParent . endDrawingSession ( ) ;
726- } else {
727- DrawingEditor . #currentPointerIds?. delete ( e . pointerId ) ;
728711 }
729712 } ,
730713 { signal }
731714 ) ;
732715 window . addEventListener (
733716 "pointerdown" ,
734717 e => {
735- if ( DrawingEditor . #currentPointerType !== e . pointerType ) {
718+ if ( ! CurrentPointers . isSamePointerType ( e . pointerType ) ) {
736719 // For example, we started with a pen and the user
737720 // is now using a finger.
738721 return ;
739722 }
740723
741724 // For example, the user is using a second finger.
742- ( DrawingEditor . #currentPointerIds ||= new Set ( ) ) . add ( e . pointerId ) ;
725+ CurrentPointers . initializeAndAddPointerId ( e . pointerId ) ;
743726
744727 // The first finger created a first point and a second finger just
745728 // started, so we stop the drawing and remove this only point.
@@ -765,7 +748,7 @@ class DrawingEditor extends AnnotationEditor {
765748 target . addEventListener (
766749 "touchmove" ,
767750 e => {
768- if ( e . timeStamp === DrawingEditor . #currentMoveTimestamp ) {
751+ if ( CurrentPointers . isSameTimeStamp ( e . timeStamp ) ) {
769752 // This move event is used to draw so we don't want to scroll.
770753 stopEvent ( e ) ;
771754 }
@@ -812,16 +795,16 @@ class DrawingEditor extends AnnotationEditor {
812795 }
813796
814797 static _drawMove ( event ) {
815- DrawingEditor . #currentMoveTimestamp = - 1 ;
798+ CurrentPointers . isSameTimeStamp ( event . timeStamp ) ;
816799 if ( ! DrawingEditor . #currentDraw) {
817800 return ;
818801 }
819802 const { offsetX, offsetY, pointerId } = event ;
820803
821- if ( DrawingEditor . #currentPointerId !== pointerId ) {
804+ if ( ! CurrentPointers . isSamePointerId ( pointerId ) ) {
822805 return ;
823806 }
824- if ( DrawingEditor . #currentPointerIds ?. size >= 1 ) {
807+ if ( CurrentPointers . isUsingMultiplePointers ( ) ) {
825808 // The user is using multiple fingers and the first one is moving.
826809 this . _endDraw ( event ) ;
827810 return ;
@@ -831,7 +814,7 @@ class DrawingEditor extends AnnotationEditor {
831814 DrawingEditor . #currentDraw. add ( offsetX , offsetY )
832815 ) ;
833816 // We track the timestamp to know if the touchmove event is used to draw.
834- DrawingEditor . #currentMoveTimestamp = event . timeStamp ;
817+ CurrentPointers . setTimeStamp ( event . timeStamp ) ;
835818 stopEvent ( event ) ;
836819 }
837820
@@ -841,15 +824,14 @@ class DrawingEditor extends AnnotationEditor {
841824 this . _currentParent = null ;
842825 DrawingEditor . #currentDraw = null ;
843826 DrawingEditor . #currentDrawingOptions = null ;
844- DrawingEditor . #currentPointerType = null ;
845- DrawingEditor . #currentMoveTimestamp = NaN ;
827+ CurrentPointers . clearPointerType ( ) ;
828+ CurrentPointers . clearTimeStamp ( ) ;
846829 }
847830
848831 if ( DrawingEditor . #currentDrawingAC) {
849832 DrawingEditor . #currentDrawingAC. abort ( ) ;
850833 DrawingEditor . #currentDrawingAC = null ;
851- DrawingEditor . #currentPointerId = NaN ;
852- DrawingEditor . #currentPointerIds = null ;
834+ CurrentPointers . clearPointerIds ( ) ;
853835 }
854836 }
855837
0 commit comments