GUAC-326: Fix handling of focus (do not try to enforce, but inform when focus is gained/lost).

This commit is contained in:
Michael Jumper
2014-04-23 13:39:45 -07:00
parent 8f7f240232
commit 5cabb0a018

View File

@@ -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);
};