Rename assumeNativeOSK to nativeOSK, automatically reset nativeOSK to false if menu...
[guacamole.git] / src / main / webapp / scripts / interface.js
index f869e35..9253a8a 100644 (file)
@@ -8,6 +8,7 @@ var GuacamoleUI = {
     "menuControl" : document.getElementById("menuControl"),
     "touchMenu"   : document.getElementById("touchMenu"),
     "logo"        : document.getElementById("status-logo"),
+    "eventTarget" : document.getElementById("eventTarget"),
 
     "buttons": {
 
@@ -177,10 +178,20 @@ var GuacamoleUI = {
 
     };
 
+    // Assume no native OSK by default
+    GuacamoleUI.nativeOSK = false;
+
     // Show/Hide keyboard
     var keyboardResizeInterval = null;
     GuacamoleUI.buttons.showKeyboard.onclick = function() {
 
+        // If we think the platform has a native OSK, use the event target to
+        // cause it to display.
+        if (GuacamoleUI.nativeOSK) {
+            GuacamoleUI.eventTarget.focus();
+            return;
+        }
+        
         var displayed = GuacamoleUI.containers.keyboard.style.display;
         if (displayed != "block") {
             GuacamoleUI.containers.keyboard.style.display = "block";
@@ -237,6 +248,10 @@ var GuacamoleUI = {
 
             // Wait and then show menu
             detectMenuOpenTimeout = window.setTimeout(function() {
+
+                // If menu opened via mouse, do not show native OSK
+                GuacamoleUI.nativeOSK = false;
+
                 GuacamoleUI.showMenu();
                 detectMenuOpenTimeout = null;
             }, 325);
@@ -246,7 +261,7 @@ var GuacamoleUI = {
     };
 
     // Initiate detection of menu close action. If not canceled through some
-    // user event, menu will close.
+    // user mouse event, menu will close.
     GuacamoleUI.startMenuCloseDetect = function() {
 
         if (!detectMenuCloseTimeout) {
@@ -282,6 +297,9 @@ var GuacamoleUI = {
             menuShowLongPressTimeout = window.setTimeout(function() {
                 
                 menuShowLongPressTimeout = null;
+
+                // Assume native OSK if menu shown via long-press
+                GuacamoleUI.nativeOSK = true;
                 GuacamoleUI.showMenu();
 
             }, 800);
@@ -294,6 +312,13 @@ var GuacamoleUI = {
         menuShowLongPressTimeout = null;
     };
 
+    // 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
     document.body.addEventListener('touchstart', GuacamoleUI.startLongPressDetect, true);
 
@@ -387,6 +412,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.nativeOSK)
+                    GuacamoleUI.resetEventTarget();
+                
                 guac.sendKeyEvent(1, keysym);
             };