diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 5fde1e226..285c6f9f6 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -49,6 +49,29 @@ var Guacamole = Guacamole || {}; Guacamole.OnScreenKeyboard = function(url) { var scaledElements = []; + + var modifiers = {}; + var currentModifier = 1; + + // Returns a unique power-of-two value for the modifier with the + // given name. The same value will be returned for the same modifier. + function getModifier(name) { + + var value = modifiers[name]; + if (!value) { + + // Get current modifier, advance to next + value = currentModifier; + currentModifier <<= 1; + + // Store value of this modifier + modifiers[name] = value; + + } + + return value; + + } function ScaledElement(element, width, height, scaleFont) { @@ -56,11 +79,11 @@ Guacamole.OnScreenKeyboard = function(url) { this.height = height; this.scale = function(pixels) { - element.style.width = width * pixels + "px"; - element.style.height = height * pixels + "px"; + element.style.width = Math.floor(width * pixels) + "px"; + element.style.height = Math.floor(height * pixels) + "px"; if (scaleFont) { - element.style.lineHeight = height * pixels + "px"; + element.style.lineHeight = Math.floor(height * pixels) + "px"; element.style.fontSize = pixels + "px"; } } @@ -143,7 +166,6 @@ Guacamole.OnScreenKeyboard = function(url) { "key": function parse_key(e) { - // Get attributes var key_size = e.attributes["size"]; @@ -151,18 +173,23 @@ Guacamole.OnScreenKeyboard = function(url) { var key_element = document.createElement("div"); key_element.className = "guacamole-keyboard-key"; - // Create cap + // Create cap element var cap_element = document.createElement("div"); cap_element.className = "guacamole-keyboard-cap"; key_element.appendChild(cap_element); + // Create key + var key = new Guacamole.OnScreenKeyboard.Key(cap_element); + // Set key size var key_units = 1; if (key_size) key_units = parseFloat(key_size.value); + key.size = key_units; + parseChildren(e, { - "cap": function cap(e) { + "cap": function parse_cap(e) { // Get attributes var required = e.attributes["if"]; @@ -173,17 +200,36 @@ Guacamole.OnScreenKeyboard = function(url) { // Get content of key cap var content = e.textContent; - // If no requirements, then show cap by default - if (!required) { - cap_element.textContent = content; + // Create cap + var cap = new Guacamole.OnScreenKeyboard.Cap(content, + keysym ? keysym.value : null); + + // Get modifier value + var modifierValue = 0; + if (required) { + + // Get modifier value for specified comma-delimited + // list of required modifiers. + var requirements = required.value.split(","); + for (var i=0; i