Changed simulated mouse to simulated touchpad. Temporary lack of tap support.

This commit is contained in:
Michael Jumper
2011-08-26 16:44:49 -07:00
parent 68de09b857
commit 1e47ace656

View File

@@ -113,41 +113,33 @@ Guacamole.Mouse = function(element) {
}; };
var last_touch_x = 0;
var last_touch_y = 0;
element.ontouchend = function(e) { element.ontouchend = function(e) {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
// Release all buttons (FIXME: for now...) // TODO: Handle tap-to-click.
if (mouseLeftButton || mouseMiddleButton || mouseRightButton) {
mouseLeftButton = 0;
mouseMiddleButton = 0;
mouseRightButton = 0;
buttonReleasedHandler(getMouseState(0, 0)); };
}
}
element.ontouchstart = function(e) { element.ontouchstart = function(e) {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
if (e.touches.length == 1) // Record initial touch location and time for single-touch movement
element.ontouchmove(e); // and tap gestures
if (e.touches.length == 1) {
else { var starting_touch = e.touches[0];
last_touch_x = starting_touch.pageX;
var button = e.touches[0]; last_touch_y = starting_touch.pageY;
var pointer = e.touches[1];
if (pointer.pageX < button.pageX) // TODO: Record time (for sake of tap-to-click)
mouseLeftButton = 1;
else
mouseRightButton = 1;
buttonPressedHandler(getMouseState(0, 0));
} }
}; };
@@ -157,8 +149,29 @@ Guacamole.Mouse = function(element) {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
var touch = e.touches[0]; // Handle single-touch movement gesture (touchpad mouse move)
moveMouse(touch.pageX, touch.pageY); if (e.touches.length == 1) {
// Get change in touch location
var touch = e.touches[0];
var delta_x = touch.pageX - last_touch_x;
var delta_y = touch.pageY - last_touch_y;
// Update mouse location
guac_mouse.currentState.x += delta_x;
guac_mouse.currentState.y += delta_y;
// FIXME: Prevent mouse from leaving screen
// Fire movement event, if defined
if (guac_mouse.onmousemove)
guac_mouse.onmousemove(guac_mouse.currentState);
// Update touch location
last_touch_x = touch.pageX;
last_touch_y = touch.pageY;
}
}; };