From 5cabb0a018474b24f76a4d18205b73150859d32e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 23 Apr 2014 13:39:45 -0700 Subject: [PATCH] GUAC-326: Fix handling of focus (do not try to enforce, but inform when focus is gained/lost). --- .../src/main/webapp/scripts/client-ui.js | 76 +++++++++++++------ 1 file changed, 52 insertions(+), 24 deletions(-) diff --git a/guacamole/src/main/webapp/scripts/client-ui.js b/guacamole/src/main/webapp/scripts/client-ui.js index 5a80deed5..909506bc7 100644 --- a/guacamole/src/main/webapp/scripts/client-ui.js +++ b/guacamole/src/main/webapp/scripts/client-ui.js @@ -1772,26 +1772,44 @@ GuacUI.Client.attach = function(guac) { GuacUI.Client.ime_none_radio.onclick = GuacUI.Client.ime_none_radio.onchange = function() { - GuacUI.Client.ime_expected = false; - GuacUI.Client.target.blur(); + + if (GuacUI.Client.ime_enabled) { + GuacUI.Client.ime_expected = false; + __ime_notify_changed(false); + GuacUI.Client.target.blur(); + } + GuacUI.Client.OnScreenKeyboard.hide(); GuacUI.Client.showMenu(false); + }; GuacUI.Client.ime_text_radio.onclick = GuacUI.Client.ime_text_radio.onchange = function() { - GuacUI.Client.ime_expected = true; - GuacUI.Client.target.focus(); + + if (!GuacUI.Client.ime_enabled) { + GuacUI.Client.ime_expected = true; + __ime_notify_changed(true); + GuacUI.Client.target.focus(); + } + GuacUI.Client.OnScreenKeyboard.hide(); GuacUI.Client.showMenu(false); + }; GuacUI.Client.ime_osk_radio.onclick = GuacUI.Client.ime_osk_radio.onchange = function() { - GuacUI.Client.ime_expected = false; - GuacUI.Client.target.blur(); + + if (GuacUI.Client.ime_enabled) { + GuacUI.Client.ime_expected = false; + __ime_notify_changed(false); + GuacUI.Client.target.blur(); + } + GuacUI.Client.OnScreenKeyboard.show(); GuacUI.Client.showMenu(false); + }; /* @@ -1840,8 +1858,32 @@ GuacUI.Client.attach = function(guac) { } + var ime_notify_enabled = null; var ime_notify_timeout = null; + function __ime_notify_changed(new_state) { + + if (ime_notify_enabled === null) + ime_notify_enabled = new_state; + + window.clearTimeout(ime_notify_timeout); + ime_notify_timeout = window.setTimeout(function() { + + // Only notify if state changed successfully + if (ime_notify_enabled === GuacUI.Client.ime_enabled) { + if (GuacUI.Client.ime_enabled) + GuacUI.Client.showNotification("Text input mode ON"); + else + GuacUI.Client.showNotification("Text input mode OFF"); + } + + // Reset for next change + ime_notify_enabled = null; + + }, 100); + + } + GuacUI.Client.target.onfocus = function() { // Acknowledge and synchronize state change @@ -1849,19 +1891,12 @@ GuacUI.Client.attach = function(guac) { GuacUI.Client.ime_text_radio.checked = true; GuacUI.Client.ime_enabled = true; - // If unexpected, try to reset state back - if (!GuacUI.Client.ime_expected) - GuacUI.Client.target.blur(); - // Reset content GuacUI.Client.target.value = new Array(257).join("\u200B"); GuacUI.Client.target.setSelectionRange(128, 128); - // Notify of change if settled within 50ms - window.clearTimeout(ime_notify_timeout); - ime_notify_timeout = window.setTimeout(function() { - GuacUI.Client.showNotification("Text input mode ON"); - }, 100); + // Notify of change after it settles + __ime_notify_changed(true); }; @@ -1872,15 +1907,8 @@ GuacUI.Client.attach = function(guac) { GuacUI.Client.ime_none_radio.checked = true; GuacUI.Client.ime_enabled = false; - // If unexpected, try to reset state back - if (GuacUI.Client.ime_expected) - GuacUI.Client.target.focus(); - - // Notify of change if settled within 50ms - window.clearTimeout(ime_notify_timeout); - ime_notify_timeout = window.setTimeout(function() { - GuacUI.Client.showNotification("Text input mode OFF"); - }, 100); + // Notify of change after it settles + __ime_notify_changed(false); };