[-]
[+]
|
Changed |
guacamole.changes
|
|
[-]
[+]
|
Changed |
guacamole.spec
^
|
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1
^
|
-(directory)
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1.war
^
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/META-INF
^
|
-(directory)
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF
^
|
-(directory)
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes
^
|
-(directory)
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net
^
|
-(directory)
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge
^
|
-(directory)
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole
^
|
-(directory)
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net
^
|
-(directory)
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic
^
|
-(directory)
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/AuthenticatingHttpServlet.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$1.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$2.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$AuthInfo$Encoding.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$AuthInfo.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$BasicUserMappingContentHandler$State.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$BasicUserMappingContentHandler.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicGuacamoleTunnelServlet$1$1.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicGuacamoleTunnelServlet$1.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicGuacamoleTunnelServlet.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicLogin.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicLogout.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/ConfigurationList.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/GuacamoleClassLoader$1.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/GuacamoleClassLoader$2.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/GuacamoleClassLoader.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/WebSocketSupportLoader.class
^
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/event
^
|
-(directory)
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/event/SessionListenerCollection.class
^
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/properties
^
|
-(directory)
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/properties/AuthenticationProviderProperty.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties$1.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties$2.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties$3.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties.class
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/classes/net/sourceforge/guacamole/net/basic/properties/EventListenersProperty.class
^
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/lib
^
|
-(directory)
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/lib/guacamole-common-0.6.1.jar
^
|
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/WEB-INF/lib/guacamole-ext-0.6.1.jar
^
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/client.xhtml
^
|
@@ -1,163 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html>
-
-<!--
- Guacamole - Clientless Remote Desktop
- Copyright (C) 2010 Michael Jumper
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
--->
-
-<html xmlns="http://www.w3.org/1999/xhtml">
-
- <head>
- <link rel="icon" type="image/png" href="images/guacamole-logo-64.png"/>
- <link rel="stylesheet" type="text/css" href="styles/client.css"/>
- <link rel="stylesheet" type="text/css" href="styles/keyboard.css"/>
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi"/>
- <meta name="apple-mobile-web-app-capable" content="yes"/>
- <title>Guacamole 0.6.1</title>
- </head>
-
- <body>
-
- <!-- Menu -->
- <div id="menu">
-
- <!-- Clipboard -->
- <button id="showClipboard">Show Clipboard</button>
- <div id="clipboardDiv">
- <h2>Clipboard</h2>
- <p>
- Text copied/cut within Guacamole will appear here. Changes to the text will affect the remote clipboard, and will be pastable within the remote desktop. Use the textbox below as an interface between the client and server clipboards.
- </p>
- <textarea rows="10" cols="40" id="clipboard"></textarea>
- </div>
-
- <button id="showKeyboard">Show Keyboard</button>
- <button id="ctrlAltDelete">Ctrl-Alt-Delete</button>
- <button id="logout">Logout</button>
-
- <!-- Logo and status -->
- <img id="status-logo" class="logo" src="images/guacamole-logo-24.png" alt="Guacamole" title="Guacamole 0.6.1"/>
-
- </div>
-
- <!-- Touch-specific menu -->
- <div id="touchMenu"><img id="touchShowClipboard" src="images/menu-icons/tango/edit-paste.png"/><img id="touchShowKeyboard" src="images/menu-icons/tango/input-keyboard.png"/><img id="touchLogout" src="images/menu-icons/tango/system-log-out.png"/></div>
-
- <!-- Touch-specific clipboard -->
- <div id="touchClipboardDiv">
- <h2>Clipboard</h2>
- <p>
- Text copied/cut within Guacamole will appear here. Changes to the text will affect the remote clipboard, and will be pastable within the remote desktop. Use the textbox below as an interface between the client and server clipboards.
- </p>
- <textarea rows="10" cols="40" id="touchClipboard"></textarea>
- </div>
-
- <!-- Keyboard event target for platforms with native OSKs -->
- <textarea id="eventTarget"></textarea>
-
- <!-- Display -->
- <div id="display">
-
- <!-- Menu trigger -->
- <div id="menuControl"></div>
-
- </div>
-
- <!-- On-screen keyboard -->
- <div id="keyboardContainer"></div>
-
- <!-- Dimensional clone of viewport -->
- <div id="viewportClone"/>
-
- <!-- Dialogs -->
- <div class="dialogOuter">
- <div class="dialogMiddle">
-
- <!-- Status Dialog -->
- <div id="statusDialog" class="dialog">
- <p id="statusText"></p>
- <div class="buttons"><button id="reconnect">Reconnect</button></div>
- </div>
-
- </div>
- </div>
-
- <!-- guacamole-common-js scripts -->
- <script type="text/javascript" src="guacamole-common-js/keyboard.js"></script>
- <script type="text/javascript" src="guacamole-common-js/mouse.js"></script>
- <script type="text/javascript" src="guacamole-common-js/layer.js"></script>
- <script type="text/javascript" src="guacamole-common-js/tunnel.js"></script>
- <script type="text/javascript" src="guacamole-common-js/guacamole.js"></script>
- <script type="text/javascript" src="guacamole-common-js/oskeyboard.js"></script>
-
- <!-- guacamole-default-webapp scripts -->
- <script type="text/javascript" src="scripts/interface.js"></script>
-
- <!-- Init -->
- <script type="text/javascript"> /* <![CDATA[ */
-
- // Start connect after control returns from onload (allow browser
- // to consider the page loaded).
- window.onload = function() {
- window.setTimeout(function() {
-
- var tunnel;
-
- // If WebSocket available, try to use it.
- if (window.WebSocket)
- tunnel = new Guacamole.ChainedTunnel(
- new Guacamole.WebSocketTunnel("websocket-tunnel"),
- new Guacamole.HTTPTunnel("tunnel")
- );
-
- // If no WebSocket, then use HTTP.
- else
- tunnel = new Guacamole.HTTPTunnel("tunnel")
-
- // Instantiate client
- var guac = new Guacamole.Client(tunnel);
-
- // Add client to UI
- guac.getDisplay().className = "software-cursor";
- GuacamoleUI.display.appendChild(guac.getDisplay());
-
- // Tie UI to client
- GuacamoleUI.attach(guac);
-
- try {
-
- // Get entire query string, and pass to connect().
- // Normally, only the "id" parameter is required, but
- // all parameters should be preserved and passed on for
- // the sake of authentication.
-
- var connect_string = window.location.search.substring(1);
- guac.connect(connect_string);
-
- }
- catch (e) {
- GuacamoleUI.showError(e.message);
- }
-
- }, 0);
- };
-
- /* ]]> */ </script>
-
- </body>
-
-</html>
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/guacamole-common-js
^
|
-(directory)
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/guacamole-common-js/guacamole.js
^
|
@@ -1,1180 +0,0 @@
-
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is guacamole-common-js.
- *
- * The Initial Developer of the Original Code is
- * Michael Jumper.
- * Portions created by the Initial Developer are Copyright (C) 2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Matt Hortman
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/**
- * Namespace for all Guacamole JavaScript objects.
- * @namespace
- */
-var Guacamole = Guacamole || {};
-
-
-/**
- * Guacamole protocol client. Given a display element and {@link Guacamole.Tunnel},
- * automatically handles incoming and outgoing Guacamole instructions via the
- * provided tunnel, updating the display using one or more canvas elements.
- *
- * @constructor
- * @param {Guacamole.Tunnel} tunnel The tunnel to use to send and receive
- * Guacamole instructions.
- */
-Guacamole.Client = function(tunnel) {
-
- var guac_client = this;
-
- var STATE_IDLE = 0;
- var STATE_CONNECTING = 1;
- var STATE_WAITING = 2;
- var STATE_CONNECTED = 3;
- var STATE_DISCONNECTING = 4;
- var STATE_DISCONNECTED = 5;
-
- var currentState = STATE_IDLE;
-
- var currentTimestamp = 0;
- var pingInterval = null;
-
- var displayWidth = 0;
- var displayHeight = 0;
- var displayScale = 1;
-
- /**
- * Translation from Guacamole protocol line caps to Layer line caps.
- * @private
- */
- var lineCap = {
- 0: "butt",
- 1: "round",
- 2: "square"
- };
-
- /**
- * Translation from Guacamole protocol line caps to Layer line caps.
- * @private
- */
- var lineJoin = {
- 0: "bevel",
- 1: "miter",
- 2: "round"
- };
-
- // Create bounding div
- var bounds = document.createElement("div");
- bounds.style.position = "relative";
- bounds.style.width = (displayWidth*displayScale) + "px";
- bounds.style.height = (displayHeight*displayScale) + "px";
-
- // Create display
- var display = document.createElement("div");
- display.style.position = "relative";
- display.style.width = displayWidth + "px";
- display.style.height = displayHeight + "px";
-
- // Ensure transformations on display originate at 0,0
- display.style.transformOrigin =
- display.style.webkitTransformOrigin =
- display.style.MozTransformOrigin =
- display.style.OTransformOrigin =
- display.style.msTransformOrigin =
- "0 0";
-
- // Create default layer
- var default_layer_container = new Guacamole.Client.LayerContainer(displayWidth, displayHeight);
-
- // Position default layer
- var default_layer_container_element = default_layer_container.getElement();
- default_layer_container_element.style.position = "absolute";
- default_layer_container_element.style.left = "0px";
- default_layer_container_element.style.top = "0px";
- default_layer_container_element.style.overflow = "hidden";
-
- // Create cursor layer
- var cursor = new Guacamole.Client.LayerContainer(0, 0);
- cursor.getLayer().setChannelMask(Guacamole.Layer.SRC);
-
- // Position cursor layer
- var cursor_element = cursor.getElement();
- cursor_element.style.position = "absolute";
- cursor_element.style.left = "0px";
- cursor_element.style.top = "0px";
-
- // Add default layer and cursor to display
- display.appendChild(default_layer_container.getElement());
- display.appendChild(cursor.getElement());
-
- // Add display to bounds
- bounds.appendChild(display);
-
- // Initially, only default layer exists
- var layers = [default_layer_container];
-
- // No initial buffers
- var buffers = [];
-
- tunnel.onerror = function(message) {
- if (guac_client.onerror)
- guac_client.onerror(message);
- };
-
- function setState(state) {
- if (state != currentState) {
- currentState = state;
- if (guac_client.onstatechange)
- guac_client.onstatechange(currentState);
- }
- }
-
- function isConnected() {
- return currentState == STATE_CONNECTED
- || currentState == STATE_WAITING;
- }
-
- var cursorHotspotX = 0;
- var cursorHotspotY = 0;
-
- var cursorX = 0;
- var cursorY = 0;
-
- function moveCursor(x, y) {
-
- // Move cursor layer
- cursor.translate(x - cursorHotspotX, y - cursorHotspotY);
-
- // Update stored position
- cursorX = x;
- cursorY = y;
-
- }
-
- /**
- * Returns an element containing the display of this Guacamole.Client.
- * Adding the element returned by this function to an element in the body
- * of a document will cause the client's display to be visible.
- *
- * @return {Element} An element containing ths display of this
- * Guacamole.Client.
- */
- this.getDisplay = function() {
- return bounds;
- };
-
- /**
- * Sends a key event having the given properties as if the user
- * pressed or released a key.
- *
- * @param {Boolean} pressed Whether the key is pressed (true) or released
- * (false).
- * @param {Number} keysym The keysym of the key being pressed or released.
- */
- this.sendKeyEvent = function(pressed, keysym) {
- // Do not send requests if not connected
- if (!isConnected())
- return;
-
- tunnel.sendMessage("key", keysym, pressed);
- };
-
- /**
- * Sends a mouse event having the properties provided by the given mouse
- * state.
- *
- * @param {Guacamole.Mouse.State} mouseState The state of the mouse to send
- * in the mouse event.
- */
- this.sendMouseState = function(mouseState) {
-
- // Do not send requests if not connected
- if (!isConnected())
- return;
-
- // Update client-side cursor
- moveCursor(
- Math.floor(mouseState.x),
- Math.floor(mouseState.y)
- );
-
- // Build mask
- var buttonMask = 0;
- if (mouseState.left) buttonMask |= 1;
- if (mouseState.middle) buttonMask |= 2;
- if (mouseState.right) buttonMask |= 4;
- if (mouseState.up) buttonMask |= 8;
- if (mouseState.down) buttonMask |= 16;
-
- // Send message
- tunnel.sendMessage("mouse", Math.floor(mouseState.x), Math.floor(mouseState.y), buttonMask);
- };
-
- /**
- * Sets the clipboard of the remote client to the given text data.
- *
- * @param {String} data The data to send as the clipboard contents.
- */
- this.setClipboard = function(data) {
-
- // Do not send requests if not connected
- if (!isConnected())
- return;
-
- tunnel.sendMessage("clipboard", data);
- };
-
- /**
- * Fired whenever the state of this Guacamole.Client changes.
- *
- * @event
- * @param {Number} state The new state of the client.
- */
- this.onstatechange = null;
-
- /**
- * Fired when the remote client sends a name update.
- *
- * @event
- * @param {String} name The new name of this client.
- */
- this.onname = null;
-
- /**
- * Fired when an error is reported by the remote client, and the connection
- * is being closed.
- *
- * @event
- * @param {String} error A human-readable description of the error.
- */
- this.onerror = null;
-
- /**
- * Fired when the clipboard of the remote client is changing.
- *
- * @event
- * @param {String} data The new text data of the remote clipboard.
- */
- this.onclipboard = null;
-
- // Layers
- function getBufferLayer(index) {
-
- index = -1 - index;
- var buffer = buffers[index];
-
- // Create buffer if necessary
- if (buffer == null) {
- buffer = new Guacamole.Layer(0, 0);
- buffer.autosize = 1;
- buffers[index] = buffer;
- }
-
- return buffer;
-
- }
-
- function getLayerContainer(index) {
-
- var layer = layers[index];
- if (layer == null) {
-
- // Add new layer
- layer = new Guacamole.Client.LayerContainer(displayWidth, displayHeight);
- layers[index] = layer;
-
- // Get and position layer
- var layer_element = layer.getElement();
- layer_element.style.position = "absolute";
- layer_element.style.left = "0px";
- layer_element.style.top = "0px";
- layer_element.style.overflow = "hidden";
-
- // Add to default layer container
- default_layer_container.getElement().appendChild(layer_element);
-
- }
-
- return layer;
-
- }
-
- function getLayer(index) {
-
- // If buffer, just get layer
- if (index < 0)
- return getBufferLayer(index);
-
- // Otherwise, retrieve layer from layer container
- return getLayerContainer(index).getLayer();
-
- }
-
- /**
- * Handlers for all defined layer properties.
- * @private
- */
- var layerPropertyHandlers = {
-
- "miter-limit": function(layer, value) {
- layer.setMiterLimit(parseFloat(value));
- }
-
- };
-
- /**
- * Handlers for all instruction opcodes receivable by a Guacamole protocol
- * client.
- * @private
- */
- var instructionHandlers = {
-
- "arc": function(parameters) {
-
- var layer = getLayer(parseInt(parameters[0]));
- var x = parseInt(parameters[1]);
- var y = parseInt(parameters[2]);
- var radius = parseInt(parameters[3]);
- var startAngle = parseFloat(parameters[4]);
- var endAngle = parseFloat(parameters[5]);
- var negative = parseInt(parameters[6]);
-
- layer.arc(x, y, radius, startAngle, endAngle, negative != 0);
-
- },
-
- "cfill": function(parameters) {
-
- var channelMask = parseInt(parameters[0]);
- var layer = getLayer(parseInt(parameters[1]));
- var r = parseInt(parameters[2]);
- var g = parseInt(parameters[3]);
- var b = parseInt(parameters[4]);
- var a = parseInt(parameters[5]);
-
- layer.setChannelMask(channelMask);
-
- layer.fillColor(r, g, b, a);
-
- },
-
- "clip": function(parameters) {
-
- var layer = getLayer(parseInt(parameters[0]));
-
- layer.clip();
-
- },
-
- "clipboard": function(parameters) {
- if (guac_client.onclipboard) guac_client.onclipboard(parameters[0]);
- },
-
- "close": function(parameters) {
-
- var layer = getLayer(parseInt(parameters[0]));
-
- layer.close();
-
- },
-
- "copy": function(parameters) {
-
- var srcL = getLayer(parseInt(parameters[0]));
- var srcX = parseInt(parameters[1]);
- var srcY = parseInt(parameters[2]);
- var srcWidth = parseInt(parameters[3]);
- var srcHeight = parseInt(parameters[4]);
- var channelMask = parseInt(parameters[5]);
- var dstL = getLayer(parseInt(parameters[6]));
- var dstX = parseInt(parameters[7]);
- var dstY = parseInt(parameters[8]);
-
- dstL.setChannelMask(channelMask);
-
- dstL.copy(
- srcL,
- srcX,
- srcY,
- srcWidth,
- srcHeight,
- dstX,
- dstY
- );
-
- },
-
- "cstroke": function(parameters) {
-
- var channelMask = parseInt(parameters[0]);
- var layer = getLayer(parseInt(parameters[1]));
- var cap = lineCap[parseInt(parameters[2])];
- var join = lineJoin[parseInt(parameters[3])];
- var thickness = parseInt(parameters[4]);
- var r = parseInt(parameters[5]);
- var g = parseInt(parameters[6]);
- var b = parseInt(parameters[7]);
- var a = parseInt(parameters[8]);
-
- layer.setChannelMask(channelMask);
-
- layer.strokeColor(cap, join, thickness, r, g, b, a);
-
- },
-
- "cursor": function(parameters) {
-
- cursorHotspotX = parseInt(parameters[0]);
- cursorHotspotY = parseInt(parameters[1]);
- var srcL = getLayer(parseInt(parameters[2]));
- var srcX = parseInt(parameters[3]);
- var srcY = parseInt(parameters[4]);
- var srcWidth = parseInt(parameters[5]);
- var srcHeight = parseInt(parameters[6]);
-
- // Reset cursor size
- cursor.resize(srcWidth, srcHeight);
-
- // Draw cursor to cursor layer
- cursor.getLayer().copy(
- srcL,
- srcX,
- srcY,
- srcWidth,
- srcHeight,
- 0,
- 0
- );
-
- // Update cursor position (hotspot may have changed)
- moveCursor(cursorX, cursorY);
-
- },
-
- "curve": function(parameters) {
-
- var layer = getLayer(parseInt(parameters[0]));
- var cp1x = parseInt(parameters[1]);
- var cp1y = parseInt(parameters[2]);
- var cp2x = parseInt(parameters[3]);
- var cp2y = parseInt(parameters[4]);
- var x = parseInt(parameters[5]);
- var y = parseInt(parameters[6]);
-
- layer.curveTo(cp1x, cp1y, cp2x, cp2y, x, y);
-
- },
-
- "dispose": function(parameters) {
-
- var layer_index = parseInt(parameters[0]);
-
- // If visible layer, remove from parent
- if (layer_index > 0) {
-
- // Get container element
- var layer_container = getLayerContainer(layer_index).getElement();
-
- // Remove from parent
- layer_container.parentNode.removeChild(layer_container);
-
- // Delete reference
- delete layers[layer_index];
-
- }
-
- // If buffer, just delete reference
- else if (layer_index < 0)
- delete buffers[-1 - layer_index];
-
- // Attempting to dispose the root layer currently has no effect.
-
- },
-
- "distort": function(parameters) {
-
- var layer_index = parseInt(parameters[0]);
- var a = parseFloat(parameters[1]);
- var b = parseFloat(parameters[2]);
- var c = parseFloat(parameters[3]);
- var d = parseFloat(parameters[4]);
- var e = parseFloat(parameters[5]);
- var f = parseFloat(parameters[6]);
-
- // Only valid for visible layers (not buffers)
- if (layer_index >= 0) {
-
- // Get container element
- var layer_container = getLayerContainer(layer_index).getElement();
-
- // Set layer transform
- layer_container.transform(a, b, c, d, e, f);
-
- }
-
- },
-
- "error": function(parameters) {
- if (guac_client.onerror) guac_client.onerror(parameters[0]);
- guac_client.disconnect();
- },
-
- "identity": function(parameters) {
-
- var layer = getLayer(parseInt(parameters[0]));
-
- layer.setTransform(1, 0, 0, 1, 0, 0);
-
- },
-
- "lfill": function(parameters) {
-
- var channelMask = parseInt(parameters[0]);
- var layer = getLayer(parseInt(parameters[1]));
- var srcLayer = getLayer(parseInt(parameters[2]));
-
- layer.setChannelMask(channelMask);
-
- layer.fillLayer(srcLayer);
-
- },
-
- "line": function(parameters) {
-
- var layer = getLayer(parseInt(parameters[0]));
- var x = parseInt(parameters[1]);
- var y = parseInt(parameters[2]);
-
- layer.lineTo(x, y);
-
- },
-
- "lstroke": function(parameters) {
-
- var channelMask = parseInt(parameters[0]);
- var layer = getLayer(parseInt(parameters[1]));
- var srcLayer = getLayer(parseInt(parameters[2]));
-
- layer.setChannelMask(channelMask);
-
- layer.strokeLayer(srcLayer);
-
- },
-
- "move": function(parameters) {
-
- var layer_index = parseInt(parameters[0]);
- var parent_index = parseInt(parameters[1]);
- var x = parseInt(parameters[2]);
- var y = parseInt(parameters[3]);
- var z = parseInt(parameters[4]);
-
- // Only valid for non-default layers
- if (layer_index > 0 && parent_index >= 0) {
-
- // Get container element
- var layer_container = getLayerContainer(layer_index);
- var layer_container_element = layer_container.getElement();
- var parent = getLayerContainer(parent_index).getElement();
-
- // Set parent if necessary
- if (!(layer_container_element.parentNode === parent))
- parent.appendChild(layer_container_element);
-
- // Move layer
- layer_container.translate(x, y);
- layer_container_element.style.zIndex = z;
-
- }
-
- },
-
- "name": function(parameters) {
- if (guac_client.onname) guac_client.onname(parameters[0]);
- },
-
- "png": function(parameters) {
-
- var channelMask = parseInt(parameters[0]);
- var layer = getLayer(parseInt(parameters[1]));
- var x = parseInt(parameters[2]);
- var y = parseInt(parameters[3]);
- var data = parameters[4];
-
- layer.setChannelMask(channelMask);
-
- layer.draw(
- x,
- y,
- "data:image/png;base64," + data
- );
-
- // If received first update, no longer waiting.
- if (currentState == STATE_WAITING)
- setState(STATE_CONNECTED);
-
- },
-
- "pop": function(parameters) {
-
- var layer = getLayer(parseInt(parameters[0]));
-
- layer.pop();
-
- },
-
- "push": function(parameters) {
-
- var layer = getLayer(parseInt(parameters[0]));
-
- layer.push();
-
- },
-
- "rect": function(parameters) {
-
- var layer = getLayer(parseInt(parameters[0]));
- var x = parseInt(parameters[1]);
- var y = parseInt(parameters[2]);
- var w = parseInt(parameters[3]);
- var h = parseInt(parameters[4]);
-
- layer.rect(x, y, w, h);
-
- },
-
- "reset": function(parameters) {
-
- var layer = getLayer(parseInt(parameters[0]));
-
- layer.reset();
-
- },
-
- "set": function(parameters) {
-
- var layer = getLayer(parseInt(parameters[0]));
- var name = parameters[1];
- var value = parameters[2];
-
- // Call property handler if defined
- var handler = layerPropertyHandlers[name];
- if (handler)
- handler(layer, value);
-
- },
-
- "shade": function(parameters) {
-
- var layer_index = parseInt(parameters[0]);
- var a = parseInt(parameters[1]);
-
- // Only valid for visible layers (not buffers)
- if (layer_index >= 0) {
-
- // Get container element
- var layer_container = getLayerContainer(layer_index).getElement();
-
- // Set layer opacity
- layer_container.style.opacity = a/255.0;
-
- }
-
- },
-
- "size": function(parameters) {
-
- var layer_index = parseInt(parameters[0]);
- var width = parseInt(parameters[1]);
- var height = parseInt(parameters[2]);
-
- // If not buffer, resize layer and container
- if (layer_index >= 0) {
-
- // Resize layer
- var layer_container = getLayerContainer(layer_index);
- layer_container.resize(width, height);
-
- // If layer is default, resize display
- if (layer_index == 0) {
-
- displayWidth = width;
- displayHeight = height;
-
- // Update (set) display size
- display.style.width = displayWidth + "px";
- display.style.height = displayHeight + "px";
-
- // Update bounds size
- bounds.style.width = (displayWidth*displayScale) + "px";
- bounds.style.height = (displayHeight*displayScale) + "px";
-
- }
-
- }
-
- // If buffer, resize layer only
- else {
- var layer = getBufferLayer(parseInt(parameters[0]));
- layer.resize(width, height);
- }
-
- },
-
- "start": function(parameters) {
-
- var layer = getLayer(parseInt(parameters[0]));
- var x = parseInt(parameters[1]);
- var y = parseInt(parameters[2]);
-
- layer.moveTo(x, y);
-
- },
-
- "sync": function(parameters) {
-
- var timestamp = parameters[0];
-
- // When all layers have finished rendering all instructions
- // UP TO THIS POINT IN TIME, send sync response.
-
- var layersToSync = 0;
- function syncLayer() {
-
- layersToSync--;
-
- // Send sync response when layers are finished
- if (layersToSync == 0) {
- if (timestamp != currentTimestamp) {
- tunnel.sendMessage("sync", timestamp);
- currentTimestamp = timestamp;
- }
- }
-
- }
-
- // Count active, not-ready layers and install sync tracking hooks
- for (var i=0; i<layers.length; i++) {
-
- var layer = layers[i].getLayer();
- if (layer && !layer.isReady()) {
- layersToSync++;
- layer.sync(syncLayer);
- }
-
- }
-
- // If all layers are ready, then we didn't install any hooks.
- // Send sync message now,
- if (layersToSync == 0) {
- if (timestamp != currentTimestamp) {
- tunnel.sendMessage("sync", timestamp);
- currentTimestamp = timestamp;
- }
- }
-
- },
-
- "transfer": function(parameters) {
-
- var srcL = getLayer(parseInt(parameters[0]));
- var srcX = parseInt(parameters[1]);
- var srcY = parseInt(parameters[2]);
- var srcWidth = parseInt(parameters[3]);
- var srcHeight = parseInt(parameters[4]);
- var transferFunction = Guacamole.Client.DefaultTransferFunction[parameters[5]];
- var dstL = getLayer(parseInt(parameters[6]));
- var dstX = parseInt(parameters[7]);
- var dstY = parseInt(parameters[8]);
-
- dstL.transfer(
- srcL,
- srcX,
- srcY,
- srcWidth,
- srcHeight,
- dstX,
- dstY,
- transferFunction
- );
-
- },
-
- "transform": function(parameters) {
-
- var layer = getLayer(parseInt(parameters[0]));
- var a = parseFloat(parameters[1]);
- var b = parseFloat(parameters[2]);
- var c = parseFloat(parameters[3]);
- var d = parseFloat(parameters[4]);
- var e = parseFloat(parameters[5]);
- var f = parseFloat(parameters[6]);
-
- layer.transform(a, b, c, d, e, f);
-
- }
-
- };
-
-
- tunnel.oninstruction = function(opcode, parameters) {
-
- var handler = instructionHandlers[opcode];
- if (handler)
- handler(parameters);
-
- };
-
-
- this.disconnect = function() {
-
- // Only attempt disconnection not disconnected.
- if (currentState != STATE_DISCONNECTED
- && currentState != STATE_DISCONNECTING) {
-
- setState(STATE_DISCONNECTING);
-
- // Stop ping
- if (pingInterval)
- window.clearInterval(pingInterval);
-
- // Send disconnect message and disconnect
- tunnel.sendMessage("disconnect");
- tunnel.disconnect();
- setState(STATE_DISCONNECTED);
-
- }
-
- };
-
- this.connect = function(data) {
-
- setState(STATE_CONNECTING);
-
- try {
- tunnel.connect(data);
- }
- catch (e) {
- setState(STATE_IDLE);
- throw e;
- }
-
- // Ping every 5 seconds (ensure connection alive)
- pingInterval = window.setInterval(function() {
- tunnel.sendMessage("sync", currentTimestamp);
- }, 5000);
-
- setState(STATE_WAITING);
- };
-
- this.scale = function(scale) {
-
- display.style.transform =
- display.style.WebkitTransform =
- display.style.MozTransform =
- display.style.OTransform =
- display.style.msTransform =
-
- "scale(" + scale + "," + scale + ")";
-
- displayScale = scale;
-
- // Update bounds size
- bounds.style.width = (displayWidth*displayScale) + "px";
- bounds.style.height = (displayHeight*displayScale) + "px";
-
- };
-
- this.getScale = function() {
- return displayScale;
- };
-
-};
-
-/**
- * Simple container for Guacamole.Layer, allowing layers to be easily
- * repositioned and nested. This allows certain operations to be accelerated
- * through DOM manipulation, rather than raster operations.
- *
- * @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.Client.LayerContainer = function(width, height) {
-
- /**
- * Reference to this LayerContainer.
- * @private
- */
- var layer_container = this;
-
- // Create layer with given size
- var layer = new Guacamole.Layer(width, height);
-
- // Set layer position
- var canvas = layer.getCanvas();
- canvas.style.position = "absolute";
- canvas.style.left = "0px";
- canvas.style.top = "0px";
-
- // Create div with given size
- var div = document.createElement("div");
- div.appendChild(canvas);
- div.style.width = width + "px";
- div.style.height = height + "px";
-
- /**
- * Changes the size of this LayerContainer and the contained Layer to the
- * given width and height.
- *
- * @param {Number} width The new width to assign to this Layer.
- * @param {Number} height The new height to assign to this Layer.
- */
- this.resize = function(width, height) {
-
- // Resize layer
- layer.resize(width, height);
-
- // Resize containing div
- div.style.width = width + "px";
- div.style.height = height + "px";
-
- };
-
- /**
- * Returns the Layer contained within this LayerContainer.
- * @returns {Guacamole.Layer} The Layer contained within this LayerContainer.
- */
- this.getLayer = function() {
- return layer;
- };
-
- /**
- * Returns the element containing the Layer within this LayerContainer.
- * @returns {Element} The element containing the Layer within this LayerContainer.
- */
- this.getElement = function() {
- return div;
- };
-
- /**
- * The translation component of this LayerContainer's transform.
- * @private
- */
- var translate = "translate(0px, 0px)"; // (0, 0)
-
- /**
- * The arbitrary matrix component of this LayerContainer's transform.
- * @private
- */
- var matrix = "matrix(1, 0, 0, 1, 0, 0)"; // Identity
-
- /**
- * Moves the upper-left corner of this LayerContainer to the given X and Y
- * coordinate.
- *
- * @param {Number} x The X coordinate to move to.
- * @param {Number} y The Y coordinate to move to.
- */
- this.translate = function(x, y) {
-
- // Generate translation
- translate = "translate("
- + x + "px,"
- + y + "px)";
-
- // Set layer transform
- div.style.transform =
- div.style.WebkitTransform =
- div.style.MozTransform =
- div.style.OTransform =
- div.style.msTransform =
-
- translate + " " + matrix;
-
- };
-
- /**
- * Applies the given affine transform (defined with six values from the
- * transform's matrix).
- *
- * @param {Number} a The first value in the affine transform's matrix.
- * @param {Number} b The second value in the affine transform's matrix.
- * @param {Number} c The third value in the affine transform's matrix.
- * @param {Number} d The fourth value in the affine transform's matrix.
- * @param {Number} e The fifth value in the affine transform's matrix.
- * @param {Number} f The sixth value in the affine transform's matrix.
- */
- this.transform = function(a, b, c, d, e, f) {
-
- // Generate matrix transformation
- matrix =
-
- /* a c e
- * b d f
- * 0 0 1
- */
-
- "matrix(" + a + "," + b + "," + c + "," + d + "," + e + "," + f + ")";
-
- // Set layer transform
- div.style.transform =
- div.style.WebkitTransform =
- div.style.MozTransform =
- div.style.OTransform =
- div.style.msTransform =
-
- translate + " " + matrix;
-
- };
-
-};
-
-/**
- * Map of all Guacamole binary raster operations to transfer functions.
- * @private
- */
-Guacamole.Client.DefaultTransferFunction = {
-
- /* BLACK */
- 0x0: function (src, dst) {
- dst.red = dst.green = dst.blue = 0x00;
- },
-
- /* WHITE */
- 0xF: function (src, dst) {
- dst.red = dst.green = dst.blue = 0xFF;
- },
-
- /* SRC */
- 0x3: function (src, dst) {
- dst.red = src.red;
- dst.green = src.green;
- dst.blue = src.blue;
- dst.alpha = src.alpha;
- },
-
- /* DEST (no-op) */
- 0x5: function (src, dst) {
- // Do nothing
- },
-
- /* Invert SRC */
- 0xC: function (src, dst) {
- dst.red = 0xFF & ~src.red;
- dst.green = 0xFF & ~src.green;
- dst.blue = 0xFF & ~src.blue;
- dst.alpha = src.alpha;
- },
-
- /* Invert DEST */
- 0xA: function (src, dst) {
- dst.red = 0xFF & ~dst.red;
- dst.green = 0xFF & ~dst.green;
- dst.blue = 0xFF & ~dst.blue;
- },
-
- /* AND */
- 0x1: function (src, dst) {
- dst.red = ( src.red & dst.red);
- dst.green = ( src.green & dst.green);
- dst.blue = ( src.blue & dst.blue);
- },
-
- /* NAND */
- 0xE: function (src, dst) {
- dst.red = 0xFF & ~( src.red & dst.red);
- dst.green = 0xFF & ~( src.green & dst.green);
- dst.blue = 0xFF & ~( src.blue & dst.blue);
- },
-
- /* OR */
- 0x7: function (src, dst) {
- dst.red = ( src.red | dst.red);
- dst.green = ( src.green | dst.green);
- dst.blue = ( src.blue | dst.blue);
- },
-
- /* NOR */
- 0x8: function (src, dst) {
- dst.red = 0xFF & ~( src.red | dst.red);
- dst.green = 0xFF & ~( src.green | dst.green);
- dst.blue = 0xFF & ~( src.blue | dst.blue);
- },
-
- /* XOR */
- 0x6: function (src, dst) {
- dst.red = ( src.red ^ dst.red);
- dst.green = ( src.green ^ dst.green);
- dst.blue = ( src.blue ^ dst.blue);
- },
-
- /* XNOR */
- 0x9: function (src, dst) {
- dst.red = 0xFF & ~( src.red ^ dst.red);
- dst.green = 0xFF & ~( src.green ^ dst.green);
- dst.blue = 0xFF & ~( src.blue ^ dst.blue);
- },
-
- /* AND inverted source */
- 0x4: function (src, dst) {
- dst.red = 0xFF & (~src.red & dst.red);
- dst.green = 0xFF & (~src.green & dst.green);
- dst.blue = 0xFF & (~src.blue & dst.blue);
- },
-
- /* OR inverted source */
- 0xD: function (src, dst) {
- dst.red = 0xFF & (~src.red | dst.red);
- dst.green = 0xFF & (~src.green | dst.green);
- dst.blue = 0xFF & (~src.blue | dst.blue);
- },
-
- /* AND inverted destination */
- 0x2: function (src, dst) {
- dst.red = 0xFF & ( src.red & ~dst.red);
- dst.green = 0xFF & ( src.green & ~dst.green);
- dst.blue = 0xFF & ( src.blue & ~dst.blue);
- },
-
- /* OR inverted destination */
- 0xB: function (src, dst) {
- dst.red = 0xFF & ( src.red | ~dst.red);
- dst.green = 0xFF & ( src.green | ~dst.green);
- dst.blue = 0xFF & ( src.blue | ~dst.blue);
- }
-
-};
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/guacamole-common-js/keyboard.js
^
|
@@ -1,550 +0,0 @@
-
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is guacamole-common-js.
- *
- * The Initial Developer of the Original Code is
- * Michael Jumper.
- * Portions created by the Initial Developer are Copyright (C) 2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/**
- * Namespace for all Guacamole JavaScript objects.
- * @namespace
- */
-var Guacamole = Guacamole || {};
-
-/**
- * Provides cross-browser and cross-keyboard keyboard for a specific element.
- * Browser and keyboard layout variation is abstracted away, providing events
- * which represent keys as their corresponding X11 keysym.
- *
- * @constructor
- * @param {Element} element The Element to use to provide keyboard events.
- */
-Guacamole.Keyboard = function(element) {
-
- /**
- * Reference to this Guacamole.Keyboard.
- * @private
- */
- var guac_keyboard = this;
-
- /**
- * Fired whenever the user presses a key with the element associated
- * with this Guacamole.Keyboard in focus.
- *
- * @event
- * @param {Number} keysym The keysym of the key being pressed.
- */
- this.onkeydown = null;
-
- /**
- * Fired whenever the user releases a key with the element associated
- * with this Guacamole.Keyboard in focus.
- *
- * @event
- * @param {Number} keysym The keysym of the key being released.
- */
- this.onkeyup = null;
-
- /**
- * Map of known JavaScript keycodes which do not map to typable characters
- * to their unshifted X11 keysym equivalents.
- * @private
- */
- var unshiftedKeySym = {
- 8: 0xFF08, // backspace
- 9: 0xFF09, // tab
- 13: 0xFF0D, // enter
- 16: 0xFFE1, // shift
- 17: 0xFFE3, // ctrl
- 18: 0xFFE9, // alt
- 19: 0xFF13, // pause/break
- 20: 0xFFE5, // caps lock
- 27: 0xFF1B, // escape
- 32: 0x0020, // space
- 33: 0xFF55, // page up
- 34: 0xFF56, // page down
- 35: 0xFF57, // end
- 36: 0xFF50, // home
- 37: 0xFF51, // left arrow
- 38: 0xFF52, // up arrow
- 39: 0xFF53, // right arrow
- 40: 0xFF54, // down arrow
- 45: 0xFF63, // insert
- 46: 0xFFFF, // delete
- 91: 0xFFEB, // left window key (super_l)
- 92: 0xFF67, // right window key (menu key?)
- 93: null, // select key
- 112: 0xFFBE, // f1
- 113: 0xFFBF, // f2
- 114: 0xFFC0, // f3
- 115: 0xFFC1, // f4
- 116: 0xFFC2, // f5
- 117: 0xFFC3, // f6
- 118: 0xFFC4, // f7
- 119: 0xFFC5, // f8
- 120: 0xFFC6, // f9
- 121: 0xFFC7, // f10
- 122: 0xFFC8, // f11
- 123: 0xFFC9, // f12
- 144: 0xFF7F, // num lock
- 145: 0xFF14 // scroll lock
- };
-
- /**
- * Map of known JavaScript keyidentifiers which do not map to typable
- * characters to their unshifted X11 keysym equivalents.
- * @private
- */
- var keyidentifier_keysym = {
- "AllCandidates": 0xFF3D,
- "Alphanumeric": 0xFF30,
- "Alt": 0xFFE9,
- "Attn": 0xFD0E,
- "AltGraph": 0xFFEA,
- "CapsLock": 0xFFE5,
- "Clear": 0xFF0B,
- "Convert": 0xFF21,
- "Copy": 0xFD15,
- "Crsel": 0xFD1C,
- "CodeInput": 0xFF37,
- "Control": 0xFFE3,
- "Down": 0xFF54,
- "End": 0xFF57,
- "Enter": 0xFF0D,
- "EraseEof": 0xFD06,
- "Execute": 0xFF62,
- "Exsel": 0xFD1D,
- "F1": 0xFFBE,
- "F2": 0xFFBF,
- "F3": 0xFFC0,
- "F4": 0xFFC1,
- "F5": 0xFFC2,
- "F6": 0xFFC3,
- "F7": 0xFFC4,
- "F8": 0xFFC5,
- "F9": 0xFFC6,
- "F10": 0xFFC7,
- "F11": 0xFFC8,
- "F12": 0xFFC9,
- "F13": 0xFFCA,
- "F14": 0xFFCB,
- "F15": 0xFFCC,
- "F16": 0xFFCD,
- "F17": 0xFFCE,
- "F18": 0xFFCF,
- "F19": 0xFFD0,
- "F20": 0xFFD1,
- "F21": 0xFFD2,
- "F22": 0xFFD3,
- "F23": 0xFFD4,
- "F24": 0xFFD5,
- "Find": 0xFF68,
- "FullWidth": null,
- "HalfWidth": null,
- "HangulMode": 0xFF31,
- "HanjaMode": 0xFF34,
- "Help": 0xFF6A,
- "Hiragana": 0xFF25,
- "Home": 0xFF50,
- "Insert": 0xFF63,
- "JapaneseHiragana": 0xFF25,
- "JapaneseKatakana": 0xFF26,
- "JapaneseRomaji": 0xFF24,
- "JunjaMode": 0xFF38,
- "KanaMode": 0xFF2D,
- "KanjiMode": 0xFF21,
- "Katakana": 0xFF26,
- "Left": 0xFF51,
- "Meta": 0xFFE7,
- "NumLock": 0xFF7F,
- "PageDown": 0xFF55,
- "PageUp": 0xFF56,
- "Pause": 0xFF13,
- "PreviousCandidate": 0xFF3E,
- "PrintScreen": 0xFD1D,
- "Right": 0xFF53,
- "RomanCharacters": null,
- "Scroll": 0xFF14,
- "Select": 0xFF60,
- "Shift": 0xFFE1,
- "Up": 0xFF52,
- "Undo": 0xFF65,
- "Win": 0xFFEB
- };
-
- /**
- * Map of known JavaScript keycodes which do not map to typable characters
- * to their shifted X11 keysym equivalents. Keycodes must only be listed
- * here if their shifted X11 keysym equivalents differ from their unshifted
- * equivalents.
- * @private
- */
- var shiftedKeySym = {
- 18: 0xFFE7 // alt
- };
-
- /**
- * All modifiers and their states.
- */
- this.modifiers = {
-
- /**
- * Whether shift is currently pressed.
- */
- "shift": false,
-
- /**
- * Whether ctrl is currently pressed.
- */
- "ctrl" : false,
-
- /**
- * Whether alt is currently pressed.
- */
- "alt" : false
-
- };
-
- /**
- * The state of every key, indexed by keysym. If a particular key is
- * pressed, the value of pressed for that keysym will be true. If a key
- * is not currently pressed, the value for that keysym may be false or
- * undefined.
- */
- this.pressed = [];
-
- var keydownChar = new Array();
-
- // ID of routine repeating keystrokes. -1 = not repeating.
- var repeatKeyTimeoutId = -1;
- var repeatKeyIntervalId = -1;
-
- // Starts repeating keystrokes
- function startRepeat(keySym) {
- repeatKeyIntervalId = setInterval(function() {
- sendKeyReleased(keySym);
- sendKeyPressed(keySym);
- }, 50);
- }
-
- // Stops repeating keystrokes
- function stopRepeat() {
- if (repeatKeyTimeoutId != -1) clearTimeout(repeatKeyTimeoutId);
- if (repeatKeyIntervalId != -1) clearInterval(repeatKeyIntervalId);
- }
-
-
- function getKeySymFromKeyIdentifier(shifted, keyIdentifier) {
-
- var unicodePrefixLocation = keyIdentifier.indexOf("U+");
- if (unicodePrefixLocation >= 0) {
-
- var hex = keyIdentifier.substring(unicodePrefixLocation+2);
- var codepoint = parseInt(hex, 16);
- var typedCharacter;
-
- // Convert case if shifted
- if (shifted == 0)
- typedCharacter = String.fromCharCode(codepoint).toLowerCase();
- else
- typedCharacter = String.fromCharCode(codepoint).toUpperCase();
-
- // Get codepoint
- codepoint = typedCharacter.charCodeAt(0);
-
- return getKeySymFromCharCode(codepoint);
-
- }
-
- return keyidentifier_keysym[keyIdentifier];
-
- }
-
- function isControlCharacter(codepoint) {
- return codepoint <= 0x1F || (codepoint >= 0x7F && codepoint <= 0x9F);
- }
-
- function getKeySymFromCharCode(codepoint) {
-
- // Keysyms for control characters
- if (isControlCharacter(codepoint)) return 0xFF00 | codepoint;
-
- // Keysyms for ASCII chars
- if (codepoint >= 0x0000 && codepoint <= 0x00FF)
- return codepoint;
-
- // Keysyms for Unicode
- if (codepoint >= 0x0100 && codepoint <= 0x10FFFF)
- return 0x01000000 | codepoint;
-
- return null;
-
- }
-
- function getKeySymFromKeyCode(keyCode) {
-
- var keysym = null;
- if (!guac_keyboard.modifiers.shift) keysym = unshiftedKeySym[keyCode];
- else {
- keysym = shiftedKeySym[keyCode];
- if (keysym == null) keysym = unshiftedKeySym[keyCode];
- }
-
- return keysym;
-
- }
-
-
- // Sends a single keystroke over the network
- function sendKeyPressed(keysym) {
-
- // Mark key as pressed
- guac_keyboard.pressed[keysym] = true;
-
- // Send key event
- if (keysym != null && guac_keyboard.onkeydown)
- guac_keyboard.onkeydown(keysym);
-
- }
-
- // Sends a single keystroke over the network
- function sendKeyReleased(keysym) {
-
- // Mark key as released
- guac_keyboard.pressed[keysym] = false;
-
- // Send key event
- if (keysym != null && guac_keyboard.onkeyup)
- guac_keyboard.onkeyup(keysym);
-
- }
-
-
- var expect_keypress = true;
- var keydown_code = null;
-
- var deferred_keypress = null;
- var keydown_keysym = null;
- var keypress_keysym = null;
-
- function handleKeyEvents() {
-
- // Prefer keysym from keypress
- var keysym = keypress_keysym || keydown_keysym;
- var keynum = keydown_code;
-
- if (keydownChar[keynum] != keysym) {
-
- // If this button is already pressed, release first
- var lastKeyDownChar = keydownChar[keydown_code];
- if (lastKeyDownChar)
- sendKeyReleased(lastKeyDownChar);
-
- // Send event
- keydownChar[keynum] = keysym;
- sendKeyPressed(keysym);
-
- // Clear old key repeat, if any.
- stopRepeat();
-
- // Start repeating (if not a modifier key) after a short delay
- if (keynum != 16 && keynum != 17 && keynum != 18)
- repeatKeyTimeoutId = setTimeout(function() { startRepeat(keysym); }, 500);
-
- }
-
- // Done with deferred key event
- deferred_keypress = null;
- keypress_keysym = null;
- keydown_keysym = null;
- keydown_code = null;
-
- }
-
- function isTypable(keyIdentifier) {
-
- // Find unicode prefix
- var unicodePrefixLocation = keyIdentifier.indexOf("U+");
- if (unicodePrefixLocation == -1)
- return false;
-
- // Parse codepoint value
- var hex = keyIdentifier.substring(unicodePrefixLocation+2);
- var codepoint = parseInt(hex, 16);
-
- // If control character, not typable
- if (isControlCharacter(codepoint)) return false;
-
- // Otherwise, typable
- return true;
-
- }
-
- // When key pressed
- element.addEventListener("keydown", function(e) {
-
- // Only intercept if handler set
- if (!guac_keyboard.onkeydown) return;
-
- var keynum;
- if (window.event) keynum = window.event.keyCode;
- else if (e.which) keynum = e.which;
-
- // Ignore any unknown key events
- if (keynum == 0 && !e.keyIdentifier) {
- e.preventDefault();
- return;
- }
-
- expect_keypress = true;
-
- // Ctrl/Alt/Shift
- if (keynum == 16) guac_keyboard.modifiers.shift = true;
- else if (keynum == 17) guac_keyboard.modifiers.ctrl = true;
- else if (keynum == 18) guac_keyboard.modifiers.alt = true;
-
- // Try to get keysym from keycode
- keydown_keysym = getKeySymFromKeyCode(keynum);
-
- // If key is known from keycode, prevent default
- if (keydown_keysym)
- expect_keypress = false;
-
- // Also try to get get keysym from keyIdentifier
- if (e.keyIdentifier) {
-
- keydown_keysym = keydown_keysym ||
- getKeySymFromKeyIdentifier(guac_keyboard.modifiers.shift, e.keyIdentifier);
-
- // Prevent default if non-typable character or if modifier combination
- // likely to be eaten by browser otherwise (NOTE: We must not prevent
- // default for Ctrl+Alt, as that combination is commonly used for
- // AltGr. If we receive AltGr, we need to handle keypress, which
- // means we cannot cancel keydown).
- if (!isTypable(e.keyIdentifier)
- || ( guac_keyboard.modifiers.ctrl && !guac_keyboard.modifiers.alt)
- || (!guac_keyboard.modifiers.ctrl && guac_keyboard.modifiers.alt))
- expect_keypress = false;
-
- }
-
- // Set keycode which will be associated with any future keypress
- keydown_code = keynum;
-
- // If we expect to handle via keypress, set failsafe timeout and
- // wait for keypress.
- if (expect_keypress) {
- if (!deferred_keypress)
- deferred_keypress = window.setTimeout(handleKeyEvents, 0);
- }
-
- // Otherwise, handle now
- else {
- e.preventDefault();
- handleKeyEvents();
- }
-
- }, true);
-
- // When key pressed
- element.addEventListener("keypress", function(e) {
-
- // Only intercept if handler set
- if (!guac_keyboard.onkeydown) return;
-
- e.preventDefault();
-
- // Do not handle if we weren't expecting this event (will have already
- // been handled by keydown)
- if (!expect_keypress) return;
-
- var keynum;
- if (window.event) keynum = window.event.keyCode;
- else if (e.which) keynum = e.which;
-
- keypress_keysym = getKeySymFromCharCode(keynum);
-
- // If event identified as a typable character, and we're holding Ctrl+Alt,
- // assume Ctrl+Alt is actually AltGr, and release both.
- if (!isControlCharacter(keynum) && guac_keyboard.modifiers.ctrl && guac_keyboard.modifiers.alt) {
- sendKeyReleased(0xFFE3);
- sendKeyReleased(0xFFE9);
- }
-
- // Clear timeout, if any
- if (deferred_keypress)
- window.clearTimeout(deferred_keypress);
-
- // Handle event with all aggregated data
- handleKeyEvents();
-
- }, true);
-
- // When key released
- element.addEventListener("keyup", function(e) {
-
- // Only intercept if handler set
- if (!guac_keyboard.onkeyup) return;
-
- e.preventDefault();
-
- var keynum;
- if (window.event) keynum = window.event.keyCode;
- else if (e.which) keynum = e.which;
-
- // Ctrl/Alt/Shift
- if (keynum == 16) guac_keyboard.modifiers.shift = false;
- else if (keynum == 17) guac_keyboard.modifiers.ctrl = false;
- else if (keynum == 18) guac_keyboard.modifiers.alt = false;
- else
- stopRepeat();
-
- // Get corresponding character
- var lastKeyDownChar = keydownChar[keynum];
-
- // Clear character record
- keydownChar[keynum] = null;
-
- // Send release event
- sendKeyReleased(lastKeyDownChar);
-
- }, true);
-
- // When focus is lost, clear modifiers.
- element.addEventListener("blur", function() {
- guac_keyboard.modifiers.alt = false;
- guac_keyboard.modifiers.ctrl = false;
- guac_keyboard.modifiers.shift = false;
- }, true);
-
-};
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/guacamole-common-js/layer.js
^
|
@@ -1,1103 +0,0 @@
-
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is guacamole-common-js.
- *
- * The Initial Developer of the Original Code is
- * Michael Jumper.
- * Portions created by the Initial Developer are Copyright (C) 2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/**
- * Namespace for all Guacamole JavaScript objects.
- * @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) {
-
- /**
- * Reference to this Layer.
- * @private
- */
- var layer = this;
-
- /**
- * The canvas element backing this Layer.
- * @private
- */
- var display = document.createElement("canvas");
-
- /**
- * The 2D display context of the canvas element backing this Layer.
- * @private
- */
- var displayContext = display.getContext("2d");
- displayContext.save();
-
- /**
- * The queue of all pending Tasks. Tasks will be run in order, with new
- * tasks added at the end of the queue and old tasks removed from the
- * front of the queue (FIFO).
- * @private
- */
- var tasks = new Array();
-
- /**
- * Whether a new path should be started with the next path drawing
- * operations.
- * @private
- */
- var pathClosed = true;
-
- /**
- * The number of states on the state stack.
- *
- * Note that there will ALWAYS be one element on the stack, but that
- * element is not exposed. It is only used to reset the layer to its
- * initial state.
- *
- * @private
- */
- var stackSize = 0;
-
- /**
- * Map of all Guacamole channel masks to HTML5 canvas composite operation
- * names. Not all channel mask combinations are currently implemented.
- * @private
- */
- var compositeOperation = {
- /* 0x0 NOT IMPLEMENTED */
- 0x1: "destination-in",
- 0x2: "destination-out",
- /* 0x3 NOT IMPLEMENTED */
- 0x4: "source-in",
- /* 0x5 NOT IMPLEMENTED */
- 0x6: "source-atop",
- /* 0x7 NOT IMPLEMENTED */
- 0x8: "source-out",
- 0x9: "destination-atop",
- 0xA: "xor",
- 0xB: "destination-over",
- 0xC: "copy",
- /* 0xD NOT IMPLEMENTED */
- 0xE: "source-over",
- 0xF: "lighter"
- };
-
- /**
- * Resizes the canvas element backing this Layer without testing the
- * new size. This function should only be used internally.
- *
- * @private
- * @param {Number} newWidth The new width to assign to this Layer.
- * @param {Number} newHeight The new height to assign to this Layer.
- */
- function resize(newWidth, newHeight) {
-
- // Only preserve old data if width/height are both non-zero
- var oldData = null;
- if (width != 0 && height != 0) {
-
- // Create canvas and context for holding old data
- oldData = document.createElement("canvas");
- oldData.width = width;
- oldData.height = height;
-
- var oldDataContext = oldData.getContext("2d");
-
- // Copy image data from current
- oldDataContext.drawImage(display,
- 0, 0, width, height,
- 0, 0, width, height);
-
- }
-
- // Preserve composite operation
- var oldCompositeOperation = displayContext.globalCompositeOperation;
-
- // Resize canvas
- display.width = newWidth;
- display.height = newHeight;
-
- // Redraw old data, if any
- if (oldData)
- displayContext.drawImage(oldData,
- 0, 0, width, height,
- 0, 0, width, height);
-
- // Restore composite operation
- displayContext.globalCompositeOperation = oldCompositeOperation;
-
- width = newWidth;
- height = newHeight;
-
- // Acknowledge reset of stack (happens on resize of canvas)
- stackSize = 0;
- displayContext.save();
-
- }
-
- /**
- * Given the X and Y coordinates of the upper-left corner of a rectangle
- * and the rectangle's width and height, resize the backing canvas element
- * as necessary to ensure that the rectangle fits within the canvas
- * element's coordinate space. This function will only make the canvas
- * larger. If the rectangle already fits within the canvas element's
- * coordinate space, the canvas is left unchanged.
- *
- * @private
- * @param {Number} x The X coordinate of the upper-left corner of the
- * rectangle to fit.
- * @param {Number} y The Y coordinate of the upper-left corner of the
- * rectangle to fit.
- * @param {Number} w The width of the the rectangle to fit.
- * @param {Number} h The height of the the rectangle to fit.
- */
- function fitRect(x, y, w, h) {
-
- // Calculate bounds
- var opBoundX = w + x;
- var opBoundY = h + y;
-
- // Determine max width
- var resizeWidth;
- if (opBoundX > width)
- resizeWidth = opBoundX;
- else
- resizeWidth = width;
-
- // Determine max height
- var resizeHeight;
- if (opBoundY > height)
- resizeHeight = opBoundY;
- else
- resizeHeight = height;
-
- // Resize if necessary
- if (resizeWidth != width || resizeHeight != height)
- resize(resizeWidth, resizeHeight);
-
- }
-
- /**
- * A container for an task handler. Each operation which must be ordered
- * is associated with a Task that goes into a task queue. Tasks in this
- * queue are executed in order once their handlers are set, while Tasks
- * without handlers block themselves and any following Tasks from running.
- *
- * @constructor
- * @private
- * @param {function} taskHandler The function to call when this task
- * runs, if any.
- * @param {boolean} blocked Whether this task should start blocked.
- */
- function Task(taskHandler, blocked) {
-
- var task = this;
-
- /**
- * Whether this Task is blocked.
- *
- * @type boolean
- */
- this.blocked = blocked;
-
- /**
- * The handler this Task is associated with, if any.
- *
- * @type function
- */
- this.handler = taskHandler;
-
- /**
- * Unblocks this Task, allowing it to run.
- */
- this.unblock = function() {
- task.blocked = false;
- handlePendingTasks();
- }
-
- }
-
- /**
- * If no tasks are pending or running, run the provided handler immediately,
- * if any. Otherwise, schedule a task to run immediately after all currently
- * running or pending tasks are complete.
- *
- * @private
- * @param {function} handler The function to call when possible, if any.
- * @param {boolean} blocked Whether the task should start blocked.
- * @returns {Task} The Task created and added to the queue for future
- * running, if any, or null if the handler was run
- * immediately and no Task needed to be created.
- */
- function scheduleTask(handler, blocked) {
-
- // If no pending tasks, just call (if available) and exit
- if (layer.isReady() && !blocked) {
- if (handler) handler();
- return null;
- }
-
- // If tasks are pending/executing, schedule a pending task
- // and return a reference to it.
- var task = new Task(handler, blocked);
- tasks.push(task);
- return task;
-
- }
-
- var tasksInProgress = false;
-
- /**
- * Run any Tasks which were pending but are now ready to run and are not
- * blocked by other Tasks.
- * @private
- */
- function handlePendingTasks() {
-
- if (tasksInProgress)
- return;
-
- tasksInProgress = true;
-
- // Draw all pending tasks.
- var task;
- while ((task = tasks[0]) != null && !task.blocked) {
- tasks.shift();
- if (task.handler) task.handler();
- }
-
- tasksInProgress = false;
-
- }
-
- /**
- * Schedules a task within the current layer just as scheduleTast() does,
- * except that another specified layer will be blocked until this task
- * completes, and this task will not start until the other layer is
- * ready.
- *
- * Essentially, a task is scheduled in both layers, and the specified task
- * will only be performed once both layers are ready, and neither layer may
- * proceed until this task completes.
- *
- * Note that there is no way to specify whether the task starts blocked,
- * as whether the task is blocked depends completely on whether the
- * other layer is currently ready.
- *
- * @private
- * @param {Guacamole.Layer} otherLayer The other layer which must be blocked
- * until this task completes.
- * @param {function} handler The function to call when possible.
- */
- function scheduleTaskSynced(otherLayer, handler) {
-
- // If we ARE the other layer, no need to sync.
- // Syncing would result in deadlock.
- if (layer === otherLayer)
- scheduleTask(handler);
-
- // Otherwise synchronize operation with other layer
- else {
-
- var drawComplete = false;
- var layerLock = null;
-
- function performTask() {
-
- // Perform task
- handler();
-
- // Unblock the other layer now that draw is complete
- if (layerLock != null)
- layerLock.unblock();
-
- // Flag operation as done
- drawComplete = true;
-
- }
-
- // Currently blocked draw task
- var task = scheduleTask(performTask, true);
-
- // Unblock draw task once source layer is ready
- otherLayer.sync(task.unblock);
-
- // Block other layer until draw completes
- // Note that the draw MAY have already been performed at this point,
- // in which case creating a lock on the other layer will lead to
- // deadlock (the draw task has already run and will thus never
- // clear the lock)
- if (!drawComplete)
- layerLock = otherLayer.sync(null, true);
-
- }
- }
-
- /**
- * Set to true if this Layer should resize itself to accomodate the
- * dimensions of any drawing operation, and false (the default) otherwise.
- *
- * Note that setting this property takes effect immediately, and thus may
- * take effect on operations that were started in the past but have not
- * yet completed. If you wish the setting of this flag to only modify
- * future operations, you will need to make the setting of this flag an
- * operation with sync().
- *
- * @example
- * // Set autosize to true for all future operations
- * layer.sync(function() {
- * layer.autosize = true;
- * });
- *
- * @type Boolean
- * @default false
- */
- this.autosize = false;
-
- /**
- * Returns the canvas element backing this Layer.
- * @returns {Element} The canvas element backing this Layer.
- */
- this.getCanvas = function() {
- return display;
- };
-
- /**
- * Returns whether this Layer is ready. A Layer is ready if it has no
- * pending operations and no operations in-progress.
- *
- * @returns {Boolean} true if this Layer is ready, false otherwise.
- */
- this.isReady = function() {
- return tasks.length == 0;
- };
-
- /**
- * 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) {
- scheduleTask(function() {
- if (newWidth != width || newHeight != height)
- resize(newWidth, newHeight);
- });
- };
-
- /**
- * Draws the specified image at the given coordinates. The image specified
- * must already be loaded.
- *
- * @param {Number} x The destination X coordinate.
- * @param {Number} y The destination Y coordinate.
- * @param {Image} image The image to draw. Note that this is an Image
- * object - not a URL.
- */
- this.drawImage = function(x, y, image) {
- scheduleTask(function() {
- if (layer.autosize != 0) fitRect(x, y, image.width, image.height);
- displayContext.drawImage(image, x, y);
- });
- };
-
- /**
- * Draws the image at the specified URL at the given coordinates. The image
- * will be loaded automatically, and this and any future operations will
- * wait for the image to finish loading.
- *
- * @param {Number} x The destination X coordinate.
- * @param {Number} y The destination Y coordinate.
- * @param {String} url The URL of the image to draw.
- */
- this.draw = function(x, y, url) {
-
- var task = scheduleTask(function() {
- if (layer.autosize != 0) fitRect(x, y, image.width, image.height);
- displayContext.drawImage(image, x, y);
- }, true);
-
- var image = new Image();
- image.onload = task.unblock;
- image.src = url;
-
- };
-
- /**
- * 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.
- * @param {boolean} blocked Whether the task should start blocked.
- */
- this.sync = scheduleTask;
-
- /**
- * Transfer a rectangle of image data from one Layer to this Layer using the
- * specified transfer function.
- *
- * @param {Guacamole.Layer} srcLayer The Layer to copy image data from.
- * @param {Number} srcx The X coordinate of the upper-left corner of the
- * rectangle within the source Layer's coordinate
- * space to copy data from.
- * @param {Number} srcy The Y coordinate of the upper-left corner of the
- * rectangle within the source Layer's coordinate
- * space to copy data from.
- * @param {Number} srcw The width of the rectangle within the source Layer's
- * coordinate space to copy data from.
- * @param {Number} srch The height of the rectangle within the source
- * Layer's coordinate space to copy data from.
- * @param {Number} x The destination X coordinate.
- * @param {Number} y The destination Y coordinate.
- * @param {Function} transferFunction The transfer function to use to
- * transfer data from source to
- * destination.
- */
- this.transfer = function(srcLayer, srcx, srcy, srcw, srch, x, y, transferFunction) {
- scheduleTaskSynced(srcLayer, function() {
-
- if (layer.autosize != 0) fitRect(x, y, srcw, srch);
-
- var srcCanvas = srcLayer.getCanvas();
- if (srcCanvas.width != 0 && srcCanvas.height != 0) {
-
- // Get image data from src and dst
- var src = srcLayer.getCanvas().getContext("2d").getImageData(srcx, srcy, srcw, srch);
- var dst = displayContext.getImageData(x , y, srcw, srch);
-
- // Apply transfer for each pixel
- for (var i=0; i<srcw*srch*4; i+=4) {
-
- // Get source pixel environment
- var src_pixel = new Guacamole.Layer.Pixel(
- src.data[i],
- src.data[i+1],
- src.data[i+2],
- src.data[i+3]
- );
-
- // Get destination pixel environment
- var dst_pixel = new Guacamole.Layer.Pixel(
- dst.data[i],
- dst.data[i+1],
- dst.data[i+2],
- dst.data[i+3]
- );
-
- // Apply transfer function
- transferFunction(src_pixel, dst_pixel);
-
- // Save pixel data
- dst.data[i ] = dst_pixel.red;
- dst.data[i+1] = dst_pixel.green;
- dst.data[i+2] = dst_pixel.blue;
- dst.data[i+3] = dst_pixel.alpha;
-
- }
-
- // Draw image data
- displayContext.putImageData(dst, x, y);
-
- }
-
- });
- };
-
- /**
- * Copy a rectangle of image data from one Layer to this Layer. This
- * operation will copy exactly the image data that will be drawn once all
- * operations of the source Layer that were pending at the time this
- * function was called are complete. This operation will not alter the
- * size of the source Layer even if its autosize property is set to true.
- *
- * @param {Guacamole.Layer} srcLayer The Layer to copy image data from.
- * @param {Number} srcx The X coordinate of the upper-left corner of the
- * rectangle within the source Layer's coordinate
- * space to copy data from.
- * @param {Number} srcy The Y coordinate of the upper-left corner of the
- * rectangle within the source Layer's coordinate
- * space to copy data from.
- * @param {Number} srcw The width of the rectangle within the source Layer's
- * coordinate space to copy data from.
- * @param {Number} srch The height of the rectangle within the source
- * Layer's coordinate space to copy data from.
- * @param {Number} x The destination X coordinate.
- * @param {Number} y The destination Y coordinate.
- */
- this.copy = function(srcLayer, srcx, srcy, srcw, srch, x, y) {
- scheduleTaskSynced(srcLayer, function() {
- if (layer.autosize != 0) fitRect(x, y, srcw, srch);
-
- var srcCanvas = srcLayer.getCanvas();
- if (srcCanvas.width != 0 && srcCanvas.height != 0)
- displayContext.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch);
-
- });
- };
-
- /**
- * Starts a new path at the specified point.
- *
- * @param {Number} x The X coordinate of the point to draw.
- * @param {Number} y The Y coordinate of the point to draw.
- */
- this.moveTo = function(x, y) {
- scheduleTask(function() {
-
- // Start a new path if current path is closed
- if (pathClosed) {
- displayContext.beginPath();
- pathClosed = false;
- }
-
- if (layer.autosize != 0) fitRect(x, y, 0, 0);
- displayContext.moveTo(x, y);
-
- });
- };
-
- /**
- * Add the specified line to the current path.
- *
- * @param {Number} x The X coordinate of the endpoint of the line to draw.
- * @param {Number} y The Y coordinate of the endpoint of the line to draw.
- */
- this.lineTo = function(x, y) {
- scheduleTask(function() {
-
- // Start a new path if current path is closed
- if (pathClosed) {
- displayContext.beginPath();
- pathClosed = false;
- }
-
- if (layer.autosize != 0) fitRect(x, y, 0, 0);
- displayContext.lineTo(x, y);
-
- });
- };
-
- /**
- * Add the specified arc to the current path.
- *
- * @param {Number} x The X coordinate of the center of the circle which
- * will contain the arc.
- * @param {Number} y The Y coordinate of the center of the circle which
- * will contain the arc.
- * @param {Number} radius The radius of the circle.
- * @param {Number} startAngle The starting angle of the arc, in radians.
- * @param {Number} endAngle The ending angle of the arc, in radians.
- * @param {Boolean} negative Whether the arc should be drawn in order of
- * decreasing angle.
- */
- this.arc = function(x, y, radius, startAngle, endAngle, negative) {
- scheduleTask(function() {
-
- // Start a new path if current path is closed
- if (pathClosed) {
- displayContext.beginPath();
- pathClosed = false;
- }
-
- if (layer.autosize != 0) fitRect(x, y, 0, 0);
- displayContext.arc(x, y, radius, startAngle, endAngle, negative);
-
- });
- };
-
- /**
- * Starts a new path at the specified point.
- *
- * @param {Number} cp1x The X coordinate of the first control point.
- * @param {Number} cp1y The Y coordinate of the first control point.
- * @param {Number} cp2x The X coordinate of the second control point.
- * @param {Number} cp2y The Y coordinate of the second control point.
- * @param {Number} x The X coordinate of the endpoint of the curve.
- * @param {Number} y The Y coordinate of the endpoint of the curve.
- */
- this.curveTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {
- scheduleTask(function() {
-
- // Start a new path if current path is closed
- if (pathClosed) {
- displayContext.beginPath();
- pathClosed = false;
- }
-
- if (layer.autosize != 0) fitRect(x, y, 0, 0);
- displayContext.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
-
- });
- };
-
- /**
- * Closes the current path by connecting the end point with the start
- * point (if any) with a straight line.
- */
- this.close = function() {
- scheduleTask(function() {
-
- // Close path
- displayContext.closePath();
- pathClosed = true;
-
- });
- };
-
- /**
- * Add the specified rectangle to the current path.
- *
- * @param {Number} x The X coordinate of the upper-left corner of the
- * rectangle to draw.
- * @param {Number} y The Y coordinate of the upper-left corner of the
- * rectangle to draw.
- * @param {Number} w The width of the rectangle to draw.
- * @param {Number} h The height of the rectangle to draw.
- */
- this.rect = function(x, y, w, h) {
- scheduleTask(function() {
-
- // Start a new path if current path is closed
- if (pathClosed) {
- displayContext.beginPath();
- pathClosed = false;
- }
-
- if (layer.autosize != 0) fitRect(x, y, w, h);
- displayContext.rect(x, y, w, h);
-
- });
- };
-
- /**
- * Clip all future drawing operations by the current path. The current path
- * is implicitly closed. The current path can continue to be reused
- * for other operations (such as fillColor()) but a new path will be started
- * once a path drawing operation (path() or rect()) is used.
- */
- this.clip = function() {
- scheduleTask(function() {
-
- // Set new clipping region
- displayContext.clip();
-
- // Path now implicitly closed
- pathClosed = true;
-
- });
- };
-
- /**
- * Stroke the current path with the specified color. The current path
- * is implicitly closed. The current path can continue to be reused
- * for other operations (such as clip()) but a new path will be started
- * once a path drawing operation (path() or rect()) is used.
- *
- * @param {String} cap The line cap style. Can be "round", "square",
- * or "butt".
- * @param {String} join The line join style. Can be "round", "bevel",
- * or "miter".
- * @param {Number} thickness The line thickness in pixels.
- * @param {Number} r The red component of the color to fill.
- * @param {Number} g The green component of the color to fill.
- * @param {Number} b The blue component of the color to fill.
- * @param {Number} a The alpha component of the color to fill.
- */
- this.strokeColor = function(cap, join, thickness, r, g, b, a) {
- scheduleTask(function() {
-
- // Stroke with color
- displayContext.lineCap = cap;
- displayContext.lineJoin = join;
- displayContext.lineWidth = thickness;
- displayContext.strokeStyle = "rgba(" + r + "," + g + "," + b + "," + a/255.0 + ")";
- displayContext.stroke();
-
- // Path now implicitly closed
- pathClosed = true;
-
- });
- };
-
- /**
- * Fills the current path with the specified color. The current path
- * is implicitly closed. The current path can continue to be reused
- * for other operations (such as clip()) but a new path will be started
- * once a path drawing operation (path() or rect()) is used.
- *
- * @param {Number} r The red component of the color to fill.
- * @param {Number} g The green component of the color to fill.
- * @param {Number} b The blue component of the color to fill.
- * @param {Number} a The alpha component of the color to fill.
- */
- this.fillColor = function(r, g, b, a) {
- scheduleTask(function() {
-
- // Fill with color
- displayContext.fillStyle = "rgba(" + r + "," + g + "," + b + "," + a/255.0 + ")";
- displayContext.fill();
-
- // Path now implicitly closed
- pathClosed = true;
-
- });
- };
-
- /**
- * Stroke the current path with the image within the specified layer. The
- * image data will be tiled infinitely within the stroke. The current path
- * is implicitly closed. The current path can continue to be reused
- * for other operations (such as clip()) but a new path will be started
- * once a path drawing operation (path() or rect()) is used.
- *
- * @param {String} cap The line cap style. Can be "round", "square",
- * or "butt".
- * @param {String} join The line join style. Can be "round", "bevel",
- * or "miter".
- * @param {Number} thickness The line thickness in pixels.
- * @param {Guacamole.Layer} srcLayer The layer to use as a repeating pattern
- * within the stroke.
- */
- this.strokeLayer = function(cap, join, thickness, srcLayer) {
- scheduleTaskSynced(srcLayer, function() {
-
- // Stroke with image data
- displayContext.lineCap = cap;
- displayContext.lineJoin = join;
- displayContext.lineWidth = thickness;
- displayContext.strokeStyle = displayContext.createPattern(
- srcLayer.getCanvas(),
- "repeat"
- );
- displayContext.stroke();
-
- // Path now implicitly closed
- pathClosed = true;
-
- });
- };
-
- /**
- * Fills the current path with the image within the specified layer. The
- * image data will be tiled infinitely within the stroke. The current path
- * is implicitly closed. The current path can continue to be reused
- * for other operations (such as clip()) but a new path will be started
- * once a path drawing operation (path() or rect()) is used.
- *
- * @param {Guacamole.Layer} srcLayer The layer to use as a repeating pattern
- * within the fill.
- */
- this.fillLayer = function(srcLayer) {
- scheduleTask(function() {
-
- // Fill with image data
- displayContext.fillStyle = displayContext.createPattern(
- srcLayer.getCanvas(),
- "repeat"
- );
- displayContext.fill();
-
- // Path now implicitly closed
- pathClosed = true;
-
- });
- };
-
- /**
- * Push current layer state onto stack.
- */
- this.push = function() {
- scheduleTask(function() {
-
- // Save current state onto stack
- displayContext.save();
- stackSize++;
-
- });
- };
-
- /**
- * Pop layer state off stack.
- */
- this.pop = function() {
- scheduleTask(function() {
-
- // Restore current state from stack
- if (stackSize > 0) {
- displayContext.restore();
- stackSize--;
- }
-
- });
- };
-
- /**
- * Reset the layer, clearing the stack, the current path, and any transform
- * matrix.
- */
- this.reset = function() {
- scheduleTask(function() {
-
- // Clear stack
- while (stackSize > 0) {
- displayContext.restore();
- stackSize--;
- }
-
- // Restore to initial state
- displayContext.restore();
- displayContext.save();
-
- // Clear path
- displayContext.beginPath();
- pathClosed = false;
-
- });
- };
-
- /**
- * Sets the given affine transform (defined with six values from the
- * transform's matrix).
- *
- * @param {Number} a The first value in the affine transform's matrix.
- * @param {Number} b The second value in the affine transform's matrix.
- * @param {Number} c The third value in the affine transform's matrix.
- * @param {Number} d The fourth value in the affine transform's matrix.
- * @param {Number} e The fifth value in the affine transform's matrix.
- * @param {Number} f The sixth value in the affine transform's matrix.
- */
- this.setTransform = function(a, b, c, d, e, f) {
- scheduleTask(function() {
-
- // Set transform
- displayContext.setTransform(
- a, b, c,
- d, e, f
- /*0, 0, 1*/
- );
-
- });
- };
-
-
- /**
- * Applies the given affine transform (defined with six values from the
- * transform's matrix).
- *
- * @param {Number} a The first value in the affine transform's matrix.
- * @param {Number} b The second value in the affine transform's matrix.
- * @param {Number} c The third value in the affine transform's matrix.
- * @param {Number} d The fourth value in the affine transform's matrix.
- * @param {Number} e The fifth value in the affine transform's matrix.
- * @param {Number} f The sixth value in the affine transform's matrix.
- */
- this.transform = function(a, b, c, d, e, f) {
- scheduleTask(function() {
-
- // Apply transform
- displayContext.transform(
- a, b, c,
- d, e, f
- /*0, 0, 1*/
- );
-
- });
- };
-
-
- /**
- * Sets the channel mask for future operations on this Layer.
- *
- * The channel mask is a Guacamole-specific compositing operation identifier
- * with a single bit representing each of four channels (in order): source
- * image where destination transparent, source where destination opaque,
- * destination where source transparent, and destination where source
- * opaque.
- *
- * @param {Number} mask The channel mask for future operations on this
- * Layer.
- */
- this.setChannelMask = function(mask) {
- scheduleTask(function() {
- displayContext.globalCompositeOperation = compositeOperation[mask];
- });
- };
-
- /**
- * Sets the miter limit for stroke operations using the miter join. This
- * limit is the maximum ratio of the size of the miter join to the stroke
- * width. If this ratio is exceeded, the miter will not be drawn for that
- * joint of the path.
- *
- * @param {Number} limit The miter limit for stroke operations using the
- * miter join.
- */
- this.setMiterLimit = function(limit) {
- scheduleTask(function() {
- displayContext.miterLimit = limit;
- });
- };
-
- // Initialize canvas dimensions
- display.width = width;
- display.height = height;
-
-};
-
-/**
- * Channel mask for the composite operation "rout".
- */
-Guacamole.Layer.ROUT = 0x2;
-
-/**
- * Channel mask for the composite operation "atop".
- */
-Guacamole.Layer.ATOP = 0x6;
-
-/**
- * Channel mask for the composite operation "xor".
- */
-Guacamole.Layer.XOR = 0xA;
-
-/**
- * Channel mask for the composite operation "rover".
- */
-Guacamole.Layer.ROVER = 0xB;
-
-/**
- * Channel mask for the composite operation "over".
- */
-Guacamole.Layer.OVER = 0xE;
-
-/**
- * Channel mask for the composite operation "plus".
- */
-Guacamole.Layer.PLUS = 0xF;
-
-/**
- * Channel mask for the composite operation "rin".
- * Beware that WebKit-based browsers may leave the contents of the destionation
- * layer where the source layer is transparent, despite the definition of this
- * operation.
- */
-Guacamole.Layer.RIN = 0x1;
-
-/**
- * Channel mask for the composite operation "in".
- * Beware that WebKit-based browsers may leave the contents of the destionation
- * layer where the source layer is transparent, despite the definition of this
- * operation.
- */
-Guacamole.Layer.IN = 0x4;
-
-/**
- * Channel mask for the composite operation "out".
- * Beware that WebKit-based browsers may leave the contents of the destionation
- * layer where the source layer is transparent, despite the definition of this
- * operation.
- */
-Guacamole.Layer.OUT = 0x8;
-
-/**
- * Channel mask for the composite operation "ratop".
- * Beware that WebKit-based browsers may leave the contents of the destionation
- * layer where the source layer is transparent, despite the definition of this
- * operation.
- */
-Guacamole.Layer.RATOP = 0x9;
-
-/**
- * Channel mask for the composite operation "src".
- * Beware that WebKit-based browsers may leave the contents of the destionation
- * layer where the source layer is transparent, despite the definition of this
- * operation.
- */
-Guacamole.Layer.SRC = 0xC;
-
-
-/**
- * Represents a single pixel of image data. All components have a minimum value
- * of 0 and a maximum value of 255.
- *
- * @constructor
- *
- * @param {Number} r The red component of this pixel.
- * @param {Number} g The green component of this pixel.
- * @param {Number} b The blue component of this pixel.
- * @param {Number} a The alpha component of this pixel.
- */
-Guacamole.Layer.Pixel = function(r, g, b, a) {
-
- /**
- * The red component of this pixel, where 0 is the minimum value,
- * and 255 is the maximum.
- */
- this.red = r;
-
- /**
- * The green component of this pixel, where 0 is the minimum value,
- * and 255 is the maximum.
- */
- this.green = g;
-
- /**
- * The blue component of this pixel, where 0 is the minimum value,
- * and 255 is the maximum.
- */
- this.blue = b;
-
- /**
- * The alpha component of this pixel, where 0 is the minimum value,
- * and 255 is the maximum.
- */
- this.alpha = a;
-
-};
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/guacamole-common-js/mouse.js
^
|
@@ -1,785 +0,0 @@
-
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is guacamole-common-js.
- *
- * The Initial Developer of the Original Code is
- * Michael Jumper.
- * Portions created by the Initial Developer are Copyright (C) 2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/**
- * Namespace for all Guacamole JavaScript objects.
- * @namespace
- */
-var Guacamole = Guacamole || {};
-
-/**
- * Provides cross-browser mouse events for a given element. The events of
- * the given element are automatically populated with handlers that translate
- * mouse events into a non-browser-specific event provided by the
- * Guacamole.Mouse instance.
- *
- * @constructor
- * @param {Element} element The Element to use to provide mouse events.
- */
-Guacamole.Mouse = function(element) {
-
- /**
- * Reference to this Guacamole.Mouse.
- * @private
- */
- var guac_mouse = this;
-
- /**
- * The number of mousemove events to require before re-enabling mouse
- * event handling after receiving a touch event.
- */
- this.touchMouseThreshold = 3;
-
- /**
- * The current mouse state. The properties of this state are updated when
- * mouse events fire. This state object is also passed in as a parameter to
- * the handler of any mouse events.
- *
- * @type Guacamole.Mouse.State
- */
- this.currentState = new Guacamole.Mouse.State(
- 0, 0,
- false, false, false, false, false
- );
-
- /**
- * Fired whenever the user presses a mouse button down over the element
- * associated with this Guacamole.Mouse.
- *
- * @event
- * @param {Guacamole.Mouse.State} state The current mouse state.
- */
- this.onmousedown = null;
-
- /**
- * Fired whenever the user releases a mouse button down over the element
- * associated with this Guacamole.Mouse.
- *
- * @event
- * @param {Guacamole.Mouse.State} state The current mouse state.
- */
- this.onmouseup = null;
-
- /**
- * Fired whenever the user moves the mouse over the element associated with
- * this Guacamole.Mouse.
- *
- * @event
- * @param {Guacamole.Mouse.State} state The current mouse state.
- */
- this.onmousemove = null;
-
- /**
- * Counter of mouse events to ignore. This decremented by mousemove, and
- * while non-zero, mouse events will have no effect.
- * @private
- */
- var ignore_mouse = 0;
-
- function cancelEvent(e) {
- e.stopPropagation();
- if (e.preventDefault) e.preventDefault();
- e.returnValue = false;
- }
-
- // Block context menu so right-click gets sent properly
- element.addEventListener("contextmenu", function(e) {
- cancelEvent(e);
- }, false);
-
- element.addEventListener("mousemove", function(e) {
-
- cancelEvent(e);
-
- // If ignoring events, decrement counter
- if (ignore_mouse) {
- ignore_mouse--;
- return;
- }
-
- guac_mouse.currentState.fromClientPosition(element, e.clientX, e.clientY);
-
- if (guac_mouse.onmousemove)
- guac_mouse.onmousemove(guac_mouse.currentState);
-
- }, false);
-
- element.addEventListener("mousedown", function(e) {
-
- cancelEvent(e);
-
- // Do not handle if ignoring events
- if (ignore_mouse)
- return;
-
- switch (e.button) {
- case 0:
- guac_mouse.currentState.left = true;
- break;
- case 1:
- guac_mouse.currentState.middle = true;
- break;
- case 2:
- guac_mouse.currentState.right = true;
- break;
- }
-
- if (guac_mouse.onmousedown)
- guac_mouse.onmousedown(guac_mouse.currentState);
-
- }, false);
-
- element.addEventListener("mouseup", function(e) {
-
- cancelEvent(e);
-
- // Do not handle if ignoring events
- if (ignore_mouse)
- return;
-
- switch (e.button) {
- case 0:
- guac_mouse.currentState.left = false;
- break;
- case 1:
- guac_mouse.currentState.middle = false;
- break;
- case 2:
- guac_mouse.currentState.right = false;
- break;
- }
-
- if (guac_mouse.onmouseup)
- guac_mouse.onmouseup(guac_mouse.currentState);
-
- }, false);
-
- element.addEventListener("mouseout", function(e) {
-
- // Get parent of the element the mouse pointer is leaving
- if (!e) e = window.event;
-
- // Check that mouseout is due to actually LEAVING the element
- var target = e.relatedTarget || e.toElement;
- while (target != null) {
- if (target === element)
- return;
- target = target.parentNode;
- }
-
- cancelEvent(e);
-
- // Release all buttons
- if (guac_mouse.currentState.left
- || guac_mouse.currentState.middle
- || guac_mouse.currentState.right) {
-
- guac_mouse.currentState.left = false;
- guac_mouse.currentState.middle = false;
- guac_mouse.currentState.right = false;
-
- if (guac_mouse.onmouseup)
- guac_mouse.onmouseup(guac_mouse.currentState);
- }
-
- }, false);
-
- // Override selection on mouse event element.
- element.addEventListener("selectstart", function(e) {
- cancelEvent(e);
- }, false);
-
- // Ignore all pending mouse events when touch events are the apparent source
- function ignorePendingMouseEvents() { ignore_mouse = guac_mouse.touchMouseThreshold; }
-
- element.addEventListener("touchmove", ignorePendingMouseEvents, false);
- element.addEventListener("touchstart", ignorePendingMouseEvents, false);
- element.addEventListener("touchend", ignorePendingMouseEvents, false);
-
- // Scroll wheel support
- function mousewheel_handler(e) {
-
- var delta = 0;
- if (e.detail)
- delta = e.detail;
- else if (e.wheelDelta)
- delta = -event.wheelDelta;
-
- // Up
- if (delta < 0) {
- if (guac_mouse.onmousedown) {
- guac_mouse.currentState.up = true;
- guac_mouse.onmousedown(guac_mouse.currentState);
- }
-
- if (guac_mouse.onmouseup) {
- guac_mouse.currentState.up = false;
- guac_mouse.onmouseup(guac_mouse.currentState);
- }
- }
-
- // Down
- if (delta > 0) {
- if (guac_mouse.onmousedown) {
- guac_mouse.currentState.down = true;
- guac_mouse.onmousedown(guac_mouse.currentState);
- }
-
- if (guac_mouse.onmouseup) {
- guac_mouse.currentState.down = false;
- guac_mouse.onmouseup(guac_mouse.currentState);
- }
- }
-
- cancelEvent(e);
-
- }
- element.addEventListener('DOMMouseScroll', mousewheel_handler, false);
- element.addEventListener('mousewheel', mousewheel_handler, false);
-
-};
-
-
-/**
- * Provides cross-browser relative touch event translation for a given element.
- *
- * Touch events are translated into mouse events as if the touches occurred
- * on a touchpad (drag to push the mouse pointer, tap to click).
- *
- * @constructor
- * @param {Element} element The Element to use to provide touch events.
- */
-Guacamole.Mouse.Touchpad = function(element) {
-
- /**
- * Reference to this Guacamole.Mouse.Touchpad.
- * @private
- */
- var guac_touchpad = this;
-
- /**
- * The distance a two-finger touch must move per scrollwheel event, in
- * pixels.
- */
- this.scrollThreshold = 20 * (window.devicePixelRatio || 1);
-
- /**
- * The maximum number of milliseconds to wait for a touch to end for the
- * gesture to be considered a click.
- */
- this.clickTimingThreshold = 250;
-
- /**
- * The maximum number of pixels to allow a touch to move for the gesture to
- * be considered a click.
- */
- this.clickMoveThreshold = 10 * (window.devicePixelRatio || 1);
-
- /**
- * The current mouse state. The properties of this state are updated when
- * mouse events fire. This state object is also passed in as a parameter to
- * the handler of any mouse events.
- *
- * @type Guacamole.Mouse.State
- */
- this.currentState = new Guacamole.Mouse.State(
- 0, 0,
- false, false, false, false, false
- );
-
- /**
- * Fired whenever a mouse button is effectively pressed. This can happen
- * as part of a "click" gesture initiated by the user by tapping one
- * or more fingers over the touchpad element, as part of a "scroll"
- * gesture initiated by dragging two fingers up or down, etc.
- *
- * @event
- * @param {Guacamole.Mouse.State} state The current mouse state.
- */
- this.onmousedown = null;
-
- /**
- * Fired whenever a mouse button is effectively released. This can happen
- * as part of a "click" gesture initiated by the user by tapping one
- * or more fingers over the touchpad element, as part of a "scroll"
- * gesture initiated by dragging two fingers up or down, etc.
- *
- * @event
- * @param {Guacamole.Mouse.State} state The current mouse state.
- */
- this.onmouseup = null;
-
- /**
- * Fired whenever the user moves the mouse by dragging their finger over
- * the touchpad element.
- *
- * @event
- * @param {Guacamole.Mouse.State} state The current mouse state.
- */
- this.onmousemove = null;
-
- var touch_count = 0;
- var last_touch_x = 0;
- var last_touch_y = 0;
- var last_touch_time = 0;
- var pixels_moved = 0;
-
- var touch_buttons = {
- 1: "left",
- 2: "right",
- 3: "middle"
- };
-
- var gesture_in_progress = false;
- var click_release_timeout = null;
-
- element.addEventListener("touchend", function(e) {
-
- e.stopPropagation();
- e.preventDefault();
-
- // If we're handling a gesture AND this is the last touch
- if (gesture_in_progress && e.touches.length == 0) {
-
- var time = new Date().getTime();
-
- // Get corresponding mouse button
- var button = touch_buttons[touch_count];
-
- // If mouse already down, release anad clear timeout
- if (guac_touchpad.currentState[button]) {
-
- // Fire button up event
- guac_touchpad.currentState[button] = false;
- if (guac_touchpad.onmouseup)
- guac_touchpad.onmouseup(guac_touchpad.currentState);
-
- // Clear timeout, if set
- if (click_release_timeout) {
- window.clearTimeout(click_release_timeout);
- click_release_timeout = null;
- }
-
- }
-
- // If single tap detected (based on time and distance)
- if (time - last_touch_time <= guac_touchpad.clickTimingThreshold
- && pixels_moved < guac_touchpad.clickMoveThreshold) {
-
- // Fire button down event
- guac_touchpad.currentState[button] = true;
- if (guac_touchpad.onmousedown)
- guac_touchpad.onmousedown(guac_touchpad.currentState);
-
- // Delay mouse up - mouse up should be canceled if
- // touchstart within timeout.
- click_release_timeout = window.setTimeout(function() {
-
- // Fire button up event
- guac_touchpad.currentState[button] = false;
- if (guac_touchpad.onmouseup)
- guac_touchpad.onmouseup(guac_touchpad.currentState);
-
- // Gesture now over
- gesture_in_progress = false;
-
- }, guac_touchpad.clickTimingThreshold);
-
- }
-
- // If we're not waiting to see if this is a click, stop gesture
- if (!click_release_timeout)
- gesture_in_progress = false;
-
- }
-
- }, false);
-
- element.addEventListener("touchstart", function(e) {
-
- e.stopPropagation();
- e.preventDefault();
-
- // Track number of touches, but no more than three
- touch_count = Math.min(e.touches.length, 3);
-
- // Clear timeout, if set
- if (click_release_timeout) {
- window.clearTimeout(click_release_timeout);
- click_release_timeout = null;
- }
-
- // Record initial touch location and time for touch movement
- // and tap gestures
- if (!gesture_in_progress) {
-
- // Stop mouse events while touching
- gesture_in_progress = true;
-
- // Record touch location and time
- var starting_touch = e.touches[0];
- last_touch_x = starting_touch.clientX;
- last_touch_y = starting_touch.clientY;
- last_touch_time = new Date().getTime();
- pixels_moved = 0;
-
- }
-
- }, false);
-
- element.addEventListener("touchmove", function(e) {
-
- e.stopPropagation();
- e.preventDefault();
-
- // Get change in touch location
- var touch = e.touches[0];
- var delta_x = touch.clientX - last_touch_x;
- var delta_y = touch.clientY - last_touch_y;
-
- // Track pixels moved
- pixels_moved += Math.abs(delta_x) + Math.abs(delta_y);
-
- // If only one touch involved, this is mouse move
- if (touch_count == 1) {
-
- // Calculate average velocity in Manhatten pixels per millisecond
- var velocity = pixels_moved / (new Date().getTime() - last_touch_time);
-
- // Scale mouse movement relative to velocity
- var scale = 1 + velocity;
-
- // Update mouse location
- guac_touchpad.currentState.x += delta_x*scale;
- guac_touchpad.currentState.y += delta_y*scale;
-
- // Prevent mouse from leaving screen
-
- if (guac_touchpad.currentState.x < 0)
- guac_touchpad.currentState.x = 0;
- else if (guac_touchpad.currentState.x >= element.offsetWidth)
- guac_touchpad.currentState.x = element.offsetWidth - 1;
-
- if (guac_touchpad.currentState.y < 0)
- guac_touchpad.currentState.y = 0;
- else if (guac_touchpad.currentState.y >= element.offsetHeight)
- guac_touchpad.currentState.y = element.offsetHeight - 1;
-
- // Fire movement event, if defined
- if (guac_touchpad.onmousemove)
- guac_touchpad.onmousemove(guac_touchpad.currentState);
-
- // Update touch location
- last_touch_x = touch.clientX;
- last_touch_y = touch.clientY;
-
- }
-
- // Interpret two-finger swipe as scrollwheel
- else if (touch_count == 2) {
-
- // If change in location passes threshold for scroll
- if (Math.abs(delta_y) >= guac_touchpad.scrollThreshold) {
-
- // Decide button based on Y movement direction
- var button;
- if (delta_y > 0) button = "down";
- else button = "up";
-
- // Fire button down event
- guac_touchpad.currentState[button] = true;
- if (guac_touchpad.onmousedown)
- guac_touchpad.onmousedown(guac_touchpad.currentState);
-
- // Fire button up event
- guac_touchpad.currentState[button] = false;
- if (guac_touchpad.onmouseup)
- guac_touchpad.onmouseup(guac_touchpad.currentState);
-
- // Only update touch location after a scroll has been
- // detected
- last_touch_x = touch.clientX;
- last_touch_y = touch.clientY;
-
- }
-
- }
-
- }, false);
-
-};
-
-/**
- * Provides cross-browser absolute touch event translation for a given element.
- *
- * Touch events are translated into mouse events as if the touches occurred
- * on a touchscreen (tapping anywhere on the screen clicks at that point,
- * long-press to right-click).
- *
- * @constructor
- * @param {Element} element The Element to use to provide touch events.
- */
-Guacamole.Mouse.Touchscreen = function(element) {
-
- /**
- * Reference to this Guacamole.Mouse.Touchscreen.
- * @private
- */
- var guac_touchscreen = this;
-
- /**
- * The distance a two-finger touch must move per scrollwheel event, in
- * pixels.
- */
- this.scrollThreshold = 20 * (window.devicePixelRatio || 1);
-
- /**
- * The current mouse state. The properties of this state are updated when
- * mouse events fire. This state object is also passed in as a parameter to
- * the handler of any mouse events.
- *
- * @type Guacamole.Mouse.State
- */
- this.currentState = new Guacamole.Mouse.State(
- 0, 0,
- false, false, false, false, false
- );
-
- /**
- * Fired whenever a mouse button is effectively pressed. This can happen
- * as part of a "mousedown" gesture initiated by the user by pressing one
- * finger over the touchscreen element, as part of a "scroll" gesture
- * initiated by dragging two fingers up or down, etc.
- *
- * @event
- * @param {Guacamole.Mouse.State} state The current mouse state.
- */
- this.onmousedown = null;
-
- /**
- * Fired whenever a mouse button is effectively released. This can happen
- * as part of a "mouseup" gesture initiated by the user by removing the
- * finger pressed against the touchscreen element, or as part of a "scroll"
- * gesture initiated by dragging two fingers up or down, etc.
- *
- * @event
- * @param {Guacamole.Mouse.State} state The current mouse state.
- */
- this.onmouseup = null;
-
- /**
- * Fired whenever the user moves the mouse by dragging their finger over
- * the touchscreen element. Note that unlike Guacamole.Mouse.Touchpad,
- * dragging a finger over the touchscreen element will always cause
- * the mouse button to be effectively down, as if clicking-and-dragging.
- *
- * @event
- * @param {Guacamole.Mouse.State} state The current mouse state.
- */
- this.onmousemove = null;
-
- element.addEventListener("touchend", function(e) {
-
- // Ignore if more than one touch
- if (e.touches.length + e.changedTouches.length != 1)
- return;
-
- e.stopPropagation();
- e.preventDefault();
-
- // Release button
- guac_touchscreen.currentState.left = false;
-
- // Fire release event when the last touch is released, if event defined
- if (e.touches.length == 0 && guac_touchscreen.onmouseup)
- guac_touchscreen.onmouseup(guac_touchscreen.currentState);
-
- }, false);
-
- element.addEventListener("touchstart", function(e) {
-
- // Ignore if more than one touch
- if (e.touches.length != 1)
- return;
-
- e.stopPropagation();
- e.preventDefault();
-
- // Get touch
- var touch = e.touches[0];
-
- // Update state
- guac_touchscreen.currentState.left = true;
- guac_touchscreen.currentState.fromClientPosition(element, touch.clientX, touch.clientY);
-
- // Fire press event, if defined
- if (guac_touchscreen.onmousedown)
- guac_touchscreen.onmousedown(guac_touchscreen.currentState);
-
-
- }, false);
-
- element.addEventListener("touchmove", function(e) {
-
- // Ignore if more than one touch
- if (e.touches.length != 1)
- return;
-
- e.stopPropagation();
- e.preventDefault();
-
- // Get touch
- var touch = e.touches[0];
-
- // Update state
- guac_touchscreen.currentState.fromClientPosition(element, touch.clientX, touch.clientY);
-
- // Fire movement event, if defined
- if (guac_touchscreen.onmousemove)
- guac_touchscreen.onmousemove(guac_touchscreen.currentState);
-
- }, false);
-
-};
-
-/**
- * Simple container for properties describing the state of a mouse.
- *
- * @constructor
- * @param {Number} x The X position of the mouse pointer in pixels.
- * @param {Number} y The Y position of the mouse pointer in pixels.
- * @param {Boolean} left Whether the left mouse button is pressed.
- * @param {Boolean} middle Whether the middle mouse button is pressed.
- * @param {Boolean} right Whether the right mouse button is pressed.
- * @param {Boolean} up Whether the up mouse button is pressed (the fourth
- * button, usually part of a scroll wheel).
- * @param {Boolean} down Whether the down mouse button is pressed (the fifth
- * button, usually part of a scroll wheel).
- */
-Guacamole.Mouse.State = function(x, y, left, middle, right, up, down) {
-
- /**
- * Reference to this Guacamole.Mouse.State.
- * @private
- */
- var guac_state = this;
-
- /**
- * The current X position of the mouse pointer.
- * @type Number
- */
- this.x = x;
-
- /**
- * The current Y position of the mouse pointer.
- * @type Number
- */
- this.y = y;
-
- /**
- * Whether the left mouse button is currently pressed.
- * @type Boolean
- */
- this.left = left;
-
- /**
- * Whether the middle mouse button is currently pressed.
- * @type Boolean
- */
- this.middle = middle
-
- /**
- * Whether the right mouse button is currently pressed.
- * @type Boolean
- */
- this.right = right;
-
- /**
- * Whether the up mouse button is currently pressed. This is the fourth
- * mouse button, associated with upward scrolling of the mouse scroll
- * wheel.
- * @type Boolean
- */
- this.up = up;
-
- /**
- * Whether the down mouse button is currently pressed. This is the fifth
- * mouse button, associated with downward scrolling of the mouse scroll
- * wheel.
- * @type Boolean
- */
- this.down = down;
-
- /**
- * Updates the position represented within this state object by the given
- * element and clientX/clientY coordinates (commonly available within event
- * objects). Position is translated from clientX/clientY (relative to
- * viewport) to element-relative coordinates.
- *
- * @param {Element} element The element the coordinates should be relative
- * to.
- * @param {Number} clientX The X coordinate to translate, viewport-relative.
- * @param {Number} clientY The Y coordinate to translate, viewport-relative.
- */
- this.fromClientPosition = function(element, clientX, clientY) {
-
- guac_state.x = clientX - element.offsetLeft;
- guac_state.y = clientY - element.offsetTop;
-
- // This is all JUST so we can get the mouse position within the element
- var parent = element.offsetParent;
- while (parent && !(parent === document.body)) {
- guac_state.x -= parent.offsetLeft - parent.scrollLeft;
- guac_state.y -= parent.offsetTop - parent.scrollTop;
-
- parent = parent.offsetParent;
- }
-
- // Element ultimately depends on positioning within document body,
- // take document scroll into account.
- if (parent) {
- var documentScrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft;
- var documentScrollTop = document.body.scrollTop || document.documentElement.scrollTop;
-
- guac_state.x -= parent.offsetLeft - documentScrollLeft;
- guac_state.y -= parent.offsetTop - documentScrollTop;
- }
-
- };
-
-};
-
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/guacamole-common-js/oskeyboard.js
^
|
@@ -1,611 +0,0 @@
-
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is guac-common-js.
- *
- * The Initial Developer of the Original Code is
- * Michael Jumper.
- * Portions created by the Initial Developer are Copyright (C) 2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/**
- * Namespace for all Guacamole JavaScript objects.
- * @namespace
- */
-var Guacamole = Guacamole || {};
-
-/**
- * Dynamic on-screen keyboard. Given the URL to an XML keyboard layout file,
- * this object will download and use the XML to construct a clickable on-screen
- * keyboard with its own key events.
- *
- * @constructor
- * @param {String} url The URL of an XML keyboard layout file.
- */
-Guacamole.OnScreenKeyboard = function(url) {
-
- var on_screen_keyboard = this;
-
- /**
- * State of all modifiers. This is the bitwise OR of all active modifier
- * values.
- *
- * @private
- */
- var modifiers = 0;
-
- var scaledElements = [];
-
- var modifiers = {};
- var currentModifier = 1;
-
- /**
- * Adds a class to an element.
- *
- * @private
- * @function
- * @param {Element} element The element to add a class to.
- * @param {String} classname The name of the class to add.
- */
- var addClass;
-
- /**
- * Removes a class from an element.
- *
- * @private
- * @function
- * @param {Element} element The element to remove a class from.
- * @param {String} classname The name of the class to remove.
- */
- var removeClass;
-
- // If Node.classList is supported, implement addClass/removeClass using that
- if (Node.classList) {
-
- /** @ignore */
- addClass = function(element, classname) {
- element.classList.add(classname);
- };
-
- /** @ignore */
- removeClass = function(element, classname) {
- element.classList.remove(classname);
- };
-
- }
-
- // Otherwise, implement own
- else {
-
- /** @ignore */
- addClass = function(element, classname) {
-
- // Simply add new class
- element.className += " " + classname;
-
- };
-
- /** @ignore */
- removeClass = function(element, classname) {
-
- // Filter out classes with given name
- element.className = element.className.replace(/([^ ]+)[ ]*/g,
- function(match, testClassname, spaces, offset, string) {
-
- // If same class, remove
- if (testClassname == classname)
- return "";
-
- // Otherwise, allow
- return match;
-
- }
- );
-
- };
-
- }
-
- // 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) {
-
- this.width = width;
- this.height = height;
-
- this.scale = function(pixels) {
- element.style.width = (width * pixels) + "px";
- element.style.height = (height * pixels) + "px";
-
- if (scaleFont) {
- element.style.lineHeight = (height * pixels) + "px";
- element.style.fontSize = pixels + "px";
- }
- }
-
- }
-
- // For each child of element, call handler defined in next
- function parseChildren(element, next) {
-
- var children = element.childNodes;
- for (var i=0; i<children.length; i++) {
-
- // Get child node
- var child = children[i];
-
- // Do not parse text nodes
- if (!child.tagName)
- continue;
-
- // Get handler for node
- var handler = next[child.tagName];
-
- // Call handler if defined
- if (handler)
- handler(child);
-
- // Throw exception if no handler
- else
- throw new Error(
- "Unexpected " + child.tagName
- + " within " + element.tagName
- );
-
- }
-
- }
-
- // Create keyboard
- var keyboard = document.createElement("div");
- keyboard.className = "guac-keyboard";
-
- // Retrieve keyboard XML
- var xmlhttprequest = new XMLHttpRequest();
- xmlhttprequest.open("GET", url, false);
- xmlhttprequest.send(null);
-
- var xml = xmlhttprequest.responseXML;
-
- if (xml) {
-
- function parse_row(e) {
-
- var row = document.createElement("div");
- row.className = "guac-keyboard-row";
-
- parseChildren(e, {
-
- "column": function(e) {
- row.appendChild(parse_column(e));
- },
-
- "gap": function parse_gap(e) {
-
- // Create element
- var gap = document.createElement("div");
- gap.className = "guac-keyboard-gap";
-
- // Set gap size
- var gap_units = 1;
- if (e.getAttribute("size"))
- gap_units = parseFloat(e.getAttribute("size"));
-
- scaledElements.push(new ScaledElement(gap, gap_units, gap_units));
- row.appendChild(gap);
-
- },
-
- "key": function parse_key(e) {
-
- // Create element
- var key_element = document.createElement("div");
- key_element.className = "guac-keyboard-key";
-
- // Append class if specified
- if (e.getAttribute("class"))
- key_element.className += " " + e.getAttribute("class");
-
- // Position keys using container div
- var key_container_element = document.createElement("div");
- key_container_element.className = "guac-keyboard-key-container";
- key_container_element.appendChild(key_element);
-
- // Create key
- var key = new Guacamole.OnScreenKeyboard.Key();
-
- // Set key size
- var key_units = 1;
- if (e.getAttribute("size"))
- key_units = parseFloat(e.getAttribute("size"));
-
- key.size = key_units;
-
- parseChildren(e, {
- "cap": function parse_cap(e) {
-
- // TODO: Handle "sticky" attribute
-
- // Get content of key cap
- var content = e.textContent || e.text;
-
- // If read as blank, assume cap is a single space.
- if (content.length == 0)
- content = " ";
-
- // Get keysym
- var real_keysym = null;
- if (e.getAttribute("keysym"))
- real_keysym = parseInt(e.getAttribute("keysym"));
-
- // If no keysym specified, try to get from key content
- else if (content.length == 1) {
-
- var charCode = content.charCodeAt(0);
- if (charCode >= 0x0000 && charCode <= 0x00FF)
- real_keysym = charCode;
- else if (charCode >= 0x0100 && charCode <= 0x10FFFF)
- real_keysym = 0x01000000 | charCode;
-
- }
-
- // Create cap
- var cap = new Guacamole.OnScreenKeyboard.Cap(content, real_keysym);
-
- if (e.getAttribute("modifier"))
- cap.modifier = e.getAttribute("modifier");
-
- // Create cap element
- var cap_element = document.createElement("div");
- cap_element.className = "guac-keyboard-cap";
- cap_element.textContent = content;
- key_element.appendChild(cap_element);
-
- // Append class if specified
- if (e.getAttribute("class"))
- cap_element.className += " " + e.getAttribute("class");
-
- // Get modifier value
- var modifierValue = 0;
- if (e.getAttribute("if")) {
-
- // Get modifier value for specified comma-delimited
- // list of required modifiers.
- var requirements = e.getAttribute("if").split(",");
- for (var i=0; i<requirements.length; i++) {
- modifierValue |= getModifier(requirements[i]);
- addClass(cap_element, "guac-keyboard-requires-" + requirements[i]);
- addClass(key_element, "guac-keyboard-uses-" + requirements[i]);
- }
-
- }
-
- // Store cap
- key.modifierMask |= modifierValue;
- key.caps[modifierValue] = cap;
-
- }
- });
-
- scaledElements.push(new ScaledElement(key_container_element, key_units, 1, true));
- row.appendChild(key_container_element);
-
- // Set up click handler for key
- function press(e) {
-
- // Press key if not yet pressed
- if (!key.pressed) {
-
- addClass(key_element, "guac-keyboard-pressed");
-
- // Get current cap based on modifier state
- var cap = key.getCap(modifiers);
-
- // Update modifier state
- if (cap.modifier) {
-
- // Construct classname for modifier
- var modifierClass = "guac-keyboard-modifier-" + cap.modifier;
- var modifierFlag = getModifier(cap.modifier);
-
- // Toggle modifier state
- modifiers ^= modifierFlag;
-
- // Activate modifier if pressed
- if (modifiers & modifierFlag) {
-
- addClass(keyboard, modifierClass);
-
- // Send key event
- if (on_screen_keyboard.onkeydown && cap.keysym)
- on_screen_keyboard.onkeydown(cap.keysym);
-
- }
-
- // Deactivate if not pressed
- else {
-
- removeClass(keyboard, modifierClass);
-
- // Send key event
- if (on_screen_keyboard.onkeyup && cap.keysym)
- on_screen_keyboard.onkeyup(cap.keysym);
-
- }
-
- }
-
- // If not modifier, send key event now
- else if (on_screen_keyboard.onkeydown && cap.keysym)
- on_screen_keyboard.onkeydown(cap.keysym);
-
- // Mark key as pressed
- key.pressed = true;
-
- }
-
- e.preventDefault();
-
- };
-
- function release(e) {
-
- // Release key if currently pressed
- if (key.pressed) {
-
- // Get current cap based on modifier state
- var cap = key.getCap(modifiers);
-
- removeClass(key_element, "guac-keyboard-pressed");
-
- // Send key event if not a modifier key
- if (!cap.modifier && on_screen_keyboard.onkeyup && cap.keysym)
- on_screen_keyboard.onkeyup(cap.keysym);
-
- // Mark key as released
- key.pressed = false;
-
- }
-
- e.preventDefault();
-
- };
-
- key_element.addEventListener("mousedown", press, true);
- key_element.addEventListener("touchstart", press, true);
-
- key_element.addEventListener("mouseup", release, true);
- key_element.addEventListener("mouseout", release, true);
- key_element.addEventListener("touchend", release, true);
-
- }
-
- });
-
- return row;
-
- }
-
- function parse_column(e) {
-
- var col = document.createElement("div");
- col.className = "guac-keyboard-column";
-
- if (col.getAttribute("align"))
- col.style.textAlign = col.getAttribute("align");
-
- // Columns can only contain rows
- parseChildren(e, {
- "row": function(e) {
- col.appendChild(parse_row(e));
- }
- });
-
- return col;
-
- }
-
-
- // Parse document
- var keyboard_element = xml.documentElement;
- if (keyboard_element.tagName != "keyboard")
- throw new Error("Root element must be keyboard");
-
- // Get attributes
- if (!keyboard_element.getAttribute("size"))
- throw new Error("size attribute is required for keyboard");
-
- var keyboard_size = parseFloat(keyboard_element.getAttribute("size"));
-
- parseChildren(keyboard_element, {
-
- "row": function(e) {
- keyboard.appendChild(parse_row(e));
- },
-
- "column": function(e) {
- keyboard.appendChild(parse_column(e));
- }
-
- });
-
- }
-
- // Do not allow selection or mouse movement to propagate/register.
- keyboard.onselectstart =
- keyboard.onmousemove =
- keyboard.onmouseup =
- keyboard.onmousedown =
- function(e) {
- e.stopPropagation();
- return false;
- };
-
- /**
- * Fired whenever the user presses a key on this Guacamole.OnScreenKeyboard.
- *
- * @event
- * @param {Number} keysym The keysym of the key being pressed.
- */
- this.onkeydown = null;
-
- /**
- * Fired whenever the user releases a key on this Guacamole.OnScreenKeyboard.
- *
- * @event
- * @param {Number} keysym The keysym of the key being released.
- */
- this.onkeyup = null;
-
- /**
- * Returns the element containing the entire on-screen keyboard.
- * @returns {Element} The element containing the entire on-screen keyboard.
- */
- this.getElement = function() {
- return keyboard;
- };
-
- /**
- * Resizes all elements within this Guacamole.OnScreenKeyboard such that
- * the width is close to but does not exceed the specified width. The
- * height of the keyboard is determined based on the width.
- *
- * @param {Number} width The width to resize this Guacamole.OnScreenKeyboard
- * to, in pixels.
- */
- this.resize = function(width) {
-
- // Get pixel size of a unit
- var unit = Math.floor(width * 10 / keyboard_size) / 10;
-
- // Resize all scaled elements
- for (var i=0; i<scaledElements.length; i++) {
- var scaledElement = scaledElements[i];
- scaledElement.scale(unit)
- }
-
- };
-
-};
-
-
-/**
- * Basic representation of a single key of a keyboard. Each key has a set of
- * caps associated with tuples of modifiers. The cap determins what happens
- * when a key is pressed, while it is the state of modifier keys that determines
- * what cap is in effect on any particular key.
- *
- * @constructor
- */
-Guacamole.OnScreenKeyboard.Key = function() {
-
- var key = this;
-
- /**
- * Whether this key is currently pressed.
- */
- this.pressed = false;
-
- /**
- * Width of the key, relative to the size of the keyboard.
- */
- this.size = 1;
-
- /**
- * An associative map of all caps by modifier.
- */
- this.caps = {};
-
- /**
- * Bit mask with all modifiers that affect this key set.
- */
- this.modifierMask = 0;
-
- /**
- * Given the bitwise OR of all active modifiers, returns the key cap
- * which applies.
- */
- this.getCap = function(modifier) {
- return key.caps[modifier & key.modifierMask];
- };
-
-};
-
-/**
- * Basic representation of a cap of a key. The cap is the visible part of a key
- * and determines the active behavior of a key when pressed. The state of all
- * modifiers on the keyboard determines the active cap for all keys, thus
- * each cap is associated with a set of modifiers.
- *
- * @constructor
- * @param {String} text The text to be displayed within this cap.
- * @param {Number} keysym The keysym this cap sends when its associated key is
- * pressed or released.
- * @param {String} modifier The modifier represented by this cap.
- */
-Guacamole.OnScreenKeyboard.Cap = function(text, keysym, modifier) {
-
- /**
- * Modifier represented by this keycap
- */
- this.modifier = null;
-
- /**
- * The text to be displayed within this keycap
- */
- this.text = text;
-
- /**
- * The keysym this cap sends when its associated key is pressed/released
- */
- this.keysym = keysym;
-
- // Set modifier if provided
- if (modifier) this.modifier = modifier;
-
-};
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/guacamole-common-js/tunnel.js
^
|
@@ -1,827 +0,0 @@
-
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is guacamole-common-js.
- *
- * The Initial Developer of the Original Code is
- * Michael Jumper.
- * Portions created by the Initial Developer are Copyright (C) 2010
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/**
- * Namespace for all Guacamole JavaScript objects.
- * @namespace
- */
-var Guacamole = Guacamole || {};
-
-/**
- * Core object providing abstract communication for Guacamole. This object
- * is a null implementation whose functions do nothing. Guacamole applications
- * should use {@link Guacamole.HTTPTunnel} instead, or implement their own tunnel based
- * on this one.
- *
- * @constructor
- * @see Guacamole.HTTPTunnel
- */
-Guacamole.Tunnel = function() {
-
- /**
- * Connect to the tunnel with the given optional data. This data is
- * typically used for authentication. The format of data accepted is
- * up to the tunnel implementation.
- *
- * @param {String} data The data to send to the tunnel when connecting.
- */
- this.connect = function(data) {};
-
- /**
- * Disconnect from the tunnel.
- */
- this.disconnect = function() {};
-
- /**
- * Send the given message through the tunnel to the service on the other
- * side. All messages are guaranteed to be received in the order sent.
- *
- * @param {...} elements The elements of the message to send to the
- * service on the other side of the tunnel.
- */
- this.sendMessage = function(elements) {};
-
- /**
- * Fired whenever an error is encountered by the tunnel.
- *
- * @event
- * @param {String} message A human-readable description of the error that
- * occurred.
- */
- this.onerror = null;
-
- /**
- * Fired once for every complete Guacamole instruction received, in order.
- *
- * @event
- * @param {String} opcode The Guacamole instruction opcode.
- * @param {Array} parameters The parameters provided for the instruction,
- * if any.
- */
- this.oninstruction = null;
-
-};
-
-/**
- * Guacamole Tunnel implemented over HTTP via XMLHttpRequest.
- *
- * @constructor
- * @augments Guacamole.Tunnel
- * @param {String} tunnelURL The URL of the HTTP tunneling service.
- */
-Guacamole.HTTPTunnel = function(tunnelURL) {
-
- /**
- * Reference to this HTTP tunnel.
- * @private
- */
- var tunnel = this;
-
- var tunnel_uuid;
-
- var TUNNEL_CONNECT = tunnelURL + "?connect";
- var TUNNEL_READ = tunnelURL + "?read:";
- var TUNNEL_WRITE = tunnelURL + "?write:";
-
- var STATE_IDLE = 0;
- var STATE_CONNECTED = 1;
- var STATE_DISCONNECTED = 2;
-
- var currentState = STATE_IDLE;
-
- var POLLING_ENABLED = 1;
- var POLLING_DISABLED = 0;
-
- // Default to polling - will be turned off automatically if not needed
- var pollingMode = POLLING_ENABLED;
-
- var sendingMessages = false;
- var outputMessageBuffer = "";
-
- this.sendMessage = function() {
-
- // Do not attempt to send messages if not connected
- if (currentState != STATE_CONNECTED)
- return;
-
- // Do not attempt to send empty messages
- if (arguments.length == 0)
- return;
-
- /**
- * Converts the given value to a length/string pair for use as an
- * element in a Guacamole instruction.
- *
- * @private
- * @param value The value to convert.
- * @return {String} The converted value.
- */
- function getElement(value) {
- var string = new String(value);
- return string.length + "." + string;
- }
-
- // Initialized message with first element
- var message = getElement(arguments[0]);
-
- // Append remaining elements
- for (var i=1; i<arguments.length; i++)
- message += "," + getElement(arguments[i]);
-
- // Final terminator
- message += ";";
-
- // Add message to buffer
- outputMessageBuffer += message;
-
- // Send if not currently sending
- if (!sendingMessages)
- sendPendingMessages();
-
- };
-
- function sendPendingMessages() {
-
- if (outputMessageBuffer.length > 0) {
-
- sendingMessages = true;
-
- var message_xmlhttprequest = new XMLHttpRequest();
- message_xmlhttprequest.open("POST", TUNNEL_WRITE + tunnel_uuid);
- message_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
-
- // Once response received, send next queued event.
- message_xmlhttprequest.onreadystatechange = function() {
- if (message_xmlhttprequest.readyState == 4) {
-
- // If an error occurs during send, handle it
- if (message_xmlhttprequest.status != 200)
- handleHTTPTunnelError(message_xmlhttprequest);
-
- // Otherwise, continue the send loop
- else
- sendPendingMessages();
-
- }
- }
-
- message_xmlhttprequest.send(outputMessageBuffer);
- outputMessageBuffer = ""; // Clear buffer
-
- }
- else
- sendingMessages = false;
-
- }
-
- function getHTTPTunnelErrorMessage(xmlhttprequest) {
-
- var status = xmlhttprequest.status;
-
- // Special cases
- if (status == 0) return "Disconnected";
- if (status == 200) return "Success";
- if (status == 403) return "Unauthorized";
- if (status == 404) return "Connection closed"; /* While it may be more
- * accurate to say the
- * connection does not
- * exist, it is confusing
- * to the user.
- *
- * In general, this error
- * will only happen when
- * the tunnel does not
- * exist, which happens
- * after the connection
- * is closed and the
- * tunnel is detached.
- */
- // Internal server errors
- if (status >= 500 && status <= 599) return "Server error";
-
- // Otherwise, unknown
- return "Unknown error";
-
- }
-
- function handleHTTPTunnelError(xmlhttprequest) {
-
- // Get error message
- var message = getHTTPTunnelErrorMessage(xmlhttprequest);
-
- // Call error handler
- if (tunnel.onerror) tunnel.onerror(message);
-
- // Finish
- tunnel.disconnect();
-
- }
-
-
- function handleResponse(xmlhttprequest) {
-
- var interval = null;
- var nextRequest = null;
-
- var dataUpdateEvents = 0;
-
- // The location of the last element's terminator
- var elementEnd = -1;
-
- // Where to start the next length search or the next element
- var startIndex = 0;
-
- // Parsed elements
- var elements = new Array();
-
- function parseResponse() {
-
- // Do not handle responses if not connected
- if (currentState != STATE_CONNECTED) {
-
- // Clean up interval if polling
- if (interval != null)
- clearInterval(interval);
-
- return;
- }
-
- // Do not parse response yet if not ready
- if (xmlhttprequest.readyState < 2) return;
-
- // Attempt to read status
- var status;
- try { status = xmlhttprequest.status; }
-
- // If status could not be read, assume successful.
- catch (e) { status = 200; }
-
- // Start next request as soon as possible IF request was successful
- if (nextRequest == null && status == 200)
- nextRequest = makeRequest();
-
- // Parse stream when data is received and when complete.
- if (xmlhttprequest.readyState == 3 ||
- xmlhttprequest.readyState == 4) {
-
- // Also poll every 30ms (some browsers don't repeatedly call onreadystatechange for new data)
- if (pollingMode == POLLING_ENABLED) {
- if (xmlhttprequest.readyState == 3 && interval == null)
- interval = setInterval(parseResponse, 30);
- else if (xmlhttprequest.readyState == 4 && interval != null)
- clearInterval(interval);
- }
-
- // If canceled, stop transfer
- if (xmlhttprequest.status == 0) {
- tunnel.disconnect();
- return;
- }
-
- // Halt on error during request
- else if (xmlhttprequest.status != 200) {
- handleHTTPTunnelError(xmlhttprequest);
- return;
- }
-
- // Attempt to read in-progress data
- var current;
- try { current = xmlhttprequest.responseText; }
-
- // Do not attempt to parse if data could not be read
- catch (e) { return; }
-
- // While search is within currently received data
- while (elementEnd < current.length) {
-
- // If we are waiting for element data
- if (elementEnd >= startIndex) {
-
- // We now have enough data for the element. Parse.
- var element = current.substring(startIndex, elementEnd);
- var terminator = current.substring(elementEnd, elementEnd+1);
-
- // Add element to array
- elements.push(element);
-
- // If last element, handle instruction
- if (terminator == ";") {
-
- // Get opcode
- var opcode = elements.shift();
-
- // Call instruction handler.
- if (tunnel.oninstruction != null)
- tunnel.oninstruction(opcode, elements);
-
- // Clear elements
- elements.length = 0;
-
- }
-
- // Start searching for length at character after
- // element terminator
- startIndex = elementEnd + 1;
-
- }
-
- // Search for end of length
- var lengthEnd = current.indexOf(".", startIndex);
- if (lengthEnd != -1) {
-
- // Parse length
- var length = parseInt(current.substring(elementEnd+1, lengthEnd));
-
- // If we're done parsing, handle the next response.
- if (length == 0) {
-
- // Clean up interval if polling
- if (interval != null)
- clearInterval(interval);
-
- // Clean up object
- xmlhttprequest.onreadystatechange = null;
- xmlhttprequest.abort();
-
- // Start handling next request
- if (nextRequest)
- handleResponse(nextRequest);
-
- // Done parsing
- break;
-
- }
-
- // Calculate start of element
- startIndex = lengthEnd + 1;
-
- // Calculate location of element terminator
- elementEnd = startIndex + length;
-
- }
-
- // If no period yet, continue search when more data
- // is received
- else {
- startIndex = current.length;
- break;
- }
-
- } // end parse loop
-
- }
-
- }
-
- // If response polling enabled, attempt to detect if still
- // necessary (via wrapping parseResponse())
- if (pollingMode == POLLING_ENABLED) {
- xmlhttprequest.onreadystatechange = function() {
-
- // If we receive two or more readyState==3 events,
- // there is no need to poll.
- if (xmlhttprequest.readyState == 3) {
- dataUpdateEvents++;
- if (dataUpdateEvents >= 2) {
- pollingMode = POLLING_DISABLED;
- xmlhttprequest.onreadystatechange = parseResponse;
- }
- }
-
- parseResponse();
- }
- }
-
- // Otherwise, just parse
- else
- xmlhttprequest.onreadystatechange = parseResponse;
-
- parseResponse();
-
- }
-
-
- function makeRequest() {
-
- // Download self
- var xmlhttprequest = new XMLHttpRequest();
- xmlhttprequest.open("POST", TUNNEL_READ + tunnel_uuid);
- xmlhttprequest.send(null);
-
- return xmlhttprequest;
-
- }
-
- this.connect = function(data) {
-
- // Start tunnel and connect synchronously
- var connect_xmlhttprequest = new XMLHttpRequest();
- connect_xmlhttprequest.open("POST", TUNNEL_CONNECT, false);
- connect_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- connect_xmlhttprequest.send(data);
-
- // If failure, throw error
- if (connect_xmlhttprequest.status != 200) {
- var message = getHTTPTunnelErrorMessage(connect_xmlhttprequest);
- throw new Error(message);
- }
-
- // Get UUID from response
- tunnel_uuid = connect_xmlhttprequest.responseText;
-
- // Start reading data
- currentState = STATE_CONNECTED;
- handleResponse(makeRequest());
-
- };
-
- this.disconnect = function() {
- currentState = STATE_DISCONNECTED;
- };
-
-};
-
-Guacamole.HTTPTunnel.prototype = new Guacamole.Tunnel();
-
-
-/**
- * Guacamole Tunnel implemented over WebSocket via XMLHttpRequest.
- *
- * @constructor
- * @augments Guacamole.Tunnel
- * @param {String} tunnelURL The URL of the WebSocket tunneling service.
- */
-Guacamole.WebSocketTunnel = function(tunnelURL) {
-
- /**
- * Reference to this WebSocket tunnel.
- * @private
- */
- var tunnel = this;
-
- /**
- * The WebSocket used by this tunnel.
- * @private
- */
- var socket = null;
-
- /**
- * The WebSocket protocol corresponding to the protocol used for the current
- * location.
- * @private
- */
- var ws_protocol = {
- "http:": "ws:",
- "https:": "wss:"
- };
-
- var status_code = {
- 1000: "Connection closed normally.",
- 1001: "Connection shut down.",
- 1002: "Protocol error.",
- 1003: "Invalid data.",
- 1004: "[UNKNOWN, RESERVED]",
- 1005: "No status code present.",
- 1006: "Connection closed abnormally.",
- 1007: "Inconsistent data type.",
- 1008: "Policy violation.",
- 1009: "Message too large.",
- 1010: "Extension negotiation failed."
- };
-
- var STATE_IDLE = 0;
- var STATE_CONNECTED = 1;
- var STATE_DISCONNECTED = 2;
-
- var currentState = STATE_IDLE;
-
- // Transform current URL to WebSocket URL
-
- // If not already a websocket URL
- if ( tunnelURL.substring(0, 3) != "ws:"
- && tunnelURL.substring(0, 4) != "wss:") {
-
- var protocol = ws_protocol[window.location.protocol];
-
- // If absolute URL, convert to absolute WS URL
- if (tunnelURL.substring(0, 1) == "/")
- tunnelURL =
- protocol
- + "//" + window.location.host
- + tunnelURL;
-
- // Otherwise, construct absolute from relative URL
- else {
-
- // Get path from pathname
- var slash = window.location.pathname.lastIndexOf("/");
- var path = window.location.pathname.substring(0, slash + 1);
-
- // Construct absolute URL
- tunnelURL =
- protocol
- + "//" + window.location.host
- + path
- + tunnelURL;
-
- }
-
- }
-
- this.sendMessage = function(elements) {
-
- // Do not attempt to send messages if not connected
- if (currentState != STATE_CONNECTED)
- return;
-
- // Do not attempt to send empty messages
- if (arguments.length == 0)
- return;
-
- /**
- * Converts the given value to a length/string pair for use as an
- * element in a Guacamole instruction.
- *
- * @private
- * @param value The value to convert.
- * @return {String} The converted value.
- */
- function getElement(value) {
- var string = new String(value);
- return string.length + "." + string;
- }
-
- // Initialized message with first element
- var message = getElement(arguments[0]);
-
- // Append remaining elements
- for (var i=1; i<arguments.length; i++)
- message += "," + getElement(arguments[i]);
-
- // Final terminator
- message += ";";
-
- socket.send(message);
-
- };
-
- this.connect = function(data) {
-
- // Connect socket
- socket = new WebSocket(tunnelURL + "?" + data, "guacamole");
-
- socket.onopen = function(event) {
- currentState = STATE_CONNECTED;
- };
-
- socket.onclose = function(event) {
-
- // If connection closed abnormally, signal error.
- if (event.code != 1000 && tunnel.onerror)
- tunnel.onerror(status_code[event.code]);
-
- };
-
- socket.onerror = function(event) {
-
- // Call error handler
- if (tunnel.onerror) tunnel.onerror(event.data);
-
- };
-
- socket.onmessage = function(event) {
-
- var message = event.data;
- var startIndex = 0;
- var elementEnd;
-
- var elements = [];
-
- do {
-
- // Search for end of length
- var lengthEnd = message.indexOf(".", startIndex);
- if (lengthEnd != -1) {
-
- // Parse length
- var length = parseInt(message.substring(elementEnd+1, lengthEnd));
-
- // Calculate start of element
- startIndex = lengthEnd + 1;
-
- // Calculate location of element terminator
- elementEnd = startIndex + length;
-
- }
-
- // If no period, incomplete instruction.
- else
- throw new Error("Incomplete instruction.");
-
- // We now have enough data for the element. Parse.
- var element = message.substring(startIndex, elementEnd);
- var terminator = message.substring(elementEnd, elementEnd+1);
-
- // Add element to array
- elements.push(element);
-
- // If last element, handle instruction
- if (terminator == ";") {
-
- // Get opcode
- var opcode = elements.shift();
-
- // Call instruction handler.
- if (tunnel.oninstruction != null)
- tunnel.oninstruction(opcode, elements);
-
- // Clear elements
- elements.length = 0;
-
- }
-
- // Start searching for length at character after
- // element terminator
- startIndex = elementEnd + 1;
-
- } while (startIndex < message.length);
-
- };
-
- };
-
- this.disconnect = function() {
- currentState = STATE_DISCONNECTED;
- socket.close();
- };
-
-};
-
-Guacamole.WebSocketTunnel.prototype = new Guacamole.Tunnel();
-
-
-/**
- * Guacamole Tunnel which cycles between all specified tunnels until
- * no tunnels are left. Another tunnel is used if an error occurs but
- * no instructions have been received. If an instruction has been
- * received, or no tunnels remain, the error is passed directly out
- * through the onerror handler (if defined).
- *
- * @constructor
- * @augments Guacamole.Tunnel
- * @param {...} tunnel_chain The tunnels to use, in order of priority.
- */
-Guacamole.ChainedTunnel = function(tunnel_chain) {
-
- /**
- * Reference to this chained tunnel.
- * @private
- */
- var chained_tunnel = this;
-
- /**
- * The currently wrapped tunnel, if any.
- * @private
- */
- var current_tunnel = null;
-
- /**
- * Data passed in via connect(), to be used for
- * wrapped calls to other tunnels' connect() functions.
- * @private
- */
- var connect_data;
-
- /**
- * Array of all tunnels passed to this ChainedTunnel through the
- * constructor arguments.
- * @private
- */
- var tunnels = [];
-
- // Load all tunnels into array
- for (var i=0; i<arguments.length; i++)
- tunnels.push(arguments[i]);
-
- /**
- * Sets the current tunnel.
- *
- * @private
- * @param {Guacamole.Tunnel} tunnel The tunnel to set as the current tunnel.
- */
- function attach(tunnel) {
-
- // Clear handlers of current tunnel, if any
- if (current_tunnel) {
- current_tunnel.onerror = null;
- current_tunnel.oninstruction = null;
- }
-
- // Set own functions to tunnel's functions
- chained_tunnel.disconnect = tunnel.disconnect;
- chained_tunnel.sendMessage = tunnel.sendMessage;
-
- // Record current tunnel
- current_tunnel = tunnel;
-
- // Wrap own oninstruction within current tunnel
- current_tunnel.oninstruction = function(opcode, elements) {
-
- // Invoke handler
- chained_tunnel.oninstruction(opcode, elements);
-
- // Use handler permanently from now on
- current_tunnel.oninstruction = chained_tunnel.oninstruction;
-
- // Pass through errors (without trying other tunnels)
- current_tunnel.onerror = chained_tunnel.onerror;
-
- }
-
- // Attach next tunnel on error
- current_tunnel.onerror = function(message) {
-
- // Get next tunnel
- var next_tunnel = tunnels.shift();
-
- // If there IS a next tunnel, try using it.
- if (next_tunnel)
- attach(next_tunnel);
-
- // Otherwise, call error handler
- else if (chained_tunnel.onerror)
- chained_tunnel.onerror(message);
-
- };
-
- try {
-
- // Attempt connection
- current_tunnel.connect(connect_data);
-
- }
- catch (e) {
-
- // Call error handler of current tunnel on error
- current_tunnel.onerror(e.message);
-
- }
-
-
- }
-
- this.connect = function(data) {
-
- // Remember connect data
- connect_data = data;
-
- // Get first tunnel
- var next_tunnel = tunnels.shift();
-
- // Attach first tunnel
- if (next_tunnel)
- attach(next_tunnel);
-
- // If there IS no first tunnel, error
- else if (chained_tunnel.onerror)
- chained_tunnel.onerror("No tunnels to try.");
-
- };
-
-};
-
-Guacamole.ChainedTunnel.prototype = new Guacamole.Tunnel();
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/images
^
|
-(directory)
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/images/mouse
^
|
-(directory)
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/images/protocol-icons
^
|
-(directory)
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/images/protocol-icons/tango
^
|
-(directory)
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/index.xhtml
^
|
@@ -1,256 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html>
-
-<!--
- Guacamole - Clientless Remote Desktop
- Copyright (C) 2010 Michael Jumper
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
--->
-
-<html xmlns="http://www.w3.org/1999/xhtml">
-
- <head>
- <link rel="icon" type="image/png" href="images/guacamole-logo-64.png"/>
- <link rel="apple-touch-icon" type="image/png" href="images/guacamole-logo-144.png"/>
- <link rel="stylesheet" type="text/css" href="styles/login.css"/>
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi"/>
- <title>Guacamole 0.6.1</title>
- </head>
-
- <body>
-
- <div id="login-ui" style="display: none">
- <div id="login-dialog-middle">
-
- <div id="login-dialog">
-
- <p id="login-error"></p>
-
- <form id="login-form" action="#" method="post">
-
- <div id="login-fields">
- <table>
- <tr>
- <th>Username</th>
- <td><input type="text" name="username" id="username" autofocus="autofocus"/></td>
- </tr>
- <tr>
- <th>Password</th>
- <td><input type="password" name="password" id="password"/></td>
- </tr>
- </table>
-
- <img class="logo" src="images/guacamole-logo-64.png" alt=""/>
- </div>
-
- <div id="buttons">
- <input type="submit" name="login" id="login" value="Login"/>
- </div>
-
- </form>
- </div>
-
- </div>
- </div>
-
- <!-- Connection list UI -->
- <div id="connection-list-ui" style="display: none">
-
- <div id="logout-panel">
- <button id="logout">Logout</button>
- </div>
-
- <h1>
- <img class="logo" src="images/guacamole-logo-64.png" alt=""/>
- Available Connections
- </h1>
-
- <table class="connections">
- <thead>
- <tr>
- <th class="protocol"> </th>
- <th class="name">Name</th>
- </tr>
- </thead>
- <tbody id="connections-tbody">
- </tbody>
- </table>
-
- </div>
-
- <div id="version-dialog">
- Guacamole 0.6.1
- </div>
-
- <script type="text/javascript" src="scripts/connections.js"></script>
-
- <!-- Init -->
- <script type="text/javascript"> /* <![CDATA[ */
-
- // Constructs the URL for a client which connects to the connection
- // with the given id.
- function getClientURL(id) {
-
- // Construct URL for client with given id
- return "client.xhtml?id=" + encodeURIComponent(id);
-
- }
-
- // Resets the interface such that the login UI is displayed if
- // the user is not authenticated (or authentication fails) and
- // the connection list UI (or the client for the only available
- // connection, if there is only one) is displayed if the user is
- // authenticated.
- function resetUI() {
-
- // Get parameters from query string
- var parameters = window.location.search.substring(1);
-
- var configs;
- try {
- configs = getConfigList(parameters);
- }
- catch (e) {
-
- // Show login UI if unable to get configs
- loginUI.style.display = "";
- connectionListUI.style.display = "none";
-
- return;
-
- }
-
- // If only one connection, redirect to that.
- if (configs.length == 1) {
- window.location.href = getClientURL(configs[0].id);
- return;
- }
-
- // Remove all rows from connections list
- var tbody = document.getElementById("connections-tbody");
- tbody.innerHTML = "";
-
- // Add one row per connection
- for (var i=0; i<configs.length; i++) {
-
- // Create row and cells
- var tr = document.createElement("tr");
- var protocol = document.createElement("td");
- var id = document.createElement("td");
-
- var protocolIcon = document.createElement("div");
- protocolIcon.className = "protocol icon " + configs[i].protocol;
-
- // Set CSS
- protocol.className = "protocol";
- id.className = "name";
-
- // Create link to client
- var clientLink = document.createElement("a");
- clientLink.setAttribute("href", getClientURL(configs[i].id));
-
- // Set cell contents
- protocol.appendChild(protocolIcon);
- //protocol.textContent = configs[i].protocol;
- clientLink.textContent = configs[i].id;
- id.appendChild(clientLink);
-
- // Add cells
- tr.appendChild(protocol);
- tr.appendChild(id);
-
- // Add row
- tbody.appendChild(tr);
-
- }
-
- // If configs could be retrieved, display list
- loginUI.style.display = "none";
- connectionListUI.style.display = "";
-
- }
-
- var loginForm = document.getElementById("login-form");
- var loginUI = document.getElementById("login-ui");
- var connectionListUI = document.getElementById("connection-list-ui");
- var logout = document.getElementById("logout");
- var username = document.getElementById("username");
- var password = document.getElementById("password");
-
- logout.onclick = function() {
- window.location.href = "logout";
- };
-
- loginForm.onsubmit = function() {
-
- // Get parameters from query string
- var parameters = window.location.search.substring(1);
-
- // Get username and password from form
- var data =
- "username=" + encodeURIComponent(username.value)
- + "&password=" + encodeURIComponent(password.value)
-
- // Include query parameters in submission data
- if (parameters) data += "&" + parameters;
-
- try {
-
- // Log in
- var xhr = new XMLHttpRequest();
- xhr.open("POST", "login", false);
- xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- xhr.send(data);
-
- // Handle failures
- if (xhr.status != 200)
- throw new Error("Invalid login");
-
- // Ensure username/password fiels are blurred after submit
- username.blur();
- password.blur();
-
- resetUI();
-
- }
- catch (e) {
-
- var loginError = document.getElementById("login-error");
-
- // Display error, reset and refocus password field
- loginError.textContent = e.message;
- password.value = "";
- password.focus();
-
- return false;
-
- }
-
- // On success, hide loginUI, get and show connection list.
- return false;
-
- }
-
- // Turn off autocorrect and autocapitalization on usename
- username.setAttribute("autocorrect", "off");
- username.setAttribute("autocapitalize", "off");
-
- resetUI();
-
- /* ]]> */ </script>
-
- </body>
-
-</html>
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/layouts
^
|
-(directory)
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/scripts
^
|
-(directory)
|
[-]
[+]
|
Deleted |
guacamole-0.6.1.tar.bz2/target/guacamole-0.6.1/styles
^
|
-(directory)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/ChangeLog
^
|
@@ -1,3 +1,8 @@
+2012-10-15 Michael Jumper <zhangmaike@users.sourceforge.net>
+
+ * Migrate to guacamole-common 0.6.2
+ * Migrate to guacamole-common-js 0.6.2
+
2012-08-11 Michael Jumper <zhangmaike@users.sourceforge.net>
* Migrate to guacamole-common 0.6.1
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/pom.xml
^
|
@@ -5,7 +5,7 @@
<groupId>net.sourceforge.guacamole</groupId>
<artifactId>guacamole</artifactId>
<packaging>war</packaging>
- <version>0.6.1</version>
+ <version>0.6.2</version>
<name>guacamole</name>
<url>http://guac-dev.org/</url>
@@ -81,21 +81,21 @@
<dependency>
<groupId>net.sourceforge.guacamole</groupId>
<artifactId>guacamole-common</artifactId>
- <version>0.6.1</version>
+ <version>0.6.2</version>
</dependency>
<!-- Guacamole Extension API -->
<dependency>
<groupId>net.sourceforge.guacamole</groupId>
<artifactId>guacamole-ext</artifactId>
- <version>0.6.1</version>
+ <version>0.6.2</version>
</dependency>
<!-- Guacamole JavaScript API -->
<dependency>
<groupId>net.sourceforge.guacamole</groupId>
<artifactId>guacamole-common-js</artifactId>
- <version>0.6.1</version>
+ <version>0.6.2</version>
<type>zip</type>
<scope>runtime</scope>
</dependency>
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2
^
|
+(directory)
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2.war
^
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/META-INF
^
|
+(directory)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/META-INF/context.xml
^
|
(renamed from target/guacamole-0.6.1/META-INF/context.xml)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/META-INF/context.xml
^
|
(renamed from target/guacamole-0.6.1/META-INF/context.xml)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic
^
|
+(directory)
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/AuthenticatingHttpServlet.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$1.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$2.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$AuthInfo$Encoding.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$AuthInfo.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$BasicUserMappingContentHandler$State.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$BasicUserMappingContentHandler.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicGuacamoleTunnelServlet$1$1.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicGuacamoleTunnelServlet$1.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicGuacamoleTunnelServlet.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicLogin.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/BasicLogout.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/ConfigurationList.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/GuacamoleClassLoader$1.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/GuacamoleClassLoader$2.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/GuacamoleClassLoader.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/WebSocketSupportLoader.class
^
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/event
^
|
+(directory)
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/event/SessionListenerCollection.class
^
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/properties
^
|
+(directory)
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/properties/AuthenticationProviderProperty.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties$1.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties$2.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties$3.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/classes/net/sourceforge/guacamole/net/basic/properties/EventListenersProperty.class
^
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/lib
^
|
+(directory)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/lib/commons-logging-1.1.1.jar
^
|
(renamed from target/guacamole-0.6.1/WEB-INF/lib/commons-logging-1.1.1.jar)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/lib/commons-logging-1.1.1.jar
^
|
(renamed from target/guacamole-0.6.1/WEB-INF/lib/commons-logging-1.1.1.jar)
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/lib/guacamole-common-0.6.2.jar
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/lib/guacamole-ext-0.6.2.jar
^
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/lib/slf4j-api-1.6.1.jar
^
|
(renamed from target/guacamole-0.6.1/WEB-INF/lib/slf4j-api-1.6.1.jar)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/lib/slf4j-api-1.6.1.jar
^
|
(renamed from target/guacamole-0.6.1/WEB-INF/lib/slf4j-api-1.6.1.jar)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/lib/slf4j-jcl-1.6.1.jar
^
|
(renamed from target/guacamole-0.6.1/WEB-INF/lib/slf4j-jcl-1.6.1.jar)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/lib/slf4j-jcl-1.6.1.jar
^
|
(renamed from target/guacamole-0.6.1/WEB-INF/lib/slf4j-jcl-1.6.1.jar)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/web.xml
^
|
(renamed from target/guacamole-0.6.1/WEB-INF/web.xml)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/web.xml
^
|
(renamed from target/guacamole-0.6.1/WEB-INF/web.xml)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/agpl-3.0-standalone.html
^
|
(renamed from target/guacamole-0.6.1/agpl-3.0-standalone.html)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/agpl-3.0-standalone.html
^
|
(renamed from target/guacamole-0.6.1/agpl-3.0-standalone.html)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/client.xhtml
^
|
@@ -0,0 +1,163 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html>
+
+<!--
+ Guacamole - Clientless Remote Desktop
+ Copyright (C) 2010 Michael Jumper
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+-->
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+ <head>
+ <link rel="icon" type="image/png" href="images/guacamole-logo-64.png"/>
+ <link rel="stylesheet" type="text/css" href="styles/client.css"/>
+ <link rel="stylesheet" type="text/css" href="styles/keyboard.css"/>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi"/>
+ <meta name="apple-mobile-web-app-capable" content="yes"/>
+ <title>Guacamole 0.6.2</title>
+ </head>
+
+ <body>
+
+ <!-- Menu -->
+ <div id="menu">
+
+ <!-- Clipboard -->
+ <button id="showClipboard">Show Clipboard</button>
+ <div id="clipboardDiv">
+ <h2>Clipboard</h2>
+ <p>
+ Text copied/cut within Guacamole will appear here. Changes to the text will affect the remote clipboard, and will be pastable within the remote desktop. Use the textbox below as an interface between the client and server clipboards.
+ </p>
+ <textarea rows="10" cols="40" id="clipboard"></textarea>
+ </div>
+
+ <button id="showKeyboard">Show Keyboard</button>
+ <button id="ctrlAltDelete">Ctrl-Alt-Delete</button>
+ <button id="logout">Logout</button>
+
+ <!-- Logo and status -->
+ <img id="status-logo" class="logo" src="images/guacamole-logo-24.png" alt="Guacamole" title="Guacamole 0.6.2"/>
+
+ </div>
+
+ <!-- Touch-specific menu -->
+ <div id="touchMenu"><img id="touchShowClipboard" src="images/menu-icons/tango/edit-paste.png"/><img id="touchShowKeyboard" src="images/menu-icons/tango/input-keyboard.png"/><img id="touchLogout" src="images/menu-icons/tango/system-log-out.png"/></div>
+
+ <!-- Touch-specific clipboard -->
+ <div id="touchClipboardDiv">
+ <h2>Clipboard</h2>
+ <p>
+ Text copied/cut within Guacamole will appear here. Changes to the text will affect the remote clipboard, and will be pastable within the remote desktop. Use the textbox below as an interface between the client and server clipboards.
+ </p>
+ <textarea rows="10" cols="40" id="touchClipboard"></textarea>
+ </div>
+
+ <!-- Keyboard event target for platforms with native OSKs -->
+ <textarea id="eventTarget"></textarea>
+
+ <!-- Display -->
+ <div id="display">
+
+ <!-- Menu trigger -->
+ <div id="menuControl"></div>
+
+ </div>
+
+ <!-- On-screen keyboard -->
+ <div id="keyboardContainer"></div>
+
+ <!-- Dimensional clone of viewport -->
+ <div id="viewportClone"/>
+
+ <!-- Dialogs -->
+ <div class="dialogOuter">
+ <div class="dialogMiddle">
+
+ <!-- Status Dialog -->
+ <div id="statusDialog" class="dialog">
+ <p id="statusText"></p>
+ <div class="buttons"><button id="reconnect">Reconnect</button></div>
+ </div>
+
+ </div>
+ </div>
+
+ <!-- guacamole-common-js scripts -->
+ <script type="text/javascript" src="guacamole-common-js/keyboard.js"></script>
+ <script type="text/javascript" src="guacamole-common-js/mouse.js"></script>
+ <script type="text/javascript" src="guacamole-common-js/layer.js"></script>
+ <script type="text/javascript" src="guacamole-common-js/tunnel.js"></script>
+ <script type="text/javascript" src="guacamole-common-js/guacamole.js"></script>
+ <script type="text/javascript" src="guacamole-common-js/oskeyboard.js"></script>
+
+ <!-- guacamole-default-webapp scripts -->
+ <script type="text/javascript" src="scripts/interface.js"></script>
+
+ <!-- Init -->
+ <script type="text/javascript"> /* <![CDATA[ */
+
+ // Start connect after control returns from onload (allow browser
+ // to consider the page loaded).
+ window.onload = function() {
+ window.setTimeout(function() {
+
+ var tunnel;
+
+ // If WebSocket available, try to use it.
+ if (window.WebSocket)
+ tunnel = new Guacamole.ChainedTunnel(
+ new Guacamole.WebSocketTunnel("websocket-tunnel"),
+ new Guacamole.HTTPTunnel("tunnel")
+ );
+
+ // If no WebSocket, then use HTTP.
+ else
+ tunnel = new Guacamole.HTTPTunnel("tunnel")
+
+ // Instantiate client
+ var guac = new Guacamole.Client(tunnel);
+
+ // Add client to UI
+ guac.getDisplay().className = "software-cursor";
+ GuacamoleUI.display.appendChild(guac.getDisplay());
+
+ // Tie UI to client
+ GuacamoleUI.attach(guac);
+
+ try {
+
+ // Get entire query string, and pass to connect().
+ // Normally, only the "id" parameter is required, but
+ // all parameters should be preserved and passed on for
+ // the sake of authentication.
+
+ var connect_string = window.location.search.substring(1);
+ guac.connect(connect_string);
+
+ }
+ catch (e) {
+ GuacamoleUI.showError(e.message);
+ }
+
+ }, 0);
+ };
+
+ /* ]]> */ </script>
+
+ </body>
+
+</html>
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/guacamole-common-js
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/guacamole-common-js/guacamole.js
^
|
@@ -0,0 +1,1180 @@
+
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is guacamole-common-js.
+ *
+ * The Initial Developer of the Original Code is
+ * Michael Jumper.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Matt Hortman
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Namespace for all Guacamole JavaScript objects.
+ * @namespace
+ */
+var Guacamole = Guacamole || {};
+
+
+/**
+ * Guacamole protocol client. Given a display element and {@link Guacamole.Tunnel},
+ * automatically handles incoming and outgoing Guacamole instructions via the
+ * provided tunnel, updating the display using one or more canvas elements.
+ *
+ * @constructor
+ * @param {Guacamole.Tunnel} tunnel The tunnel to use to send and receive
+ * Guacamole instructions.
+ */
+Guacamole.Client = function(tunnel) {
+
+ var guac_client = this;
+
+ var STATE_IDLE = 0;
+ var STATE_CONNECTING = 1;
+ var STATE_WAITING = 2;
+ var STATE_CONNECTED = 3;
+ var STATE_DISCONNECTING = 4;
+ var STATE_DISCONNECTED = 5;
+
+ var currentState = STATE_IDLE;
+
+ var currentTimestamp = 0;
+ var pingInterval = null;
+
+ var displayWidth = 0;
+ var displayHeight = 0;
+ var displayScale = 1;
+
+ /**
+ * Translation from Guacamole protocol line caps to Layer line caps.
+ * @private
+ */
+ var lineCap = {
+ 0: "butt",
+ 1: "round",
+ 2: "square"
+ };
+
+ /**
+ * Translation from Guacamole protocol line caps to Layer line caps.
+ * @private
+ */
+ var lineJoin = {
+ 0: "bevel",
+ 1: "miter",
+ 2: "round"
+ };
+
+ // Create bounding div
+ var bounds = document.createElement("div");
+ bounds.style.position = "relative";
+ bounds.style.width = (displayWidth*displayScale) + "px";
+ bounds.style.height = (displayHeight*displayScale) + "px";
+
+ // Create display
+ var display = document.createElement("div");
+ display.style.position = "relative";
+ display.style.width = displayWidth + "px";
+ display.style.height = displayHeight + "px";
+
+ // Ensure transformations on display originate at 0,0
+ display.style.transformOrigin =
+ display.style.webkitTransformOrigin =
+ display.style.MozTransformOrigin =
+ display.style.OTransformOrigin =
+ display.style.msTransformOrigin =
+ "0 0";
+
+ // Create default layer
+ var default_layer_container = new Guacamole.Client.LayerContainer(displayWidth, displayHeight);
+
+ // Position default layer
+ var default_layer_container_element = default_layer_container.getElement();
+ default_layer_container_element.style.position = "absolute";
+ default_layer_container_element.style.left = "0px";
+ default_layer_container_element.style.top = "0px";
+ default_layer_container_element.style.overflow = "hidden";
+
+ // Create cursor layer
+ var cursor = new Guacamole.Client.LayerContainer(0, 0);
+ cursor.getLayer().setChannelMask(Guacamole.Layer.SRC);
+
+ // Position cursor layer
+ var cursor_element = cursor.getElement();
+ cursor_element.style.position = "absolute";
+ cursor_element.style.left = "0px";
+ cursor_element.style.top = "0px";
+
+ // Add default layer and cursor to display
+ display.appendChild(default_layer_container.getElement());
+ display.appendChild(cursor.getElement());
+
+ // Add display to bounds
+ bounds.appendChild(display);
+
+ // Initially, only default layer exists
+ var layers = [default_layer_container];
+
+ // No initial buffers
+ var buffers = [];
+
+ tunnel.onerror = function(message) {
+ if (guac_client.onerror)
+ guac_client.onerror(message);
+ };
+
+ function setState(state) {
+ if (state != currentState) {
+ currentState = state;
+ if (guac_client.onstatechange)
+ guac_client.onstatechange(currentState);
+ }
+ }
+
+ function isConnected() {
+ return currentState == STATE_CONNECTED
+ || currentState == STATE_WAITING;
+ }
+
+ var cursorHotspotX = 0;
+ var cursorHotspotY = 0;
+
+ var cursorX = 0;
+ var cursorY = 0;
+
+ function moveCursor(x, y) {
+
+ // Move cursor layer
+ cursor.translate(x - cursorHotspotX, y - cursorHotspotY);
+
+ // Update stored position
+ cursorX = x;
+ cursorY = y;
+
+ }
+
+ /**
+ * Returns an element containing the display of this Guacamole.Client.
+ * Adding the element returned by this function to an element in the body
+ * of a document will cause the client's display to be visible.
+ *
+ * @return {Element} An element containing ths display of this
+ * Guacamole.Client.
+ */
+ this.getDisplay = function() {
+ return bounds;
+ };
+
+ /**
+ * Sends a key event having the given properties as if the user
+ * pressed or released a key.
+ *
+ * @param {Boolean} pressed Whether the key is pressed (true) or released
+ * (false).
+ * @param {Number} keysym The keysym of the key being pressed or released.
+ */
+ this.sendKeyEvent = function(pressed, keysym) {
+ // Do not send requests if not connected
+ if (!isConnected())
+ return;
+
+ tunnel.sendMessage("key", keysym, pressed);
+ };
+
+ /**
+ * Sends a mouse event having the properties provided by the given mouse
+ * state.
+ *
+ * @param {Guacamole.Mouse.State} mouseState The state of the mouse to send
+ * in the mouse event.
+ */
+ this.sendMouseState = function(mouseState) {
+
+ // Do not send requests if not connected
+ if (!isConnected())
+ return;
+
+ // Update client-side cursor
+ moveCursor(
+ Math.floor(mouseState.x),
+ Math.floor(mouseState.y)
+ );
+
+ // Build mask
+ var buttonMask = 0;
+ if (mouseState.left) buttonMask |= 1;
+ if (mouseState.middle) buttonMask |= 2;
+ if (mouseState.right) buttonMask |= 4;
+ if (mouseState.up) buttonMask |= 8;
+ if (mouseState.down) buttonMask |= 16;
+
+ // Send message
+ tunnel.sendMessage("mouse", Math.floor(mouseState.x), Math.floor(mouseState.y), buttonMask);
+ };
+
+ /**
+ * Sets the clipboard of the remote client to the given text data.
+ *
+ * @param {String} data The data to send as the clipboard contents.
+ */
+ this.setClipboard = function(data) {
+
+ // Do not send requests if not connected
+ if (!isConnected())
+ return;
+
+ tunnel.sendMessage("clipboard", data);
+ };
+
+ /**
+ * Fired whenever the state of this Guacamole.Client changes.
+ *
+ * @event
+ * @param {Number} state The new state of the client.
+ */
+ this.onstatechange = null;
+
+ /**
+ * Fired when the remote client sends a name update.
+ *
+ * @event
+ * @param {String} name The new name of this client.
+ */
+ this.onname = null;
+
+ /**
+ * Fired when an error is reported by the remote client, and the connection
+ * is being closed.
+ *
+ * @event
+ * @param {String} error A human-readable description of the error.
+ */
+ this.onerror = null;
+
+ /**
+ * Fired when the clipboard of the remote client is changing.
+ *
+ * @event
+ * @param {String} data The new text data of the remote clipboard.
+ */
+ this.onclipboard = null;
+
+ // Layers
+ function getBufferLayer(index) {
+
+ index = -1 - index;
+ var buffer = buffers[index];
+
+ // Create buffer if necessary
+ if (buffer == null) {
+ buffer = new Guacamole.Layer(0, 0);
+ buffer.autosize = 1;
+ buffers[index] = buffer;
+ }
+
+ return buffer;
+
+ }
+
+ function getLayerContainer(index) {
+
+ var layer = layers[index];
+ if (layer == null) {
+
+ // Add new layer
+ layer = new Guacamole.Client.LayerContainer(displayWidth, displayHeight);
+ layers[index] = layer;
+
+ // Get and position layer
+ var layer_element = layer.getElement();
+ layer_element.style.position = "absolute";
+ layer_element.style.left = "0px";
+ layer_element.style.top = "0px";
+ layer_element.style.overflow = "hidden";
+
+ // Add to default layer container
+ default_layer_container.getElement().appendChild(layer_element);
+
+ }
+
+ return layer;
+
+ }
+
+ function getLayer(index) {
+
+ // If buffer, just get layer
+ if (index < 0)
+ return getBufferLayer(index);
+
+ // Otherwise, retrieve layer from layer container
+ return getLayerContainer(index).getLayer();
+
+ }
+
+ /**
+ * Handlers for all defined layer properties.
+ * @private
+ */
+ var layerPropertyHandlers = {
+
+ "miter-limit": function(layer, value) {
+ layer.setMiterLimit(parseFloat(value));
+ }
+
+ };
+
+ /**
+ * Handlers for all instruction opcodes receivable by a Guacamole protocol
+ * client.
+ * @private
+ */
+ var instructionHandlers = {
+
+ "arc": function(parameters) {
+
+ var layer = getLayer(parseInt(parameters[0]));
+ var x = parseInt(parameters[1]);
+ var y = parseInt(parameters[2]);
+ var radius = parseInt(parameters[3]);
+ var startAngle = parseFloat(parameters[4]);
+ var endAngle = parseFloat(parameters[5]);
+ var negative = parseInt(parameters[6]);
+
+ layer.arc(x, y, radius, startAngle, endAngle, negative != 0);
+
+ },
+
+ "cfill": function(parameters) {
+
+ var channelMask = parseInt(parameters[0]);
+ var layer = getLayer(parseInt(parameters[1]));
+ var r = parseInt(parameters[2]);
+ var g = parseInt(parameters[3]);
+ var b = parseInt(parameters[4]);
+ var a = parseInt(parameters[5]);
+
+ layer.setChannelMask(channelMask);
+
+ layer.fillColor(r, g, b, a);
+
+ },
+
+ "clip": function(parameters) {
+
+ var layer = getLayer(parseInt(parameters[0]));
+
+ layer.clip();
+
+ },
+
+ "clipboard": function(parameters) {
+ if (guac_client.onclipboard) guac_client.onclipboard(parameters[0]);
+ },
+
+ "close": function(parameters) {
+
+ var layer = getLayer(parseInt(parameters[0]));
+
+ layer.close();
+
+ },
+
+ "copy": function(parameters) {
+
+ var srcL = getLayer(parseInt(parameters[0]));
+ var srcX = parseInt(parameters[1]);
+ var srcY = parseInt(parameters[2]);
+ var srcWidth = parseInt(parameters[3]);
+ var srcHeight = parseInt(parameters[4]);
+ var channelMask = parseInt(parameters[5]);
+ var dstL = getLayer(parseInt(parameters[6]));
+ var dstX = parseInt(parameters[7]);
+ var dstY = parseInt(parameters[8]);
+
+ dstL.setChannelMask(channelMask);
+
+ dstL.copy(
+ srcL,
+ srcX,
+ srcY,
+ srcWidth,
+ srcHeight,
+ dstX,
+ dstY
+ );
+
+ },
+
+ "cstroke": function(parameters) {
+
+ var channelMask = parseInt(parameters[0]);
+ var layer = getLayer(parseInt(parameters[1]));
+ var cap = lineCap[parseInt(parameters[2])];
+ var join = lineJoin[parseInt(parameters[3])];
+ var thickness = parseInt(parameters[4]);
+ var r = parseInt(parameters[5]);
+ var g = parseInt(parameters[6]);
+ var b = parseInt(parameters[7]);
+ var a = parseInt(parameters[8]);
+
+ layer.setChannelMask(channelMask);
+
+ layer.strokeColor(cap, join, thickness, r, g, b, a);
+
+ },
+
+ "cursor": function(parameters) {
+
+ cursorHotspotX = parseInt(parameters[0]);
+ cursorHotspotY = parseInt(parameters[1]);
+ var srcL = getLayer(parseInt(parameters[2]));
+ var srcX = parseInt(parameters[3]);
+ var srcY = parseInt(parameters[4]);
+ var srcWidth = parseInt(parameters[5]);
+ var srcHeight = parseInt(parameters[6]);
+
+ // Reset cursor size
+ cursor.resize(srcWidth, srcHeight);
+
+ // Draw cursor to cursor layer
+ cursor.getLayer().copy(
+ srcL,
+ srcX,
+ srcY,
+ srcWidth,
+ srcHeight,
+ 0,
+ 0
+ );
+
+ // Update cursor position (hotspot may have changed)
+ moveCursor(cursorX, cursorY);
+
+ },
+
+ "curve": function(parameters) {
+
+ var layer = getLayer(parseInt(parameters[0]));
+ var cp1x = parseInt(parameters[1]);
+ var cp1y = parseInt(parameters[2]);
+ var cp2x = parseInt(parameters[3]);
+ var cp2y = parseInt(parameters[4]);
+ var x = parseInt(parameters[5]);
+ var y = parseInt(parameters[6]);
+
+ layer.curveTo(cp1x, cp1y, cp2x, cp2y, x, y);
+
+ },
+
+ "dispose": function(parameters) {
+
+ var layer_index = parseInt(parameters[0]);
+
+ // If visible layer, remove from parent
+ if (layer_index > 0) {
+
+ // Get container element
+ var layer_container = getLayerContainer(layer_index).getElement();
+
+ // Remove from parent
+ layer_container.parentNode.removeChild(layer_container);
+
+ // Delete reference
+ delete layers[layer_index];
+
+ }
+
+ // If buffer, just delete reference
+ else if (layer_index < 0)
+ delete buffers[-1 - layer_index];
+
+ // Attempting to dispose the root layer currently has no effect.
+
+ },
+
+ "distort": function(parameters) {
+
+ var layer_index = parseInt(parameters[0]);
+ var a = parseFloat(parameters[1]);
+ var b = parseFloat(parameters[2]);
+ var c = parseFloat(parameters[3]);
+ var d = parseFloat(parameters[4]);
+ var e = parseFloat(parameters[5]);
+ var f = parseFloat(parameters[6]);
+
+ // Only valid for visible layers (not buffers)
+ if (layer_index >= 0) {
+
+ // Get container element
+ var layer_container = getLayerContainer(layer_index).getElement();
+
+ // Set layer transform
+ layer_container.transform(a, b, c, d, e, f);
+
+ }
+
+ },
+
+ "error": function(parameters) {
+ if (guac_client.onerror) guac_client.onerror(parameters[0]);
+ guac_client.disconnect();
+ },
+
+ "identity": function(parameters) {
+
+ var layer = getLayer(parseInt(parameters[0]));
+
+ layer.setTransform(1, 0, 0, 1, 0, 0);
+
+ },
+
+ "lfill": function(parameters) {
+
+ var channelMask = parseInt(parameters[0]);
+ var layer = getLayer(parseInt(parameters[1]));
+ var srcLayer = getLayer(parseInt(parameters[2]));
+
+ layer.setChannelMask(channelMask);
+
+ layer.fillLayer(srcLayer);
+
+ },
+
+ "line": function(parameters) {
+
+ var layer = getLayer(parseInt(parameters[0]));
+ var x = parseInt(parameters[1]);
+ var y = parseInt(parameters[2]);
+
+ layer.lineTo(x, y);
+
+ },
+
+ "lstroke": function(parameters) {
+
+ var channelMask = parseInt(parameters[0]);
+ var layer = getLayer(parseInt(parameters[1]));
+ var srcLayer = getLayer(parseInt(parameters[2]));
+
+ layer.setChannelMask(channelMask);
+
+ layer.strokeLayer(srcLayer);
+
+ },
+
+ "move": function(parameters) {
+
+ var layer_index = parseInt(parameters[0]);
+ var parent_index = parseInt(parameters[1]);
+ var x = parseInt(parameters[2]);
+ var y = parseInt(parameters[3]);
+ var z = parseInt(parameters[4]);
+
+ // Only valid for non-default layers
+ if (layer_index > 0 && parent_index >= 0) {
+
+ // Get container element
+ var layer_container = getLayerContainer(layer_index);
+ var layer_container_element = layer_container.getElement();
+ var parent = getLayerContainer(parent_index).getElement();
+
+ // Set parent if necessary
+ if (!(layer_container_element.parentNode === parent))
+ parent.appendChild(layer_container_element);
+
+ // Move layer
+ layer_container.translate(x, y);
+ layer_container_element.style.zIndex = z;
+
+ }
+
+ },
+
+ "name": function(parameters) {
+ if (guac_client.onname) guac_client.onname(parameters[0]);
+ },
+
+ "png": function(parameters) {
+
+ var channelMask = parseInt(parameters[0]);
+ var layer = getLayer(parseInt(parameters[1]));
+ var x = parseInt(parameters[2]);
+ var y = parseInt(parameters[3]);
+ var data = parameters[4];
+
+ layer.setChannelMask(channelMask);
+
+ layer.draw(
+ x,
+ y,
+ "data:image/png;base64," + data
+ );
+
+ // If received first update, no longer waiting.
+ if (currentState == STATE_WAITING)
+ setState(STATE_CONNECTED);
+
+ },
+
+ "pop": function(parameters) {
+
+ var layer = getLayer(parseInt(parameters[0]));
+
+ layer.pop();
+
+ },
+
+ "push": function(parameters) {
+
+ var layer = getLayer(parseInt(parameters[0]));
+
+ layer.push();
+
+ },
+
+ "rect": function(parameters) {
+
+ var layer = getLayer(parseInt(parameters[0]));
+ var x = parseInt(parameters[1]);
+ var y = parseInt(parameters[2]);
+ var w = parseInt(parameters[3]);
+ var h = parseInt(parameters[4]);
+
+ layer.rect(x, y, w, h);
+
+ },
+
+ "reset": function(parameters) {
+
+ var layer = getLayer(parseInt(parameters[0]));
+
+ layer.reset();
+
+ },
+
+ "set": function(parameters) {
+
+ var layer = getLayer(parseInt(parameters[0]));
+ var name = parameters[1];
+ var value = parameters[2];
+
+ // Call property handler if defined
+ var handler = layerPropertyHandlers[name];
+ if (handler)
+ handler(layer, value);
+
+ },
+
+ "shade": function(parameters) {
+
+ var layer_index = parseInt(parameters[0]);
+ var a = parseInt(parameters[1]);
+
+ // Only valid for visible layers (not buffers)
+ if (layer_index >= 0) {
+
+ // Get container element
+ var layer_container = getLayerContainer(layer_index).getElement();
+
+ // Set layer opacity
+ layer_container.style.opacity = a/255.0;
+
+ }
+
+ },
+
+ "size": function(parameters) {
+
+ var layer_index = parseInt(parameters[0]);
+ var width = parseInt(parameters[1]);
+ var height = parseInt(parameters[2]);
+
+ // If not buffer, resize layer and container
+ if (layer_index >= 0) {
+
+ // Resize layer
+ var layer_container = getLayerContainer(layer_index);
+ layer_container.resize(width, height);
+
+ // If layer is default, resize display
+ if (layer_index == 0) {
+
+ displayWidth = width;
+ displayHeight = height;
+
+ // Update (set) display size
+ display.style.width = displayWidth + "px";
+ display.style.height = displayHeight + "px";
+
+ // Update bounds size
+ bounds.style.width = (displayWidth*displayScale) + "px";
+ bounds.style.height = (displayHeight*displayScale) + "px";
+
+ }
+
+ }
+
+ // If buffer, resize layer only
+ else {
+ var layer = getBufferLayer(parseInt(parameters[0]));
+ layer.resize(width, height);
+ }
+
+ },
+
+ "start": function(parameters) {
+
+ var layer = getLayer(parseInt(parameters[0]));
+ var x = parseInt(parameters[1]);
+ var y = parseInt(parameters[2]);
+
+ layer.moveTo(x, y);
+
+ },
+
+ "sync": function(parameters) {
+
+ var timestamp = parameters[0];
+
+ // When all layers have finished rendering all instructions
+ // UP TO THIS POINT IN TIME, send sync response.
+
+ var layersToSync = 0;
+ function syncLayer() {
+
+ layersToSync--;
+
+ // Send sync response when layers are finished
+ if (layersToSync == 0) {
+ if (timestamp != currentTimestamp) {
+ tunnel.sendMessage("sync", timestamp);
+ currentTimestamp = timestamp;
+ }
+ }
+
+ }
+
+ // Count active, not-ready layers and install sync tracking hooks
+ for (var i=0; i<layers.length; i++) {
+
+ var layer = layers[i].getLayer();
+ if (layer && !layer.isReady()) {
+ layersToSync++;
+ layer.sync(syncLayer);
+ }
+
+ }
+
+ // If all layers are ready, then we didn't install any hooks.
+ // Send sync message now,
+ if (layersToSync == 0) {
+ if (timestamp != currentTimestamp) {
+ tunnel.sendMessage("sync", timestamp);
+ currentTimestamp = timestamp;
+ }
+ }
+
+ },
+
+ "transfer": function(parameters) {
+
+ var srcL = getLayer(parseInt(parameters[0]));
+ var srcX = parseInt(parameters[1]);
+ var srcY = parseInt(parameters[2]);
+ var srcWidth = parseInt(parameters[3]);
+ var srcHeight = parseInt(parameters[4]);
+ var transferFunction = Guacamole.Client.DefaultTransferFunction[parameters[5]];
+ var dstL = getLayer(parseInt(parameters[6]));
+ var dstX = parseInt(parameters[7]);
+ var dstY = parseInt(parameters[8]);
+
+ dstL.transfer(
+ srcL,
+ srcX,
+ srcY,
+ srcWidth,
+ srcHeight,
+ dstX,
+ dstY,
+ transferFunction
+ );
+
+ },
+
+ "transform": function(parameters) {
+
+ var layer = getLayer(parseInt(parameters[0]));
+ var a = parseFloat(parameters[1]);
+ var b = parseFloat(parameters[2]);
+ var c = parseFloat(parameters[3]);
+ var d = parseFloat(parameters[4]);
+ var e = parseFloat(parameters[5]);
+ var f = parseFloat(parameters[6]);
+
+ layer.transform(a, b, c, d, e, f);
+
+ }
+
+ };
+
+
+ tunnel.oninstruction = function(opcode, parameters) {
+
+ var handler = instructionHandlers[opcode];
+ if (handler)
+ handler(parameters);
+
+ };
+
+
+ this.disconnect = function() {
+
+ // Only attempt disconnection not disconnected.
+ if (currentState != STATE_DISCONNECTED
+ && currentState != STATE_DISCONNECTING) {
+
+ setState(STATE_DISCONNECTING);
+
+ // Stop ping
+ if (pingInterval)
+ window.clearInterval(pingInterval);
+
+ // Send disconnect message and disconnect
+ tunnel.sendMessage("disconnect");
+ tunnel.disconnect();
+ setState(STATE_DISCONNECTED);
+
+ }
+
+ };
+
+ this.connect = function(data) {
+
+ setState(STATE_CONNECTING);
+
+ try {
+ tunnel.connect(data);
+ }
+ catch (e) {
+ setState(STATE_IDLE);
+ throw e;
+ }
+
+ // Ping every 5 seconds (ensure connection alive)
+ pingInterval = window.setInterval(function() {
+ tunnel.sendMessage("sync", currentTimestamp);
+ }, 5000);
+
+ setState(STATE_WAITING);
+ };
+
+ this.scale = function(scale) {
+
+ display.style.transform =
+ display.style.WebkitTransform =
+ display.style.MozTransform =
+ display.style.OTransform =
+ display.style.msTransform =
+
+ "scale(" + scale + "," + scale + ")";
+
+ displayScale = scale;
+
+ // Update bounds size
+ bounds.style.width = (displayWidth*displayScale) + "px";
+ bounds.style.height = (displayHeight*displayScale) + "px";
+
+ };
+
+ this.getScale = function() {
+ return displayScale;
+ };
+
+};
+
+/**
+ * Simple container for Guacamole.Layer, allowing layers to be easily
+ * repositioned and nested. This allows certain operations to be accelerated
+ * through DOM manipulation, rather than raster operations.
+ *
+ * @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.Client.LayerContainer = function(width, height) {
+
+ /**
+ * Reference to this LayerContainer.
+ * @private
+ */
+ var layer_container = this;
+
+ // Create layer with given size
+ var layer = new Guacamole.Layer(width, height);
+
+ // Set layer position
+ var canvas = layer.getCanvas();
+ canvas.style.position = "absolute";
+ canvas.style.left = "0px";
+ canvas.style.top = "0px";
+
+ // Create div with given size
+ var div = document.createElement("div");
+ div.appendChild(canvas);
+ div.style.width = width + "px";
+ div.style.height = height + "px";
+
+ /**
+ * Changes the size of this LayerContainer and the contained Layer to the
+ * given width and height.
+ *
+ * @param {Number} width The new width to assign to this Layer.
+ * @param {Number} height The new height to assign to this Layer.
+ */
+ this.resize = function(width, height) {
+
+ // Resize layer
+ layer.resize(width, height);
+
+ // Resize containing div
+ div.style.width = width + "px";
+ div.style.height = height + "px";
+
+ };
+
+ /**
+ * Returns the Layer contained within this LayerContainer.
+ * @returns {Guacamole.Layer} The Layer contained within this LayerContainer.
+ */
+ this.getLayer = function() {
+ return layer;
+ };
+
+ /**
+ * Returns the element containing the Layer within this LayerContainer.
+ * @returns {Element} The element containing the Layer within this LayerContainer.
+ */
+ this.getElement = function() {
+ return div;
+ };
+
+ /**
+ * The translation component of this LayerContainer's transform.
+ * @private
+ */
+ var translate = "translate(0px, 0px)"; // (0, 0)
+
+ /**
+ * The arbitrary matrix component of this LayerContainer's transform.
+ * @private
+ */
+ var matrix = "matrix(1, 0, 0, 1, 0, 0)"; // Identity
+
+ /**
+ * Moves the upper-left corner of this LayerContainer to the given X and Y
+ * coordinate.
+ *
+ * @param {Number} x The X coordinate to move to.
+ * @param {Number} y The Y coordinate to move to.
+ */
+ this.translate = function(x, y) {
+
+ // Generate translation
+ translate = "translate("
+ + x + "px,"
+ + y + "px)";
+
+ // Set layer transform
+ div.style.transform =
+ div.style.WebkitTransform =
+ div.style.MozTransform =
+ div.style.OTransform =
+ div.style.msTransform =
+
+ translate + " " + matrix;
+
+ };
+
+ /**
+ * Applies the given affine transform (defined with six values from the
+ * transform's matrix).
+ *
+ * @param {Number} a The first value in the affine transform's matrix.
+ * @param {Number} b The second value in the affine transform's matrix.
+ * @param {Number} c The third value in the affine transform's matrix.
+ * @param {Number} d The fourth value in the affine transform's matrix.
+ * @param {Number} e The fifth value in the affine transform's matrix.
+ * @param {Number} f The sixth value in the affine transform's matrix.
+ */
+ this.transform = function(a, b, c, d, e, f) {
+
+ // Generate matrix transformation
+ matrix =
+
+ /* a c e
+ * b d f
+ * 0 0 1
+ */
+
+ "matrix(" + a + "," + b + "," + c + "," + d + "," + e + "," + f + ")";
+
+ // Set layer transform
+ div.style.transform =
+ div.style.WebkitTransform =
+ div.style.MozTransform =
+ div.style.OTransform =
+ div.style.msTransform =
+
+ translate + " " + matrix;
+
+ };
+
+};
+
+/**
+ * Map of all Guacamole binary raster operations to transfer functions.
+ * @private
+ */
+Guacamole.Client.DefaultTransferFunction = {
+
+ /* BLACK */
+ 0x0: function (src, dst) {
+ dst.red = dst.green = dst.blue = 0x00;
+ },
+
+ /* WHITE */
+ 0xF: function (src, dst) {
+ dst.red = dst.green = dst.blue = 0xFF;
+ },
+
+ /* SRC */
+ 0x3: function (src, dst) {
+ dst.red = src.red;
+ dst.green = src.green;
+ dst.blue = src.blue;
+ dst.alpha = src.alpha;
+ },
+
+ /* DEST (no-op) */
+ 0x5: function (src, dst) {
+ // Do nothing
+ },
+
+ /* Invert SRC */
+ 0xC: function (src, dst) {
+ dst.red = 0xFF & ~src.red;
+ dst.green = 0xFF & ~src.green;
+ dst.blue = 0xFF & ~src.blue;
+ dst.alpha = src.alpha;
+ },
+
+ /* Invert DEST */
+ 0xA: function (src, dst) {
+ dst.red = 0xFF & ~dst.red;
+ dst.green = 0xFF & ~dst.green;
+ dst.blue = 0xFF & ~dst.blue;
+ },
+
+ /* AND */
+ 0x1: function (src, dst) {
+ dst.red = ( src.red & dst.red);
+ dst.green = ( src.green & dst.green);
+ dst.blue = ( src.blue & dst.blue);
+ },
+
+ /* NAND */
+ 0xE: function (src, dst) {
+ dst.red = 0xFF & ~( src.red & dst.red);
+ dst.green = 0xFF & ~( src.green & dst.green);
+ dst.blue = 0xFF & ~( src.blue & dst.blue);
+ },
+
+ /* OR */
+ 0x7: function (src, dst) {
+ dst.red = ( src.red | dst.red);
+ dst.green = ( src.green | dst.green);
+ dst.blue = ( src.blue | dst.blue);
+ },
+
+ /* NOR */
+ 0x8: function (src, dst) {
+ dst.red = 0xFF & ~( src.red | dst.red);
+ dst.green = 0xFF & ~( src.green | dst.green);
+ dst.blue = 0xFF & ~( src.blue | dst.blue);
+ },
+
+ /* XOR */
+ 0x6: function (src, dst) {
+ dst.red = ( src.red ^ dst.red);
+ dst.green = ( src.green ^ dst.green);
+ dst.blue = ( src.blue ^ dst.blue);
+ },
+
+ /* XNOR */
+ 0x9: function (src, dst) {
+ dst.red = 0xFF & ~( src.red ^ dst.red);
+ dst.green = 0xFF & ~( src.green ^ dst.green);
+ dst.blue = 0xFF & ~( src.blue ^ dst.blue);
+ },
+
+ /* AND inverted source */
+ 0x4: function (src, dst) {
+ dst.red = 0xFF & (~src.red & dst.red);
+ dst.green = 0xFF & (~src.green & dst.green);
+ dst.blue = 0xFF & (~src.blue & dst.blue);
+ },
+
+ /* OR inverted source */
+ 0xD: function (src, dst) {
+ dst.red = 0xFF & (~src.red | dst.red);
+ dst.green = 0xFF & (~src.green | dst.green);
+ dst.blue = 0xFF & (~src.blue | dst.blue);
+ },
+
+ /* AND inverted destination */
+ 0x2: function (src, dst) {
+ dst.red = 0xFF & ( src.red & ~dst.red);
+ dst.green = 0xFF & ( src.green & ~dst.green);
+ dst.blue = 0xFF & ( src.blue & ~dst.blue);
+ },
+
+ /* OR inverted destination */
+ 0xB: function (src, dst) {
+ dst.red = 0xFF & ( src.red | ~dst.red);
+ dst.green = 0xFF & ( src.green | ~dst.green);
+ dst.blue = 0xFF & ( src.blue | ~dst.blue);
+ }
+
+};
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/guacamole-common-js/keyboard.js
^
|
@@ -0,0 +1,550 @@
+
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is guacamole-common-js.
+ *
+ * The Initial Developer of the Original Code is
+ * Michael Jumper.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Namespace for all Guacamole JavaScript objects.
+ * @namespace
+ */
+var Guacamole = Guacamole || {};
+
+/**
+ * Provides cross-browser and cross-keyboard keyboard for a specific element.
+ * Browser and keyboard layout variation is abstracted away, providing events
+ * which represent keys as their corresponding X11 keysym.
+ *
+ * @constructor
+ * @param {Element} element The Element to use to provide keyboard events.
+ */
+Guacamole.Keyboard = function(element) {
+
+ /**
+ * Reference to this Guacamole.Keyboard.
+ * @private
+ */
+ var guac_keyboard = this;
+
+ /**
+ * Fired whenever the user presses a key with the element associated
+ * with this Guacamole.Keyboard in focus.
+ *
+ * @event
+ * @param {Number} keysym The keysym of the key being pressed.
+ */
+ this.onkeydown = null;
+
+ /**
+ * Fired whenever the user releases a key with the element associated
+ * with this Guacamole.Keyboard in focus.
+ *
+ * @event
+ * @param {Number} keysym The keysym of the key being released.
+ */
+ this.onkeyup = null;
+
+ /**
+ * Map of known JavaScript keycodes which do not map to typable characters
+ * to their unshifted X11 keysym equivalents.
+ * @private
+ */
+ var unshiftedKeySym = {
+ 8: 0xFF08, // backspace
+ 9: 0xFF09, // tab
+ 13: 0xFF0D, // enter
+ 16: 0xFFE1, // shift
+ 17: 0xFFE3, // ctrl
+ 18: 0xFFE9, // alt
+ 19: 0xFF13, // pause/break
+ 20: 0xFFE5, // caps lock
+ 27: 0xFF1B, // escape
+ 32: 0x0020, // space
+ 33: 0xFF55, // page up
+ 34: 0xFF56, // page down
+ 35: 0xFF57, // end
+ 36: 0xFF50, // home
+ 37: 0xFF51, // left arrow
+ 38: 0xFF52, // up arrow
+ 39: 0xFF53, // right arrow
+ 40: 0xFF54, // down arrow
+ 45: 0xFF63, // insert
+ 46: 0xFFFF, // delete
+ 91: 0xFFEB, // left window key (super_l)
+ 92: 0xFF67, // right window key (menu key?)
+ 93: null, // select key
+ 112: 0xFFBE, // f1
+ 113: 0xFFBF, // f2
+ 114: 0xFFC0, // f3
+ 115: 0xFFC1, // f4
+ 116: 0xFFC2, // f5
+ 117: 0xFFC3, // f6
+ 118: 0xFFC4, // f7
+ 119: 0xFFC5, // f8
+ 120: 0xFFC6, // f9
+ 121: 0xFFC7, // f10
+ 122: 0xFFC8, // f11
+ 123: 0xFFC9, // f12
+ 144: 0xFF7F, // num lock
+ 145: 0xFF14 // scroll lock
+ };
+
+ /**
+ * Map of known JavaScript keyidentifiers which do not map to typable
+ * characters to their unshifted X11 keysym equivalents.
+ * @private
+ */
+ var keyidentifier_keysym = {
+ "AllCandidates": 0xFF3D,
+ "Alphanumeric": 0xFF30,
+ "Alt": 0xFFE9,
+ "Attn": 0xFD0E,
+ "AltGraph": 0xFFEA,
+ "CapsLock": 0xFFE5,
+ "Clear": 0xFF0B,
+ "Convert": 0xFF21,
+ "Copy": 0xFD15,
+ "Crsel": 0xFD1C,
+ "CodeInput": 0xFF37,
+ "Control": 0xFFE3,
+ "Down": 0xFF54,
+ "End": 0xFF57,
+ "Enter": 0xFF0D,
+ "EraseEof": 0xFD06,
+ "Execute": 0xFF62,
+ "Exsel": 0xFD1D,
+ "F1": 0xFFBE,
+ "F2": 0xFFBF,
+ "F3": 0xFFC0,
+ "F4": 0xFFC1,
+ "F5": 0xFFC2,
+ "F6": 0xFFC3,
+ "F7": 0xFFC4,
+ "F8": 0xFFC5,
+ "F9": 0xFFC6,
+ "F10": 0xFFC7,
+ "F11": 0xFFC8,
+ "F12": 0xFFC9,
+ "F13": 0xFFCA,
+ "F14": 0xFFCB,
+ "F15": 0xFFCC,
+ "F16": 0xFFCD,
+ "F17": 0xFFCE,
+ "F18": 0xFFCF,
+ "F19": 0xFFD0,
+ "F20": 0xFFD1,
+ "F21": 0xFFD2,
+ "F22": 0xFFD3,
+ "F23": 0xFFD4,
+ "F24": 0xFFD5,
+ "Find": 0xFF68,
+ "FullWidth": null,
+ "HalfWidth": null,
+ "HangulMode": 0xFF31,
+ "HanjaMode": 0xFF34,
+ "Help": 0xFF6A,
+ "Hiragana": 0xFF25,
+ "Home": 0xFF50,
+ "Insert": 0xFF63,
+ "JapaneseHiragana": 0xFF25,
+ "JapaneseKatakana": 0xFF26,
+ "JapaneseRomaji": 0xFF24,
+ "JunjaMode": 0xFF38,
+ "KanaMode": 0xFF2D,
+ "KanjiMode": 0xFF21,
+ "Katakana": 0xFF26,
+ "Left": 0xFF51,
+ "Meta": 0xFFE7,
+ "NumLock": 0xFF7F,
+ "PageDown": 0xFF55,
+ "PageUp": 0xFF56,
+ "Pause": 0xFF13,
+ "PreviousCandidate": 0xFF3E,
+ "PrintScreen": 0xFD1D,
+ "Right": 0xFF53,
+ "RomanCharacters": null,
+ "Scroll": 0xFF14,
+ "Select": 0xFF60,
+ "Shift": 0xFFE1,
+ "Up": 0xFF52,
+ "Undo": 0xFF65,
+ "Win": 0xFFEB
+ };
+
+ /**
+ * Map of known JavaScript keycodes which do not map to typable characters
+ * to their shifted X11 keysym equivalents. Keycodes must only be listed
+ * here if their shifted X11 keysym equivalents differ from their unshifted
+ * equivalents.
+ * @private
+ */
+ var shiftedKeySym = {
+ 18: 0xFFE7 // alt
+ };
+
+ /**
+ * All modifiers and their states.
+ */
+ this.modifiers = {
+
+ /**
+ * Whether shift is currently pressed.
+ */
+ "shift": false,
+
+ /**
+ * Whether ctrl is currently pressed.
+ */
+ "ctrl" : false,
+
+ /**
+ * Whether alt is currently pressed.
+ */
+ "alt" : false
+
+ };
+
+ /**
+ * The state of every key, indexed by keysym. If a particular key is
+ * pressed, the value of pressed for that keysym will be true. If a key
+ * is not currently pressed, the value for that keysym may be false or
+ * undefined.
+ */
+ this.pressed = [];
+
+ var keydownChar = new Array();
+
+ // ID of routine repeating keystrokes. -1 = not repeating.
+ var repeatKeyTimeoutId = -1;
+ var repeatKeyIntervalId = -1;
+
+ // Starts repeating keystrokes
+ function startRepeat(keySym) {
+ repeatKeyIntervalId = setInterval(function() {
+ sendKeyReleased(keySym);
+ sendKeyPressed(keySym);
+ }, 50);
+ }
+
+ // Stops repeating keystrokes
+ function stopRepeat() {
+ if (repeatKeyTimeoutId != -1) clearTimeout(repeatKeyTimeoutId);
+ if (repeatKeyIntervalId != -1) clearInterval(repeatKeyIntervalId);
+ }
+
+
+ function getKeySymFromKeyIdentifier(shifted, keyIdentifier) {
+
+ var unicodePrefixLocation = keyIdentifier.indexOf("U+");
+ if (unicodePrefixLocation >= 0) {
+
+ var hex = keyIdentifier.substring(unicodePrefixLocation+2);
+ var codepoint = parseInt(hex, 16);
+ var typedCharacter;
+
+ // Convert case if shifted
+ if (shifted == 0)
+ typedCharacter = String.fromCharCode(codepoint).toLowerCase();
+ else
+ typedCharacter = String.fromCharCode(codepoint).toUpperCase();
+
+ // Get codepoint
+ codepoint = typedCharacter.charCodeAt(0);
+
+ return getKeySymFromCharCode(codepoint);
+
+ }
+
+ return keyidentifier_keysym[keyIdentifier];
+
+ }
+
+ function isControlCharacter(codepoint) {
+ return codepoint <= 0x1F || (codepoint >= 0x7F && codepoint <= 0x9F);
+ }
+
+ function getKeySymFromCharCode(codepoint) {
+
+ // Keysyms for control characters
+ if (isControlCharacter(codepoint)) return 0xFF00 | codepoint;
+
+ // Keysyms for ASCII chars
+ if (codepoint >= 0x0000 && codepoint <= 0x00FF)
+ return codepoint;
+
+ // Keysyms for Unicode
+ if (codepoint >= 0x0100 && codepoint <= 0x10FFFF)
+ return 0x01000000 | codepoint;
+
+ return null;
+
+ }
+
+ function getKeySymFromKeyCode(keyCode) {
+
+ var keysym = null;
+ if (!guac_keyboard.modifiers.shift) keysym = unshiftedKeySym[keyCode];
+ else {
+ keysym = shiftedKeySym[keyCode];
+ if (keysym == null) keysym = unshiftedKeySym[keyCode];
+ }
+
+ return keysym;
+
+ }
+
+
+ // Sends a single keystroke over the network
+ function sendKeyPressed(keysym) {
+
+ // Mark key as pressed
+ guac_keyboard.pressed[keysym] = true;
+
+ // Send key event
+ if (keysym != null && guac_keyboard.onkeydown)
+ guac_keyboard.onkeydown(keysym);
+
+ }
+
+ // Sends a single keystroke over the network
+ function sendKeyReleased(keysym) {
+
+ // Mark key as released
+ guac_keyboard.pressed[keysym] = false;
+
+ // Send key event
+ if (keysym != null && guac_keyboard.onkeyup)
+ guac_keyboard.onkeyup(keysym);
+
+ }
+
+
+ var expect_keypress = true;
+ var keydown_code = null;
+
+ var deferred_keypress = null;
+ var keydown_keysym = null;
+ var keypress_keysym = null;
+
+ function handleKeyEvents() {
+
+ // Prefer keysym from keypress
+ var keysym = keypress_keysym || keydown_keysym;
+ var keynum = keydown_code;
+
+ if (keydownChar[keynum] != keysym) {
+
+ // If this button is already pressed, release first
+ var lastKeyDownChar = keydownChar[keydown_code];
+ if (lastKeyDownChar)
+ sendKeyReleased(lastKeyDownChar);
+
+ // Send event
+ keydownChar[keynum] = keysym;
+ sendKeyPressed(keysym);
+
+ // Clear old key repeat, if any.
+ stopRepeat();
+
+ // Start repeating (if not a modifier key) after a short delay
+ if (keynum != 16 && keynum != 17 && keynum != 18)
+ repeatKeyTimeoutId = setTimeout(function() { startRepeat(keysym); }, 500);
+
+ }
+
+ // Done with deferred key event
+ deferred_keypress = null;
+ keypress_keysym = null;
+ keydown_keysym = null;
+ keydown_code = null;
+
+ }
+
+ function isTypable(keyIdentifier) {
+
+ // Find unicode prefix
+ var unicodePrefixLocation = keyIdentifier.indexOf("U+");
+ if (unicodePrefixLocation == -1)
+ return false;
+
+ // Parse codepoint value
+ var hex = keyIdentifier.substring(unicodePrefixLocation+2);
+ var codepoint = parseInt(hex, 16);
+
+ // If control character, not typable
+ if (isControlCharacter(codepoint)) return false;
+
+ // Otherwise, typable
+ return true;
+
+ }
+
+ // When key pressed
+ element.addEventListener("keydown", function(e) {
+
+ // Only intercept if handler set
+ if (!guac_keyboard.onkeydown) return;
+
+ var keynum;
+ if (window.event) keynum = window.event.keyCode;
+ else if (e.which) keynum = e.which;
+
+ // Ignore any unknown key events
+ if (keynum == 0 && !e.keyIdentifier) {
+ e.preventDefault();
+ return;
+ }
+
+ expect_keypress = true;
+
+ // Ctrl/Alt/Shift
+ if (keynum == 16) guac_keyboard.modifiers.shift = true;
+ else if (keynum == 17) guac_keyboard.modifiers.ctrl = true;
+ else if (keynum == 18) guac_keyboard.modifiers.alt = true;
+
+ // Try to get keysym from keycode
+ keydown_keysym = getKeySymFromKeyCode(keynum);
+
+ // If key is known from keycode, prevent default
+ if (keydown_keysym)
+ expect_keypress = false;
+
+ // Also try to get get keysym from keyIdentifier
+ if (e.keyIdentifier) {
+
+ keydown_keysym = keydown_keysym ||
+ getKeySymFromKeyIdentifier(guac_keyboard.modifiers.shift, e.keyIdentifier);
+
+ // Prevent default if non-typable character or if modifier combination
+ // likely to be eaten by browser otherwise (NOTE: We must not prevent
+ // default for Ctrl+Alt, as that combination is commonly used for
+ // AltGr. If we receive AltGr, we need to handle keypress, which
+ // means we cannot cancel keydown).
+ if (!isTypable(e.keyIdentifier)
+ || ( guac_keyboard.modifiers.ctrl && !guac_keyboard.modifiers.alt)
+ || (!guac_keyboard.modifiers.ctrl && guac_keyboard.modifiers.alt))
+ expect_keypress = false;
+
+ }
+
+ // Set keycode which will be associated with any future keypress
+ keydown_code = keynum;
+
+ // If we expect to handle via keypress, set failsafe timeout and
+ // wait for keypress.
+ if (expect_keypress) {
+ if (!deferred_keypress)
+ deferred_keypress = window.setTimeout(handleKeyEvents, 0);
+ }
+
+ // Otherwise, handle now
+ else {
+ e.preventDefault();
+ handleKeyEvents();
+ }
+
+ }, true);
+
+ // When key pressed
+ element.addEventListener("keypress", function(e) {
+
+ // Only intercept if handler set
+ if (!guac_keyboard.onkeydown) return;
+
+ e.preventDefault();
+
+ // Do not handle if we weren't expecting this event (will have already
+ // been handled by keydown)
+ if (!expect_keypress) return;
+
+ var keynum;
+ if (window.event) keynum = window.event.keyCode;
+ else if (e.which) keynum = e.which;
+
+ keypress_keysym = getKeySymFromCharCode(keynum);
+
+ // If event identified as a typable character, and we're holding Ctrl+Alt,
+ // assume Ctrl+Alt is actually AltGr, and release both.
+ if (!isControlCharacter(keynum) && guac_keyboard.modifiers.ctrl && guac_keyboard.modifiers.alt) {
+ sendKeyReleased(0xFFE3);
+ sendKeyReleased(0xFFE9);
+ }
+
+ // Clear timeout, if any
+ if (deferred_keypress)
+ window.clearTimeout(deferred_keypress);
+
+ // Handle event with all aggregated data
+ handleKeyEvents();
+
+ }, true);
+
+ // When key released
+ element.addEventListener("keyup", function(e) {
+
+ // Only intercept if handler set
+ if (!guac_keyboard.onkeyup) return;
+
+ e.preventDefault();
+
+ var keynum;
+ if (window.event) keynum = window.event.keyCode;
+ else if (e.which) keynum = e.which;
+
+ // Ctrl/Alt/Shift
+ if (keynum == 16) guac_keyboard.modifiers.shift = false;
+ else if (keynum == 17) guac_keyboard.modifiers.ctrl = false;
+ else if (keynum == 18) guac_keyboard.modifiers.alt = false;
+ else
+ stopRepeat();
+
+ // Get corresponding character
+ var lastKeyDownChar = keydownChar[keynum];
+
+ // Clear character record
+ keydownChar[keynum] = null;
+
+ // Send release event
+ sendKeyReleased(lastKeyDownChar);
+
+ }, true);
+
+ // When focus is lost, clear modifiers.
+ element.addEventListener("blur", function() {
+ guac_keyboard.modifiers.alt = false;
+ guac_keyboard.modifiers.ctrl = false;
+ guac_keyboard.modifiers.shift = false;
+ }, true);
+
+};
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/guacamole-common-js/layer.js
^
|
@@ -0,0 +1,1103 @@
+
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is guacamole-common-js.
+ *
+ * The Initial Developer of the Original Code is
+ * Michael Jumper.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Namespace for all Guacamole JavaScript objects.
+ * @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) {
+
+ /**
+ * Reference to this Layer.
+ * @private
+ */
+ var layer = this;
+
+ /**
+ * The canvas element backing this Layer.
+ * @private
+ */
+ var display = document.createElement("canvas");
+
+ /**
+ * The 2D display context of the canvas element backing this Layer.
+ * @private
+ */
+ var displayContext = display.getContext("2d");
+ displayContext.save();
+
+ /**
+ * The queue of all pending Tasks. Tasks will be run in order, with new
+ * tasks added at the end of the queue and old tasks removed from the
+ * front of the queue (FIFO).
+ * @private
+ */
+ var tasks = new Array();
+
+ /**
+ * Whether a new path should be started with the next path drawing
+ * operations.
+ * @private
+ */
+ var pathClosed = true;
+
+ /**
+ * The number of states on the state stack.
+ *
+ * Note that there will ALWAYS be one element on the stack, but that
+ * element is not exposed. It is only used to reset the layer to its
+ * initial state.
+ *
+ * @private
+ */
+ var stackSize = 0;
+
+ /**
+ * Map of all Guacamole channel masks to HTML5 canvas composite operation
+ * names. Not all channel mask combinations are currently implemented.
+ * @private
+ */
+ var compositeOperation = {
+ /* 0x0 NOT IMPLEMENTED */
+ 0x1: "destination-in",
+ 0x2: "destination-out",
+ /* 0x3 NOT IMPLEMENTED */
+ 0x4: "source-in",
+ /* 0x5 NOT IMPLEMENTED */
+ 0x6: "source-atop",
+ /* 0x7 NOT IMPLEMENTED */
+ 0x8: "source-out",
+ 0x9: "destination-atop",
+ 0xA: "xor",
+ 0xB: "destination-over",
+ 0xC: "copy",
+ /* 0xD NOT IMPLEMENTED */
+ 0xE: "source-over",
+ 0xF: "lighter"
+ };
+
+ /**
+ * Resizes the canvas element backing this Layer without testing the
+ * new size. This function should only be used internally.
+ *
+ * @private
+ * @param {Number} newWidth The new width to assign to this Layer.
+ * @param {Number} newHeight The new height to assign to this Layer.
+ */
+ function resize(newWidth, newHeight) {
+
+ // Only preserve old data if width/height are both non-zero
+ var oldData = null;
+ if (width != 0 && height != 0) {
+
+ // Create canvas and context for holding old data
+ oldData = document.createElement("canvas");
+ oldData.width = width;
+ oldData.height = height;
+
+ var oldDataContext = oldData.getContext("2d");
+
+ // Copy image data from current
+ oldDataContext.drawImage(display,
+ 0, 0, width, height,
+ 0, 0, width, height);
+
+ }
+
+ // Preserve composite operation
+ var oldCompositeOperation = displayContext.globalCompositeOperation;
+
+ // Resize canvas
+ display.width = newWidth;
+ display.height = newHeight;
+
+ // Redraw old data, if any
+ if (oldData)
+ displayContext.drawImage(oldData,
+ 0, 0, width, height,
+ 0, 0, width, height);
+
+ // Restore composite operation
+ displayContext.globalCompositeOperation = oldCompositeOperation;
+
+ width = newWidth;
+ height = newHeight;
+
+ // Acknowledge reset of stack (happens on resize of canvas)
+ stackSize = 0;
+ displayContext.save();
+
+ }
+
+ /**
+ * Given the X and Y coordinates of the upper-left corner of a rectangle
+ * and the rectangle's width and height, resize the backing canvas element
+ * as necessary to ensure that the rectangle fits within the canvas
+ * element's coordinate space. This function will only make the canvas
+ * larger. If the rectangle already fits within the canvas element's
+ * coordinate space, the canvas is left unchanged.
+ *
+ * @private
+ * @param {Number} x The X coordinate of the upper-left corner of the
+ * rectangle to fit.
+ * @param {Number} y The Y coordinate of the upper-left corner of the
+ * rectangle to fit.
+ * @param {Number} w The width of the the rectangle to fit.
+ * @param {Number} h The height of the the rectangle to fit.
+ */
+ function fitRect(x, y, w, h) {
+
+ // Calculate bounds
+ var opBoundX = w + x;
+ var opBoundY = h + y;
+
+ // Determine max width
+ var resizeWidth;
+ if (opBoundX > width)
+ resizeWidth = opBoundX;
+ else
+ resizeWidth = width;
+
+ // Determine max height
+ var resizeHeight;
+ if (opBoundY > height)
+ resizeHeight = opBoundY;
+ else
+ resizeHeight = height;
+
+ // Resize if necessary
+ if (resizeWidth != width || resizeHeight != height)
+ resize(resizeWidth, resizeHeight);
+
+ }
+
+ /**
+ * A container for an task handler. Each operation which must be ordered
+ * is associated with a Task that goes into a task queue. Tasks in this
+ * queue are executed in order once their handlers are set, while Tasks
+ * without handlers block themselves and any following Tasks from running.
+ *
+ * @constructor
+ * @private
+ * @param {function} taskHandler The function to call when this task
+ * runs, if any.
+ * @param {boolean} blocked Whether this task should start blocked.
+ */
+ function Task(taskHandler, blocked) {
+
+ var task = this;
+
+ /**
+ * Whether this Task is blocked.
+ *
+ * @type boolean
+ */
+ this.blocked = blocked;
+
+ /**
+ * The handler this Task is associated with, if any.
+ *
+ * @type function
+ */
+ this.handler = taskHandler;
+
+ /**
+ * Unblocks this Task, allowing it to run.
+ */
+ this.unblock = function() {
+ task.blocked = false;
+ handlePendingTasks();
+ }
+
+ }
+
+ /**
+ * If no tasks are pending or running, run the provided handler immediately,
+ * if any. Otherwise, schedule a task to run immediately after all currently
+ * running or pending tasks are complete.
+ *
+ * @private
+ * @param {function} handler The function to call when possible, if any.
+ * @param {boolean} blocked Whether the task should start blocked.
+ * @returns {Task} The Task created and added to the queue for future
+ * running, if any, or null if the handler was run
+ * immediately and no Task needed to be created.
+ */
+ function scheduleTask(handler, blocked) {
+
+ // If no pending tasks, just call (if available) and exit
+ if (layer.isReady() && !blocked) {
+ if (handler) handler();
+ return null;
+ }
+
+ // If tasks are pending/executing, schedule a pending task
+ // and return a reference to it.
+ var task = new Task(handler, blocked);
+ tasks.push(task);
+ return task;
+
+ }
+
+ var tasksInProgress = false;
+
+ /**
+ * Run any Tasks which were pending but are now ready to run and are not
+ * blocked by other Tasks.
+ * @private
+ */
+ function handlePendingTasks() {
+
+ if (tasksInProgress)
+ return;
+
+ tasksInProgress = true;
+
+ // Draw all pending tasks.
+ var task;
+ while ((task = tasks[0]) != null && !task.blocked) {
+ tasks.shift();
+ if (task.handler) task.handler();
+ }
+
+ tasksInProgress = false;
+
+ }
+
+ /**
+ * Schedules a task within the current layer just as scheduleTast() does,
+ * except that another specified layer will be blocked until this task
+ * completes, and this task will not start until the other layer is
+ * ready.
+ *
+ * Essentially, a task is scheduled in both layers, and the specified task
+ * will only be performed once both layers are ready, and neither layer may
+ * proceed until this task completes.
+ *
+ * Note that there is no way to specify whether the task starts blocked,
+ * as whether the task is blocked depends completely on whether the
+ * other layer is currently ready.
+ *
+ * @private
+ * @param {Guacamole.Layer} otherLayer The other layer which must be blocked
+ * until this task completes.
+ * @param {function} handler The function to call when possible.
+ */
+ function scheduleTaskSynced(otherLayer, handler) {
+
+ // If we ARE the other layer, no need to sync.
+ // Syncing would result in deadlock.
+ if (layer === otherLayer)
+ scheduleTask(handler);
+
+ // Otherwise synchronize operation with other layer
+ else {
+
+ var drawComplete = false;
+ var layerLock = null;
+
+ function performTask() {
+
+ // Perform task
+ handler();
+
+ // Unblock the other layer now that draw is complete
+ if (layerLock != null)
+ layerLock.unblock();
+
+ // Flag operation as done
+ drawComplete = true;
+
+ }
+
+ // Currently blocked draw task
+ var task = scheduleTask(performTask, true);
+
+ // Unblock draw task once source layer is ready
+ otherLayer.sync(task.unblock);
+
+ // Block other layer until draw completes
+ // Note that the draw MAY have already been performed at this point,
+ // in which case creating a lock on the other layer will lead to
+ // deadlock (the draw task has already run and will thus never
+ // clear the lock)
+ if (!drawComplete)
+ layerLock = otherLayer.sync(null, true);
+
+ }
+ }
+
+ /**
+ * Set to true if this Layer should resize itself to accomodate the
+ * dimensions of any drawing operation, and false (the default) otherwise.
+ *
+ * Note that setting this property takes effect immediately, and thus may
+ * take effect on operations that were started in the past but have not
+ * yet completed. If you wish the setting of this flag to only modify
+ * future operations, you will need to make the setting of this flag an
+ * operation with sync().
+ *
+ * @example
+ * // Set autosize to true for all future operations
+ * layer.sync(function() {
+ * layer.autosize = true;
+ * });
+ *
+ * @type Boolean
+ * @default false
+ */
+ this.autosize = false;
+
+ /**
+ * Returns the canvas element backing this Layer.
+ * @returns {Element} The canvas element backing this Layer.
+ */
+ this.getCanvas = function() {
+ return display;
+ };
+
+ /**
+ * Returns whether this Layer is ready. A Layer is ready if it has no
+ * pending operations and no operations in-progress.
+ *
+ * @returns {Boolean} true if this Layer is ready, false otherwise.
+ */
+ this.isReady = function() {
+ return tasks.length == 0;
+ };
+
+ /**
+ * 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) {
+ scheduleTask(function() {
+ if (newWidth != width || newHeight != height)
+ resize(newWidth, newHeight);
+ });
+ };
+
+ /**
+ * Draws the specified image at the given coordinates. The image specified
+ * must already be loaded.
+ *
+ * @param {Number} x The destination X coordinate.
+ * @param {Number} y The destination Y coordinate.
+ * @param {Image} image The image to draw. Note that this is an Image
+ * object - not a URL.
+ */
+ this.drawImage = function(x, y, image) {
+ scheduleTask(function() {
+ if (layer.autosize != 0) fitRect(x, y, image.width, image.height);
+ displayContext.drawImage(image, x, y);
+ });
+ };
+
+ /**
+ * Draws the image at the specified URL at the given coordinates. The image
+ * will be loaded automatically, and this and any future operations will
+ * wait for the image to finish loading.
+ *
+ * @param {Number} x The destination X coordinate.
+ * @param {Number} y The destination Y coordinate.
+ * @param {String} url The URL of the image to draw.
+ */
+ this.draw = function(x, y, url) {
+
+ var task = scheduleTask(function() {
+ if (layer.autosize != 0) fitRect(x, y, image.width, image.height);
+ displayContext.drawImage(image, x, y);
+ }, true);
+
+ var image = new Image();
+ image.onload = task.unblock;
+ image.src = url;
+
+ };
+
+ /**
+ * 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.
+ * @param {boolean} blocked Whether the task should start blocked.
+ */
+ this.sync = scheduleTask;
+
+ /**
+ * Transfer a rectangle of image data from one Layer to this Layer using the
+ * specified transfer function.
+ *
+ * @param {Guacamole.Layer} srcLayer The Layer to copy image data from.
+ * @param {Number} srcx The X coordinate of the upper-left corner of the
+ * rectangle within the source Layer's coordinate
+ * space to copy data from.
+ * @param {Number} srcy The Y coordinate of the upper-left corner of the
+ * rectangle within the source Layer's coordinate
+ * space to copy data from.
+ * @param {Number} srcw The width of the rectangle within the source Layer's
+ * coordinate space to copy data from.
+ * @param {Number} srch The height of the rectangle within the source
+ * Layer's coordinate space to copy data from.
+ * @param {Number} x The destination X coordinate.
+ * @param {Number} y The destination Y coordinate.
+ * @param {Function} transferFunction The transfer function to use to
+ * transfer data from source to
+ * destination.
+ */
+ this.transfer = function(srcLayer, srcx, srcy, srcw, srch, x, y, transferFunction) {
+ scheduleTaskSynced(srcLayer, function() {
+
+ if (layer.autosize != 0) fitRect(x, y, srcw, srch);
+
+ var srcCanvas = srcLayer.getCanvas();
+ if (srcCanvas.width != 0 && srcCanvas.height != 0) {
+
+ // Get image data from src and dst
+ var src = srcLayer.getCanvas().getContext("2d").getImageData(srcx, srcy, srcw, srch);
+ var dst = displayContext.getImageData(x , y, srcw, srch);
+
+ // Apply transfer for each pixel
+ for (var i=0; i<srcw*srch*4; i+=4) {
+
+ // Get source pixel environment
+ var src_pixel = new Guacamole.Layer.Pixel(
+ src.data[i],
+ src.data[i+1],
+ src.data[i+2],
+ src.data[i+3]
+ );
+
+ // Get destination pixel environment
+ var dst_pixel = new Guacamole.Layer.Pixel(
+ dst.data[i],
+ dst.data[i+1],
+ dst.data[i+2],
+ dst.data[i+3]
+ );
+
+ // Apply transfer function
+ transferFunction(src_pixel, dst_pixel);
+
+ // Save pixel data
+ dst.data[i ] = dst_pixel.red;
+ dst.data[i+1] = dst_pixel.green;
+ dst.data[i+2] = dst_pixel.blue;
+ dst.data[i+3] = dst_pixel.alpha;
+
+ }
+
+ // Draw image data
+ displayContext.putImageData(dst, x, y);
+
+ }
+
+ });
+ };
+
+ /**
+ * Copy a rectangle of image data from one Layer to this Layer. This
+ * operation will copy exactly the image data that will be drawn once all
+ * operations of the source Layer that were pending at the time this
+ * function was called are complete. This operation will not alter the
+ * size of the source Layer even if its autosize property is set to true.
+ *
+ * @param {Guacamole.Layer} srcLayer The Layer to copy image data from.
+ * @param {Number} srcx The X coordinate of the upper-left corner of the
+ * rectangle within the source Layer's coordinate
+ * space to copy data from.
+ * @param {Number} srcy The Y coordinate of the upper-left corner of the
+ * rectangle within the source Layer's coordinate
+ * space to copy data from.
+ * @param {Number} srcw The width of the rectangle within the source Layer's
+ * coordinate space to copy data from.
+ * @param {Number} srch The height of the rectangle within the source
+ * Layer's coordinate space to copy data from.
+ * @param {Number} x The destination X coordinate.
+ * @param {Number} y The destination Y coordinate.
+ */
+ this.copy = function(srcLayer, srcx, srcy, srcw, srch, x, y) {
+ scheduleTaskSynced(srcLayer, function() {
+ if (layer.autosize != 0) fitRect(x, y, srcw, srch);
+
+ var srcCanvas = srcLayer.getCanvas();
+ if (srcCanvas.width != 0 && srcCanvas.height != 0)
+ displayContext.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch);
+
+ });
+ };
+
+ /**
+ * Starts a new path at the specified point.
+ *
+ * @param {Number} x The X coordinate of the point to draw.
+ * @param {Number} y The Y coordinate of the point to draw.
+ */
+ this.moveTo = function(x, y) {
+ scheduleTask(function() {
+
+ // Start a new path if current path is closed
+ if (pathClosed) {
+ displayContext.beginPath();
+ pathClosed = false;
+ }
+
+ if (layer.autosize != 0) fitRect(x, y, 0, 0);
+ displayContext.moveTo(x, y);
+
+ });
+ };
+
+ /**
+ * Add the specified line to the current path.
+ *
+ * @param {Number} x The X coordinate of the endpoint of the line to draw.
+ * @param {Number} y The Y coordinate of the endpoint of the line to draw.
+ */
+ this.lineTo = function(x, y) {
+ scheduleTask(function() {
+
+ // Start a new path if current path is closed
+ if (pathClosed) {
+ displayContext.beginPath();
+ pathClosed = false;
+ }
+
+ if (layer.autosize != 0) fitRect(x, y, 0, 0);
+ displayContext.lineTo(x, y);
+
+ });
+ };
+
+ /**
+ * Add the specified arc to the current path.
+ *
+ * @param {Number} x The X coordinate of the center of the circle which
+ * will contain the arc.
+ * @param {Number} y The Y coordinate of the center of the circle which
+ * will contain the arc.
+ * @param {Number} radius The radius of the circle.
+ * @param {Number} startAngle The starting angle of the arc, in radians.
+ * @param {Number} endAngle The ending angle of the arc, in radians.
+ * @param {Boolean} negative Whether the arc should be drawn in order of
+ * decreasing angle.
+ */
+ this.arc = function(x, y, radius, startAngle, endAngle, negative) {
+ scheduleTask(function() {
+
+ // Start a new path if current path is closed
+ if (pathClosed) {
+ displayContext.beginPath();
+ pathClosed = false;
+ }
+
+ if (layer.autosize != 0) fitRect(x, y, 0, 0);
+ displayContext.arc(x, y, radius, startAngle, endAngle, negative);
+
+ });
+ };
+
+ /**
+ * Starts a new path at the specified point.
+ *
+ * @param {Number} cp1x The X coordinate of the first control point.
+ * @param {Number} cp1y The Y coordinate of the first control point.
+ * @param {Number} cp2x The X coordinate of the second control point.
+ * @param {Number} cp2y The Y coordinate of the second control point.
+ * @param {Number} x The X coordinate of the endpoint of the curve.
+ * @param {Number} y The Y coordinate of the endpoint of the curve.
+ */
+ this.curveTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {
+ scheduleTask(function() {
+
+ // Start a new path if current path is closed
+ if (pathClosed) {
+ displayContext.beginPath();
+ pathClosed = false;
+ }
+
+ if (layer.autosize != 0) fitRect(x, y, 0, 0);
+ displayContext.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
+
+ });
+ };
+
+ /**
+ * Closes the current path by connecting the end point with the start
+ * point (if any) with a straight line.
+ */
+ this.close = function() {
+ scheduleTask(function() {
+
+ // Close path
+ displayContext.closePath();
+ pathClosed = true;
+
+ });
+ };
+
+ /**
+ * Add the specified rectangle to the current path.
+ *
+ * @param {Number} x The X coordinate of the upper-left corner of the
+ * rectangle to draw.
+ * @param {Number} y The Y coordinate of the upper-left corner of the
+ * rectangle to draw.
+ * @param {Number} w The width of the rectangle to draw.
+ * @param {Number} h The height of the rectangle to draw.
+ */
+ this.rect = function(x, y, w, h) {
+ scheduleTask(function() {
+
+ // Start a new path if current path is closed
+ if (pathClosed) {
+ displayContext.beginPath();
+ pathClosed = false;
+ }
+
+ if (layer.autosize != 0) fitRect(x, y, w, h);
+ displayContext.rect(x, y, w, h);
+
+ });
+ };
+
+ /**
+ * Clip all future drawing operations by the current path. The current path
+ * is implicitly closed. The current path can continue to be reused
+ * for other operations (such as fillColor()) but a new path will be started
+ * once a path drawing operation (path() or rect()) is used.
+ */
+ this.clip = function() {
+ scheduleTask(function() {
+
+ // Set new clipping region
+ displayContext.clip();
+
+ // Path now implicitly closed
+ pathClosed = true;
+
+ });
+ };
+
+ /**
+ * Stroke the current path with the specified color. The current path
+ * is implicitly closed. The current path can continue to be reused
+ * for other operations (such as clip()) but a new path will be started
+ * once a path drawing operation (path() or rect()) is used.
+ *
+ * @param {String} cap The line cap style. Can be "round", "square",
+ * or "butt".
+ * @param {String} join The line join style. Can be "round", "bevel",
+ * or "miter".
+ * @param {Number} thickness The line thickness in pixels.
+ * @param {Number} r The red component of the color to fill.
+ * @param {Number} g The green component of the color to fill.
+ * @param {Number} b The blue component of the color to fill.
+ * @param {Number} a The alpha component of the color to fill.
+ */
+ this.strokeColor = function(cap, join, thickness, r, g, b, a) {
+ scheduleTask(function() {
+
+ // Stroke with color
+ displayContext.lineCap = cap;
+ displayContext.lineJoin = join;
+ displayContext.lineWidth = thickness;
+ displayContext.strokeStyle = "rgba(" + r + "," + g + "," + b + "," + a/255.0 + ")";
+ displayContext.stroke();
+
+ // Path now implicitly closed
+ pathClosed = true;
+
+ });
+ };
+
+ /**
+ * Fills the current path with the specified color. The current path
+ * is implicitly closed. The current path can continue to be reused
+ * for other operations (such as clip()) but a new path will be started
+ * once a path drawing operation (path() or rect()) is used.
+ *
+ * @param {Number} r The red component of the color to fill.
+ * @param {Number} g The green component of the color to fill.
+ * @param {Number} b The blue component of the color to fill.
+ * @param {Number} a The alpha component of the color to fill.
+ */
+ this.fillColor = function(r, g, b, a) {
+ scheduleTask(function() {
+
+ // Fill with color
+ displayContext.fillStyle = "rgba(" + r + "," + g + "," + b + "," + a/255.0 + ")";
+ displayContext.fill();
+
+ // Path now implicitly closed
+ pathClosed = true;
+
+ });
+ };
+
+ /**
+ * Stroke the current path with the image within the specified layer. The
+ * image data will be tiled infinitely within the stroke. The current path
+ * is implicitly closed. The current path can continue to be reused
+ * for other operations (such as clip()) but a new path will be started
+ * once a path drawing operation (path() or rect()) is used.
+ *
+ * @param {String} cap The line cap style. Can be "round", "square",
+ * or "butt".
+ * @param {String} join The line join style. Can be "round", "bevel",
+ * or "miter".
+ * @param {Number} thickness The line thickness in pixels.
+ * @param {Guacamole.Layer} srcLayer The layer to use as a repeating pattern
+ * within the stroke.
+ */
+ this.strokeLayer = function(cap, join, thickness, srcLayer) {
+ scheduleTaskSynced(srcLayer, function() {
+
+ // Stroke with image data
+ displayContext.lineCap = cap;
+ displayContext.lineJoin = join;
+ displayContext.lineWidth = thickness;
+ displayContext.strokeStyle = displayContext.createPattern(
+ srcLayer.getCanvas(),
+ "repeat"
+ );
+ displayContext.stroke();
+
+ // Path now implicitly closed
+ pathClosed = true;
+
+ });
+ };
+
+ /**
+ * Fills the current path with the image within the specified layer. The
+ * image data will be tiled infinitely within the stroke. The current path
+ * is implicitly closed. The current path can continue to be reused
+ * for other operations (such as clip()) but a new path will be started
+ * once a path drawing operation (path() or rect()) is used.
+ *
+ * @param {Guacamole.Layer} srcLayer The layer to use as a repeating pattern
+ * within the fill.
+ */
+ this.fillLayer = function(srcLayer) {
+ scheduleTask(function() {
+
+ // Fill with image data
+ displayContext.fillStyle = displayContext.createPattern(
+ srcLayer.getCanvas(),
+ "repeat"
+ );
+ displayContext.fill();
+
+ // Path now implicitly closed
+ pathClosed = true;
+
+ });
+ };
+
+ /**
+ * Push current layer state onto stack.
+ */
+ this.push = function() {
+ scheduleTask(function() {
+
+ // Save current state onto stack
+ displayContext.save();
+ stackSize++;
+
+ });
+ };
+
+ /**
+ * Pop layer state off stack.
+ */
+ this.pop = function() {
+ scheduleTask(function() {
+
+ // Restore current state from stack
+ if (stackSize > 0) {
+ displayContext.restore();
+ stackSize--;
+ }
+
+ });
+ };
+
+ /**
+ * Reset the layer, clearing the stack, the current path, and any transform
+ * matrix.
+ */
+ this.reset = function() {
+ scheduleTask(function() {
+
+ // Clear stack
+ while (stackSize > 0) {
+ displayContext.restore();
+ stackSize--;
+ }
+
+ // Restore to initial state
+ displayContext.restore();
+ displayContext.save();
+
+ // Clear path
+ displayContext.beginPath();
+ pathClosed = false;
+
+ });
+ };
+
+ /**
+ * Sets the given affine transform (defined with six values from the
+ * transform's matrix).
+ *
+ * @param {Number} a The first value in the affine transform's matrix.
+ * @param {Number} b The second value in the affine transform's matrix.
+ * @param {Number} c The third value in the affine transform's matrix.
+ * @param {Number} d The fourth value in the affine transform's matrix.
+ * @param {Number} e The fifth value in the affine transform's matrix.
+ * @param {Number} f The sixth value in the affine transform's matrix.
+ */
+ this.setTransform = function(a, b, c, d, e, f) {
+ scheduleTask(function() {
+
+ // Set transform
+ displayContext.setTransform(
+ a, b, c,
+ d, e, f
+ /*0, 0, 1*/
+ );
+
+ });
+ };
+
+
+ /**
+ * Applies the given affine transform (defined with six values from the
+ * transform's matrix).
+ *
+ * @param {Number} a The first value in the affine transform's matrix.
+ * @param {Number} b The second value in the affine transform's matrix.
+ * @param {Number} c The third value in the affine transform's matrix.
+ * @param {Number} d The fourth value in the affine transform's matrix.
+ * @param {Number} e The fifth value in the affine transform's matrix.
+ * @param {Number} f The sixth value in the affine transform's matrix.
+ */
+ this.transform = function(a, b, c, d, e, f) {
+ scheduleTask(function() {
+
+ // Apply transform
+ displayContext.transform(
+ a, b, c,
+ d, e, f
+ /*0, 0, 1*/
+ );
+
+ });
+ };
+
+
+ /**
+ * Sets the channel mask for future operations on this Layer.
+ *
+ * The channel mask is a Guacamole-specific compositing operation identifier
+ * with a single bit representing each of four channels (in order): source
+ * image where destination transparent, source where destination opaque,
+ * destination where source transparent, and destination where source
+ * opaque.
+ *
+ * @param {Number} mask The channel mask for future operations on this
+ * Layer.
+ */
+ this.setChannelMask = function(mask) {
+ scheduleTask(function() {
+ displayContext.globalCompositeOperation = compositeOperation[mask];
+ });
+ };
+
+ /**
+ * Sets the miter limit for stroke operations using the miter join. This
+ * limit is the maximum ratio of the size of the miter join to the stroke
+ * width. If this ratio is exceeded, the miter will not be drawn for that
+ * joint of the path.
+ *
+ * @param {Number} limit The miter limit for stroke operations using the
+ * miter join.
+ */
+ this.setMiterLimit = function(limit) {
+ scheduleTask(function() {
+ displayContext.miterLimit = limit;
+ });
+ };
+
+ // Initialize canvas dimensions
+ display.width = width;
+ display.height = height;
+
+};
+
+/**
+ * Channel mask for the composite operation "rout".
+ */
+Guacamole.Layer.ROUT = 0x2;
+
+/**
+ * Channel mask for the composite operation "atop".
+ */
+Guacamole.Layer.ATOP = 0x6;
+
+/**
+ * Channel mask for the composite operation "xor".
+ */
+Guacamole.Layer.XOR = 0xA;
+
+/**
+ * Channel mask for the composite operation "rover".
+ */
+Guacamole.Layer.ROVER = 0xB;
+
+/**
+ * Channel mask for the composite operation "over".
+ */
+Guacamole.Layer.OVER = 0xE;
+
+/**
+ * Channel mask for the composite operation "plus".
+ */
+Guacamole.Layer.PLUS = 0xF;
+
+/**
+ * Channel mask for the composite operation "rin".
+ * Beware that WebKit-based browsers may leave the contents of the destionation
+ * layer where the source layer is transparent, despite the definition of this
+ * operation.
+ */
+Guacamole.Layer.RIN = 0x1;
+
+/**
+ * Channel mask for the composite operation "in".
+ * Beware that WebKit-based browsers may leave the contents of the destionation
+ * layer where the source layer is transparent, despite the definition of this
+ * operation.
+ */
+Guacamole.Layer.IN = 0x4;
+
+/**
+ * Channel mask for the composite operation "out".
+ * Beware that WebKit-based browsers may leave the contents of the destionation
+ * layer where the source layer is transparent, despite the definition of this
+ * operation.
+ */
+Guacamole.Layer.OUT = 0x8;
+
+/**
+ * Channel mask for the composite operation "ratop".
+ * Beware that WebKit-based browsers may leave the contents of the destionation
+ * layer where the source layer is transparent, despite the definition of this
+ * operation.
+ */
+Guacamole.Layer.RATOP = 0x9;
+
+/**
+ * Channel mask for the composite operation "src".
+ * Beware that WebKit-based browsers may leave the contents of the destionation
+ * layer where the source layer is transparent, despite the definition of this
+ * operation.
+ */
+Guacamole.Layer.SRC = 0xC;
+
+
+/**
+ * Represents a single pixel of image data. All components have a minimum value
+ * of 0 and a maximum value of 255.
+ *
+ * @constructor
+ *
+ * @param {Number} r The red component of this pixel.
+ * @param {Number} g The green component of this pixel.
+ * @param {Number} b The blue component of this pixel.
+ * @param {Number} a The alpha component of this pixel.
+ */
+Guacamole.Layer.Pixel = function(r, g, b, a) {
+
+ /**
+ * The red component of this pixel, where 0 is the minimum value,
+ * and 255 is the maximum.
+ */
+ this.red = r;
+
+ /**
+ * The green component of this pixel, where 0 is the minimum value,
+ * and 255 is the maximum.
+ */
+ this.green = g;
+
+ /**
+ * The blue component of this pixel, where 0 is the minimum value,
+ * and 255 is the maximum.
+ */
+ this.blue = b;
+
+ /**
+ * The alpha component of this pixel, where 0 is the minimum value,
+ * and 255 is the maximum.
+ */
+ this.alpha = a;
+
+};
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/guacamole-common-js/mouse.js
^
|
@@ -0,0 +1,785 @@
+
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is guacamole-common-js.
+ *
+ * The Initial Developer of the Original Code is
+ * Michael Jumper.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Namespace for all Guacamole JavaScript objects.
+ * @namespace
+ */
+var Guacamole = Guacamole || {};
+
+/**
+ * Provides cross-browser mouse events for a given element. The events of
+ * the given element are automatically populated with handlers that translate
+ * mouse events into a non-browser-specific event provided by the
+ * Guacamole.Mouse instance.
+ *
+ * @constructor
+ * @param {Element} element The Element to use to provide mouse events.
+ */
+Guacamole.Mouse = function(element) {
+
+ /**
+ * Reference to this Guacamole.Mouse.
+ * @private
+ */
+ var guac_mouse = this;
+
+ /**
+ * The number of mousemove events to require before re-enabling mouse
+ * event handling after receiving a touch event.
+ */
+ this.touchMouseThreshold = 3;
+
+ /**
+ * The current mouse state. The properties of this state are updated when
+ * mouse events fire. This state object is also passed in as a parameter to
+ * the handler of any mouse events.
+ *
+ * @type Guacamole.Mouse.State
+ */
+ this.currentState = new Guacamole.Mouse.State(
+ 0, 0,
+ false, false, false, false, false
+ );
+
+ /**
+ * Fired whenever the user presses a mouse button down over the element
+ * associated with this Guacamole.Mouse.
+ *
+ * @event
+ * @param {Guacamole.Mouse.State} state The current mouse state.
+ */
+ this.onmousedown = null;
+
+ /**
+ * Fired whenever the user releases a mouse button down over the element
+ * associated with this Guacamole.Mouse.
+ *
+ * @event
+ * @param {Guacamole.Mouse.State} state The current mouse state.
+ */
+ this.onmouseup = null;
+
+ /**
+ * Fired whenever the user moves the mouse over the element associated with
+ * this Guacamole.Mouse.
+ *
+ * @event
+ * @param {Guacamole.Mouse.State} state The current mouse state.
+ */
+ this.onmousemove = null;
+
+ /**
+ * Counter of mouse events to ignore. This decremented by mousemove, and
+ * while non-zero, mouse events will have no effect.
+ * @private
+ */
+ var ignore_mouse = 0;
+
+ function cancelEvent(e) {
+ e.stopPropagation();
+ if (e.preventDefault) e.preventDefault();
+ e.returnValue = false;
+ }
+
+ // Block context menu so right-click gets sent properly
+ element.addEventListener("contextmenu", function(e) {
+ cancelEvent(e);
+ }, false);
+
+ element.addEventListener("mousemove", function(e) {
+
+ cancelEvent(e);
+
+ // If ignoring events, decrement counter
+ if (ignore_mouse) {
+ ignore_mouse--;
+ return;
+ }
+
+ guac_mouse.currentState.fromClientPosition(element, e.clientX, e.clientY);
+
+ if (guac_mouse.onmousemove)
+ guac_mouse.onmousemove(guac_mouse.currentState);
+
+ }, false);
+
+ element.addEventListener("mousedown", function(e) {
+
+ cancelEvent(e);
+
+ // Do not handle if ignoring events
+ if (ignore_mouse)
+ return;
+
+ switch (e.button) {
+ case 0:
+ guac_mouse.currentState.left = true;
+ break;
+ case 1:
+ guac_mouse.currentState.middle = true;
+ break;
+ case 2:
+ guac_mouse.currentState.right = true;
+ break;
+ }
+
+ if (guac_mouse.onmousedown)
+ guac_mouse.onmousedown(guac_mouse.currentState);
+
+ }, false);
+
+ element.addEventListener("mouseup", function(e) {
+
+ cancelEvent(e);
+
+ // Do not handle if ignoring events
+ if (ignore_mouse)
+ return;
+
+ switch (e.button) {
+ case 0:
+ guac_mouse.currentState.left = false;
+ break;
+ case 1:
+ guac_mouse.currentState.middle = false;
+ break;
+ case 2:
+ guac_mouse.currentState.right = false;
+ break;
+ }
+
+ if (guac_mouse.onmouseup)
+ guac_mouse.onmouseup(guac_mouse.currentState);
+
+ }, false);
+
+ element.addEventListener("mouseout", function(e) {
+
+ // Get parent of the element the mouse pointer is leaving
+ if (!e) e = window.event;
+
+ // Check that mouseout is due to actually LEAVING the element
+ var target = e.relatedTarget || e.toElement;
+ while (target != null) {
+ if (target === element)
+ return;
+ target = target.parentNode;
+ }
+
+ cancelEvent(e);
+
+ // Release all buttons
+ if (guac_mouse.currentState.left
+ || guac_mouse.currentState.middle
+ || guac_mouse.currentState.right) {
+
+ guac_mouse.currentState.left = false;
+ guac_mouse.currentState.middle = false;
+ guac_mouse.currentState.right = false;
+
+ if (guac_mouse.onmouseup)
+ guac_mouse.onmouseup(guac_mouse.currentState);
+ }
+
+ }, false);
+
+ // Override selection on mouse event element.
+ element.addEventListener("selectstart", function(e) {
+ cancelEvent(e);
+ }, false);
+
+ // Ignore all pending mouse events when touch events are the apparent source
+ function ignorePendingMouseEvents() { ignore_mouse = guac_mouse.touchMouseThreshold; }
+
+ element.addEventListener("touchmove", ignorePendingMouseEvents, false);
+ element.addEventListener("touchstart", ignorePendingMouseEvents, false);
+ element.addEventListener("touchend", ignorePendingMouseEvents, false);
+
+ // Scroll wheel support
+ function mousewheel_handler(e) {
+
+ var delta = 0;
+ if (e.detail)
+ delta = e.detail;
+ else if (e.wheelDelta)
+ delta = -event.wheelDelta;
+
+ // Up
+ if (delta < 0) {
+ if (guac_mouse.onmousedown) {
+ guac_mouse.currentState.up = true;
+ guac_mouse.onmousedown(guac_mouse.currentState);
+ }
+
+ if (guac_mouse.onmouseup) {
+ guac_mouse.currentState.up = false;
+ guac_mouse.onmouseup(guac_mouse.currentState);
+ }
+ }
+
+ // Down
+ if (delta > 0) {
+ if (guac_mouse.onmousedown) {
+ guac_mouse.currentState.down = true;
+ guac_mouse.onmousedown(guac_mouse.currentState);
+ }
+
+ if (guac_mouse.onmouseup) {
+ guac_mouse.currentState.down = false;
+ guac_mouse.onmouseup(guac_mouse.currentState);
+ }
+ }
+
+ cancelEvent(e);
+
+ }
+ element.addEventListener('DOMMouseScroll', mousewheel_handler, false);
+ element.addEventListener('mousewheel', mousewheel_handler, false);
+
+};
+
+
+/**
+ * Provides cross-browser relative touch event translation for a given element.
+ *
+ * Touch events are translated into mouse events as if the touches occurred
+ * on a touchpad (drag to push the mouse pointer, tap to click).
+ *
+ * @constructor
+ * @param {Element} element The Element to use to provide touch events.
+ */
+Guacamole.Mouse.Touchpad = function(element) {
+
+ /**
+ * Reference to this Guacamole.Mouse.Touchpad.
+ * @private
+ */
+ var guac_touchpad = this;
+
+ /**
+ * The distance a two-finger touch must move per scrollwheel event, in
+ * pixels.
+ */
+ this.scrollThreshold = 20 * (window.devicePixelRatio || 1);
+
+ /**
+ * The maximum number of milliseconds to wait for a touch to end for the
+ * gesture to be considered a click.
+ */
+ this.clickTimingThreshold = 250;
+
+ /**
+ * The maximum number of pixels to allow a touch to move for the gesture to
+ * be considered a click.
+ */
+ this.clickMoveThreshold = 10 * (window.devicePixelRatio || 1);
+
+ /**
+ * The current mouse state. The properties of this state are updated when
+ * mouse events fire. This state object is also passed in as a parameter to
+ * the handler of any mouse events.
+ *
+ * @type Guacamole.Mouse.State
+ */
+ this.currentState = new Guacamole.Mouse.State(
+ 0, 0,
+ false, false, false, false, false
+ );
+
+ /**
+ * Fired whenever a mouse button is effectively pressed. This can happen
+ * as part of a "click" gesture initiated by the user by tapping one
+ * or more fingers over the touchpad element, as part of a "scroll"
+ * gesture initiated by dragging two fingers up or down, etc.
+ *
+ * @event
+ * @param {Guacamole.Mouse.State} state The current mouse state.
+ */
+ this.onmousedown = null;
+
+ /**
+ * Fired whenever a mouse button is effectively released. This can happen
+ * as part of a "click" gesture initiated by the user by tapping one
+ * or more fingers over the touchpad element, as part of a "scroll"
+ * gesture initiated by dragging two fingers up or down, etc.
+ *
+ * @event
+ * @param {Guacamole.Mouse.State} state The current mouse state.
+ */
+ this.onmouseup = null;
+
+ /**
+ * Fired whenever the user moves the mouse by dragging their finger over
+ * the touchpad element.
+ *
+ * @event
+ * @param {Guacamole.Mouse.State} state The current mouse state.
+ */
+ this.onmousemove = null;
+
+ var touch_count = 0;
+ var last_touch_x = 0;
+ var last_touch_y = 0;
+ var last_touch_time = 0;
+ var pixels_moved = 0;
+
+ var touch_buttons = {
+ 1: "left",
+ 2: "right",
+ 3: "middle"
+ };
+
+ var gesture_in_progress = false;
+ var click_release_timeout = null;
+
+ element.addEventListener("touchend", function(e) {
+
+ e.stopPropagation();
+ e.preventDefault();
+
+ // If we're handling a gesture AND this is the last touch
+ if (gesture_in_progress && e.touches.length == 0) {
+
+ var time = new Date().getTime();
+
+ // Get corresponding mouse button
+ var button = touch_buttons[touch_count];
+
+ // If mouse already down, release anad clear timeout
+ if (guac_touchpad.currentState[button]) {
+
+ // Fire button up event
+ guac_touchpad.currentState[button] = false;
+ if (guac_touchpad.onmouseup)
+ guac_touchpad.onmouseup(guac_touchpad.currentState);
+
+ // Clear timeout, if set
+ if (click_release_timeout) {
+ window.clearTimeout(click_release_timeout);
+ click_release_timeout = null;
+ }
+
+ }
+
+ // If single tap detected (based on time and distance)
+ if (time - last_touch_time <= guac_touchpad.clickTimingThreshold
+ && pixels_moved < guac_touchpad.clickMoveThreshold) {
+
+ // Fire button down event
+ guac_touchpad.currentState[button] = true;
+ if (guac_touchpad.onmousedown)
+ guac_touchpad.onmousedown(guac_touchpad.currentState);
+
+ // Delay mouse up - mouse up should be canceled if
+ // touchstart within timeout.
+ click_release_timeout = window.setTimeout(function() {
+
+ // Fire button up event
+ guac_touchpad.currentState[button] = false;
+ if (guac_touchpad.onmouseup)
+ guac_touchpad.onmouseup(guac_touchpad.currentState);
+
+ // Gesture now over
+ gesture_in_progress = false;
+
+ }, guac_touchpad.clickTimingThreshold);
+
+ }
+
+ // If we're not waiting to see if this is a click, stop gesture
+ if (!click_release_timeout)
+ gesture_in_progress = false;
+
+ }
+
+ }, false);
+
+ element.addEventListener("touchstart", function(e) {
+
+ e.stopPropagation();
+ e.preventDefault();
+
+ // Track number of touches, but no more than three
+ touch_count = Math.min(e.touches.length, 3);
+
+ // Clear timeout, if set
+ if (click_release_timeout) {
+ window.clearTimeout(click_release_timeout);
+ click_release_timeout = null;
+ }
+
+ // Record initial touch location and time for touch movement
+ // and tap gestures
+ if (!gesture_in_progress) {
+
+ // Stop mouse events while touching
+ gesture_in_progress = true;
+
+ // Record touch location and time
+ var starting_touch = e.touches[0];
+ last_touch_x = starting_touch.clientX;
+ last_touch_y = starting_touch.clientY;
+ last_touch_time = new Date().getTime();
+ pixels_moved = 0;
+
+ }
+
+ }, false);
+
+ element.addEventListener("touchmove", function(e) {
+
+ e.stopPropagation();
+ e.preventDefault();
+
+ // Get change in touch location
+ var touch = e.touches[0];
+ var delta_x = touch.clientX - last_touch_x;
+ var delta_y = touch.clientY - last_touch_y;
+
+ // Track pixels moved
+ pixels_moved += Math.abs(delta_x) + Math.abs(delta_y);
+
+ // If only one touch involved, this is mouse move
+ if (touch_count == 1) {
+
+ // Calculate average velocity in Manhatten pixels per millisecond
+ var velocity = pixels_moved / (new Date().getTime() - last_touch_time);
+
+ // Scale mouse movement relative to velocity
+ var scale = 1 + velocity;
+
+ // Update mouse location
+ guac_touchpad.currentState.x += delta_x*scale;
+ guac_touchpad.currentState.y += delta_y*scale;
+
+ // Prevent mouse from leaving screen
+
+ if (guac_touchpad.currentState.x < 0)
+ guac_touchpad.currentState.x = 0;
+ else if (guac_touchpad.currentState.x >= element.offsetWidth)
+ guac_touchpad.currentState.x = element.offsetWidth - 1;
+
+ if (guac_touchpad.currentState.y < 0)
+ guac_touchpad.currentState.y = 0;
+ else if (guac_touchpad.currentState.y >= element.offsetHeight)
+ guac_touchpad.currentState.y = element.offsetHeight - 1;
+
+ // Fire movement event, if defined
+ if (guac_touchpad.onmousemove)
+ guac_touchpad.onmousemove(guac_touchpad.currentState);
+
+ // Update touch location
+ last_touch_x = touch.clientX;
+ last_touch_y = touch.clientY;
+
+ }
+
+ // Interpret two-finger swipe as scrollwheel
+ else if (touch_count == 2) {
+
+ // If change in location passes threshold for scroll
+ if (Math.abs(delta_y) >= guac_touchpad.scrollThreshold) {
+
+ // Decide button based on Y movement direction
+ var button;
+ if (delta_y > 0) button = "down";
+ else button = "up";
+
+ // Fire button down event
+ guac_touchpad.currentState[button] = true;
+ if (guac_touchpad.onmousedown)
+ guac_touchpad.onmousedown(guac_touchpad.currentState);
+
+ // Fire button up event
+ guac_touchpad.currentState[button] = false;
+ if (guac_touchpad.onmouseup)
+ guac_touchpad.onmouseup(guac_touchpad.currentState);
+
+ // Only update touch location after a scroll has been
+ // detected
+ last_touch_x = touch.clientX;
+ last_touch_y = touch.clientY;
+
+ }
+
+ }
+
+ }, false);
+
+};
+
+/**
+ * Provides cross-browser absolute touch event translation for a given element.
+ *
+ * Touch events are translated into mouse events as if the touches occurred
+ * on a touchscreen (tapping anywhere on the screen clicks at that point,
+ * long-press to right-click).
+ *
+ * @constructor
+ * @param {Element} element The Element to use to provide touch events.
+ */
+Guacamole.Mouse.Touchscreen = function(element) {
+
+ /**
+ * Reference to this Guacamole.Mouse.Touchscreen.
+ * @private
+ */
+ var guac_touchscreen = this;
+
+ /**
+ * The distance a two-finger touch must move per scrollwheel event, in
+ * pixels.
+ */
+ this.scrollThreshold = 20 * (window.devicePixelRatio || 1);
+
+ /**
+ * The current mouse state. The properties of this state are updated when
+ * mouse events fire. This state object is also passed in as a parameter to
+ * the handler of any mouse events.
+ *
+ * @type Guacamole.Mouse.State
+ */
+ this.currentState = new Guacamole.Mouse.State(
+ 0, 0,
+ false, false, false, false, false
+ );
+
+ /**
+ * Fired whenever a mouse button is effectively pressed. This can happen
+ * as part of a "mousedown" gesture initiated by the user by pressing one
+ * finger over the touchscreen element, as part of a "scroll" gesture
+ * initiated by dragging two fingers up or down, etc.
+ *
+ * @event
+ * @param {Guacamole.Mouse.State} state The current mouse state.
+ */
+ this.onmousedown = null;
+
+ /**
+ * Fired whenever a mouse button is effectively released. This can happen
+ * as part of a "mouseup" gesture initiated by the user by removing the
+ * finger pressed against the touchscreen element, or as part of a "scroll"
+ * gesture initiated by dragging two fingers up or down, etc.
+ *
+ * @event
+ * @param {Guacamole.Mouse.State} state The current mouse state.
+ */
+ this.onmouseup = null;
+
+ /**
+ * Fired whenever the user moves the mouse by dragging their finger over
+ * the touchscreen element. Note that unlike Guacamole.Mouse.Touchpad,
+ * dragging a finger over the touchscreen element will always cause
+ * the mouse button to be effectively down, as if clicking-and-dragging.
+ *
+ * @event
+ * @param {Guacamole.Mouse.State} state The current mouse state.
+ */
+ this.onmousemove = null;
+
+ element.addEventListener("touchend", function(e) {
+
+ // Ignore if more than one touch
+ if (e.touches.length + e.changedTouches.length != 1)
+ return;
+
+ e.stopPropagation();
+ e.preventDefault();
+
+ // Release button
+ guac_touchscreen.currentState.left = false;
+
+ // Fire release event when the last touch is released, if event defined
+ if (e.touches.length == 0 && guac_touchscreen.onmouseup)
+ guac_touchscreen.onmouseup(guac_touchscreen.currentState);
+
+ }, false);
+
+ element.addEventListener("touchstart", function(e) {
+
+ // Ignore if more than one touch
+ if (e.touches.length != 1)
+ return;
+
+ e.stopPropagation();
+ e.preventDefault();
+
+ // Get touch
+ var touch = e.touches[0];
+
+ // Update state
+ guac_touchscreen.currentState.left = true;
+ guac_touchscreen.currentState.fromClientPosition(element, touch.clientX, touch.clientY);
+
+ // Fire press event, if defined
+ if (guac_touchscreen.onmousedown)
+ guac_touchscreen.onmousedown(guac_touchscreen.currentState);
+
+
+ }, false);
+
+ element.addEventListener("touchmove", function(e) {
+
+ // Ignore if more than one touch
+ if (e.touches.length != 1)
+ return;
+
+ e.stopPropagation();
+ e.preventDefault();
+
+ // Get touch
+ var touch = e.touches[0];
+
+ // Update state
+ guac_touchscreen.currentState.fromClientPosition(element, touch.clientX, touch.clientY);
+
+ // Fire movement event, if defined
+ if (guac_touchscreen.onmousemove)
+ guac_touchscreen.onmousemove(guac_touchscreen.currentState);
+
+ }, false);
+
+};
+
+/**
+ * Simple container for properties describing the state of a mouse.
+ *
+ * @constructor
+ * @param {Number} x The X position of the mouse pointer in pixels.
+ * @param {Number} y The Y position of the mouse pointer in pixels.
+ * @param {Boolean} left Whether the left mouse button is pressed.
+ * @param {Boolean} middle Whether the middle mouse button is pressed.
+ * @param {Boolean} right Whether the right mouse button is pressed.
+ * @param {Boolean} up Whether the up mouse button is pressed (the fourth
+ * button, usually part of a scroll wheel).
+ * @param {Boolean} down Whether the down mouse button is pressed (the fifth
+ * button, usually part of a scroll wheel).
+ */
+Guacamole.Mouse.State = function(x, y, left, middle, right, up, down) {
+
+ /**
+ * Reference to this Guacamole.Mouse.State.
+ * @private
+ */
+ var guac_state = this;
+
+ /**
+ * The current X position of the mouse pointer.
+ * @type Number
+ */
+ this.x = x;
+
+ /**
+ * The current Y position of the mouse pointer.
+ * @type Number
+ */
+ this.y = y;
+
+ /**
+ * Whether the left mouse button is currently pressed.
+ * @type Boolean
+ */
+ this.left = left;
+
+ /**
+ * Whether the middle mouse button is currently pressed.
+ * @type Boolean
+ */
+ this.middle = middle
+
+ /**
+ * Whether the right mouse button is currently pressed.
+ * @type Boolean
+ */
+ this.right = right;
+
+ /**
+ * Whether the up mouse button is currently pressed. This is the fourth
+ * mouse button, associated with upward scrolling of the mouse scroll
+ * wheel.
+ * @type Boolean
+ */
+ this.up = up;
+
+ /**
+ * Whether the down mouse button is currently pressed. This is the fifth
+ * mouse button, associated with downward scrolling of the mouse scroll
+ * wheel.
+ * @type Boolean
+ */
+ this.down = down;
+
+ /**
+ * Updates the position represented within this state object by the given
+ * element and clientX/clientY coordinates (commonly available within event
+ * objects). Position is translated from clientX/clientY (relative to
+ * viewport) to element-relative coordinates.
+ *
+ * @param {Element} element The element the coordinates should be relative
+ * to.
+ * @param {Number} clientX The X coordinate to translate, viewport-relative.
+ * @param {Number} clientY The Y coordinate to translate, viewport-relative.
+ */
+ this.fromClientPosition = function(element, clientX, clientY) {
+
+ guac_state.x = clientX - element.offsetLeft;
+ guac_state.y = clientY - element.offsetTop;
+
+ // This is all JUST so we can get the mouse position within the element
+ var parent = element.offsetParent;
+ while (parent && !(parent === document.body)) {
+ guac_state.x -= parent.offsetLeft - parent.scrollLeft;
+ guac_state.y -= parent.offsetTop - parent.scrollTop;
+
+ parent = parent.offsetParent;
+ }
+
+ // Element ultimately depends on positioning within document body,
+ // take document scroll into account.
+ if (parent) {
+ var documentScrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft;
+ var documentScrollTop = document.body.scrollTop || document.documentElement.scrollTop;
+
+ guac_state.x -= parent.offsetLeft - documentScrollLeft;
+ guac_state.y -= parent.offsetTop - documentScrollTop;
+ }
+
+ };
+
+};
+
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/guacamole-common-js/oskeyboard.js
^
|
@@ -0,0 +1,611 @@
+
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is guac-common-js.
+ *
+ * The Initial Developer of the Original Code is
+ * Michael Jumper.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Namespace for all Guacamole JavaScript objects.
+ * @namespace
+ */
+var Guacamole = Guacamole || {};
+
+/**
+ * Dynamic on-screen keyboard. Given the URL to an XML keyboard layout file,
+ * this object will download and use the XML to construct a clickable on-screen
+ * keyboard with its own key events.
+ *
+ * @constructor
+ * @param {String} url The URL of an XML keyboard layout file.
+ */
+Guacamole.OnScreenKeyboard = function(url) {
+
+ var on_screen_keyboard = this;
+
+ /**
+ * State of all modifiers. This is the bitwise OR of all active modifier
+ * values.
+ *
+ * @private
+ */
+ var modifiers = 0;
+
+ var scaledElements = [];
+
+ var modifier_masks = {};
+ var next_mask = 1;
+
+ /**
+ * Adds a class to an element.
+ *
+ * @private
+ * @function
+ * @param {Element} element The element to add a class to.
+ * @param {String} classname The name of the class to add.
+ */
+ var addClass;
+
+ /**
+ * Removes a class from an element.
+ *
+ * @private
+ * @function
+ * @param {Element} element The element to remove a class from.
+ * @param {String} classname The name of the class to remove.
+ */
+ var removeClass;
+
+ // If Node.classList is supported, implement addClass/removeClass using that
+ if (Node.classList) {
+
+ /** @ignore */
+ addClass = function(element, classname) {
+ element.classList.add(classname);
+ };
+
+ /** @ignore */
+ removeClass = function(element, classname) {
+ element.classList.remove(classname);
+ };
+
+ }
+
+ // Otherwise, implement own
+ else {
+
+ /** @ignore */
+ addClass = function(element, classname) {
+
+ // Simply add new class
+ element.className += " " + classname;
+
+ };
+
+ /** @ignore */
+ removeClass = function(element, classname) {
+
+ // Filter out classes with given name
+ element.className = element.className.replace(/([^ ]+)[ ]*/g,
+ function(match, testClassname, spaces, offset, string) {
+
+ // If same class, remove
+ if (testClassname == classname)
+ return "";
+
+ // Otherwise, allow
+ return match;
+
+ }
+ );
+
+ };
+
+ }
+
+ // 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 getModifierMask(name) {
+
+ var value = modifier_masks[name];
+ if (!value) {
+
+ // Get current modifier, advance to next
+ value = next_mask;
+ next_mask <<= 1;
+
+ // Store value of this modifier
+ modifier_masks[name] = value;
+
+ }
+
+ return value;
+
+ }
+
+ function ScaledElement(element, width, height, scaleFont) {
+
+ this.width = width;
+ this.height = height;
+
+ this.scale = function(pixels) {
+ element.style.width = (width * pixels) + "px";
+ element.style.height = (height * pixels) + "px";
+
+ if (scaleFont) {
+ element.style.lineHeight = (height * pixels) + "px";
+ element.style.fontSize = pixels + "px";
+ }
+ }
+
+ }
+
+ // For each child of element, call handler defined in next
+ function parseChildren(element, next) {
+
+ var children = element.childNodes;
+ for (var i=0; i<children.length; i++) {
+
+ // Get child node
+ var child = children[i];
+
+ // Do not parse text nodes
+ if (!child.tagName)
+ continue;
+
+ // Get handler for node
+ var handler = next[child.tagName];
+
+ // Call handler if defined
+ if (handler)
+ handler(child);
+
+ // Throw exception if no handler
+ else
+ throw new Error(
+ "Unexpected " + child.tagName
+ + " within " + element.tagName
+ );
+
+ }
+
+ }
+
+ // Create keyboard
+ var keyboard = document.createElement("div");
+ keyboard.className = "guac-keyboard";
+
+ // Retrieve keyboard XML
+ var xmlhttprequest = new XMLHttpRequest();
+ xmlhttprequest.open("GET", url, false);
+ xmlhttprequest.send(null);
+
+ var xml = xmlhttprequest.responseXML;
+
+ if (xml) {
+
+ function parse_row(e) {
+
+ var row = document.createElement("div");
+ row.className = "guac-keyboard-row";
+
+ parseChildren(e, {
+
+ "column": function(e) {
+ row.appendChild(parse_column(e));
+ },
+
+ "gap": function parse_gap(e) {
+
+ // Create element
+ var gap = document.createElement("div");
+ gap.className = "guac-keyboard-gap";
+
+ // Set gap size
+ var gap_units = 1;
+ if (e.getAttribute("size"))
+ gap_units = parseFloat(e.getAttribute("size"));
+
+ scaledElements.push(new ScaledElement(gap, gap_units, gap_units));
+ row.appendChild(gap);
+
+ },
+
+ "key": function parse_key(e) {
+
+ // Create element
+ var key_element = document.createElement("div");
+ key_element.className = "guac-keyboard-key";
+
+ // Append class if specified
+ if (e.getAttribute("class"))
+ key_element.className += " " + e.getAttribute("class");
+
+ // Position keys using container div
+ var key_container_element = document.createElement("div");
+ key_container_element.className = "guac-keyboard-key-container";
+ key_container_element.appendChild(key_element);
+
+ // Create key
+ var key = new Guacamole.OnScreenKeyboard.Key();
+
+ // Set key size
+ var key_units = 1;
+ if (e.getAttribute("size"))
+ key_units = parseFloat(e.getAttribute("size"));
+
+ key.size = key_units;
+
+ parseChildren(e, {
+ "cap": function parse_cap(e) {
+
+ // TODO: Handle "sticky" attribute
+
+ // Get content of key cap
+ var content = e.textContent || e.text;
+
+ // If read as blank, assume cap is a single space.
+ if (content.length == 0)
+ content = " ";
+
+ // Get keysym
+ var real_keysym = null;
+ if (e.getAttribute("keysym"))
+ real_keysym = parseInt(e.getAttribute("keysym"));
+
+ // If no keysym specified, try to get from key content
+ else if (content.length == 1) {
+
+ var charCode = content.charCodeAt(0);
+ if (charCode >= 0x0000 && charCode <= 0x00FF)
+ real_keysym = charCode;
+ else if (charCode >= 0x0100 && charCode <= 0x10FFFF)
+ real_keysym = 0x01000000 | charCode;
+
+ }
+
+ // Create cap
+ var cap = new Guacamole.OnScreenKeyboard.Cap(content, real_keysym);
+
+ if (e.getAttribute("modifier"))
+ cap.modifier = e.getAttribute("modifier");
+
+ // Create cap element
+ var cap_element = document.createElement("div");
+ cap_element.className = "guac-keyboard-cap";
+ cap_element.textContent = content;
+ key_element.appendChild(cap_element);
+
+ // Append class if specified
+ if (e.getAttribute("class"))
+ cap_element.className += " " + e.getAttribute("class");
+
+ // Get modifier value
+ var modifierValue = 0;
+ if (e.getAttribute("if")) {
+
+ // Get modifier value for specified comma-delimited
+ // list of required modifiers.
+ var requirements = e.getAttribute("if").split(",");
+ for (var i=0; i<requirements.length; i++) {
+ modifierValue |= getModifierMask(requirements[i]);
+ addClass(cap_element, "guac-keyboard-requires-" + requirements[i]);
+ addClass(key_element, "guac-keyboard-uses-" + requirements[i]);
+ }
+
+ }
+
+ // Store cap
+ key.modifierMask |= modifierValue;
+ key.caps[modifierValue] = cap;
+
+ }
+ });
+
+ scaledElements.push(new ScaledElement(key_container_element, key_units, 1, true));
+ row.appendChild(key_container_element);
+
+ // Set up click handler for key
+ function press(e) {
+
+ // Press key if not yet pressed
+ if (!key.pressed) {
+
+ addClass(key_element, "guac-keyboard-pressed");
+
+ // Get current cap based on modifier state
+ var cap = key.getCap(modifiers);
+
+ // Update modifier state
+ if (cap.modifier) {
+
+ // Construct classname for modifier
+ var modifierClass = "guac-keyboard-modifier-" + cap.modifier;
+ var modifierMask = getModifierMask(cap.modifier);
+
+ // Toggle modifier state
+ modifiers ^= modifierMask;
+
+ // Activate modifier if pressed
+ if (modifiers & modifierMask) {
+
+ addClass(keyboard, modifierClass);
+
+ // Send key event
+ if (on_screen_keyboard.onkeydown && cap.keysym)
+ on_screen_keyboard.onkeydown(cap.keysym);
+
+ }
+
+ // Deactivate if not pressed
+ else {
+
+ removeClass(keyboard, modifierClass);
+
+ // Send key event
+ if (on_screen_keyboard.onkeyup && cap.keysym)
+ on_screen_keyboard.onkeyup(cap.keysym);
+
+ }
+
+ }
+
+ // If not modifier, send key event now
+ else if (on_screen_keyboard.onkeydown && cap.keysym)
+ on_screen_keyboard.onkeydown(cap.keysym);
+
+ // Mark key as pressed
+ key.pressed = true;
+
+ }
+
+ e.preventDefault();
+
+ }
+
+ function release(e) {
+
+ // Release key if currently pressed
+ if (key.pressed) {
+
+ // Get current cap based on modifier state
+ var cap = key.getCap(modifiers);
+
+ removeClass(key_element, "guac-keyboard-pressed");
+
+ // Send key event if not a modifier key
+ if (!cap.modifier && on_screen_keyboard.onkeyup && cap.keysym)
+ on_screen_keyboard.onkeyup(cap.keysym);
+
+ // Mark key as released
+ key.pressed = false;
+
+ }
+
+ e.preventDefault();
+
+ }
+
+ key_element.addEventListener("mousedown", press, true);
+ key_element.addEventListener("touchstart", press, true);
+
+ key_element.addEventListener("mouseup", release, true);
+ key_element.addEventListener("mouseout", release, true);
+ key_element.addEventListener("touchend", release, true);
+
+ }
+
+ });
+
+ return row;
+
+ }
+
+ function parse_column(e) {
+
+ var col = document.createElement("div");
+ col.className = "guac-keyboard-column";
+
+ if (col.getAttribute("align"))
+ col.style.textAlign = col.getAttribute("align");
+
+ // Columns can only contain rows
+ parseChildren(e, {
+ "row": function(e) {
+ col.appendChild(parse_row(e));
+ }
+ });
+
+ return col;
+
+ }
+
+
+ // Parse document
+ var keyboard_element = xml.documentElement;
+ if (keyboard_element.tagName != "keyboard")
+ throw new Error("Root element must be keyboard");
+
+ // Get attributes
+ if (!keyboard_element.getAttribute("size"))
+ throw new Error("size attribute is required for keyboard");
+
+ var keyboard_size = parseFloat(keyboard_element.getAttribute("size"));
+
+ parseChildren(keyboard_element, {
+
+ "row": function(e) {
+ keyboard.appendChild(parse_row(e));
+ },
+
+ "column": function(e) {
+ keyboard.appendChild(parse_column(e));
+ }
+
+ });
+
+ }
+
+ // Do not allow selection or mouse movement to propagate/register.
+ keyboard.onselectstart =
+ keyboard.onmousemove =
+ keyboard.onmouseup =
+ keyboard.onmousedown =
+ function(e) {
+ e.stopPropagation();
+ return false;
+ };
+
+ /**
+ * Fired whenever the user presses a key on this Guacamole.OnScreenKeyboard.
+ *
+ * @event
+ * @param {Number} keysym The keysym of the key being pressed.
+ */
+ this.onkeydown = null;
+
+ /**
+ * Fired whenever the user releases a key on this Guacamole.OnScreenKeyboard.
+ *
+ * @event
+ * @param {Number} keysym The keysym of the key being released.
+ */
+ this.onkeyup = null;
+
+ /**
+ * Returns the element containing the entire on-screen keyboard.
+ * @returns {Element} The element containing the entire on-screen keyboard.
+ */
+ this.getElement = function() {
+ return keyboard;
+ };
+
+ /**
+ * Resizes all elements within this Guacamole.OnScreenKeyboard such that
+ * the width is close to but does not exceed the specified width. The
+ * height of the keyboard is determined based on the width.
+ *
+ * @param {Number} width The width to resize this Guacamole.OnScreenKeyboard
+ * to, in pixels.
+ */
+ this.resize = function(width) {
+
+ // Get pixel size of a unit
+ var unit = Math.floor(width * 10 / keyboard_size) / 10;
+
+ // Resize all scaled elements
+ for (var i=0; i<scaledElements.length; i++) {
+ var scaledElement = scaledElements[i];
+ scaledElement.scale(unit)
+ }
+
+ };
+
+};
+
+
+/**
+ * Basic representation of a single key of a keyboard. Each key has a set of
+ * caps associated with tuples of modifiers. The cap determins what happens
+ * when a key is pressed, while it is the state of modifier keys that determines
+ * what cap is in effect on any particular key.
+ *
+ * @constructor
+ */
+Guacamole.OnScreenKeyboard.Key = function() {
+
+ var key = this;
+
+ /**
+ * Whether this key is currently pressed.
+ */
+ this.pressed = false;
+
+ /**
+ * Width of the key, relative to the size of the keyboard.
+ */
+ this.size = 1;
+
+ /**
+ * An associative map of all caps by modifier.
+ */
+ this.caps = {};
+
+ /**
+ * Bit mask with all modifiers that affect this key set.
+ */
+ this.modifierMask = 0;
+
+ /**
+ * Given the bitwise OR of all active modifiers, returns the key cap
+ * which applies.
+ */
+ this.getCap = function(modifier) {
+ return key.caps[modifier & key.modifierMask];
+ };
+
+};
+
+/**
+ * Basic representation of a cap of a key. The cap is the visible part of a key
+ * and determines the active behavior of a key when pressed. The state of all
+ * modifiers on the keyboard determines the active cap for all keys, thus
+ * each cap is associated with a set of modifiers.
+ *
+ * @constructor
+ * @param {String} text The text to be displayed within this cap.
+ * @param {Number} keysym The keysym this cap sends when its associated key is
+ * pressed or released.
+ * @param {String} modifier The modifier represented by this cap.
+ */
+Guacamole.OnScreenKeyboard.Cap = function(text, keysym, modifier) {
+
+ /**
+ * Modifier represented by this keycap
+ */
+ this.modifier = null;
+
+ /**
+ * The text to be displayed within this keycap
+ */
+ this.text = text;
+
+ /**
+ * The keysym this cap sends when its associated key is pressed/released
+ */
+ this.keysym = keysym;
+
+ // Set modifier if provided
+ if (modifier) this.modifier = modifier;
+
+};
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/guacamole-common-js/tunnel.js
^
|
@@ -0,0 +1,831 @@
+
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is guacamole-common-js.
+ *
+ * The Initial Developer of the Original Code is
+ * Michael Jumper.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Namespace for all Guacamole JavaScript objects.
+ * @namespace
+ */
+var Guacamole = Guacamole || {};
+
+/**
+ * Core object providing abstract communication for Guacamole. This object
+ * is a null implementation whose functions do nothing. Guacamole applications
+ * should use {@link Guacamole.HTTPTunnel} instead, or implement their own tunnel based
+ * on this one.
+ *
+ * @constructor
+ * @see Guacamole.HTTPTunnel
+ */
+Guacamole.Tunnel = function() {
+
+ /**
+ * Connect to the tunnel with the given optional data. This data is
+ * typically used for authentication. The format of data accepted is
+ * up to the tunnel implementation.
+ *
+ * @param {String} data The data to send to the tunnel when connecting.
+ */
+ this.connect = function(data) {};
+
+ /**
+ * Disconnect from the tunnel.
+ */
+ this.disconnect = function() {};
+
+ /**
+ * Send the given message through the tunnel to the service on the other
+ * side. All messages are guaranteed to be received in the order sent.
+ *
+ * @param {...} elements The elements of the message to send to the
+ * service on the other side of the tunnel.
+ */
+ this.sendMessage = function(elements) {};
+
+ /**
+ * Fired whenever an error is encountered by the tunnel.
+ *
+ * @event
+ * @param {String} message A human-readable description of the error that
+ * occurred.
+ */
+ this.onerror = null;
+
+ /**
+ * Fired once for every complete Guacamole instruction received, in order.
+ *
+ * @event
+ * @param {String} opcode The Guacamole instruction opcode.
+ * @param {Array} parameters The parameters provided for the instruction,
+ * if any.
+ */
+ this.oninstruction = null;
+
+};
+
+/**
+ * Guacamole Tunnel implemented over HTTP via XMLHttpRequest.
+ *
+ * @constructor
+ * @augments Guacamole.Tunnel
+ * @param {String} tunnelURL The URL of the HTTP tunneling service.
+ */
+Guacamole.HTTPTunnel = function(tunnelURL) {
+
+ /**
+ * Reference to this HTTP tunnel.
+ * @private
+ */
+ var tunnel = this;
+
+ var tunnel_uuid;
+
+ var TUNNEL_CONNECT = tunnelURL + "?connect";
+ var TUNNEL_READ = tunnelURL + "?read:";
+ var TUNNEL_WRITE = tunnelURL + "?write:";
+
+ var STATE_IDLE = 0;
+ var STATE_CONNECTED = 1;
+ var STATE_DISCONNECTED = 2;
+
+ var currentState = STATE_IDLE;
+
+ var POLLING_ENABLED = 1;
+ var POLLING_DISABLED = 0;
+
+ // Default to polling - will be turned off automatically if not needed
+ var pollingMode = POLLING_ENABLED;
+
+ var sendingMessages = false;
+ var outputMessageBuffer = "";
+
+ this.sendMessage = function() {
+
+ // Do not attempt to send messages if not connected
+ if (currentState != STATE_CONNECTED)
+ return;
+
+ // Do not attempt to send empty messages
+ if (arguments.length == 0)
+ return;
+
+ /**
+ * Converts the given value to a length/string pair for use as an
+ * element in a Guacamole instruction.
+ *
+ * @private
+ * @param value The value to convert.
+ * @return {String} The converted value.
+ */
+ function getElement(value) {
+ var string = new String(value);
+ return string.length + "." + string;
+ }
+
+ // Initialized message with first element
+ var message = getElement(arguments[0]);
+
+ // Append remaining elements
+ for (var i=1; i<arguments.length; i++)
+ message += "," + getElement(arguments[i]);
+
+ // Final terminator
+ message += ";";
+
+ // Add message to buffer
+ outputMessageBuffer += message;
+
+ // Send if not currently sending
+ if (!sendingMessages)
+ sendPendingMessages();
+
+ };
+
+ function sendPendingMessages() {
+
+ if (outputMessageBuffer.length > 0) {
+
+ sendingMessages = true;
+
+ var message_xmlhttprequest = new XMLHttpRequest();
+ message_xmlhttprequest.open("POST", TUNNEL_WRITE + tunnel_uuid);
+ message_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+
+ // Once response received, send next queued event.
+ message_xmlhttprequest.onreadystatechange = function() {
+ if (message_xmlhttprequest.readyState == 4) {
+
+ // If an error occurs during send, handle it
+ if (message_xmlhttprequest.status != 200)
+ handleHTTPTunnelError(message_xmlhttprequest);
+
+ // Otherwise, continue the send loop
+ else
+ sendPendingMessages();
+
+ }
+ }
+
+ message_xmlhttprequest.send(outputMessageBuffer);
+ outputMessageBuffer = ""; // Clear buffer
+
+ }
+ else
+ sendingMessages = false;
+
+ }
+
+ function getHTTPTunnelErrorMessage(xmlhttprequest) {
+
+ var status = xmlhttprequest.status;
+
+ // Special cases
+ if (status == 0) return "Disconnected";
+ if (status == 200) return "Success";
+ if (status == 403) return "Unauthorized";
+ if (status == 404) return "Connection closed"; /* While it may be more
+ * accurate to say the
+ * connection does not
+ * exist, it is confusing
+ * to the user.
+ *
+ * In general, this error
+ * will only happen when
+ * the tunnel does not
+ * exist, which happens
+ * after the connection
+ * is closed and the
+ * tunnel is detached.
+ */
+ // Internal server errors
+ if (status >= 500 && status <= 599) return "Server error";
+
+ // Otherwise, unknown
+ return "Unknown error";
+
+ }
+
+ function handleHTTPTunnelError(xmlhttprequest) {
+
+ // Get error message
+ var message = getHTTPTunnelErrorMessage(xmlhttprequest);
+
+ // Call error handler
+ if (tunnel.onerror) tunnel.onerror(message);
+
+ // Finish
+ tunnel.disconnect();
+
+ }
+
+
+ function handleResponse(xmlhttprequest) {
+
+ var interval = null;
+ var nextRequest = null;
+
+ var dataUpdateEvents = 0;
+
+ // The location of the last element's terminator
+ var elementEnd = -1;
+
+ // Where to start the next length search or the next element
+ var startIndex = 0;
+
+ // Parsed elements
+ var elements = new Array();
+
+ function parseResponse() {
+
+ // Do not handle responses if not connected
+ if (currentState != STATE_CONNECTED) {
+
+ // Clean up interval if polling
+ if (interval != null)
+ clearInterval(interval);
+
+ return;
+ }
+
+ // Do not parse response yet if not ready
+ if (xmlhttprequest.readyState < 2) return;
+
+ // Attempt to read status
+ var status;
+ try { status = xmlhttprequest.status; }
+
+ // If status could not be read, assume successful.
+ catch (e) { status = 200; }
+
+ // Start next request as soon as possible IF request was successful
+ if (nextRequest == null && status == 200)
+ nextRequest = makeRequest();
+
+ // Parse stream when data is received and when complete.
+ if (xmlhttprequest.readyState == 3 ||
+ xmlhttprequest.readyState == 4) {
+
+ // Also poll every 30ms (some browsers don't repeatedly call onreadystatechange for new data)
+ if (pollingMode == POLLING_ENABLED) {
+ if (xmlhttprequest.readyState == 3 && interval == null)
+ interval = setInterval(parseResponse, 30);
+ else if (xmlhttprequest.readyState == 4 && interval != null)
+ clearInterval(interval);
+ }
+
+ // If canceled, stop transfer
+ if (xmlhttprequest.status == 0) {
+ tunnel.disconnect();
+ return;
+ }
+
+ // Halt on error during request
+ else if (xmlhttprequest.status != 200) {
+ handleHTTPTunnelError(xmlhttprequest);
+ return;
+ }
+
+ // Attempt to read in-progress data
+ var current;
+ try { current = xmlhttprequest.responseText; }
+
+ // Do not attempt to parse if data could not be read
+ catch (e) { return; }
+
+ // While search is within currently received data
+ while (elementEnd < current.length) {
+
+ // If we are waiting for element data
+ if (elementEnd >= startIndex) {
+
+ // We now have enough data for the element. Parse.
+ var element = current.substring(startIndex, elementEnd);
+ var terminator = current.substring(elementEnd, elementEnd+1);
+
+ // Add element to array
+ elements.push(element);
+
+ // If last element, handle instruction
+ if (terminator == ";") {
+
+ // Get opcode
+ var opcode = elements.shift();
+
+ // Call instruction handler.
+ if (tunnel.oninstruction != null)
+ tunnel.oninstruction(opcode, elements);
+
+ // Clear elements
+ elements.length = 0;
+
+ }
+
+ // Start searching for length at character after
+ // element terminator
+ startIndex = elementEnd + 1;
+
+ }
+
+ // Search for end of length
+ var lengthEnd = current.indexOf(".", startIndex);
+ if (lengthEnd != -1) {
+
+ // Parse length
+ var length = parseInt(current.substring(elementEnd+1, lengthEnd));
+
+ // If we're done parsing, handle the next response.
+ if (length == 0) {
+
+ // Clean up interval if polling
+ if (interval != null)
+ clearInterval(interval);
+
+ // Clean up object
+ xmlhttprequest.onreadystatechange = null;
+ xmlhttprequest.abort();
+
+ // Start handling next request
+ if (nextRequest)
+ handleResponse(nextRequest);
+
+ // Done parsing
+ break;
+
+ }
+
+ // Calculate start of element
+ startIndex = lengthEnd + 1;
+
+ // Calculate location of element terminator
+ elementEnd = startIndex + length;
+
+ }
+
+ // If no period yet, continue search when more data
+ // is received
+ else {
+ startIndex = current.length;
+ break;
+ }
+
+ } // end parse loop
+
+ }
+
+ }
+
+ // If response polling enabled, attempt to detect if still
+ // necessary (via wrapping parseResponse())
+ if (pollingMode == POLLING_ENABLED) {
+ xmlhttprequest.onreadystatechange = function() {
+
+ // If we receive two or more readyState==3 events,
+ // there is no need to poll.
+ if (xmlhttprequest.readyState == 3) {
+ dataUpdateEvents++;
+ if (dataUpdateEvents >= 2) {
+ pollingMode = POLLING_DISABLED;
+ xmlhttprequest.onreadystatechange = parseResponse;
+ }
+ }
+
+ parseResponse();
+ }
+ }
+
+ // Otherwise, just parse
+ else
+ xmlhttprequest.onreadystatechange = parseResponse;
+
+ parseResponse();
+
+ }
+
+ /**
+ * Arbitrary integer, unique for each tunnel read request.
+ */
+ var request_id = 0;
+
+ function makeRequest() {
+
+ // Make request, increment request ID
+ var xmlhttprequest = new XMLHttpRequest();
+ xmlhttprequest.open("GET", TUNNEL_READ + tunnel_uuid + ":" + (request_id++));
+ xmlhttprequest.send(null);
+
+ return xmlhttprequest;
+
+ }
+
+ this.connect = function(data) {
+
+ // Start tunnel and connect synchronously
+ var connect_xmlhttprequest = new XMLHttpRequest();
+ connect_xmlhttprequest.open("POST", TUNNEL_CONNECT, false);
+ connect_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+ connect_xmlhttprequest.send(data);
+
+ // If failure, throw error
+ if (connect_xmlhttprequest.status != 200) {
+ var message = getHTTPTunnelErrorMessage(connect_xmlhttprequest);
+ throw new Error(message);
+ }
+
+ // Get UUID from response
+ tunnel_uuid = connect_xmlhttprequest.responseText;
+
+ // Start reading data
+ currentState = STATE_CONNECTED;
+ handleResponse(makeRequest());
+
+ };
+
+ this.disconnect = function() {
+ currentState = STATE_DISCONNECTED;
+ };
+
+};
+
+Guacamole.HTTPTunnel.prototype = new Guacamole.Tunnel();
+
+
+/**
+ * Guacamole Tunnel implemented over WebSocket via XMLHttpRequest.
+ *
+ * @constructor
+ * @augments Guacamole.Tunnel
+ * @param {String} tunnelURL The URL of the WebSocket tunneling service.
+ */
+Guacamole.WebSocketTunnel = function(tunnelURL) {
+
+ /**
+ * Reference to this WebSocket tunnel.
+ * @private
+ */
+ var tunnel = this;
+
+ /**
+ * The WebSocket used by this tunnel.
+ * @private
+ */
+ var socket = null;
+
+ /**
+ * The WebSocket protocol corresponding to the protocol used for the current
+ * location.
+ * @private
+ */
+ var ws_protocol = {
+ "http:": "ws:",
+ "https:": "wss:"
+ };
+
+ var status_code = {
+ 1000: "Connection closed normally.",
+ 1001: "Connection shut down.",
+ 1002: "Protocol error.",
+ 1003: "Invalid data.",
+ 1004: "[UNKNOWN, RESERVED]",
+ 1005: "No status code present.",
+ 1006: "Connection closed abnormally.",
+ 1007: "Inconsistent data type.",
+ 1008: "Policy violation.",
+ 1009: "Message too large.",
+ 1010: "Extension negotiation failed."
+ };
+
+ var STATE_IDLE = 0;
+ var STATE_CONNECTED = 1;
+ var STATE_DISCONNECTED = 2;
+
+ var currentState = STATE_IDLE;
+
+ // Transform current URL to WebSocket URL
+
+ // If not already a websocket URL
+ if ( tunnelURL.substring(0, 3) != "ws:"
+ && tunnelURL.substring(0, 4) != "wss:") {
+
+ var protocol = ws_protocol[window.location.protocol];
+
+ // If absolute URL, convert to absolute WS URL
+ if (tunnelURL.substring(0, 1) == "/")
+ tunnelURL =
+ protocol
+ + "//" + window.location.host
+ + tunnelURL;
+
+ // Otherwise, construct absolute from relative URL
+ else {
+
+ // Get path from pathname
+ var slash = window.location.pathname.lastIndexOf("/");
+ var path = window.location.pathname.substring(0, slash + 1);
+
+ // Construct absolute URL
+ tunnelURL =
+ protocol
+ + "//" + window.location.host
+ + path
+ + tunnelURL;
+
+ }
+
+ }
+
+ this.sendMessage = function(elements) {
+
+ // Do not attempt to send messages if not connected
+ if (currentState != STATE_CONNECTED)
+ return;
+
+ // Do not attempt to send empty messages
+ if (arguments.length == 0)
+ return;
+
+ /**
+ * Converts the given value to a length/string pair for use as an
+ * element in a Guacamole instruction.
+ *
+ * @private
+ * @param value The value to convert.
+ * @return {String} The converted value.
+ */
+ function getElement(value) {
+ var string = new String(value);
+ return string.length + "." + string;
+ }
+
+ // Initialized message with first element
+ var message = getElement(arguments[0]);
+
+ // Append remaining elements
+ for (var i=1; i<arguments.length; i++)
+ message += "," + getElement(arguments[i]);
+
+ // Final terminator
+ message += ";";
+
+ socket.send(message);
+
+ };
+
+ this.connect = function(data) {
+
+ // Connect socket
+ socket = new WebSocket(tunnelURL + "?" + data, "guacamole");
+
+ socket.onopen = function(event) {
+ currentState = STATE_CONNECTED;
+ };
+
+ socket.onclose = function(event) {
+
+ // If connection closed abnormally, signal error.
+ if (event.code != 1000 && tunnel.onerror)
+ tunnel.onerror(status_code[event.code]);
+
+ };
+
+ socket.onerror = function(event) {
+
+ // Call error handler
+ if (tunnel.onerror) tunnel.onerror(event.data);
+
+ };
+
+ socket.onmessage = function(event) {
+
+ var message = event.data;
+ var startIndex = 0;
+ var elementEnd;
+
+ var elements = [];
+
+ do {
+
+ // Search for end of length
+ var lengthEnd = message.indexOf(".", startIndex);
+ if (lengthEnd != -1) {
+
+ // Parse length
+ var length = parseInt(message.substring(elementEnd+1, lengthEnd));
+
+ // Calculate start of element
+ startIndex = lengthEnd + 1;
+
+ // Calculate location of element terminator
+ elementEnd = startIndex + length;
+
+ }
+
+ // If no period, incomplete instruction.
+ else
+ throw new Error("Incomplete instruction.");
+
+ // We now have enough data for the element. Parse.
+ var element = message.substring(startIndex, elementEnd);
+ var terminator = message.substring(elementEnd, elementEnd+1);
+
+ // Add element to array
+ elements.push(element);
+
+ // If last element, handle instruction
+ if (terminator == ";") {
+
+ // Get opcode
+ var opcode = elements.shift();
+
+ // Call instruction handler.
+ if (tunnel.oninstruction != null)
+ tunnel.oninstruction(opcode, elements);
+
+ // Clear elements
+ elements.length = 0;
+
+ }
+
+ // Start searching for length at character after
+ // element terminator
+ startIndex = elementEnd + 1;
+
+ } while (startIndex < message.length);
+
+ };
+
+ };
+
+ this.disconnect = function() {
+ currentState = STATE_DISCONNECTED;
+ socket.close();
+ };
+
+};
+
+Guacamole.WebSocketTunnel.prototype = new Guacamole.Tunnel();
+
+
+/**
+ * Guacamole Tunnel which cycles between all specified tunnels until
+ * no tunnels are left. Another tunnel is used if an error occurs but
+ * no instructions have been received. If an instruction has been
+ * received, or no tunnels remain, the error is passed directly out
+ * through the onerror handler (if defined).
+ *
+ * @constructor
+ * @augments Guacamole.Tunnel
+ * @param {...} tunnel_chain The tunnels to use, in order of priority.
+ */
+Guacamole.ChainedTunnel = function(tunnel_chain) {
+
+ /**
+ * Reference to this chained tunnel.
+ * @private
+ */
+ var chained_tunnel = this;
+
+ /**
+ * The currently wrapped tunnel, if any.
+ * @private
+ */
+ var current_tunnel = null;
+
+ /**
+ * Data passed in via connect(), to be used for
+ * wrapped calls to other tunnels' connect() functions.
+ * @private
+ */
+ var connect_data;
+
+ /**
+ * Array of all tunnels passed to this ChainedTunnel through the
+ * constructor arguments.
+ * @private
+ */
+ var tunnels = [];
+
+ // Load all tunnels into array
+ for (var i=0; i<arguments.length; i++)
+ tunnels.push(arguments[i]);
+
+ /**
+ * Sets the current tunnel.
+ *
+ * @private
+ * @param {Guacamole.Tunnel} tunnel The tunnel to set as the current tunnel.
+ */
+ function attach(tunnel) {
+
+ // Clear handlers of current tunnel, if any
+ if (current_tunnel) {
+ current_tunnel.onerror = null;
+ current_tunnel.oninstruction = null;
+ }
+
+ // Set own functions to tunnel's functions
+ chained_tunnel.disconnect = tunnel.disconnect;
+ chained_tunnel.sendMessage = tunnel.sendMessage;
+
+ // Record current tunnel
+ current_tunnel = tunnel;
+
+ // Wrap own oninstruction within current tunnel
+ current_tunnel.oninstruction = function(opcode, elements) {
+
+ // Invoke handler
+ chained_tunnel.oninstruction(opcode, elements);
+
+ // Use handler permanently from now on
+ current_tunnel.oninstruction = chained_tunnel.oninstruction;
+
+ // Pass through errors (without trying other tunnels)
+ current_tunnel.onerror = chained_tunnel.onerror;
+
+ }
+
+ // Attach next tunnel on error
+ current_tunnel.onerror = function(message) {
+
+ // Get next tunnel
+ var next_tunnel = tunnels.shift();
+
+ // If there IS a next tunnel, try using it.
+ if (next_tunnel)
+ attach(next_tunnel);
+
+ // Otherwise, call error handler
+ else if (chained_tunnel.onerror)
+ chained_tunnel.onerror(message);
+
+ };
+
+ try {
+
+ // Attempt connection
+ current_tunnel.connect(connect_data);
+
+ }
+ catch (e) {
+
+ // Call error handler of current tunnel on error
+ current_tunnel.onerror(e.message);
+
+ }
+
+
+ }
+
+ this.connect = function(data) {
+
+ // Remember connect data
+ connect_data = data;
+
+ // Get first tunnel
+ var next_tunnel = tunnels.shift();
+
+ // Attach first tunnel
+ if (next_tunnel)
+ attach(next_tunnel);
+
+ // If there IS no first tunnel, error
+ else if (chained_tunnel.onerror)
+ chained_tunnel.onerror("No tunnels to try.");
+
+ };
+
+};
+
+Guacamole.ChainedTunnel.prototype = new Guacamole.Tunnel();
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images
^
|
+(directory)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/guacamole-logo-144.png
^
|
(renamed from target/guacamole-0.6.1/images/guacamole-logo-144.png)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/guacamole-logo-144.png
^
|
(renamed from target/guacamole-0.6.1/images/guacamole-logo-144.png)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/guacamole-logo-24.png
^
|
(renamed from target/guacamole-0.6.1/images/guacamole-logo-24.png)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/guacamole-logo-24.png
^
|
(renamed from target/guacamole-0.6.1/images/guacamole-logo-24.png)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/guacamole-logo-64.png
^
|
(renamed from target/guacamole-0.6.1/images/guacamole-logo-64.png)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/guacamole-logo-64.png
^
|
(renamed from target/guacamole-0.6.1/images/guacamole-logo-64.png)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/mouse
^
|
+(directory)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/mouse/blank.cur
^
|
(renamed from target/guacamole-0.6.1/images/mouse/blank.cur)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/mouse/blank.cur
^
|
(renamed from target/guacamole-0.6.1/images/mouse/blank.cur)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/mouse/blank.gif
^
|
(renamed from target/guacamole-0.6.1/images/mouse/blank.gif)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/mouse/blank.gif
^
|
(renamed from target/guacamole-0.6.1/images/mouse/blank.gif)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/mouse/dot.gif
^
|
(renamed from target/guacamole-0.6.1/images/mouse/dot.gif)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/mouse/dot.gif
^
|
(renamed from target/guacamole-0.6.1/images/mouse/dot.gif)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/noguacamole-logo-24.png
^
|
(renamed from target/guacamole-0.6.1/images/noguacamole-logo-24.png)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/noguacamole-logo-24.png
^
|
(renamed from target/guacamole-0.6.1/images/noguacamole-logo-24.png)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/protocol-icons
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/protocol-icons/tango
^
|
+(directory)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/protocol-icons/tango/terminal.png
^
|
(renamed from target/guacamole-0.6.1/images/protocol-icons/tango/terminal.png)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/protocol-icons/tango/terminal.png
^
|
(renamed from target/guacamole-0.6.1/images/protocol-icons/tango/terminal.png)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/protocol-icons/tango/video-display.png
^
|
(renamed from target/guacamole-0.6.1/images/protocol-icons/tango/video-display.png)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/protocol-icons/tango/video-display.png
^
|
(renamed from target/guacamole-0.6.1/images/protocol-icons/tango/video-display.png)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/index.xhtml
^
|
@@ -0,0 +1,256 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html>
+
+<!--
+ Guacamole - Clientless Remote Desktop
+ Copyright (C) 2010 Michael Jumper
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+-->
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+ <head>
+ <link rel="icon" type="image/png" href="images/guacamole-logo-64.png"/>
+ <link rel="apple-touch-icon" type="image/png" href="images/guacamole-logo-144.png"/>
+ <link rel="stylesheet" type="text/css" href="styles/login.css"/>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi"/>
+ <title>Guacamole 0.6.2</title>
+ </head>
+
+ <body>
+
+ <div id="login-ui" style="display: none">
+ <div id="login-dialog-middle">
+
+ <div id="login-dialog">
+
+ <p id="login-error"></p>
+
+ <form id="login-form" action="#" method="post">
+
+ <div id="login-fields">
+ <table>
+ <tr>
+ <th>Username</th>
+ <td><input type="text" name="username" id="username" autofocus="autofocus"/></td>
+ </tr>
+ <tr>
+ <th>Password</th>
+ <td><input type="password" name="password" id="password"/></td>
+ </tr>
+ </table>
+
+ <img class="logo" src="images/guacamole-logo-64.png" alt=""/>
+ </div>
+
+ <div id="buttons">
+ <input type="submit" name="login" id="login" value="Login"/>
+ </div>
+
+ </form>
+ </div>
+
+ </div>
+ </div>
+
+ <!-- Connection list UI -->
+ <div id="connection-list-ui" style="display: none">
+
+ <div id="logout-panel">
+ <button id="logout">Logout</button>
+ </div>
+
+ <h1>
+ <img class="logo" src="images/guacamole-logo-64.png" alt=""/>
+ Available Connections
+ </h1>
+
+ <table class="connections">
+ <thead>
+ <tr>
+ <th class="protocol"> </th>
+ <th class="name">Name</th>
+ </tr>
+ </thead>
+ <tbody id="connections-tbody">
+ </tbody>
+ </table>
+
+ </div>
+
+ <div id="version-dialog">
+ Guacamole 0.6.2
+ </div>
+
+ <script type="text/javascript" src="scripts/connections.js"></script>
+
+ <!-- Init -->
+ <script type="text/javascript"> /* <![CDATA[ */
+
+ // Constructs the URL for a client which connects to the connection
+ // with the given id.
+ function getClientURL(id) {
+
+ // Construct URL for client with given id
+ return "client.xhtml?id=" + encodeURIComponent(id);
+
+ }
+
+ // Resets the interface such that the login UI is displayed if
+ // the user is not authenticated (or authentication fails) and
+ // the connection list UI (or the client for the only available
+ // connection, if there is only one) is displayed if the user is
+ // authenticated.
+ function resetUI() {
+
+ // Get parameters from query string
+ var parameters = window.location.search.substring(1);
+
+ var configs;
+ try {
+ configs = getConfigList(parameters);
+ }
+ catch (e) {
+
+ // Show login UI if unable to get configs
+ loginUI.style.display = "";
+ connectionListUI.style.display = "none";
+
+ return;
+
+ }
+
+ // If only one connection, redirect to that.
+ if (configs.length == 1) {
+ window.location.href = getClientURL(configs[0].id);
+ return;
+ }
+
+ // Remove all rows from connections list
+ var tbody = document.getElementById("connections-tbody");
+ tbody.innerHTML = "";
+
+ // Add one row per connection
+ for (var i=0; i<configs.length; i++) {
+
+ // Create row and cells
+ var tr = document.createElement("tr");
+ var protocol = document.createElement("td");
+ var id = document.createElement("td");
+
+ var protocolIcon = document.createElement("div");
+ protocolIcon.className = "protocol icon " + configs[i].protocol;
+
+ // Set CSS
+ protocol.className = "protocol";
+ id.className = "name";
+
+ // Create link to client
+ var clientLink = document.createElement("a");
+ clientLink.setAttribute("href", getClientURL(configs[i].id));
+
+ // Set cell contents
+ protocol.appendChild(protocolIcon);
+ //protocol.textContent = configs[i].protocol;
+ clientLink.textContent = configs[i].id;
+ id.appendChild(clientLink);
+
+ // Add cells
+ tr.appendChild(protocol);
+ tr.appendChild(id);
+
+ // Add row
+ tbody.appendChild(tr);
+
+ }
+
+ // If configs could be retrieved, display list
+ loginUI.style.display = "none";
+ connectionListUI.style.display = "";
+
+ }
+
+ var loginForm = document.getElementById("login-form");
+ var loginUI = document.getElementById("login-ui");
+ var connectionListUI = document.getElementById("connection-list-ui");
+ var logout = document.getElementById("logout");
+ var username = document.getElementById("username");
+ var password = document.getElementById("password");
+
+ logout.onclick = function() {
+ window.location.href = "logout";
+ };
+
+ loginForm.onsubmit = function() {
+
+ // Get parameters from query string
+ var parameters = window.location.search.substring(1);
+
+ // Get username and password from form
+ var data =
+ "username=" + encodeURIComponent(username.value)
+ + "&password=" + encodeURIComponent(password.value)
+
+ // Include query parameters in submission data
+ if (parameters) data += "&" + parameters;
+
+ try {
+
+ // Log in
+ var xhr = new XMLHttpRequest();
+ xhr.open("POST", "login", false);
+ xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+ xhr.send(data);
+
+ // Handle failures
+ if (xhr.status != 200)
+ throw new Error("Invalid login");
+
+ // Ensure username/password fiels are blurred after submit
+ username.blur();
+ password.blur();
+
+ resetUI();
+
+ }
+ catch (e) {
+
+ var loginError = document.getElementById("login-error");
+
+ // Display error, reset and refocus password field
+ loginError.textContent = e.message;
+ password.value = "";
+ password.focus();
+
+ return false;
+
+ }
+
+ // On success, hide loginUI, get and show connection list.
+ return false;
+
+ }
+
+ // Turn off autocorrect and autocapitalization on usename
+ username.setAttribute("autocorrect", "off");
+ username.setAttribute("autocapitalize", "off");
+
+ resetUI();
+
+ /* ]]> */ </script>
+
+ </body>
+
+</html>
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/layouts
^
|
+(directory)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/layouts/en-us-qwerty-mobile.xml
^
|
(renamed from target/guacamole-0.6.1/layouts/en-us-qwerty-mobile.xml)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/layouts/en-us-qwerty-mobile.xml
^
|
(renamed from target/guacamole-0.6.1/layouts/en-us-qwerty-mobile.xml)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/layouts/en-us-qwerty.xml
^
|
(renamed from target/guacamole-0.6.1/layouts/en-us-qwerty.xml)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/layouts/en-us-qwerty.xml
^
|
(renamed from target/guacamole-0.6.1/layouts/en-us-qwerty.xml)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/scripts
^
|
+(directory)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/scripts/connections.js
^
|
(renamed from target/guacamole-0.6.1/scripts/connections.js)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/scripts/connections.js
^
|
(renamed from target/guacamole-0.6.1/scripts/connections.js)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/scripts/interface.js
^
|
(renamed from target/guacamole-0.6.1/scripts/interface.js)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/scripts/interface.js
^
|
(renamed from target/guacamole-0.6.1/scripts/interface.js)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/styles
^
|
+(directory)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/styles/client.css
^
|
(renamed from target/guacamole-0.6.1/styles/client.css)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/styles/client.css
^
|
(renamed from target/guacamole-0.6.1/styles/client.css)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/styles/keyboard.css
^
|
(renamed from target/guacamole-0.6.1/styles/keyboard.css)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/styles/keyboard.css
^
|
(renamed from target/guacamole-0.6.1/styles/keyboard.css)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/styles/login.css
^
|
(renamed from target/guacamole-0.6.1/styles/login.css)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/styles/login.css
^
|
(renamed from target/guacamole-0.6.1/styles/login.css)
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/maven-archiver/pom.properties
^
|
@@ -1,5 +1,5 @@
#Generated by Maven
-#Sun Sep 30 14:42:41 CEST 2012
-version=0.6.1
+#Fri Oct 19 20:56:18 CEST 2012
+version=0.6.2
groupId=net.sourceforge.guacamole
artifactId=guacamole
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/war/work/net.sourceforge.guacamole/guacamole-common-js/guacamole-common-js/oskeyboard.js
^
|
@@ -63,8 +63,8 @@
var scaledElements = [];
- var modifiers = {};
- var currentModifier = 1;
+ var modifier_masks = {};
+ var next_mask = 1;
/**
* Adds a class to an element.
@@ -135,17 +135,17 @@
// 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) {
+ function getModifierMask(name) {
- var value = modifiers[name];
+ var value = modifier_masks[name];
if (!value) {
// Get current modifier, advance to next
- value = currentModifier;
- currentModifier <<= 1;
+ value = next_mask;
+ next_mask <<= 1;
// Store value of this modifier
- modifiers[name] = value;
+ modifier_masks[name] = value;
}
@@ -318,7 +318,7 @@
// list of required modifiers.
var requirements = e.getAttribute("if").split(",");
for (var i=0; i<requirements.length; i++) {
- modifierValue |= getModifier(requirements[i]);
+ modifierValue |= getModifierMask(requirements[i]);
addClass(cap_element, "guac-keyboard-requires-" + requirements[i]);
addClass(key_element, "guac-keyboard-uses-" + requirements[i]);
}
@@ -351,13 +351,13 @@
// Construct classname for modifier
var modifierClass = "guac-keyboard-modifier-" + cap.modifier;
- var modifierFlag = getModifier(cap.modifier);
+ var modifierMask = getModifierMask(cap.modifier);
// Toggle modifier state
- modifiers ^= modifierFlag;
+ modifiers ^= modifierMask;
// Activate modifier if pressed
- if (modifiers & modifierFlag) {
+ if (modifiers & modifierMask) {
addClass(keyboard, modifierClass);
@@ -391,7 +391,7 @@
e.preventDefault();
- };
+ }
function release(e) {
@@ -414,7 +414,7 @@
e.preventDefault();
- };
+ }
key_element.addEventListener("mousedown", press, true);
key_element.addEventListener("touchstart", press, true);
|
[-]
[+]
|
Changed |
guacamole-0.6.2.tar.bz2/target/war/work/net.sourceforge.guacamole/guacamole-common-js/guacamole-common-js/tunnel.js
^
|
@@ -434,12 +434,16 @@
}
+ /**
+ * Arbitrary integer, unique for each tunnel read request.
+ */
+ var request_id = 0;
function makeRequest() {
- // Download self
+ // Make request, increment request ID
var xmlhttprequest = new XMLHttpRequest();
- xmlhttprequest.open("POST", TUNNEL_READ + tunnel_uuid);
+ xmlhttprequest.open("GET", TUNNEL_READ + tunnel_uuid + ":" + (request_id++));
xmlhttprequest.send(null);
return xmlhttprequest;
|