Commit 7e24f50b authored by samhed's avatar samhed

Merge branch 'master' of https://github.com/kanaka/noVNC into framebufferupdate

parents dfcedffc f3ff971d
/*
* noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin
* Copyright (C) 2013 Samuel Mannehed for Cendio AB
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
*/
......@@ -489,6 +490,9 @@ var that = {}, // Public API methods
conf = {}, // Configuration attributes
mouseCaptured = false;
var doubleClickTimer = null,
lastTouchPos = null;
// Configuration attributes
Util.conf_defaults(conf, that, defaults, [
['target', 'ro', 'dom', document, 'DOM element that captures mouse input'],
......@@ -521,6 +525,10 @@ function releaseMouse() {
// Private functions
//
function resetDoubleClickTimer() {
doubleClickTimer = null;
}
function onMouseButton(e, down) {
var evt, pos, bmask;
if (! conf.focused) {
......@@ -528,8 +536,34 @@ function onMouseButton(e, down) {
}
evt = (e ? e : window.event);
pos = Util.getEventPosition(e, conf.target, conf.scale);
if (e.touches || e.changedTouches) {
// Touch device
// When two touches occur within 500 ms of each other and are
// closer than 20 pixels together a double click is triggered.
if (down == 1) {
if (doubleClickTimer == null) {
lastTouchPos = pos;
} else {
clearTimeout(doubleClickTimer);
// When the distance between the two touches is small enough
// force the position of the latter touch to the position of
// the first.
var xs = lastTouchPos.x - pos.x;
var ys = lastTouchPos.y - pos.y;
var d = Math.sqrt((xs * xs) + (ys * ys));
// The goal is to trigger on a certain physical width, the
// devicePixelRatio brings us a bit closer but is not optimal.
if (d < 20 * window.devicePixelRatio) {
pos = lastTouchPos;
}
}
doubleClickTimer = setTimeout(resetDoubleClickTimer, 500);
}
bmask = conf.touchButton;
// If bmask is set
} else if (evt.which) {
......@@ -543,7 +577,7 @@ function onMouseButton(e, down) {
}
//Util.Debug("mouse " + pos.x + "," + pos.y + " down: " + down +
// " bmask: " + bmask + "(evt.button: " + evt.button + ")");
if (bmask > 0 && conf.onMouseButton) {
if (conf.onMouseButton) {
Util.Debug("onMouseButton " + (down ? "down" : "up") +
", x: " + pos.x + ", y: " + pos.y + ", bmask: " + bmask);
conf.onMouseButton(pos.x, pos.y, down, bmask);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment