From 968431dd46246ea03d9d4c7f5c7be03ad7b0c88b Mon Sep 17 00:00:00 2001 From: samhed Date: Tue, 17 Sep 2013 15:01:52 +0200 Subject: [PATCH 1/7] Catch input events to make the onscreen keyboard work in chrome on android. --- include/ui.js | 45 ++++++++++++++++++++++++++++++++++++++++----- vnc.html | 2 +- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/include/ui.js b/include/ui.js index b933d312..1dfc67cf 100644 --- a/include/ui.js +++ b/include/ui.js @@ -155,7 +155,8 @@ addMouseHandlers: function() { $D("noVNC_mouse_button2").onclick = function () { UI.setMouseButton(4); }; $D("noVNC_mouse_button4").onclick = function () { UI.setMouseButton(0); }; $D("showKeyboard").onclick = UI.showKeyboard; - //$D("keyboardinput").onkeydown = function (event) { onKeyDown(event); }; + + $D("keyboardinput").oninput = UI.keyInput; $D("keyboardinput").onblur = UI.keyInputBlur; $D("sendCtrlAltDelButton").onclick = UI.sendCtrlAltDel; @@ -701,17 +702,51 @@ setViewDrag: function(drag) { // On touch devices, show the OS keyboard showKeyboard: function() { + var kbi, skb, l; + kbi = $D('keyboardinput'); + skb = $D('showKeyboard'); + l = kbi.value.length; if(UI.keyboardVisible === false) { - $D('keyboardinput').focus(); + kbi.focus(); + kbi.setSelectionRange(l, l); // Move the caret to the end UI.keyboardVisible = true; - $D('showKeyboard').className = "noVNC_status_button_selected"; + skb.className = "noVNC_status_button_selected"; } else if(UI.keyboardVisible === true) { - $D('keyboardinput').blur(); - $D('showKeyboard').className = "noVNC_status_button"; + kbi.blur(); + skb.className = "noVNC_status_button"; UI.keyboardVisible = false; } }, +// When keypress events are left uncought, catch the input events from +// the keyboardinput element instead and send the corresponding key events. +keyInput: function(event) { + var elem, input, len; + elem = $D('keyboardinput'); + input = event.target.value; + len = (elem.selectionStart > input.length) ? elem.selectionStart : input.length; + + if (len < 1) { // something removed? + UI.rfb.sendKey(0xff08); // send BACKSPACE + } else if (len > 1) { // new input? + for (var i = len-1; i > 0; i -= 1) { + // HTML does not consider trailing whitespaces as a part of the string + // and they are therefore undefined. + if (input[len-i] !== undefined) { + UI.rfb.sendKey(input.charCodeAt(len-i)); // send charCode + } else { + UI.rfb.sendKey(0x0020); // send SPACE + } + } + } + + // In order to be able to delete text which has been written in + // another session there has to always be text in the + // keyboardinput element with which backspace can interact. + // We also need to reset the input field text to avoid overflow. + elem.value = "x"; +}, + keyInputBlur: function() { $D('showKeyboard').className = "noVNC_status_button"; //Weird bug in iOS if you change keyboardVisible diff --git a/vnc.html b/vnc.html index 66b70259..89349f22 100644 --- a/vnc.html +++ b/vnc.html @@ -67,7 +67,7 @@ id="showKeyboard" class="noVNC_status_button" value="Keyboard" title="Show Keyboard"/> + id="keyboardinput" class="" value=" "/> From eb955f8c20b64991e90b2b6f04148a98f1fb9321 Mon Sep 17 00:00:00 2001 From: John Dewey Date: Sat, 21 Sep 2013 12:19:09 -0700 Subject: [PATCH 2/7] The https check should come first A similar change was made to ui.js in #252. --- vnc_auto.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vnc_auto.html b/vnc_auto.html index 2aa21889..bd905ffa 100644 --- a/vnc_auto.html +++ b/vnc_auto.html @@ -128,12 +128,12 @@ // if port == 80 (or 443) then it won't be present and should be // set manually if (!port) { - if (window.location.protocol.substring(0,4) == 'http') { - port = 80; - } - else if (window.location.protocol.substring(0,5) == 'https') { + if (window.location.protocol.substring(0,5) == 'https') { port = 443; } + else if (window.location.protocol.substring(0,4) == 'http') { + port = 80; + } } // If a token variable is passed in, set the parameter in a cookie. From 82744aa8ee760520dafad8a3bd299879927d3398 Mon Sep 17 00:00:00 2001 From: John Dewey Date: Sat, 21 Sep 2013 12:19:59 -0700 Subject: [PATCH 3/7] Removed trailing white space terds --- vnc_auto.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vnc_auto.html b/vnc_auto.html index bd905ffa..7704bf69 100644 --- a/vnc_auto.html +++ b/vnc_auto.html @@ -2,7 +2,7 @@ -