Skip to content

Commit aded454

Browse files
committed
fix(RenderWindowInteractor): Handle event outside window when dragging
1 parent f46691c commit aded454

File tree

1 file changed

+17
-10
lines changed
  • Sources/Rendering/Core/RenderWindowInteractor

1 file changed

+17
-10
lines changed

Sources/Rendering/Core/RenderWindowInteractor/index.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ function vtkRenderWindowInteractor(publicAPI, model) {
151151
publicAPI.getLastAnimationEventPosition = (pointer) =>
152152
model.lastAnimationEventPositions.get(pointer);
153153

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+
154165
publicAPI.bindEvents = (canvas) => {
155166
model.canvas = canvas;
156167
canvas.addEventListener('contextmenu', preventDefault);
@@ -165,15 +176,12 @@ function vtkRenderWindowInteractor(publicAPI, model) {
165176
document
166177
.querySelector('body')
167178
.addEventListener('keyup', publicAPI.handleKeyUp);
168-
canvas.addEventListener('mouseup', publicAPI.handleMouseUp);
169-
canvas.addEventListener('mousemove', publicAPI.handleMouseMove);
179+
170180
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);
174181
};
175182

176183
publicAPI.unbindEvents = (canvas) => {
184+
interactionRegistration(false);
177185
canvas.removeEventListener('contextmenu', preventDefault);
178186
canvas.removeEventListener('click', preventDefault);
179187
canvas.removeEventListener('mousewheel', publicAPI.handleWheel);
@@ -186,12 +194,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
186194
document
187195
.querySelector('body')
188196
.removeEventListener('keyup', publicAPI.handleKeyUp);
189-
canvas.removeEventListener('mouseup', publicAPI.handleMouseUp);
190-
canvas.removeEventListener('mousemove', publicAPI.handleMouseMove);
191197
canvas.removeEventListener('touchstart', publicAPI.handleTouchStart);
192-
canvas.removeEventListener('touchend', publicAPI.handleTouchEnd);
193-
canvas.removeEventListener('touchcancel', publicAPI.handleTouchEnd);
194-
canvas.removeEventListener('touchmove', publicAPI.handleTouchMove);
195198
};
196199

197200
publicAPI.handleKeyPress = (event) => {
@@ -213,6 +216,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
213216
};
214217

215218
publicAPI.handleMouseDown = (event) => {
219+
interactionRegistration(true);
216220
event.stopPropagation();
217221
event.preventDefault();
218222

@@ -413,6 +417,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
413417
};
414418

415419
publicAPI.handleMouseUp = (event) => {
420+
interactionRegistration(false);
416421
event.stopPropagation();
417422
event.preventDefault();
418423

@@ -439,6 +444,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
439444
};
440445

441446
publicAPI.handleTouchStart = (event) => {
447+
interactionRegistration(true);
442448
event.stopPropagation();
443449
event.preventDefault();
444450

@@ -475,6 +481,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
475481
};
476482

477483
publicAPI.handleTouchEnd = (event) => {
484+
interactionRegistration(false);
478485
event.stopPropagation();
479486
event.preventDefault();
480487

0 commit comments

Comments
 (0)