From b98302f9119a59e08b3609bc79593f88b605ab3a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 22 Apr 2014 11:26:56 -0700 Subject: [PATCH] GUAC-324: Scroll page with emulated mouse. --- .../src/main/webapp/scripts/client-ui.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/guacamole/src/main/webapp/scripts/client-ui.js b/guacamole/src/main/webapp/scripts/client-ui.js index c4cf928f8..5f6636d05 100644 --- a/guacamole/src/main/webapp/scripts/client-ui.js +++ b/guacamole/src/main/webapp/scripts/client-ui.js @@ -997,6 +997,37 @@ GuacUI.Client.setMouseEmulationAbsolute = function(absolute) { // Get client - do nothing if not attached var guac = GuacUI.Client.attachedClient; if (!guac) return; + + // Determine mouse position within view + var guac_display = guac.getDisplay(); + var mouse_view_x = mouseState.x + guac_display.offsetLeft - GuacUI.Client.main.scrollLeft; + var mouse_view_y = mouseState.y + guac_display.offsetTop - GuacUI.Client.main.scrollTop; + + // Determine viewport dimensioins + var view_width = GuacUI.Client.main.offsetWidth; + var view_height = GuacUI.Client.main.offsetHeight; + + // Determine scroll amounts based on mouse position relative to document + + var scroll_amount_x; + if (mouse_view_x > view_width) + scroll_amount_x = mouse_view_x - view_width; + else if (mouse_view_x < 0) + scroll_amount_x = mouse_view_x; + else + scroll_amount_x = 0; + + var scroll_amount_y; + if (mouse_view_y > view_height) + scroll_amount_y = mouse_view_y - view_height; + else if (mouse_view_y < 0) + scroll_amount_y = mouse_view_y; + else + scroll_amount_y = 0; + + // Scroll (if necessary) to keep mouse on screen. + GuacUI.Client.main.scrollLeft += scroll_amount_x; + GuacUI.Client.main.scrollTop += scroll_amount_y; // Scale event by current scale var scaledState = new Guacamole.Mouse.State(