Implement and document Magnifier and NativeKeyboard components.

This commit is contained in:
Michael Jumper
2012-11-12 01:50:55 -08:00
parent 3f02525a2c
commit f5e754dd5d
4 changed files with 81 additions and 36 deletions

View File

@@ -40,8 +40,6 @@
</div> </div>
</div> </div>
<textarea id="eventTarget"></textarea>
<div id="pan-overlay"></div> <div id="pan-overlay"></div>
<!-- On-screen keyboard --> <!-- On-screen keyboard -->

View File

@@ -49,7 +49,6 @@ GuacUI.Client = {
"viewport" : document.getElementById("viewportClone"), "viewport" : document.getElementById("viewportClone"),
"display" : document.getElementById("display"), "display" : document.getElementById("display"),
"logo" : document.getElementById("status-logo"), "logo" : document.getElementById("status-logo"),
"eventTarget" : document.getElementById("eventTarget"),
"buttons": { "buttons": {
"reconnect" : document.getElementById("reconnect") "reconnect" : document.getElementById("reconnect")
@@ -63,7 +62,14 @@ GuacUI.Client = {
"pan_overlay" : document.getElementById("pan-overlay"), "pan_overlay" : document.getElementById("pan-overlay"),
"state" : document.getElementById("statusText"), "state" : document.getElementById("statusText"),
"client" : null, "client" : null,
"sessionState" : new GuacamoleSessionState() "sessionState" : new GuacamoleSessionState(),
/* Expected Input Rectangle */
"expected_input_x" : 0,
"expected_input_y" : 0,
"expected_input_width" : 0,
"expected_input_height" : 0
}; };
@@ -144,8 +150,11 @@ GuacUI.Client.Magnifier = function() {
magnifier_display.style.transform = "translate(" magnifier_display.style.transform = "translate("
+ (-clip_x) + "px, " + (-clip_y) + "px)"; + (-clip_x) + "px, " + (-clip_y) + "px)";
GuacamoleUI.eventTarget.style.left = clip_x + "px"; /* Update expected input rectangle */
GuacamoleUI.eventTarget.style.top = clip_y + "px"; GuacUI.Client.expected_input_x = clip_x;
GuacUI.Client.expected_input_y = clip_y;
GuacUI.Client.expected_input_width = width;
GuacUI.Client.expected_input_height = height;
}; };
@@ -163,9 +172,6 @@ GuacUI.Client.Magnifier = function() {
// Show magnifier container // Show magnifier container
document.body.appendChild(magnifier_background); document.body.appendChild(magnifier_background);
GuacamoleUI.eventTarget.style.width = magnifier.offsetWidth + "px";
GuacamoleUI.eventTarget.style.height = magnifier.offsetHeight + "px";
}; };
/* /*
@@ -208,11 +214,13 @@ GuacUI.StateManager.registerComponent(
GuacUI.Client.states.MAGNIFIER GuacUI.Client.states.MAGNIFIER
); );
/* /**
* Zoomed Display * Zoomed Display, a pseudo-component.
*
* @constructor
* @augments GuacUI.Component
*/ */
GuacUI.Client.ZoomedDisplay = function() {
GuacUI.Client.ZoomedDisplay = function(client) {
var old_scale = null; var old_scale = null;
@@ -229,16 +237,23 @@ GuacUI.Client.ZoomedDisplay = function(client) {
GuacUI.Client.ZoomedDisplay.prototype = new GuacUI.Component(); GuacUI.Client.ZoomedDisplay.prototype = new GuacUI.Component();
/*
* Zoom the main display during PAN and PAN_TYPING modes.
*/
GuacUI.StateManager.registerComponent( GuacUI.StateManager.registerComponent(
new GuacUI.Client.ZoomedDisplay(), new GuacUI.Client.ZoomedDisplay(),
GuacUI.Client.states.PAN, GuacUI.Client.states.PAN,
GuacUI.Client.states.PAN_TYPING GuacUI.Client.states.PAN_TYPING
); );
/* /**
* Pan UI * Pan overlay UI. This component functions to receive touch events and
* translate them into scrolling of the main UI.
*
* @constructor
* @augments GuacUI.Component
*/ */
GuacUI.Client.PanOverlay = function(pan_overlay) { GuacUI.Client.PanOverlay = function(pan_overlay) {
this.show = function() { this.show = function() {
@@ -249,6 +264,10 @@ GuacUI.Client.PanOverlay = function(pan_overlay) {
pan_overlay.style.display = "none"; pan_overlay.style.display = "none";
}; };
/*
* Transition to PAN_TYPING when the user taps on the overlay.
*/
pan_overlay.addEventListener("click", function() { pan_overlay.addEventListener("click", function() {
GuacUI.StateManager.setState(GuacUI.Client.PAN_TYPING); GuacUI.StateManager.setState(GuacUI.Client.PAN_TYPING);
}, false); }, false);
@@ -257,6 +276,10 @@ GuacUI.Client.PanOverlay = function(pan_overlay) {
GuacUI.Client.PanOverlay.prototype = new GuacUI.Component(); GuacUI.Client.PanOverlay.prototype = new GuacUI.Component();
/*
* Show the pan overlay during PAN or PAN_TYPING modes.
*/
GuacUI.StateManager.registerComponent( GuacUI.StateManager.registerComponent(
new GuacUI.Client.PanOverlay( new GuacUI.Client.PanOverlay(
document.getElementById("pan-overlay") document.getElementById("pan-overlay")
@@ -265,32 +288,66 @@ GuacUI.StateManager.registerComponent(
GuacUI.Client.states.PAN_TYPING GuacUI.Client.states.PAN_TYPING
); );
/* /**
* Native Keyboard * Native Keyboard. This component uses a hidden textarea field to show the
* platforms native on-screen keyboard (if any) or otherwise enable typing,
* should the platform require a text field with focus for keyboard events to
* register.
*
* @constructor
* @augments GuacUI.Component
*/ */
GuacUI.Client.NativeKeyboard = function() {
GuacUI.Client.NativeKeyboard = function(eventTarget) { /**
* Event target. This is a hidden textarea element which will receive
* key events.
* @private
*/
var eventTarget = GuacUI.createElement("textarea", "event-target");
eventTarget.setAttribute("autocorrect", "off");
eventTarget.setAttribute("autocapitalize", "off");
this.show = function() { this.show = function() {
eventTarget.style.display = "block";
// Move to location of expected input
eventTarget.style.left = GuacUI.Client.expected_input_x + "px";
eventTarget.style.top = GuacUI.Client.expected_input_y + "px";
eventTarget.style.width = GuacUI.Client.expected_input_width + "px";
eventTarget.style.height = GuacUI.Client.expected_input_height + "px";
// Show and focus target
document.body.appendChild(eventTarget);
eventTarget.focus(); eventTarget.focus();
}; };
this.hide = function() { this.hide = function() {
// Hide and blur target
eventTarget.blur(); eventTarget.blur();
eventTarget.style.display = "none"; document.body.removeChild(eventTarget);
}; };
/*
* Automatically switch to INTERACTIVE mode after target loses focus
*/
eventTarget.addEventListener("blur", function() { eventTarget.addEventListener("blur", function() {
GuacUI.StateManager.setState(GuacUI.Client.states.INTERACTIVE); GuacUI.StateManager.setState(GuacUI.Client.states.INTERACTIVE);
}, false); }, false);
}; };
GuacUI.Client.NativeKeyboard.prototype = new GuacUI.Component();
/*
* Show native keyboard during PAN_TYPING mode only.
*/
GuacUI.StateManager.registerComponent( GuacUI.StateManager.registerComponent(
new GuacUI.Client.NativeKeyboard( new GuacUI.Client.NativeKeyboard(),
document.getElementById("eventTarget")
),
GuacUI.Client.states.PAN_TYPING GuacUI.Client.states.PAN_TYPING
); );

View File

@@ -31,7 +31,6 @@ var GuacamoleUI = {
"viewport" : document.getElementById("viewportClone"), "viewport" : document.getElementById("viewportClone"),
"display" : document.getElementById("display"), "display" : document.getElementById("display"),
"logo" : document.getElementById("status-logo"), "logo" : document.getElementById("status-logo"),
"eventTarget" : document.getElementById("eventTarget"),
"buttons": { "buttons": {
"reconnect" : document.getElementById("reconnect") "reconnect" : document.getElementById("reconnect")
@@ -39,11 +38,9 @@ var GuacamoleUI = {
"containers": { "containers": {
"state" : document.getElementById("statusDialog"), "state" : document.getElementById("statusDialog"),
"keyboard" : document.getElementById("keyboardContainer"), "keyboard" : document.getElementById("keyboardContainer")
"magnifier" : document.getElementById("magnifier")
}, },
"magnifier" : document.getElementById("magnifier-display"),
"state" : document.getElementById("statusText"), "state" : document.getElementById("statusText"),
"client" : null, "client" : null,
"sessionState" : new GuacamoleSessionState() "sessionState" : new GuacamoleSessionState()
@@ -215,9 +212,6 @@ if (!GuacamoleUI.sessionState.getProperty("disable-sound"))
Array.prototype.push.apply(GuacamoleUI.supportedAudio, maybe_supported); Array.prototype.push.apply(GuacamoleUI.supportedAudio, maybe_supported);
})(); })();
GuacamoleUI.eventTarget.setAttribute("autocorrect", "off");
GuacamoleUI.eventTarget.setAttribute("autocapitalize", "off");
// Query video support // Query video support
(function () { (function () {
var probably_supported = []; var probably_supported = [];

View File

@@ -41,12 +41,8 @@ img {
-webkit-tap-highlight-color: rgba(0,0,0,0); -webkit-tap-highlight-color: rgba(0,0,0,0);
} }
#eventTarget { .event-target {
position: fixed; position: fixed;
left: 0;
top: 0;
width: 1px;
height: 1px;
opacity: 0; opacity: 0;
} }