changeset 545:e1ba16436d59 dev

set events passive again
author Alain Mazy <alain@mazy.be>
date Fri, 29 Mar 2019 15:21:33 +0100
parents 11510f92cc38
children fb7f4a5bdfc0 90f3a60576a9 92305ee35b1c
files Platforms/Wasm/wasm-application-runner.ts Platforms/Wasm/wasm-viewport.ts
diffstat 2 files changed, 5 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/Platforms/Wasm/wasm-application-runner.ts	Mon Mar 25 15:23:45 2019 +0100
+++ b/Platforms/Wasm/wasm-application-runner.ts	Fri Mar 29 15:21:33 2019 +0100
@@ -107,7 +107,7 @@
     // Prevent scrolling
     document.body.addEventListener('touchmove', function (event) {
       event.preventDefault();
-    }, { passive: false});
+    }, { passive: false}); // must not be passive if calling event.preventDefault, ie to cancel scroll or zoom of the whole interface
 
     _InitializeWasmApplication(orthancBaseUrl);
   });
--- a/Platforms/Wasm/wasm-viewport.ts	Mon Mar 25 15:23:45 2019 +0100
+++ b/Platforms/Wasm/wasm-viewport.ts	Fri Mar 29 15:21:33 2019 +0100
@@ -1,5 +1,4 @@
 import wasmApplicationRunner = require('./wasm-application-runner');
-//import stoneFrameworkLoader = require('./stone-framework-loader');
 import * as Logger from './logger'
 
 var isPendingRedraw = false;
@@ -31,13 +30,6 @@
  
 (<any>window).CreateWasmViewport = CreateWasmViewport;
 
-//  export declare type InitializationCallback = () => void;
-  
-//  export declare var StoneFrameworkModule : any;
-  
-  //const ASSETS_FOLDER : string = "assets/lib";
-  //const WASM_FILENAME : string = "orthanc-framework";
-
 export class WasmViewport {
 
     private static viewportsMapByCppHandle_ : Map<number, WasmViewport> = new Map<number, WasmViewport>(); // key = the C++ handle
@@ -235,7 +227,7 @@
         var y = event.pageY - this.offsetTop;
         that.ViewportMouseWheel(that.pimpl_, event.deltaY, x, y, event.ctrlKey);
         event.preventDefault();
-      }, {passive: true});
+      }, {passive: false}); // must not be passive if calling event.preventDefault, ie to cancel scroll or zoom of the whole interface
 
       this.htmlCanvas_.addEventListener('touchstart', function(event: TouchEvent) {
         // don't propagate events to the whole body (this could zoom the entire page instead of zooming the viewport)
@@ -263,7 +255,7 @@
         }
 
         that.ViewportTouchStart(that.pimpl_, event.targetTouches.length, x0, y0, x1, y1, x2, y2);
-      }, {passive: true});
+      }, {passive: false}); // must not be passive if calling event.preventDefault, ie to cancel scroll or zoom of the whole interface
     
       this.htmlCanvas_.addEventListener('touchend', function(event) {
         // don't propagate events to the whole body (this could zoom the entire page instead of zooming the viewport)
@@ -323,53 +315,7 @@
         that.ViewportTouchMove(that.pimpl_, event.targetTouches.length, x0, y0, x1, y1, x2, y2);
         return;
 
-        // if (!that.touchGestureInProgress_) {
-        //   // starting a new gesture
-        //   that.touchCount_ = event.targetTouches.length;
-        //   for (var t = 0; t < event.targetTouches.length; t++) {
-        //     that.touchGestureLastCoordinates_.push([event.targetTouches[t].pageX, event.targetTouches[t].pageY]);
-        //   }
-        //   that.touchGestureInProgress_ = true;
-        // } else {
-        //   // continuing a gesture
-        //   // TODO: we shall probably forward all touches to the C++ code and let the "interactors/trackers" handle them
-
-        //   if (that.touchCount_ == 1) { // consider it's a left mouse drag
-
-        //   }
-        // }
-
-        // TODO: we shall probably forward all touches to the C++ code and let the "interactors/trackers" handle them
-
-        if (that.touchTranslation_.length == 2) { // 
-          var t = that.GetTouchTranslation(event);
-          that.ViewportMouseMove(that.pimpl_, t[0], t[1]);
-        }
-        else if (that.touchZoom_.length == 3) {
-          var z0 = that.touchZoom_;
-          var z1 = that.GetTouchZoom(event);
-          that.ViewportMouseMove(that.pimpl_, z0[0], z0[1] - z0[2] + z1[2]);
-        }
-        else {
-          // Realize the gesture event
-          if (event.targetTouches.length == 1) {
-            // Exactly one finger inside the canvas => Setup a translation
-            that.touchTranslation_ = that.GetTouchTranslation(event);
-            that.ViewportMouseDown(that.pimpl_, 
-                                  0 /* left button */,
-                                  that.touchTranslation_[0],
-                                  that.touchTranslation_[1], 0);
-          } else if (event.targetTouches.length == 2) {
-            // Exactly 2 fingers inside the canvas => Setup a pinch/zoom
-            that.touchZoom_ = that.GetTouchZoom(event);
-            var z0 = that.touchZoom_;
-            that.ViewportMouseDown(that.pimpl_, 
-                                  2 /* right button */,
-                                  z0[0],
-                                  z0[1], 0);
-          }        
-        }
-      }, {passive: true});
+      }, {passive: false}); // must not be passive if calling event.preventDefault, ie to cancel scroll or zoom of the whole interface
     }  
 
   public ResetTouch() {
@@ -380,10 +326,6 @@
 
     this.touchTranslation_ = false;
     this.touchZoom_ = false;
-
-    // this.touchGestureInProgress_ = false;
-    // this.touchCount_ = 0;
-    // this.touchGestureLastCoordinates_ = [];
   }
   
   public GetTouchTranslation(event) {
@@ -406,7 +348,5 @@
       d
     ];
   }
-    
+   
 }
-
-  
\ No newline at end of file