From bb0cc1c63aa596e958be656429a98cee0f24c273 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 21 Apr 2014 19:31:57 -0700 Subject: [PATCH] GUAC-324: Maintain scroll state of menu. Separate touch from mouse. Allow default actions from touch events on menu only. --- .../src/main/webapp/scripts/client-ui.js | 64 ++++++++++++------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/guacamole/src/main/webapp/scripts/client-ui.js b/guacamole/src/main/webapp/scripts/client-ui.js index 43a56ec30..7f0e0d203 100644 --- a/guacamole/src/main/webapp/scripts/client-ui.js +++ b/guacamole/src/main/webapp/scripts/client-ui.js @@ -817,11 +817,8 @@ GuacUI.Client.showMenu = function(shown) { GuacUI.Client.menu.className = "closed"; GuacUI.Client.commitClipboard(); } - else { - GuacUI.Client.menu.scrollLeft = 0; - GuacUI.Client.menu.scrollTop = 0; + else GuacUI.Client.menu.className = "open"; - } }; /** @@ -1162,29 +1159,30 @@ GuacUI.Client.attach = function(guac) { */ // Mouse - var mouse = new Guacamole.Mouse(guac_display); + function __handle_mouse_state(mouseState) { + + // Scale event by current scale + var scaledState = new Guacamole.Mouse.State( + mouseState.x / guac.getScale(), + mouseState.y / guac.getScale(), + mouseState.left, + mouseState.middle, + mouseState.right, + mouseState.up, + mouseState.down); + + // Send mouse event + guac.sendMouseState(scaledState); + + }; + var touch = new Guacamole.Mouse.Touchscreen(guac_display); - touch.onmousedown = touch.onmouseup = touch.onmousemove = - mouse.onmousedown = mouse.onmouseup = mouse.onmousemove = - function(mouseState) { - - // Scale event by current scale - var scaledState = new Guacamole.Mouse.State( - mouseState.x / guac.getScale(), - mouseState.y / guac.getScale(), - mouseState.left, - mouseState.middle, - mouseState.right, - mouseState.up, - mouseState.down); - - // Send mouse event - guac.sendMouseState(scaledState); - - }; - + touch.onmousedown = touch.onmouseup = touch.onmousemove = __handle_mouse_state; GuacUI.Client.touch = touch; + var mouse = new Guacamole.Mouse(guac_display); + mouse.onmousedown = mouse.onmouseup = mouse.onmousemove = __handle_mouse_state; + // Hide any existing status notifications GuacUI.Client.hideStatus(); @@ -1620,7 +1618,25 @@ GuacUI.Client.attach = function(guac) { // Prevent default on all touch events document.addEventListener("touchstart", function(e) { + + // Inspect touch event target to determine whether the touch should + // be allowed. + if (e.touches.length === 1) { + + var element = e.target; + while (element) { + + // Allow single-touch events on the menu + if (element === GuacUI.Client.menu) + return; + + element = element.parentNode; + } + + } + e.preventDefault(); + }, false); })();