@@ -151,6 +151,17 @@ function vtkRenderWindowInteractor(publicAPI, model) {
151
151
publicAPI . getLastAnimationEventPosition = ( pointer ) =>
152
152
model . lastAnimationEventPositions . get ( pointer ) ;
153
153
154
+ function interactionRegistration ( addListeners ) {
155
+ const rootElm = document . querySelector ( 'body' ) ;
156
+ const method = addListeners ? 'addEventListener' : 'removeEventListener' ;
157
+
158
+ rootElm [ method ] ( 'mouseup' , publicAPI . handleMouseUp ) ;
159
+ rootElm [ method ] ( 'mousemove' , publicAPI . handleMouseMove ) ;
160
+ rootElm [ method ] ( 'touchend' , publicAPI . handleTouchEnd , false ) ;
161
+ rootElm [ method ] ( 'touchcancel' , publicAPI . handleTouchEnd , false ) ;
162
+ rootElm [ method ] ( 'touchmove' , publicAPI . handleTouchMove , false ) ;
163
+ }
164
+
154
165
publicAPI . bindEvents = ( canvas ) => {
155
166
model . canvas = canvas ;
156
167
canvas . addEventListener ( 'contextmenu' , preventDefault ) ;
@@ -165,15 +176,12 @@ function vtkRenderWindowInteractor(publicAPI, model) {
165
176
document
166
177
. querySelector ( 'body' )
167
178
. addEventListener ( 'keyup' , publicAPI . handleKeyUp ) ;
168
- canvas . addEventListener ( 'mouseup' , publicAPI . handleMouseUp ) ;
169
- canvas . addEventListener ( 'mousemove' , publicAPI . handleMouseMove ) ;
179
+
170
180
canvas . addEventListener ( 'touchstart' , publicAPI . handleTouchStart , false ) ;
171
- canvas . addEventListener ( 'touchend' , publicAPI . handleTouchEnd , false ) ;
172
- canvas . addEventListener ( 'touchcancel' , publicAPI . handleTouchEnd , false ) ;
173
- canvas . addEventListener ( 'touchmove' , publicAPI . handleTouchMove , false ) ;
174
181
} ;
175
182
176
183
publicAPI . unbindEvents = ( canvas ) => {
184
+ interactionRegistration ( false ) ;
177
185
canvas . removeEventListener ( 'contextmenu' , preventDefault ) ;
178
186
canvas . removeEventListener ( 'click' , preventDefault ) ;
179
187
canvas . removeEventListener ( 'mousewheel' , publicAPI . handleWheel ) ;
@@ -186,12 +194,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
186
194
document
187
195
. querySelector ( 'body' )
188
196
. removeEventListener ( 'keyup' , publicAPI . handleKeyUp ) ;
189
- canvas . removeEventListener ( 'mouseup' , publicAPI . handleMouseUp ) ;
190
- canvas . removeEventListener ( 'mousemove' , publicAPI . handleMouseMove ) ;
191
197
canvas . removeEventListener ( 'touchstart' , publicAPI . handleTouchStart ) ;
192
- canvas . removeEventListener ( 'touchend' , publicAPI . handleTouchEnd ) ;
193
- canvas . removeEventListener ( 'touchcancel' , publicAPI . handleTouchEnd ) ;
194
- canvas . removeEventListener ( 'touchmove' , publicAPI . handleTouchMove ) ;
195
198
} ;
196
199
197
200
publicAPI . handleKeyPress = ( event ) => {
@@ -213,6 +216,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
213
216
} ;
214
217
215
218
publicAPI . handleMouseDown = ( event ) => {
219
+ interactionRegistration ( true ) ;
216
220
event . stopPropagation ( ) ;
217
221
event . preventDefault ( ) ;
218
222
@@ -413,6 +417,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
413
417
} ;
414
418
415
419
publicAPI . handleMouseUp = ( event ) => {
420
+ interactionRegistration ( false ) ;
416
421
event . stopPropagation ( ) ;
417
422
event . preventDefault ( ) ;
418
423
@@ -439,6 +444,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
439
444
} ;
440
445
441
446
publicAPI . handleTouchStart = ( event ) => {
447
+ interactionRegistration ( true ) ;
442
448
event . stopPropagation ( ) ;
443
449
event . preventDefault ( ) ;
444
450
@@ -475,6 +481,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
475
481
} ;
476
482
477
483
publicAPI . handleTouchEnd = ( event ) => {
484
+ interactionRegistration ( false ) ;
478
485
event . stopPropagation ( ) ;
479
486
event . preventDefault ( ) ;
480
487
0 commit comments