Don't capture touch events

They are implicitly captured anyway, and we get problems if we try
to explicitly capture them.
This commit is contained in:
Samuel Mannehed 2017-05-11 13:34:43 +02:00
parent 4f1c81dca9
commit 333ad45c70
3 changed files with 12 additions and 34 deletions

View File

@ -731,7 +731,11 @@ const UI = {
var handle = document.getElementById("noVNC_control_bar_handle"); var handle = document.getElementById("noVNC_control_bar_handle");
var bounds = handle.getBoundingClientRect(); var bounds = handle.getBoundingClientRect();
setCapture(handle); // Touch events have implicit capture
if (e.type === "mousedown") {
setCapture(handle);
}
UI.controlbarGrabbed = true; UI.controlbarGrabbed = true;
UI.controlbarDrag = false; UI.controlbarDrag = false;

View File

@ -10,7 +10,7 @@
import * as Log from '../util/logging.js'; import * as Log from '../util/logging.js';
import { isTouchDevice } from '../util/browsers.js' import { isTouchDevice } from '../util/browsers.js'
import { setCapture, releaseCapture, stopEvent, getPointerEvent } from '../util/events.js'; import { setCapture, stopEvent, getPointerEvent } from '../util/events.js';
import { set_defaults, make_properties } from '../util/properties.js'; import { set_defaults, make_properties } from '../util/properties.js';
import * as KeyboardUtil from "./util.js"; import * as KeyboardUtil from "./util.js";
import KeyTable from "./keysym.js"; import KeyTable from "./keysym.js";
@ -299,14 +299,6 @@ const Mouse = function (defaults) {
Mouse.prototype = { Mouse.prototype = {
// private methods // private methods
_captureMouse: function () {
// capturing the mouse ensures we get the mouseup event
setCapture(this._target);
},
_releaseMouse: function () {
releaseCapture();
},
_resetDoubleClickTimer: function () { _resetDoubleClickTimer: function () {
this._doubleClickTimer = null; this._doubleClickTimer = null;
@ -367,13 +359,16 @@ Mouse.prototype = {
}, },
_handleMouseDown: function (e) { _handleMouseDown: function (e) {
this._captureMouse(); // Touch events have implicit capture
if (e.type === "mousedown") {
setCapture(this._target);
}
this._handleMouseButton(e, 1); this._handleMouseButton(e, 1);
}, },
_handleMouseUp: function (e) { _handleMouseUp: function (e) {
this._handleMouseButton(e, 0); this._handleMouseButton(e, 0);
this._releaseMouse();
}, },
_handleMouseWheel: function (e) { _handleMouseWheel: function (e) {

View File

@ -44,7 +44,7 @@ const _captureProxy = function (e) {
} }
// Implicitly release the capture on button release // Implicitly release the capture on button release
if ((e.type === "mouseup") || (e.type === "touchend")) { if (e.type === "mouseup") {
releaseCapture(); releaseCapture();
} }
}; };
@ -65,24 +65,12 @@ export function setCapture (elem) {
// IE releases capture on 'click' events which might not trigger // IE releases capture on 'click' events which might not trigger
elem.addEventListener('mouseup', releaseCapture); elem.addEventListener('mouseup', releaseCapture);
elem.addEventListener('touchend', releaseCapture);
} else { } else {
// Release any existing capture in case this method is // Release any existing capture in case this method is
// called multiple times without coordination // called multiple times without coordination
releaseCapture(); releaseCapture();
// Safari on iOS 9 has a broken constructor for TouchEvent.
// We are fine in this case however, since Safari seems to
// have some sort of implicit setCapture magic anyway.
if (window.TouchEvent !== undefined) {
try {
new TouchEvent("touchstart");
} catch (TypeError) {
return;
}
}
var captureElem = document.getElementById("noVNC_mouse_capture_elem"); var captureElem = document.getElementById("noVNC_mouse_capture_elem");
if (captureElem === null) { if (captureElem === null) {
@ -103,9 +91,6 @@ export function setCapture (elem) {
captureElem.addEventListener('mousemove', _captureProxy); captureElem.addEventListener('mousemove', _captureProxy);
captureElem.addEventListener('mouseup', _captureProxy); captureElem.addEventListener('mouseup', _captureProxy);
captureElem.addEventListener('touchmove', _captureProxy);
captureElem.addEventListener('touchend', _captureProxy);
} }
_captureElem = elem; _captureElem = elem;
@ -121,9 +106,6 @@ export function setCapture (elem) {
// happens to leave the viewport // happens to leave the viewport
window.addEventListener('mousemove', _captureProxy); window.addEventListener('mousemove', _captureProxy);
window.addEventListener('mouseup', _captureProxy); window.addEventListener('mouseup', _captureProxy);
window.addEventListener('touchmove', _captureProxy);
window.addEventListener('touchend', _captureProxy);
} }
}; };
@ -154,8 +136,5 @@ export function releaseCapture () {
window.removeEventListener('mousemove', _captureProxy); window.removeEventListener('mousemove', _captureProxy);
window.removeEventListener('mouseup', _captureProxy); window.removeEventListener('mouseup', _captureProxy);
window.removeEventListener('touchmove', _captureProxy);
window.removeEventListener('touchend', _captureProxy);
} }
}; };