diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js
index b13a80a56..371ba73e6 100644
--- a/guacamole-common-js/src/main/resources/guacamole.js
+++ b/guacamole-common-js/src/main/resources/guacamole.js
@@ -16,7 +16,10 @@
* You should have received a copy of the GNU Affero General Public License
*/
-function GuacamoleClient(display, tunnel) {
+// Guacamole namespace
+var Guacamole = Guacamole || {};
+
+Guacamole.Client = function(display, tunnel) {
var guac_client = this;
@@ -150,7 +153,7 @@ function GuacamoleClient(display, tunnel) {
// Create buffer if necessary
if (buffer == null) {
- buffer = new Layer(0, 0);
+ buffer = new Guacamole.Layer(0, 0);
buffer.setAutosize(1);
buffers[index] = buffer;
}
@@ -165,7 +168,7 @@ function GuacamoleClient(display, tunnel) {
if (layer == null) {
// Add new layer
- layer = new Layer(displayWidth, displayHeight);
+ layer = new Guacamole.Layer(displayWidth, displayHeight);
layers[index] = layer;
// (Re)-add existing layers in order
@@ -174,18 +177,18 @@ function GuacamoleClient(display, tunnel) {
// If already present, remove
if (layers[i].parentNode === display)
- display.removeChild(layers[i]);
+ display.removeChild(layers[i].getCanvas());
// Add to end
- display.appendChild(layers[i]);
+ display.appendChild(layers[i].getCanvas());
}
}
// Add cursor layer last
if (cursor != null) {
if (cursor.parentNode === display)
- display.removeChild(cursor);
- display.appendChild(cursor);
+ display.removeChild(cursor.getCanvas());
+ display.appendChild(cursor.getCanvas());
}
}
@@ -284,8 +287,8 @@ function GuacamoleClient(display, tunnel) {
var data = parameters[2];
if (cursor == null) {
- cursor = new Layer(displayWidth, displayHeight);
- display.appendChild(cursor);
+ cursor = new Guacamole.Layer(displayWidth, displayHeight);
+ display.appendChild(cursor.getCanvas());
}
// Start cursor image load
diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js
index edbe313fa..e798f59f7 100644
--- a/guacamole-common-js/src/main/resources/keyboard.js
+++ b/guacamole-common-js/src/main/resources/keyboard.js
@@ -17,7 +17,10 @@
* along with this program. If not, see .
*/
-function GuacamoleKeyboard(element) {
+// Guacamole namespace
+var Guacamole = Guacamole || {};
+
+Guacamole.Keyboard = function(element) {
var guac_keyboard = this;
diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js
index 775b23683..16fef960a 100644
--- a/guacamole-common-js/src/main/resources/layer.js
+++ b/guacamole-common-js/src/main/resources/layer.js
@@ -17,12 +17,40 @@
* along with this program. If not, see .
*/
-function Layer(width, height) {
+// Guacamole namespace
+var Guacamole = Guacamole || {};
+
+/**
+ * Abstract ordered drawing surface. Each Layer contains a canvas element and
+ * provides simple drawing instructions for drawing to that canvas element,
+ * however unlike the canvas element itself, drawing operations on a Layer are
+ * guaranteed to run in order, even if such an operation must wait for an image
+ * to load before completing.
+ *
+ * @constructor
+ *
+ * @param {Number} width The width of the Layer, in pixels. The canvas element
+ * backing this Layer will be given this width.
+ *
+ * @param {Number} height The height of the Layer, in pixels. The canvas element
+ * backing this Layer will be given this height.
+ */
+Guacamole.Layer = function(width, height) {
+
+ var layer = this;
// Off-screen buffer
var display = document.createElement("canvas");
var displayContext = display.getContext("2d");
+ /**
+ * Returns the canvas element backing this Layer.
+ * @returns {Element} The canvas element backing this Layer.
+ */
+ this.getCanvas = function() {
+ return display;
+ };
+
function resize(newWidth, newHeight) {
display.style.position = "absolute";
display.style.left = "0px";
@@ -35,7 +63,15 @@ function Layer(width, height) {
height = newHeight;
}
- display.resize = function(newWidth, newHeight) {
+ /**
+ * Changes the size of this Layer to the given width and height. Resizing
+ * is only attempted if the new size provided is actually different from
+ * the current size.
+ *
+ * @param {Number} newWidth The new width to assign to this Layer.
+ * @param {Number} newHeight The new height to assign to this Layer.
+ */
+ this.resize = function(newWidth, newHeight) {
if (newWidth != width || newHeight != height)
resize(newWidth, newHeight);
};
@@ -87,14 +123,14 @@ function Layer(width, height) {
}
- display.setAutosize = function(flag) {
+ this.setAutosize = function(flag) {
autosize = flag;
};
function reserveJob(handler) {
// If no pending updates, just call (if available) and exit
- if (display.isReady() && handler != null) {
+ if (layer.isReady() && handler != null) {
handler();
return null;
}
@@ -118,12 +154,12 @@ function Layer(width, height) {
}
- display.isReady = function() {
+ this.isReady = function() {
return updates.length == 0;
};
- display.drawImage = function(x, y, image) {
+ this.drawImage = function(x, y, image) {
reserveJob(function() {
if (autosize != 0) fitRect(x, y, image.width, image.height);
displayContext.drawImage(image, x, y);
@@ -131,7 +167,7 @@ function Layer(width, height) {
};
- display.draw = function(x, y, url) {
+ this.draw = function(x, y, url) {
var update = reserveJob(null);
var image = new Image();
@@ -151,14 +187,18 @@ function Layer(width, height) {
};
- // Run arbitrary function as soon as currently pending operations complete.
- // Future operations will not block this function from being called (unlike
- // the ready handler, which requires no pending updates)
- display.sync = function(handler) {
+ /**
+ * Run an arbitrary function as soon as currently pending operations
+ * are complete.
+ *
+ * @param {function} handler The function to call once all currently
+ * pending operations are complete.
+ */
+ this.sync = function(handler) {
reserveJob(handler);
};
- display.copyRect = function(srcLayer, srcx, srcy, w, h, x, y) {
+ this.copyRect = function(srcLayer, srcx, srcy, w, h, x, y) {
function doCopyRect() {
if (autosize != 0) fitRect(x, y, w, h);
@@ -167,7 +207,7 @@ function Layer(width, height) {
// If we ARE the source layer, no need to sync.
// Syncing would result in deadlock.
- if (display === srcLayer)
+ if (layer === srcLayer)
reserveJob(doCopyRect);
// Otherwise synchronize copy operation with source layer
@@ -186,14 +226,14 @@ function Layer(width, height) {
};
- display.clearRect = function(x, y, w, h) {
+ this.clearRect = function(x, y, w, h) {
reserveJob(function() {
if (autosize != 0) fitRect(x, y, w, h);
displayContext.clearRect(x, y, w, h);
});
};
- display.filter = function(filter) {
+ this.filter = function(filter) {
reserveJob(function() {
var imageData = displayContext.getImageData(0, 0, width, height);
filter(imageData.data, width, height);
@@ -220,13 +260,11 @@ function Layer(width, height) {
0xF: "lighter"
};
- display.setChannelMask = function(mask) {
+ this.setChannelMask = function(mask) {
reserveJob(function() {
displayContext.globalCompositeOperation = compositeOperation[mask];
});
};
- return display;
-
}
diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js
index 31d5185d0..ec4c7b1a2 100644
--- a/guacamole-common-js/src/main/resources/mouse.js
+++ b/guacamole-common-js/src/main/resources/mouse.js
@@ -17,8 +17,10 @@
* along with this program. If not, see .
*/
+// Guacamole namespace
+var Guacamole = Guacamole || {};
-function GuacamoleMouse(element) {
+Guacamole.Mouse = function(element) {
var guac_mouse = this;
diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js
index 872bac223..0e6a9ccef 100644
--- a/guacamole-common-js/src/main/resources/oskeyboard.js
+++ b/guacamole-common-js/src/main/resources/oskeyboard.js
@@ -17,10 +17,11 @@
* along with this program. If not, see .
*/
+// Guacamole namespace
+var Guacamole = Guacamole || {};
-function GuacamoleOnScreenKeyboard(url) {
+Guacamole.OnScreenKeyboard = function(url) {
- var tabIndex = 1;
var allKeys = new Array();
var modifierState = new function() {};
diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js
index bb89b241f..e092088cb 100644
--- a/guacamole-common-js/src/main/resources/tunnel.js
+++ b/guacamole-common-js/src/main/resources/tunnel.js
@@ -16,7 +16,10 @@
* You should have received a copy of the GNU Affero General Public License
*/
-function GuacamoleHTTPTunnel(tunnelURL) {
+// Guacamole namespace
+var Guacamole = Guacamole || {};
+
+Guacamole.HTTPTunnel = function(tunnelURL) {
var tunnel = this;