Automatically reset text area on keyboard events if native OSK is enabled/assumed...
authorMichael Jumper <zhangmaike@users.sourceforge.net>
Wed, 21 Mar 2012 23:42:01 +0000 (16:42 -0700)
committerMichael Jumper <zhangmaike@users.sourceforge.net>
Wed, 21 Mar 2012 23:42:01 +0000 (16:42 -0700)
src/main/webapp/client.xhtml
src/main/webapp/scripts/interface.js
src/main/webapp/styles/client.css

index 3523bae..c0b0749 100644 (file)
 
         </div>
 
-        <input id="eventTarget"
-               type="text"
-               style="width: 0; height: 0; position: fixed; opacity: 0"
-               value="x"/>
+        <!-- Keyboard event target for platforms with native OSKs -->
+        <textarea id="eventTarget">GUAC</textarea>
 
         <!-- Display -->
         <div id="display">
index 73a9384..dfa1b3d 100644 (file)
@@ -178,7 +178,8 @@ var GuacamoleUI = {
 
     };
 
-    var assumeNativeOSK = false;
+    // Assume no native OSK by default
+    GuacamoleUI.assumeNativeOSK = false;
 
     // Show/Hide keyboard
     var keyboardResizeInterval = null;
@@ -186,7 +187,7 @@ var GuacamoleUI = {
 
         // If we think the platform has a native OSK, use the event target to
         // cause it to display.
-        if (assumeNativeOSK) {
+        if (GuacamoleUI.assumeNativeOSK) {
             GuacamoleUI.eventTarget.focus();
             return;
         }
@@ -294,7 +295,7 @@ var GuacamoleUI = {
                 menuShowLongPressTimeout = null;
 
                 // Assume native OSK if menu shown via long-press
-                assumeNativeOSK = true;
+                GuacamoleUI.assumeNativeOSK = true;
                 GuacamoleUI.showMenu();
 
             }, 800);
@@ -307,9 +308,11 @@ var GuacamoleUI = {
         menuShowLongPressTimeout = null;
     };
 
-    // Ensure the event target ALWAYS has text inside.
-    GuacamoleUI.eventTarget.onchange = function() {
-        GuacamoleUI.eventTarget.value = "x";
+    // Reset event target (add content, reposition cursor in middle.
+    GuacamoleUI.resetEventTarget = function() {
+        GuacamoleUI.eventTarget.value = "GUAC";
+        GuacamoleUI.eventTarget.selectionStart =
+        GuacamoleUI.eventTarget.selectionEnd   = 2;
     };
 
     // Detect long-press at bottom of screen
@@ -405,6 +408,12 @@ GuacamoleUI.attach = function(guac) {
     function enableKeyboard() {
         keyboard.onkeydown = 
             function (keysym) {
+          
+                // If we're using native OSK, ensure event target is reset
+                // on each key event.
+                if (GuacamoleUI.assumeNativeOSK)
+                    GuacamoleUI.resetEventTarget();
+                
                 guac.sendKeyEvent(1, keysym);
             };
 
index 9d0f9d2..6147dee 100644 (file)
@@ -211,3 +211,10 @@ div#viewportClone {
 
     visibility: hidden;
 }
+
+textarea#eventTarget {
+    position: fixed;
+    width: 0;
+    height: 0;
+    opacity: 0;
+}
\ No newline at end of file