From bd477daa2c6ecc5ace6cf0307b45f9113b80dbf5 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 5 Jul 2011 10:16:03 -0700 Subject: [PATCH] More migration to traditional JS events. --- .../src/main/resources/keyboard.js | 28 ++++------ .../src/main/resources/mouse.js | 54 +++++++++---------- 2 files changed, 38 insertions(+), 44 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index e0f784db0..edbe313fa 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -19,6 +19,8 @@ function GuacamoleKeyboard(element) { + var guac_keyboard = this; + // Keymap var unshiftedKeySym = new Array(); @@ -64,11 +66,6 @@ function GuacamoleKeyboard(element) { var shiftedKeySym = new Array(); shiftedKeySym[18] = 0xFFE7; // alt - - /*****************************************/ - /*** Keyboard Handler ***/ - /*****************************************/ - // Single key state/modifier buffer var modShift = 0; var modCtrl = 0; @@ -150,14 +147,14 @@ function GuacamoleKeyboard(element) { // Sends a single keystroke over the network function sendKeyPressed(keysym) { - if (keysym != null && keyPressedHandler) - keyPressedHandler(keysym); + if (keysym != null && guac_keyboard.onkeydown) + guac_keyboard.onkeydown(keysym); } // Sends a single keystroke over the network function sendKeyReleased(keysym) { - if (keysym != null) - keyReleasedHandler(keysym); + if (keysym != null && guac_keyboard.onkeyup) + guac_keyboard.onkeyup(keysym); } @@ -171,7 +168,7 @@ function GuacamoleKeyboard(element) { element.onkeydown = function(e) { // Only intercept if handler set - if (!keyPressedHandler) return true; + if (!guac_keyboard.onkeydown) return true; var keynum; if (window.event) keynum = window.event.keyCode; @@ -237,7 +234,7 @@ function GuacamoleKeyboard(element) { element.onkeypress = function(e) { // Only intercept if handler set - if (!keyPressedHandler) return true; + if (!guac_keyboard.onkeydown) return true; if (keySymSource != KEYPRESS) return false; @@ -272,7 +269,7 @@ function GuacamoleKeyboard(element) { element.onkeyup = function(e) { // Only intercept if handler set - if (!keyReleasedHandler) return true; + if (!guac_keyboard.onkeyup) return true; var keynum; if (window.event) keynum = window.event.keyCode; @@ -309,10 +306,7 @@ function GuacamoleKeyboard(element) { if (docOnblur != null) docOnblur(); }; - var keyPressedHandler = null; - var keyReleasedHandler = null; - - this.setKeyPressedHandler = function(kh) { keyPressedHandler = kh; }; - this.setKeyReleasedHandler = function(kh) { keyReleasedHandler = kh; }; + guac_keyboard.onkeydown = null; + guac_keyboard.onkeyup = null; } diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index fb8600519..31d5185d0 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -20,12 +20,7 @@ function GuacamoleMouse(element) { - /*****************************************/ - /*** Mouse Handler ***/ - /*****************************************/ - - - var mouseIndex = 0; + var guac_mouse = this; var mouseLeftButton = 0; var mouseMiddleButton = 0; @@ -69,7 +64,8 @@ function GuacamoleMouse(element) { parent = parent.offsetParent; } - movementHandler(getMouseState(0, 0)); + if (guac_mouse.onmousemove) + guac_mouse.onmousemove(getMouseState(0, 0)); }; @@ -89,7 +85,8 @@ function GuacamoleMouse(element) { break; } - buttonPressedHandler(getMouseState(0, 0)); + if (guac_mouse.onmousedown) + guac_mouse.onmousedown(getMouseState(0, 0)); }; @@ -109,7 +106,8 @@ function GuacamoleMouse(element) { break; } - buttonReleasedHandler(getMouseState(0, 0)); + if (guac_mouse.onmouseup) + guac_mouse.onmouseup(getMouseState(0, 0)); }; element.onmouseout = function(e) { @@ -122,7 +120,8 @@ function GuacamoleMouse(element) { mouseMiddleButton = 0; mouseRightButton = 0; - buttonReleasedHandler(getMouseState(0, 0)); + if (guac_mouse.onmouseup) + guac_mouse.onmouseup(getMouseState(0, 0)); } }; @@ -143,14 +142,20 @@ function GuacamoleMouse(element) { // Up if (delta < 0) { - buttonPressedHandler(getMouseState(1, 0)); - buttonReleasedHandler(getMouseState(0, 0)); + if (guac_mouse.onmousedown) + guac_mouse.onmousedown(getMouseState(1, 0)); + + if (guac_mouse.onmouseup) + guac_mouse.onmouseup(getMouseState(0, 0)); } // Down if (delta > 0) { - buttonPressedHandler(getMouseState(0, 1)); - buttonReleasedHandler(getMouseState(0, 0)); + if (guac_mouse.onmousedown) + guac_mouse.onmousedown(getMouseState(0, 1)); + + if (guac_mouse.onmouseup) + guac_mouse.onmouseup(getMouseState(0, 0)); } if (e.preventDefault) @@ -165,20 +170,15 @@ function GuacamoleMouse(element) { handleScroll(e); } - var buttonPressedHandler = null; - var buttonReleasedHandler = null; - var movementHandler = null; + guac_mouse.onmousedown = null; + guac_mouse.onmouseup = null; + guac_mouse.onmousemove = null; - this.setButtonPressedHandler = function(mh) {buttonPressedHandler = mh;}; - this.setButtonReleasedHandler = function(mh) {buttonReleasedHandler = mh;}; - this.setMovementHandler = function(mh) {movementHandler = mh;}; - - - this.getX = function() {return mouseX;}; - this.getY = function() {return mouseY;}; - this.getLeftButton = function() {return mouseLeftButton;}; - this.getMiddleButton = function() {return mouseMiddleButton;}; - this.getRightButton = function() {return mouseRightButton;}; + guac_mouse.getX = function() {return mouseX;}; + guac_mouse.getY = function() {return mouseY;}; + guac_mouse.getLeftButton = function() {return mouseLeftButton;}; + guac_mouse.getMiddleButton = function() {return mouseMiddleButton;}; + guac_mouse.getRightButton = function() {return mouseRightButton;}; }