Skip to content

Commit

Permalink
Don't capture touch events
Browse files Browse the repository at this point in the history
They are implicitly captured anyway, and we get problems if we try
to explicitly capture them.
  • Loading branch information
samhed committed May 11, 2017
1 parent 4f1c81d commit 333ad45
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 34 deletions.
6 changes: 5 additions & 1 deletion app/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,11 @@ const UI = {
var handle = document.getElementById("noVNC_control_bar_handle");
var bounds = handle.getBoundingClientRect();

setCapture(handle);
// Touch events have implicit capture
if (e.type === "mousedown") {
setCapture(handle);
}

UI.controlbarGrabbed = true;
UI.controlbarDrag = false;

Expand Down
17 changes: 6 additions & 11 deletions core/input/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import * as Log from '../util/logging.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 * as KeyboardUtil from "./util.js";
import KeyTable from "./keysym.js";
Expand Down Expand Up @@ -299,14 +299,6 @@ const Mouse = function (defaults) {

Mouse.prototype = {
// private methods
_captureMouse: function () {
// capturing the mouse ensures we get the mouseup event
setCapture(this._target);
},

_releaseMouse: function () {
releaseCapture();
},

_resetDoubleClickTimer: function () {
this._doubleClickTimer = null;
Expand Down Expand Up @@ -367,13 +359,16 @@ Mouse.prototype = {
},

_handleMouseDown: function (e) {
this._captureMouse();
// Touch events have implicit capture
if (e.type === "mousedown") {
setCapture(this._target);
}

this._handleMouseButton(e, 1);
},

_handleMouseUp: function (e) {
this._handleMouseButton(e, 0);
this._releaseMouse();
},

_handleMouseWheel: function (e) {
Expand Down
23 changes: 1 addition & 22 deletions core/util/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const _captureProxy = function (e) {
}

// Implicitly release the capture on button release
if ((e.type === "mouseup") || (e.type === "touchend")) {
if (e.type === "mouseup") {
releaseCapture();
}
};
Expand All @@ -65,24 +65,12 @@ export function setCapture (elem) {

// IE releases capture on 'click' events which might not trigger
elem.addEventListener('mouseup', releaseCapture);
elem.addEventListener('touchend', releaseCapture);

} else {
// Release any existing capture in case this method is
// called multiple times without coordination
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");

if (captureElem === null) {
Expand All @@ -103,9 +91,6 @@ export function setCapture (elem) {

captureElem.addEventListener('mousemove', _captureProxy);
captureElem.addEventListener('mouseup', _captureProxy);

captureElem.addEventListener('touchmove', _captureProxy);
captureElem.addEventListener('touchend', _captureProxy);
}

_captureElem = elem;
Expand All @@ -121,9 +106,6 @@ export function setCapture (elem) {
// happens to leave the viewport
window.addEventListener('mousemove', _captureProxy);
window.addEventListener('mouseup', _captureProxy);

window.addEventListener('touchmove', _captureProxy);
window.addEventListener('touchend', _captureProxy);
}
};

Expand Down Expand Up @@ -154,8 +136,5 @@ export function releaseCapture () {

window.removeEventListener('mousemove', _captureProxy);
window.removeEventListener('mouseup', _captureProxy);

window.removeEventListener('touchmove', _captureProxy);
window.removeEventListener('touchend', _captureProxy);
}
};

0 comments on commit 333ad45

Please sign in to comment.