Skip to content

Commit

Permalink
fix(RenderWindowInteractor): Better support passive events and forced…
Browse files Browse the repository at this point in the history
…Renderer
  • Loading branch information
jourdain committed May 28, 2021
1 parent ef919a9 commit 139c4d7
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions Sources/Rendering/Core/RenderWindowInteractor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ const handledEvents = [
];

function preventDefault(event) {
event.stopPropagation();
event.preventDefault();
if (event.cancelable) {
event.stopPropagation();
event.preventDefault();
}

return false;
}

Expand Down Expand Up @@ -141,7 +144,9 @@ function vtkRenderWindowInteractor(publicAPI, model) {
publicAPI.startEventLoop = () => vtkWarningMacro('empty event loop');

function updateCurrentRenderer(x, y) {
model.currentRenderer = publicAPI.findPokedRenderer(x, y);
if (!model._forcedRenderer) {
model.currentRenderer = publicAPI.findPokedRenderer(x, y);
}
}

publicAPI.getCurrentRenderer = () => {
Expand Down Expand Up @@ -300,8 +305,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
}

interactionRegistration(true);
event.stopPropagation();
event.preventDefault();
preventDefault(event);

const callData = {
...getModifierKeysFor(event),
Expand Down Expand Up @@ -468,8 +472,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {

publicAPI.handleMouseMove = (event) => {
// Do not consume event for move
// event.stopPropagation();
// event.preventDefault();
// preventDefault(event);

const callData = {
...getModifierKeysFor(event),
Expand Down Expand Up @@ -505,8 +508,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
};

publicAPI.handleWheel = (event) => {
event.stopPropagation();
event.preventDefault();
preventDefault(event);

/**
* wheel event values can vary significantly across browsers, platforms
Expand Down Expand Up @@ -563,8 +565,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {

publicAPI.handleMouseUp = (event) => {
interactionRegistration(false);
event.stopPropagation();
event.preventDefault();
preventDefault(event);

const callData = {
...getModifierKeysFor(event),
Expand All @@ -588,8 +589,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {

publicAPI.handleTouchStart = (event) => {
interactionRegistration(true);
event.stopPropagation();
event.preventDefault();
preventDefault(event);

// If multitouch
if (model.recognizeGestures && event.touches.length > 1) {
Expand Down Expand Up @@ -620,8 +620,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
};

publicAPI.handleTouchMove = (event) => {
event.stopPropagation();
event.preventDefault();
preventDefault(event);

if (model.recognizeGestures && event.touches.length > 1) {
const positions = getTouchEventPositionsFor(event.touches);
Expand All @@ -639,8 +638,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
};

publicAPI.handleTouchEnd = (event) => {
event.stopPropagation();
event.preventDefault();
preventDefault(event);

if (model.recognizeGestures) {
// No more fingers down
Expand Down Expand Up @@ -980,6 +978,11 @@ function vtkRenderWindowInteractor(publicAPI, model) {
model.lastFrameStart = Date.now();
};

publicAPI.setCurrentRenderer = (r) => {
model._forcedRenderer = !!r;
model.currentRenderer = r;
};

// Stop animating if the renderWindowInteractor is deleted.
const superDelete = publicAPI.delete;
publicAPI.delete = () => {
Expand Down

0 comments on commit 139c4d7

Please sign in to comment.