GUAC-326: Remove GuacUI component object. Make OSK global.

This commit is contained in:
Michael Jumper
2014-04-22 17:50:12 -07:00
parent 2e6f7c5d8e
commit f091971928
2 changed files with 14 additions and 237 deletions

View File

@@ -25,23 +25,6 @@
*/
GuacUI.Client = {
/**
* Collection of all Guacamole client UI states.
*/
"states": {
/**
* The normal default Guacamole client UI mode
*/
"INTERACTIVE" : 0,
/**
* Same as INTERACTIVE except with visible on-screen keyboard.
*/
"OSK" : 1
},
/**
* Enumeration of all tunnel-specific error messages for each applicable
* error code.
@@ -261,9 +244,8 @@ GuacUI.Client = {
* which sends key events to the Guacamole client.
*
* @constructor
* @augments GuacUI.Component
*/
GuacUI.Client.OnScreenKeyboard = function() {
GuacUI.Client.OnScreenKeyboard = new (function() {
/**
* Event target. This is a hidden textarea element which will receive
@@ -290,15 +272,21 @@ GuacUI.Client.OnScreenKeyboard = function() {
}
keyboard.onkeydown = function(keysym) {
GuacUI.Client.attachedClient.sendKeyEvent(1, keysym);
if (GuacUI.Client.attachedClient)
GuacUI.Client.attachedClient.sendKeyEvent(1, keysym);
};
keyboard.onkeyup = function(keysym) {
GuacUI.Client.attachedClient.sendKeyEvent(0, keysym);
if (GuacUI.Client.attachedClient)
GuacUI.Client.attachedClient.sendKeyEvent(0, keysym);
};
this.show = function() {
// Only add if not already present
if (keyboard_container.parentNode === document.body)
return;
// Show keyboard
document.body.appendChild(keyboard_container);
@@ -317,6 +305,10 @@ GuacUI.Client.OnScreenKeyboard = function() {
this.hide = function() {
// Only remove if present
if (keyboard_container.parentNode !== document.body)
return;
// Hide keyboard
document.body.removeChild(keyboard_container);
window.clearInterval(keyboard_resize_interval);
@@ -324,24 +316,7 @@ GuacUI.Client.OnScreenKeyboard = function() {
};
};
GuacUI.Client.OnScreenKeyboard.prototype = new GuacUI.Component();
/*
* Show on-screen keyboard during OSK mode only.
*/
GuacUI.StateManager.registerComponent(
new GuacUI.Client.OnScreenKeyboard(),
GuacUI.Client.states.OSK
);
/*
* Set initial state
*/
GuacUI.StateManager.setState(GuacUI.Client.states.INTERACTIVE);
})();
/**
* Modal status display. Displays a message to the user, covering the entire
@@ -351,7 +326,6 @@ GuacUI.StateManager.setState(GuacUI.Client.states.INTERACTIVE);
* components is impossible.
*
* @constructor
* @augments GuacUI.Component
*/
GuacUI.Client.ModalStatus = function(title_text, text, classname, reconnect) {
@@ -430,8 +404,6 @@ GuacUI.Client.ModalStatus = function(title_text, text, classname, reconnect) {
};
GuacUI.Client.ModalStatus.prototype = new GuacUI.Component();
/**
* Monitors a given element for touch events, firing drag-specific events
* based on pre-defined gestures.

View File

@@ -262,201 +262,6 @@ GuacUI.Video = new (function() {
})();
/**
* Central registry of all components for all states.
*/
GuacUI.StateManager = new (function() {
/**
* The current state.
*/
var current_state = null;
/**
* Array of arrays of components, indexed by the states they are in.
*/
var components = [];
/**
* Registers the given component with this state manager, to be shown
* during the given states.
*
* @param {GuacUI.Component} component The component to register.
* @param {Number} [...] The list of states this component should be
* visible during.
*/
this.registerComponent = function(component) {
// For each state specified, add the given component
for (var i=1; i<arguments.length; i++) {
// Get specified state
var state = arguments[i];
// Get array of components in that state
var component_array = components[state];
if (!component_array)
component_array = components[state] = [];
// Add component
component_array.push(component);
}
};
function allComponents(components, name) {
// Invoke given function on all components in array
for (var i=0; i<components.length; i++)
components[i][name]();
}
/**
* Sets the current visible state.
*/
this.setState = function(state) {
// Hide components in current state
if (current_state && components[current_state])
allComponents(components[current_state], "hide");
// Show all components in new state
current_state = state;
if (components[state])
allComponents(components[state], "show");
};
/**
* Returns the current visible state.
*/
this.getState = function() {
return current_state;
};
})();
/**
* Abstract component which can be registered with GuacUI and shown or hidden
* dynamically based on interface mode.
*
* @constructor
*/
GuacUI.Component = function() {
/**
* Called whenever this component needs to be shown and activated.
* @event
*/
this.onshow = null;
/**
* Called whenever this component needs to be hidden and deactivated.
* @event
*/
this.onhide = null;
};
/**
* A Guacamole UI component which can be repositioned by dragging.
*
* @constructor
* @augments GuacUI.Component
*/
GuacUI.DraggableComponent = function(element) {
var draggable_component = this;
var position_x = 0;
var position_y = 0;
var start_x = 0;
var start_y = 0;
/*
* Record drag start when finger hits element
*/
if (element)
element.addEventListener("touchstart", function(e) {
if (e.touches.length == 1) {
start_x = e.touches[0].screenX;
start_y = e.touches[0].screenY;
}
e.stopPropagation();
}, true);
/*
* Update position based on last touch
*/
if (element)
element.addEventListener("touchmove", function(e) {
if (e.touches.length == 1) {
var new_x = e.touches[0].screenX;
var new_y = e.touches[0].screenY;
position_x += new_x - start_x;
position_y += new_y - start_y;
start_x = new_x;
start_y = new_y;
// Move magnifier to new position
draggable_component.move(position_x, position_y);
}
e.preventDefault();
e.stopPropagation();
}, true);
if (element)
element.addEventListener("touchend", function(e) {
e.stopPropagation();
}, true);
/**
* Moves this component to the specified location relative to its normal
* position.
*
* @param {Number} x The X coordinate in pixels.
* @param {Number} y The Y coordinate in pixels.
*/
this.move = function(x, y) {
element.style.WebkitTransform =
element.style.MozTransform =
element.style.OTransform =
element.style.msTransform =
element.style.transform = "translate("
+ x + "px, " + y + "px)";
if (draggable_component.onmove)
draggable_component.onmove(x, y);
};
/**
* Trigered whenever this element is moved.
*
* @event
* @param {Number} x The new X coordinate.
* @param {Number} y The new Y coordinate.
*/
this.onmove = null;
};
/**
* A connection UI object which can be easily added to a list of connections
* for sake of display.