[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/classes
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic
^
|
+(directory)
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/AuthenticatingHttpServlet.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$1.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$2.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$AuthInfo$Encoding.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$AuthInfo.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$BasicUserMappingContentHandler$State.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider$BasicUserMappingContentHandler.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/BasicFileAuthenticationProvider.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/BasicGuacamoleTunnelServlet$1$1.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/BasicGuacamoleTunnelServlet$1.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/BasicGuacamoleTunnelServlet.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/BasicLogin.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/BasicLogout.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/ConfigurationList.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/GuacamoleClassLoader$1.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/GuacamoleClassLoader$2.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/GuacamoleClassLoader.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/WebSocketSupportLoader.class
^
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/event
^
|
+(directory)
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/event/SessionListenerCollection.class
^
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/properties
^
|
+(directory)
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/properties/AuthenticationProviderProperty.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties$1.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties$2.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties$3.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/properties/BasicGuacamoleProperties.class
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/classes/net/sourceforge/guacamole/net/basic/properties/EventListenersProperty.class
^
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/generated-sources
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/generated-sources/annotations
^
|
+(directory)
|
[-]
[+]
|
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)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/META-INF/context.xml
^
|
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Context antiJARLocking="true" path=""/>
|
[-]
[+]
|
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)
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/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
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/lib/slf4j-api-1.6.1.jar
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/lib/slf4j-jcl-1.6.1.jar
^
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/WEB-INF/web.xml
^
|
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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/>.
+-->
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <!-- Basic config -->
+ <welcome-file-list>
+ <welcome-file>index.xhtml</welcome-file>
+ </welcome-file-list>
+ <session-config>
+ <session-timeout>
+ 30
+ </session-timeout>
+ </session-config>
+
+ <!-- Automatically detect and load WebSocket support -->
+ <listener>
+ <listener-class>net.sourceforge.guacamole.net.basic.WebSocketSupportLoader</listener-class>
+ </listener>
+
+ <!-- Basic Login Servlet -->
+ <servlet>
+ <description>Login servlet.</description>
+ <servlet-name>Login</servlet-name>
+ <servlet-class>net.sourceforge.guacamole.net.basic.BasicLogin</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Login</servlet-name>
+ <url-pattern>/login</url-pattern>
+ </servlet-mapping>
+
+ <!-- Basic Logout Servlet -->
+ <servlet>
+ <description>Logout servlet.</description>
+ <servlet-name>Logout</servlet-name>
+ <servlet-class>net.sourceforge.guacamole.net.basic.BasicLogout</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Logout</servlet-name>
+ <url-pattern>/logout</url-pattern>
+ </servlet-mapping>
+
+ <!-- Configuration List Servlet -->
+ <servlet>
+ <description>Configuration list servlet.</description>
+ <servlet-name>Configs</servlet-name>
+ <servlet-class>net.sourceforge.guacamole.net.basic.ConfigurationList</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Configs</servlet-name>
+ <url-pattern>/configs</url-pattern>
+ </servlet-mapping>
+
+ <!-- Guacamole Tunnel Servlet -->
+ <servlet>
+ <description>Tunnel servlet.</description>
+ <servlet-name>Tunnel</servlet-name>
+ <servlet-class>net.sourceforge.guacamole.net.basic.BasicGuacamoleTunnelServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Tunnel</servlet-name>
+ <url-pattern>/tunnel</url-pattern>
+ </servlet-mapping>
+
+</web-app>
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/agpl-3.0-standalone.html
^
|
@@ -0,0 +1,688 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>GNU Affero General Public License - GNU Project - Free Software Foundation (FSF)</title>
+</head>
+ <link rel="alternate" type="application/rdf+xml"
+ href="http://www.gnu.org/licenses/agpl-3.0.rdf" />
+<body>
+<h3 style="text-align: center;">GNU AFFERO GENERAL PUBLIC LICENSE</h3>
+<p style="text-align: center;">Version 3, 19 November 2007</p>
+
+<p>Copyright © 2007 Free Software Foundation,
+Inc. <<a href="http://fsf.org/">http://fsf.org/</a>>
+ <br />
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.</p>
+
+<h3><a name="preamble"></a>Preamble</h3>
+
+<p>The GNU Affero General Public License is a free, copyleft license
+for software and other kinds of works, specifically designed to ensure
+cooperation with the community in the case of network server software.</p>
+
+<p>The licenses for most software and other practical works are
+designed to take away your freedom to share and change the works. By
+contrast, our General Public Licenses are intended to guarantee your
+freedom to share and change all versions of a program--to make sure it
+remains free software for all its users.</p>
+
+<p>When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.</p>
+
+<p>Developers that use our General Public Licenses protect your rights
+with two steps: (1) assert copyright on the software, and (2) offer
+you this License which gives you legal permission to copy, distribute
+and/or modify the software.</p>
+
+<p>A secondary benefit of defending all users' freedom is that
+improvements made in alternate versions of the program, if they
+receive widespread use, become available for other developers to
+incorporate. Many developers of free software are heartened and
+encouraged by the resulting cooperation. However, in the case of
+software used on network servers, this result may fail to come about.
+The GNU General Public License permits making a modified version and
+letting the public access it on a server without ever releasing its
+source code to the public.</p>
+
+<p>The GNU Affero General Public License is designed specifically to
+ensure that, in such cases, the modified source code becomes available
+to the community. It requires the operator of a network server to
+provide the source code of the modified version running there to the
+users of that server. Therefore, public use of a modified version, on
+a publicly accessible server, gives the public access to the source
+code of the modified version.</p>
+
+<p>An older license, called the Affero General Public License and
+published by Affero, was designed to accomplish similar goals. This is
+a different license, not a version of the Affero GPL, but Affero has
+released a new version of the Affero GPL which permits relicensing under
+this license.</p>
+
+<p>The precise terms and conditions for copying, distribution and
+modification follow.</p>
+
+<h3><a name="terms"></a>TERMS AND CONDITIONS</h3>
+
+<h4><a name="section0"></a>0. Definitions.</h4>
+
+<p>"This License" refers to version 3 of the GNU Affero General Public
+License.</p>
+
+<p>"Copyright" also means copyright-like laws that apply to other kinds
+of works, such as semiconductor masks.</p>
+
+<p>"The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.</p>
+
+<p>To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.</p>
+
+<p>A "covered work" means either the unmodified Program or a work based
+on the Program.</p>
+
+<p>To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.</p>
+
+<p>To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.</p>
+
+<p>An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.</p>
+
+<h4><a name="section1"></a>1. Source Code.</h4>
+
+<p>The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.</p>
+
+<p>A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.</p>
+
+<p>The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.</p>
+
+<p>The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.</p>
+
+<p>The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.</p>
+
+<p>The Corresponding Source for a work in source code form is that
+same work.</p>
+
+<h4><a name="section2"></a>2. Basic Permissions.</h4>
+
+<p>All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.</p>
+
+<p>You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.</p>
+
+<p>Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.</p>
+
+<h4><a name="section3"></a>3. Protecting Users' Legal Rights From Anti-Circumvention Law.</h4>
+
+<p>No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.</p>
+
+<p>When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.</p>
+
+<h4><a name="section4"></a>4. Conveying Verbatim Copies.</h4>
+
+<p>You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.</p>
+
+<p>You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.</p>
+
+<h4><a name="section5"></a>5. Conveying Modified Source Versions.</h4>
+
+<p>You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:</p>
+
+<ul>
+
+<li>a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.</li>
+
+<li>b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".</li>
+
+<li>c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.</li>
+
+<li>d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.</li>
+
+</ul>
+
+<p>A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.</p>
+
+<h4><a name="section6"></a>6. Conveying Non-Source Forms.</h4>
+
+<p>You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:</p>
+
+<ul>
+
+<li>a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.</li>
+
+<li>b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.</li>
+
+<li>c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.</li>
+
+<li>d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.</li>
+
+<li>e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.</li>
+
+</ul>
+
+<p>A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.</p>
+
+<p>A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.</p>
+
+<p>"Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.</p>
+
+<p>If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).</p>
+
+<p>The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.</p>
+
+<p>Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.</p>
+
+<h4><a name="section7"></a>7. Additional Terms.</h4>
+
+<p>"Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.</p>
+
+<p>When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.</p>
+
+<p>Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:</p>
+
+<ul>
+
+<li>a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or</li>
+
+<li>b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or</li>
+
+<li>c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or</li>
+
+<li>d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or</li>
+
+<li>e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or</li>
+
+<li>f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.</li>
+
+</ul>
+
+<p>All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further restriction,
+you may remove that term. If a license document contains a further
+restriction but permits relicensing or conveying under this License, you
+may add to a covered work material governed by the terms of that license
+document, provided that the further restriction does not survive such
+relicensing or conveying.</p>
+
+<p>If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.</p>
+
+<p>Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.</p>
+
+<h4><a name="section8"></a>8. Termination.</h4>
+
+<p>You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).</p>
+
+<p>However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.</p>
+
+<p>Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.</p>
+
+<p>Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.</p>
+
+<h4><a name="section9"></a>9. Acceptance Not Required for Having Copies.</h4>
+
+<p>You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.</p>
+
+<h4><a name="section10"></a>10. Automatic Licensing of Downstream Recipients.</h4>
+
+<p>Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.</p>
+
+<p>An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.</p>
+
+<p>You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.</p>
+
+<h4><a name="section11"></a>11. Patents.</h4>
+
+<p>A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".</p>
+
+<p>A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.</p>
+
+<p>Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.</p>
+
+<p>In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.</p>
+
+<p>If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.</p>
+
+<p>If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.</p>
+
+<p>A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.</p>
+
+<p>Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.</p>
+
+<h4><a name="section12"></a>12. No Surrender of Others' Freedom.</h4>
+
+<p>If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.</p>
+
+<h4><a name="section13"></a>13. Remote Network Interaction; Use with the GNU General Public License.</h4>
+
+<p>Notwithstanding any other provision of this License, if you modify the
+Program, your modified version must prominently offer all users
+interacting with it remotely through a computer network (if your version
+supports such interaction) an opportunity to receive the Corresponding
+Source of your version by providing access to the Corresponding Source
+from a network server at no charge, through some standard or customary
+means of facilitating copying of software. This Corresponding Source
+shall include the Corresponding Source for any work covered by version 3
+of the GNU General Public License that is incorporated pursuant to the
+following paragraph.</p>
+
+<p>Notwithstanding any other provision of this License, you have permission
+to link or combine any covered work with a work licensed under version 3
+of the GNU General Public License into a single combined work, and to
+convey the resulting work. The terms of this License will continue to
+apply to the part which is the covered work, but the work with which it is
+combined will remain governed by version 3 of the GNU General Public
+License.</p>
+
+<h4><a name="section14"></a>14. Revised Versions of this License.</h4>
+
+<p>The Free Software Foundation may publish revised and/or new versions of
+the GNU Affero General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may differ
+in detail to address new problems or concerns.</p>
+
+<p>Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU Affero
+General Public License "or any later version" applies to it, you have
+the option of following the terms and conditions either of that
+numbered version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number
+of the GNU Affero General Public License, you may choose any version
+ever published by the Free Software Foundation.</p>
+
+<p>If the Program specifies that a proxy can decide which future
+versions of the GNU Affero General Public License can be used, that
+proxy's public statement of acceptance of a version permanently
+authorizes you to choose that version for the Program.</p>
+
+<p>Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.</p>
+
+<h4><a name="section15"></a>15. Disclaimer of Warranty.</h4>
+
+<p>THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.</p>
+
+<h4><a name="section16"></a>16. Limitation of Liability.</h4>
+
+<p>IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.</p>
+
+<h4><a name="section17"></a>17. Interpretation of Sections 15 and 16.</h4>
+
+<p>If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.</p>
+
+<p>END OF TERMS AND CONDITIONS</p>
+
+<h3><a name="howto"></a>How to Apply These Terms to Your New Programs</h3>
+
+<p>If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.</p>
+
+<p>To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.</p>
+
+<pre> <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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/>.
+</pre>
+
+<p>Also add information on how to contact you by electronic and paper mail.</p>
+
+<p>If your software can interact with users remotely through a computer
+network, you should also make sure that it provides a way for users to
+get its source. For example, if your program is a web application, its
+interface could display a "Source" link that leads users to an archive
+of the code. There are many ways you could offer source, and different
+solutions will be better for different programs; see section 13 for the
+specific requirements.</p>
+
+<p>You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU AGPL, see
+<<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>>.</p>
+
+</body></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)
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/guacamole-logo-144.png
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/guacamole-logo-24.png
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/guacamole-logo-64.png
^
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/mouse
^
|
+(directory)
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/mouse/blank.cur
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/mouse/blank.gif
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/mouse/dot.gif
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/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)
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/images/protocol-icons/tango/terminal.png
^
|
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/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)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/layouts/en-us-qwerty-mobile.xml
^
|
@@ -0,0 +1,312 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE keyboard PUBLIC
+ "-//Guacamole/Guacamole Onscreen Keyboard DTD 0.6.0//EN"
+ "http://guac-dev.org/pub/dtd/guacamole-osk-0.6.0.dtd">
+
+<!--
+ 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/>.
+-->
+
+<keyboard lang="en_US" layout="qwerty" size="16.3">
+ <row>
+ <key size="1.5">
+ <cap keysym="0xFF09">Tab</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>q</cap>
+ <cap if="numsym">1</cap>
+ <cap if="shift">Q</cap>
+ <cap if="numsym,shift">q</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>w</cap>
+ <cap if="numsym">2</cap>
+ <cap if="shift">W</cap>
+ <cap if="numsym,shift">w</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>e</cap>
+ <cap if="numsym">3</cap>
+ <cap if="shift">E</cap>
+ <cap if="numsym,shift">e</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>r</cap>
+ <cap if="numsym">4</cap>
+ <cap if="shift">R</cap>
+ <cap if="numsym,shift">r</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>t</cap>
+ <cap if="numsym">5</cap>
+ <cap if="shift">T</cap>
+ <cap if="numsym,shift">t</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>y</cap>
+ <cap if="numsym">6</cap>
+ <cap if="shift">Y</cap>
+ <cap if="numsym,shift">y</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>u</cap>
+ <cap if="numsym">7</cap>
+ <cap if="shift">U</cap>
+ <cap if="numsym,shift">u</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>i</cap>
+ <cap if="numsym">8</cap>
+ <cap if="shift">I</cap>
+ <cap if="numsym,shift">i</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>o</cap>
+ <cap if="numsym">9</cap>
+ <cap if="shift">O</cap>
+ <cap if="numsym,shift">o</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>p</cap>
+ <cap if="numsym">0</cap>
+ <cap if="shift">P</cap>
+ <cap if="numsym,shift">p</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>[</cap>
+ <cap if="shift">{</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>]</cap>
+ <cap if="shift">}</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.5">
+ <cap keysym="0xFF08">Back</cap>
+ </key>
+ </row>
+
+ <row><gap size="0.1"/></row>
+
+ <row>
+ <key size="1.85" class="numsym">
+ <cap modifier="numsym" sticky="true">?123</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>a</cap>
+ <cap if="numsym">#</cap>
+ <cap if="shift">A</cap>
+ <cap if="numsym,shift">a</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>s</cap>
+ <cap if="numsym">$</cap>
+ <cap if="shift">S</cap>
+ <cap if="numsym,shift">s</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>d</cap>
+ <cap if="numsym">%</cap>
+ <cap if="shift">D</cap>
+ <cap if="numsym,shift">d</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>f</cap>
+ <cap if="numsym">&</cap>
+ <cap if="shift">F</cap>
+ <cap if="numsym,shift">f</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>g</cap>
+ <cap if="numsym">*</cap>
+ <cap if="shift">G</cap>
+ <cap if="numsym,shift">g</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>h</cap>
+ <cap if="numsym">-</cap>
+ <cap if="shift">H</cap>
+ <cap if="numsym,shift">h</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>j</cap>
+ <cap if="numsym">+</cap>
+ <cap if="shift">J</cap>
+ <cap if="numsym,shift">j</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>k</cap>
+ <cap if="numsym">(</cap>
+ <cap if="shift">K</cap>
+ <cap if="numsym,shift">k</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>l</cap>
+ <cap if="numsym">)</cap>
+ <cap if="shift">L</cap>
+ <cap if="numsym,shift">l</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>;</cap>
+ <cap if="shift">:</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>'</cap>
+ <cap if="shift">"</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="2.25">
+ <cap keysym="0xFF0D">Enter</cap>
+ </key>
+ </row>
+
+ <row><gap size="0.1"/></row>
+
+ <row>
+ <key size="2.1" class="shift">
+ <cap modifier="shift" keysym="0xFFE1">Shift</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>z</cap>
+ <cap if="numsym"><</cap>
+ <cap if="shift">Z</cap>
+ <cap if="numsym,shift">z</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>x</cap>
+ <cap if="numsym">></cap>
+ <cap if="shift">X</cap>
+ <cap if="numsym,shift">x</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>c</cap>
+ <cap if="numsym">=</cap>
+ <cap if="shift">C</cap>
+ <cap if="numsym,shift">c</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>v</cap>
+ <cap if="numsym">'</cap>
+ <cap if="shift">V</cap>
+ <cap if="numsym,shift">v</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>b</cap>
+ <cap if="numsym">;</cap>
+ <cap if="shift">B</cap>
+ <cap if="numsym,shift">b</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>n</cap>
+ <cap if="numsym">,</cap>
+ <cap if="shift">N</cap>
+ <cap if="numsym,shift">n</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>m</cap>
+ <cap if="numsym">.</cap>
+ <cap if="shift">M</cap>
+ <cap if="numsym,shift">m</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>,</cap>
+ <cap if="numsym">!</cap>
+ <cap if="shift">!</cap>
+ <cap if="numsym,shift">!</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>.</cap>
+ <cap if="numsym">?</cap>
+ <cap if="shift">?</cap>
+ <cap if="numsym,shift">?</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>/</cap>
+ <cap if="shift">?</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="3.1" class="shift">
+ <cap modifier="shift" keysym="0xFFE2">Shift</cap>
+ </key>
+ </row>
+
+ <row><gap size="0.1"/></row>
+
+ <row>
+ <key size="1.6" class="control">
+ <cap modifier="control" keysym="0xFFE3">Ctrl</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.6" class="super">
+ <cap modifier="super" keysym="0xFFEB">Super</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.6" class="alt">
+ <cap modifier="alt" keysym="0xFFE9">Alt</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="6.1">
+ <cap> </cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.6" class="alt">
+ <cap modifier="alt" keysym="0xFFEA">Alt</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.6">
+ <cap keysym="0xFF67">Menu</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.6" class="control">
+ <cap modifier="control" keysym="0xFFE4">Ctrl</cap>
+ </key>
+ </row>
+</keyboard>
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/layouts/en-us-qwerty.xml
^
|
@@ -0,0 +1,496 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE keyboard PUBLIC
+ "-//Guacamole/Guacamole Onscreen Keyboard DTD 0.6.0//EN"
+ "http://guac-dev.org/pub/dtd/guacamole-osk-0.6.0.dtd">
+
+<!--
+ 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/>.
+-->
+
+<keyboard lang="en_US" layout="qwerty" size="22">
+ <row>
+ <key>
+ <cap keysym="0xFF1B">Esc</cap>
+ </key>
+ <gap size="0.8"/>
+ <key>
+ <cap keysym="0xFFBE">F1</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap keysym="0xFFBF">F2</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap keysym="0xFFC0">F3</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap keysym="0xFFC1">F4</cap>
+ </key>
+ <gap size="0.8"/>
+ <key>
+ <cap keysym="0xFFC2">F5</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap keysym="0xFFC3">F6</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap keysym="0xFFC4">F7</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap keysym="0xFFC5">F8</cap>
+ </key>
+ <gap size="0.8"/>
+ <key>
+ <cap keysym="0xFFC6">F9</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap keysym="0xFFC7">F10</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap keysym="0xFFC8">F11</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap keysym="0xFFC9">F12</cap>
+ </key>
+ </row>
+ <row>
+ <gap size="0.25"/>
+ </row>
+ <column>
+ <row>
+ <key>
+ <cap>`</cap>
+ <cap if="shift">~</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>1</cap>
+ <cap if="shift">!</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>2</cap>
+ <cap if="shift">@</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>3</cap>
+ <cap if="shift">#</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>4</cap>
+ <cap if="shift">$</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>5</cap>
+ <cap if="shift">%</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>6</cap>
+ <cap if="shift">^</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>7</cap>
+ <cap if="shift">&</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>8</cap>
+ <cap if="shift">*</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>9</cap>
+ <cap if="shift">(</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>0</cap>
+ <cap if="shift">)</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>-</cap>
+ <cap if="shift">_</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>=</cap>
+ <cap if="shift">+</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="2">
+ <cap keysym="0xFF08">Back</cap>
+ </key>
+ </row>
+
+ <row><gap size="0.1"/></row>
+
+ <row>
+ <key size="1.5">
+ <cap keysym="0xFF09">Tab</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>q</cap>
+ <cap if="caps">Q</cap>
+ <cap if="shift">Q</cap>
+ <cap if="caps,shift">q</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>w</cap>
+ <cap if="caps">W</cap>
+ <cap if="shift">W</cap>
+ <cap if="caps,shift">w</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>e</cap>
+ <cap if="caps">E</cap>
+ <cap if="shift">E</cap>
+ <cap if="caps,shift">e</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>r</cap>
+ <cap if="caps">R</cap>
+ <cap if="shift">R</cap>
+ <cap if="caps,shift">r</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>t</cap>
+ <cap if="caps">T</cap>
+ <cap if="shift">T</cap>
+ <cap if="caps,shift">t</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>y</cap>
+ <cap if="caps">Y</cap>
+ <cap if="shift">Y</cap>
+ <cap if="caps,shift">y</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>u</cap>
+ <cap if="caps">U</cap>
+ <cap if="shift">U</cap>
+ <cap if="caps,shift">u</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>i</cap>
+ <cap if="caps">I</cap>
+ <cap if="shift">I</cap>
+ <cap if="caps,shift">i</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>o</cap>
+ <cap if="caps">O</cap>
+ <cap if="shift">O</cap>
+ <cap if="caps,shift">o</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>p</cap>
+ <cap if="caps">P</cap>
+ <cap if="shift">P</cap>
+ <cap if="caps,shift">p</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>[</cap>
+ <cap if="shift">{</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>]</cap>
+ <cap if="shift">}</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.5">
+ <cap>\</cap>
+ <cap if="shift">|</cap>
+ </key>
+ </row>
+
+ <row><gap size="0.1"/></row>
+
+ <row>
+ <key size="1.85">
+ <cap modifier="caps" keysym="0xFFE5" sticky="true">Caps</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>a</cap>
+ <cap if="caps">A</cap>
+ <cap if="shift">A</cap>
+ <cap if="caps,shift">a</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>s</cap>
+ <cap if="caps">S</cap>
+ <cap if="shift">S</cap>
+ <cap if="caps,shift">s</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>d</cap>
+ <cap if="caps">D</cap>
+ <cap if="shift">D</cap>
+ <cap if="caps,shift">d</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>f</cap>
+ <cap if="caps">F</cap>
+ <cap if="shift">F</cap>
+ <cap if="caps,shift">f</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>g</cap>
+ <cap if="caps">G</cap>
+ <cap if="shift">G</cap>
+ <cap if="caps,shift">g</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>h</cap>
+ <cap if="caps">H</cap>
+ <cap if="shift">H</cap>
+ <cap if="caps,shift">h</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>j</cap>
+ <cap if="caps">J</cap>
+ <cap if="shift">J</cap>
+ <cap if="caps,shift">j</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>k</cap>
+ <cap if="caps">K</cap>
+ <cap if="shift">K</cap>
+ <cap if="caps,shift">k</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>l</cap>
+ <cap if="caps">L</cap>
+ <cap if="shift">L</cap>
+ <cap if="caps,shift">l</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>;</cap>
+ <cap if="shift">:</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>'</cap>
+ <cap if="shift">"</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="2.25">
+ <cap keysym="0xFF0D">Enter</cap>
+ </key>
+ </row>
+
+ <row><gap size="0.1"/></row>
+
+ <row>
+ <key size="2.1" class="shift">
+ <cap modifier="shift" keysym="0xFFE1">Shift</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>z</cap>
+ <cap if="caps">Z</cap>
+ <cap if="shift">Z</cap>
+ <cap if="caps,shift">z</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>x</cap>
+ <cap if="caps">X</cap>
+ <cap if="shift">X</cap>
+ <cap if="caps,shift">x</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>c</cap>
+ <cap if="caps">C</cap>
+ <cap if="shift">C</cap>
+ <cap if="caps,shift">c</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>v</cap>
+ <cap if="caps">V</cap>
+ <cap if="shift">V</cap>
+ <cap if="caps,shift">v</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>b</cap>
+ <cap if="caps">B</cap>
+ <cap if="shift">B</cap>
+ <cap if="caps,shift">b</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>n</cap>
+ <cap if="caps">N</cap>
+ <cap if="shift">N</cap>
+ <cap if="caps,shift">n</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>m</cap>
+ <cap if="caps">M</cap>
+ <cap if="shift">M</cap>
+ <cap if="caps,shift">m</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>,</cap>
+ <cap if="shift"><</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>.</cap>
+ <cap if="shift">></cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap>/</cap>
+ <cap if="shift">?</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="3.1" class="shift">
+ <cap modifier="shift" keysym="0xFFE2">Shift</cap>
+ </key>
+ </row>
+
+ <row><gap size="0.1"/></row>
+
+ <row>
+ <key size="1.6" class="control">
+ <cap modifier="control" keysym="0xFFE3">Ctrl</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.6" class="super">
+ <cap modifier="super" keysym="0xFFEB">Super</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.6" class="alt">
+ <cap modifier="alt" keysym="0xFFE9">Alt</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="6.1">
+ <cap> </cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.6" class="alt">
+ <cap modifier="alt" keysym="0xFFE3">Alt</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.6" class="super">
+ <cap modifier="super" keysym="0xFF67">Menu</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.6" class="control">
+ <cap modifier="control" keysym="0xFFE4">Ctrl</cap>
+ </key>
+ </row>
+ </column>
+ <column>
+ <row>
+ <gap size="0.25"/>
+ </row>
+ </column>
+ <column align="center">
+ <row>
+ <key size="1.75">
+ <cap keysym="0xFF63">Ins</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.75">
+ <cap keysym="0xFF50">Home</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.75">
+ <cap keysym="0xFF55">PgUp</cap>
+ </key>
+ </row>
+ <row><gap size="0.1"/></row>
+ <row>
+ <key size="1.75">
+ <cap keysym="0xFFFF">Del</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.75">
+ <cap keysym="0xFF57">End</cap>
+ </key>
+ <gap size="0.1"/>
+ <key size="1.75">
+ <cap keysym="0xFF56">PgDn</cap>
+ </key>
+ </row>
+ <row>
+ <gap/>
+ </row>
+ <row>
+ <key>
+ <cap keysym="0xFF52">↑</cap>
+ </key>
+ </row>
+ <row><gap size="0.1"/></row>
+ <row>
+ <key>
+ <cap keysym="0xFF51">←</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap keysym="0xFF54">↓</cap>
+ </key>
+ <gap size="0.1"/>
+ <key>
+ <cap keysym="0xFF53">→</cap>
+ </key>
+ </row>
+ </column>
+</keyboard>
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/scripts
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/scripts/connections.js
^
|
@@ -0,0 +1,36 @@
+
+
+function Config(protocol, id) {
+ this.protocol = protocol;
+ this.id = id;
+}
+
+function getConfigList(parameters) {
+
+ // Construct request URL
+ var configs_url = "configs";
+ if (parameters) configs_url += "?" + parameters;
+
+ // Get config list
+ var xhr = new XMLHttpRequest();
+ xhr.open("GET", configs_url, false);
+ xhr.send(null);
+
+ // If fail, throw error
+ if (xhr.status != 200)
+ throw new Error(xhr.statusText);
+
+ // Otherwise, get list
+ var configs = new Array();
+
+ var configElements = xhr.responseXML.getElementsByTagName("config");
+ for (var i=0; i<configElements.length; i++) {
+ configs.push(new Config(
+ configElements[i].getAttribute("protocol"),
+ configElements[i].getAttribute("id")
+ ));
+ }
+
+ return configs;
+
+}
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/scripts/interface.js
^
|
@@ -0,0 +1,783 @@
+
+// UI Definition
+var GuacamoleUI = {
+
+ "LOGOUT_PROMPT" : "Logging out will disconnect all of your active "
+ + "Guacamole sessions. Are you sure you wish to log out?",
+
+ /* Detection Constants */
+
+ "LONG_PRESS_DETECT_TIMEOUT" : 800, /* milliseconds */
+ "LONG_PRESS_MOVEMENT_THRESHOLD" : 10, /* pixels */
+ "MENU_CLOSE_DETECT_TIMEOUT" : 500, /* milliseconds */
+ "MENU_OPEN_DETECT_TIMEOUT" : 325, /* milliseconds */
+ "KEYBOARD_AUTO_RESIZE_INTERVAL" : 30, /* milliseconds */
+
+ /* Animation Constants */
+
+ "MENU_SHADE_STEPS" : 10, /* frames */
+ "MENU_SHADE_INTERVAL" : 30, /* milliseconds */
+ "MENU_SHOW_STEPS" : 5, /* frames */
+ "MENU_SHOW_INTERVAL" : 30, /* milliseconds */
+
+ /* OSK Mode Constants */
+ "OSK_MODE_NATIVE" : 1, /* "Show Keyboard" will show the platform's native OSK */
+ "OSK_MODE_GUAC" : 2, /* "Show Keyboard" will show Guac's built-in OSK */
+
+ /* UI Elements */
+
+ "viewport" : document.getElementById("viewportClone"),
+ "display" : document.getElementById("display"),
+ "menu" : document.getElementById("menu"),
+ "menuControl" : document.getElementById("menuControl"),
+ "touchMenu" : document.getElementById("touchMenu"),
+ "logo" : document.getElementById("status-logo"),
+ "eventTarget" : document.getElementById("eventTarget"),
+
+ "buttons": {
+
+ "showClipboard": document.getElementById("showClipboard"),
+ "showKeyboard" : document.getElementById("showKeyboard"),
+ "ctrlAltDelete": document.getElementById("ctrlAltDelete"),
+ "reconnect" : document.getElementById("reconnect"),
+ "logout" : document.getElementById("logout"),
+
+ "touchShowClipboard" : document.getElementById("touchShowClipboard"),
+ "touchShowKeyboard" : document.getElementById("touchShowKeyboard"),
+ "touchLogout" : document.getElementById("touchLogout")
+
+ },
+
+ "containers": {
+ "state" : document.getElementById("statusDialog"),
+ "clipboard" : document.getElementById("clipboardDiv"),
+ "touchClipboard": document.getElementById("touchClipboardDiv"),
+ "keyboard" : document.getElementById("keyboardContainer")
+ },
+
+ "state" : document.getElementById("statusText"),
+ "clipboard" : document.getElementById("clipboard"),
+ "touchClipboard" : document.getElementById("touchClipboard")
+
+};
+
+// Constant UI initialization and behavior
+(function() {
+
+ var menu_shaded = false;
+
+ var shade_interval = null;
+ var show_interval = null;
+
+ // Cache error image (might not be available when error occurs)
+ var guacErrorImage = new Image();
+ guacErrorImage.src = "images/noguacamole-logo-24.png";
+
+ // Function for adding a class to an element
+ var addClass;
+
+ // Function for removing a class from an element
+ var removeClass;
+
+ // If Node.classList is supported, implement addClass/removeClass using that
+ if (Node.classList) {
+
+ addClass = function(element, classname) {
+ element.classList.add(classname);
+ };
+
+ removeClass = function(element, classname) {
+ element.classList.remove(classname);
+ };
+
+ }
+
+ // Otherwise, implement own
+ else {
+
+ addClass = function(element, classname) {
+
+ // Simply add new class
+ element.className += " " + classname;
+
+ };
+
+ 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;
+
+ }
+ );
+
+ };
+
+ }
+
+
+ GuacamoleUI.hideStatus = function() {
+ removeClass(document.body, "guac-error");
+ GuacamoleUI.containers.state.style.visibility = "hidden";
+ GuacamoleUI.display.style.opacity = "1";
+ };
+
+ GuacamoleUI.showStatus = function(text) {
+ removeClass(document.body, "guac-error");
+ GuacamoleUI.containers.state.style.visibility = "visible";
+ GuacamoleUI.state.textContent = text;
+ GuacamoleUI.display.style.opacity = "1";
+ };
+
+ GuacamoleUI.showError = function(error) {
+ addClass(document.body, "guac-error");
+ GuacamoleUI.state.textContent = error;
+ GuacamoleUI.display.style.opacity = "0.1";
+ };
+
+ GuacamoleUI.hideTouchMenu = function() {
+ GuacamoleUI.touchMenu.style.visibility = "hidden";
+ };
+
+ function positionCentered(element) {
+ element.style.left =
+ ((GuacamoleUI.viewport.offsetWidth - element.offsetWidth) / 2
+ + window.pageXOffset)
+ + "px";
+
+ element.style.top =
+ ((GuacamoleUI.viewport.offsetHeight - element.offsetHeight) / 2
+ + window.pageYOffset)
+ + "px";
+ }
+
+ GuacamoleUI.showTouchMenu = function() {
+ positionCentered(GuacamoleUI.touchMenu);
+ GuacamoleUI.touchMenu.style.visibility = "visible";
+ };
+
+ GuacamoleUI.hideTouchClipboard = function() {
+ GuacamoleUI.touchClipboard.blur();
+ GuacamoleUI.containers.touchClipboard.style.visibility = "hidden";
+ };
+
+ GuacamoleUI.showTouchClipboard = function() {
+ positionCentered(GuacamoleUI.containers.touchClipboard);
+ GuacamoleUI.containers.touchClipboard.style.visibility = "visible";
+ };
+
+ GuacamoleUI.shadeMenu = function() {
+
+ if (!menu_shaded) {
+
+ var step = Math.floor(GuacamoleUI.menu.offsetHeight / GuacamoleUI.MENU_SHADE_STEPS) + 1;
+ var offset = 0;
+ menu_shaded = true;
+
+ window.clearInterval(show_interval);
+ shade_interval = window.setInterval(function() {
+
+ offset -= step;
+
+ GuacamoleUI.menu.style.transform =
+ GuacamoleUI.menu.style.WebkitTransform =
+ GuacamoleUI.menu.style.MozTransform =
+ GuacamoleUI.menu.style.OTransform =
+ GuacamoleUI.menu.style.msTransform =
+
+ "translateY(" + offset + "px)";
+
+ if (offset <= -GuacamoleUI.menu.offsetHeight) {
+ window.clearInterval(shade_interval);
+ GuacamoleUI.menu.style.visiblity = "hidden";
+ }
+
+ }, GuacamoleUI.MENU_SHADE_INTERVAL);
+ }
+
+ };
+
+ GuacamoleUI.showMenu = function() {
+
+ if (menu_shaded) {
+
+ var step = Math.floor(GuacamoleUI.menu.offsetHeight / GuacamoleUI.MENU_SHOW_STEPS) + 1;
+ var offset = -GuacamoleUI.menu.offsetHeight;
+ menu_shaded = false;
+ GuacamoleUI.menu.style.visiblity = "";
+
+ window.clearInterval(shade_interval);
+ show_interval = window.setInterval(function() {
+
+ offset += step;
+
+ if (offset >= 0) {
+ offset = 0;
+ window.clearInterval(show_interval);
+ }
+
+ GuacamoleUI.menu.style.transform =
+ GuacamoleUI.menu.style.WebkitTransform =
+ GuacamoleUI.menu.style.MozTransform =
+ GuacamoleUI.menu.style.OTransform =
+ GuacamoleUI.menu.style.msTransform =
+
+ "translateY(" + offset + "px)";
+
+ }, GuacamoleUI.MENU_SHOW_INTERVAL);
+ }
+
+ };
+
+ // Show/Hide clipboard
+ GuacamoleUI.buttons.showClipboard.onclick = function() {
+
+ var displayed = GuacamoleUI.containers.clipboard.style.display;
+ if (displayed != "block") {
+ GuacamoleUI.containers.clipboard.style.display = "block";
+ GuacamoleUI.buttons.showClipboard.innerHTML = "Hide Clipboard";
+ }
+ else {
+ GuacamoleUI.containers.clipboard.style.display = "none";
+ GuacamoleUI.buttons.showClipboard.innerHTML = "Show Clipboard";
+ GuacamoleUI.clipboard.onchange();
+ }
+
+ };
+
+ GuacamoleUI.buttons.touchShowClipboard.onclick = function() {
+ GuacamoleUI.hideTouchMenu();
+ GuacamoleUI.showTouchClipboard();
+ };
+
+ // Show/Hide keyboard
+ var keyboardResizeInterval = null;
+ GuacamoleUI.buttons.showKeyboard.onclick = function() {
+
+ // If Guac OSK shown, hide it.
+ var displayed = GuacamoleUI.containers.keyboard.style.display;
+ if (displayed == "block") {
+ GuacamoleUI.containers.keyboard.style.display = "none";
+ GuacamoleUI.buttons.showKeyboard.textContent = "Show Keyboard";
+
+ window.onresize = null;
+ window.clearInterval(keyboardResizeInterval);
+ }
+
+ // Otherwise, show it
+ else {
+
+ // Ensure event target is NOT focused if we are using the Guac OSK.
+ GuacamoleUI.eventTarget.blur();
+
+ GuacamoleUI.containers.keyboard.style.display = "block";
+ GuacamoleUI.buttons.showKeyboard.textContent = "Hide Keyboard";
+
+ // Automatically update size
+ window.onresize = updateKeyboardSize;
+ keyboardResizeInterval = window.setInterval(updateKeyboardSize,
+ GuacamoleUI.KEYBOARD_AUTO_RESIZE_INTERVAL);
+
+ updateKeyboardSize();
+
+ }
+
+ };
+
+ // Touch-specific keyboard show
+ GuacamoleUI.buttons.touchShowKeyboard.onclick =
+ function(e) {
+
+ // Center event target in case browser automatically centers
+ // input fields on focus.
+ GuacamoleUI.eventTarget.style.left =
+ (window.pageXOffset + GuacamoleUI.viewport.offsetWidth / 2) + "px";
+
+ GuacamoleUI.eventTarget.style.top =
+ (window.pageYOffset + GuacamoleUI.viewport.offsetHeight / 2) + "px";
+
+ GuacamoleUI.eventTarget.focus();
+ GuacamoleUI.hideTouchMenu();
+
+ };
+
+ // Logout
+ GuacamoleUI.buttons.logout.onclick =
+ GuacamoleUI.buttons.touchLogout.onclick =
+ function() {
+
+ // Logout after warning user about session disconnect
+ if (confirm(GuacamoleUI.LOGOUT_PROMPT)) {
+ window.location.href = "logout";
+ GuacamoleUI.hideTouchMenu();
+ }
+
+ };
+
+ // Timeouts for detecting if users wants menu to open or close
+ var detectMenuOpenTimeout = null;
+ var detectMenuCloseTimeout = null;
+
+ // Clear detection timeouts
+ GuacamoleUI.resetMenuDetect = function() {
+
+ if (detectMenuOpenTimeout != null) {
+ window.clearTimeout(detectMenuOpenTimeout);
+ detectMenuOpenTimeout = null;
+ }
+
+ if (detectMenuCloseTimeout != null) {
+ window.clearTimeout(detectMenuCloseTimeout);
+ detectMenuCloseTimeout = null;
+ }
+
+ };
+
+ // Initiate detection of menu open action. If not canceled through some
+ // user event, menu will open.
+ GuacamoleUI.startMenuOpenDetect = function() {
+
+ if (!detectMenuOpenTimeout) {
+
+ // Clear detection state
+ GuacamoleUI.resetMenuDetect();
+
+ // Wait and then show menu
+ detectMenuOpenTimeout = window.setTimeout(function() {
+
+ // If menu opened via mouse, do not show native OSK
+ GuacamoleUI.oskMode = GuacamoleUI.OSK_MODE_GUAC;
+
+ GuacamoleUI.showMenu();
+ detectMenuOpenTimeout = null;
+ }, GuacamoleUI.MENU_OPEN_DETECT_TIMEOUT);
+
+ }
+
+ };
+
+ // Initiate detection of menu close action. If not canceled through some
+ // user mouse event, menu will close.
+ GuacamoleUI.startMenuCloseDetect = function() {
+
+ if (!detectMenuCloseTimeout) {
+
+ // Clear detection state
+ GuacamoleUI.resetMenuDetect();
+
+ // Wait and then shade menu
+ detectMenuCloseTimeout = window.setTimeout(function() {
+ GuacamoleUI.shadeMenu();
+ detectMenuCloseTimeout = null;
+ }, GuacamoleUI.MENU_CLOSE_DETECT_TIMEOUT);
+
+ }
+
+ };
+
+ // Show menu if mouseover any part of menu
+ GuacamoleUI.menu.addEventListener('mouseover', GuacamoleUI.showMenu, true);
+
+ // Stop detecting menu state change intents if mouse is over menu
+ GuacamoleUI.menu.addEventListener('mouseover', GuacamoleUI.resetMenuDetect, true);
+
+ // When mouse hovers over top of screen, start detection of intent to open menu
+ GuacamoleUI.menuControl.addEventListener('mousemove', GuacamoleUI.startMenuOpenDetect, true);
+
+ var long_press_start_x = 0;
+ var long_press_start_y = 0;
+ var menuShowLongPressTimeout = null;
+
+ GuacamoleUI.startLongPressDetect = function() {
+
+ if (!menuShowLongPressTimeout) {
+
+ menuShowLongPressTimeout = window.setTimeout(function() {
+
+ menuShowLongPressTimeout = null;
+
+ // Assume native OSK if menu shown via long-press
+ GuacamoleUI.oskMode = GuacamoleUI.OSK_MODE_NATIVE;
+ GuacamoleUI.showTouchMenu();
+
+ }, GuacamoleUI.LONG_PRESS_DETECT_TIMEOUT);
+
+ }
+ };
+
+ GuacamoleUI.stopLongPressDetect = function() {
+ window.clearTimeout(menuShowLongPressTimeout);
+ menuShowLongPressTimeout = null;
+ };
+
+ // Detect long-press at bottom of screen
+ GuacamoleUI.display.addEventListener('touchstart', function(e) {
+
+ // Close menu if shown
+ GuacamoleUI.shadeMenu();
+ GuacamoleUI.hideTouchMenu();
+ GuacamoleUI.hideTouchClipboard();
+
+ // Record touch location
+ if (e.touches.length == 1) {
+ var touch = e.touches[0];
+ long_press_start_x = touch.screenX;
+ long_press_start_y = touch.screenY;
+ }
+
+ // Start detection
+ GuacamoleUI.startLongPressDetect();
+
+ }, true);
+
+ // Stop detection if touch moves significantly
+ GuacamoleUI.display.addEventListener('touchmove', function(e) {
+
+ // If touch distance from start exceeds threshold, cancel long press
+ var touch = e.touches[0];
+ if (Math.abs(touch.screenX - long_press_start_x) >= GuacamoleUI.LONG_PRESS_MOVEMENT_THRESHOLD
+ || Math.abs(touch.screenY - long_press_start_y) >= GuacamoleUI.LONG_PRESS_MOVEMENT_THRESHOLD)
+ GuacamoleUI.stopLongPressDetect();
+
+ }, true);
+
+ // Stop detection if press stops
+ GuacamoleUI.display.addEventListener('touchend', GuacamoleUI.stopLongPressDetect, true);
+
+ // Close menu on mouse movement
+ GuacamoleUI.display.addEventListener('mousemove', GuacamoleUI.startMenuCloseDetect, true);
+ GuacamoleUI.display.addEventListener('mousedown', GuacamoleUI.startMenuCloseDetect, true);
+
+ // Reconnect button
+ GuacamoleUI.buttons.reconnect.onclick = function() {
+ window.location.reload();
+ };
+
+ // On-screen keyboard
+ GuacamoleUI.keyboard = new Guacamole.OnScreenKeyboard("layouts/en-us-qwerty.xml");
+ GuacamoleUI.containers.keyboard.appendChild(GuacamoleUI.keyboard.getElement());
+
+ // Function for automatically updating keyboard size
+ var lastKeyboardWidth;
+ function updateKeyboardSize() {
+ var currentSize = GuacamoleUI.keyboard.getElement().offsetWidth;
+ if (lastKeyboardWidth != currentSize) {
+ GuacamoleUI.keyboard.resize(currentSize);
+ lastKeyboardWidth = currentSize;
+ }
+ };
+
+ // Turn off autocorrect and autocapitalization on eventTarget
+ GuacamoleUI.eventTarget.setAttribute("autocorrect", "off");
+ GuacamoleUI.eventTarget.setAttribute("autocapitalize", "off");
+
+ // Automatically reposition event target on scroll
+ window.addEventListener("scroll", function() {
+ GuacamoleUI.eventTarget.style.left = window.pageXOffset + "px";
+ GuacamoleUI.eventTarget.style.top = window.pageYOffset + "px";
+ });
+
+})();
+
+// Tie UI events / behavior to a specific Guacamole client
+GuacamoleUI.attach = function(guac) {
+
+ var title_prefix = null;
+ var connection_name = "Guacamole";
+
+ var guac_display = guac.getDisplay();
+
+ // Set document title appropriately, based on prefix and connection name
+ function updateTitle() {
+
+ // Use title prefix if present
+ if (title_prefix) {
+
+ document.title = title_prefix;
+
+ // Include connection name, if present
+ if (connection_name)
+ document.title += " " + connection_name;
+
+ }
+
+ // Otherwise, just set to connection name
+ else if (connection_name)
+ document.title = connection_name;
+
+ }
+
+ // When mouse enters display, start detection of intent to close menu
+ guac_display.addEventListener('mouseover', GuacamoleUI.startMenuCloseDetect, true);
+
+ guac_display.onclick = function(e) {
+ e.preventDefault();
+ return false;
+ };
+
+ // Mouse
+ var mouse = new Guacamole.Mouse(guac_display);
+ var touch = new Guacamole.Mouse.Touchpad(guac_display);
+ touch.onmousedown = touch.onmouseup = touch.onmousemove =
+ mouse.onmousedown = mouse.onmouseup = mouse.onmousemove =
+ function(mouseState) {
+
+ // Determine mouse position within view
+ var mouse_view_x = mouseState.x + guac_display.offsetLeft - window.pageXOffset;
+ var mouse_view_y = mouseState.y + guac_display.offsetTop - window.pageYOffset;
+
+ // Determine viewport dimensioins
+ var view_width = GuacamoleUI.viewport.offsetWidth;
+ var view_height = GuacamoleUI.viewport.offsetHeight;
+
+ // Determine scroll amounts based on mouse position relative to document
+
+ var scroll_amount_x;
+ if (mouse_view_x > view_width)
+ scroll_amount_x = mouse_view_x - view_width;
+ else if (mouse_view_x < 0)
+ scroll_amount_x = mouse_view_x;
+ else
+ scroll_amount_x = 0;
+
+ var scroll_amount_y;
+ if (mouse_view_y > view_height)
+ scroll_amount_y = mouse_view_y - view_height;
+ else if (mouse_view_y < 0)
+ scroll_amount_y = mouse_view_y;
+ else
+ scroll_amount_y = 0;
+
+ // Scroll (if necessary) to keep mouse on screen.
+ window.scrollBy(scroll_amount_x, scroll_amount_y);
+
+ // Send mouse event
+ guac.sendMouseState(mouseState);
+
+ };
+
+ // Keyboard
+ var keyboard = new Guacamole.Keyboard(document);
+
+ // Monitor whether the event target is focused
+ var eventTargetFocused = false;
+
+ // Save length for calculation of changed value
+ var currentLength = GuacamoleUI.eventTarget.value.length;
+
+ GuacamoleUI.eventTarget.onfocus = function() {
+ eventTargetFocused = true;
+ GuacamoleUI.eventTarget.value = "";
+ currentLength = 0;
+ };
+
+ GuacamoleUI.eventTarget.onblur = function() {
+ eventTargetFocused = false;
+ };
+
+ // If text is input directly into event target without typing (as with
+ // voice input, for example), type automatically.
+ GuacamoleUI.eventTarget.oninput = function(e) {
+
+ // Calculate current length and change in length
+ var oldLength = currentLength;
+ currentLength = GuacamoleUI.eventTarget.value.length;
+
+ // If deleted or replaced text, ignore
+ if (currentLength <= oldLength)
+ return;
+
+ // Get changed text
+ var text = GuacamoleUI.eventTarget.value.substring(oldLength);
+
+ // Send each character
+ for (var i=0; i<text.length; i++) {
+
+ // Get char code
+ var charCode = text.charCodeAt(i);
+
+ // Convert to keysym
+ var keysym = 0x003F; // Default to a question mark
+ if (charCode >= 0x0000 && charCode <= 0x00FF)
+ keysym = charCode;
+ else if (charCode >= 0x0100 && charCode <= 0x10FFFF)
+ keysym = 0x01000000 | charCode;
+
+ // Send keysym only if not already pressed
+ if (!keyboard.pressed[keysym]) {
+
+ // Press and release key
+ guac.sendKeyEvent(1, keysym);
+ guac.sendKeyEvent(0, keysym);
+
+ }
+
+ }
+
+ }
+
+ function isTypableCharacter(keysym) {
+ return (keysym & 0xFFFF00) != 0xFF00;
+ }
+
+ function disableKeyboard() {
+ keyboard.onkeydown = null;
+ keyboard.onkeyup = null;
+ }
+
+ function enableKeyboard() {
+
+ keyboard.onkeydown = function (keysym) {
+ guac.sendKeyEvent(1, keysym);
+ return eventTargetFocused && isTypableCharacter(keysym);
+ };
+
+ keyboard.onkeyup = function (keysym) {
+ guac.sendKeyEvent(0, keysym);
+ return eventTargetFocused && isTypableCharacter(keysym);
+ };
+
+ }
+
+ // Enable keyboard by default
+ enableKeyboard();
+
+ // Handle client state change
+ guac.onstatechange = function(clientState) {
+
+ switch (clientState) {
+
+ // Idle
+ case 0:
+ GuacamoleUI.showStatus("Idle.");
+ title_prefix = "[Idle]";
+ break;
+
+ // Connecting
+ case 1:
+ GuacamoleUI.shadeMenu();
+ GuacamoleUI.showStatus("Connecting...");
+ title_prefix = "[Connecting...]";
+ break;
+
+ // Connected + waiting
+ case 2:
+ GuacamoleUI.showStatus("Connected, waiting for first update...");
+ title_prefix = "[Waiting...]";
+ break;
+
+ // Connected
+ case 3:
+ GuacamoleUI.hideStatus();
+ title_prefix = null;
+ break;
+
+ // Disconnecting
+ case 4:
+ GuacamoleUI.showStatus("Disconnecting...");
+ title_prefix = "[Disconnecting...]";
+ break;
+
+ // Disconnected
+ case 5:
+ GuacamoleUI.showStatus("Disconnected.");
+ title_prefix = "[Disconnected]";
+ break;
+
+ // Unknown status code
+ default:
+ GuacamoleUI.showStatus("[UNKNOWN STATUS]");
+
+ }
+
+ updateTitle();
+ };
+
+ // Name instruction handler
+ guac.onname = function(name) {
+ connection_name = name;
+ updateTitle();
+ };
+
+ // Error handler
+ guac.onerror = function(error) {
+
+ // Disconnect, if connected
+ guac.disconnect();
+
+ // Display error message
+ GuacamoleUI.showError(error);
+
+ };
+
+ // Disconnect on close
+ window.onunload = function() {
+ guac.disconnect();
+ };
+
+ // Handle clipboard events
+ GuacamoleUI.clipboard.onchange = function() {
+
+ var text = GuacamoleUI.clipboard.value;
+ GuacamoleUI.touchClipboard.value = text;
+ guac.setClipboard(text);
+
+ };
+
+ GuacamoleUI.touchClipboard.onchange = function() {
+
+ var text = GuacamoleUI.touchClipboard.value;
+ GuacamoleUI.clipboard.value = text;
+ guac.setClipboard(text);
+
+ };
+
+ // Ignore keypresses when clipboard is focused
+ GuacamoleUI.clipboard.onfocus =
+ GuacamoleUI.touchClipboard.onfocus = function() {
+ disableKeyboard();
+ };
+
+ // Capture keypresses when clipboard is not focused
+ GuacamoleUI.clipboard.onblur =
+ GuacamoleUI.touchClipboard.onblur = function() {
+ enableKeyboard();
+ };
+
+ // Server copy handler
+ guac.onclipboard = function(data) {
+ GuacamoleUI.clipboard.value = data;
+ GuacamoleUI.touchClipboard.value = data;
+ };
+
+ GuacamoleUI.keyboard.onkeydown = function(keysym) {
+ guac.sendKeyEvent(1, keysym);
+ };
+
+ GuacamoleUI.keyboard.onkeyup = function(keysym) {
+ guac.sendKeyEvent(0, keysym);
+ };
+
+ // Send Ctrl-Alt-Delete
+ GuacamoleUI.buttons.ctrlAltDelete.onclick = function() {
+
+ var KEYSYM_CTRL = 0xFFE3;
+ var KEYSYM_ALT = 0xFFE9;
+ var KEYSYM_DELETE = 0xFFFF;
+
+ guac.sendKeyEvent(1, KEYSYM_CTRL);
+ guac.sendKeyEvent(1, KEYSYM_ALT);
+ guac.sendKeyEvent(1, KEYSYM_DELETE);
+ guac.sendKeyEvent(0, KEYSYM_DELETE);
+ guac.sendKeyEvent(0, KEYSYM_ALT);
+ guac.sendKeyEvent(0, KEYSYM_CTRL);
+ };
+
+};
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/styles
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/styles/client.css
^
|
@@ -0,0 +1,300 @@
+
+/*
+ * 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/>.
+ */
+
+body {
+ background: black;
+ font-family: sans-serif;
+ padding: 0;
+ margin: 0;
+}
+
+img {
+ border: none;
+}
+
+.software-cursor {
+ cursor: url('../images/mouse/dot.gif'),url('../images/mouse/blank.cur'),default;
+ overflow: hidden;
+}
+
+.guac-error .software-cursor {
+ cursor: default;
+}
+
+* {
+ -webkit-tap-highlight-color: rgba(0,0,0,0);
+}
+
+/* Dialogs */
+
+div.dialogOuter {
+ display: table;
+ height: 100%;
+ width: 100%;
+ position: fixed;
+ left: 0;
+ top: 0;
+
+ visibility: hidden;
+}
+
+div.dialogMiddle {
+ width: 100%;
+ text-align: center;
+ display: table-cell;
+ vertical-align: middle;
+}
+
+div.dialog {
+ padding: 1em;
+
+ max-width: 75%;
+ text-align: left;
+
+ display: inline-block;
+ visibility: visible;
+}
+
+div.dialog h1 {
+ margin: 0;
+ margin-bottom: 0.25em;
+ text-align: center;
+}
+
+div.dialog div.buttons {
+ margin: 0;
+ margin-top: 0.5em;
+ text-align: center;
+}
+
+button {
+
+ border-style: solid;
+ border-width: 1px;
+
+ padding: 0.25em;
+ padding-right: 1em;
+ padding-left: 1em;
+
+}
+
+button:active {
+
+ padding-top: 0.35em;
+ padding-left: 1.1em;
+
+ padding-bottom: 0.15em;
+ padding-right: 0.9em;
+
+}
+
+button#reconnect {
+ display: none;
+}
+
+.guac-error button#reconnect {
+ display: inline;
+
+ background: #200;
+ border-color: #822;
+ color: #944;
+}
+
+.guac-error button#reconnect:hover {
+ background: #822;
+ border-color: #B33;
+ color: black;
+}
+
+
+div.dialog p {
+ margin: 0;
+}
+
+#statusText {
+ text-shadow: 0 0 0.25em black, 0 0 0.25em black, 0 0 0.25em black, 0 0 0.25em black;
+ font-size: xx-large;
+ color: white;
+}
+
+.guac-error #statusText {
+ text-shadow: 0 0 0.25em black, 0 0 0.25em black, 0 0 0.25em black, 0 0 0.25em black;
+ color: #D44;
+}
+
+/* Menu */
+
+#menu {
+ position: fixed;
+ left: 0;
+ top: 0;
+ width: 100%;
+ z-index: 4;
+ background: #FEA;
+ border-bottom: 1px solid black;
+ font-size: 0.8em;
+}
+
+.guac-error #menu {
+ background: #D44;
+}
+
+div#display * {
+ position: relative;
+ margin-left: auto;
+ margin-right: auto;
+}
+
+#menu img {
+ vertical-align: middle;
+}
+
+#menu span {
+ vertical-align: middle;
+}
+
+#menu button {
+ vertical-align: middle;
+ background: #DC8;
+ border-color: #986;
+ color: black;
+}
+
+#menu button:hover {
+ background: #FFC;
+ border-color: #DC8;
+}
+
+.guac-error #menu button {
+ background: #B33;
+ border-color: #822;
+}
+
+.guac-error #menu button:hover {
+ background: #F44;
+ border-color: #B33;
+}
+
+div#clipboardDiv {
+ display: none;
+ position: absolute;
+ background: #FA5;
+ padding: 1em;
+
+ border: 1px solid black;
+
+ width: 50em;
+ z-index: 2;
+ opacity: 0.5;
+}
+
+#menu:hover div#clipboardDiv {
+ opacity: 1;
+}
+
+div#clipboardDiv h2 {
+ margin: 0;
+ font-size: 1em;
+}
+
+div#clipboardDiv textarea {
+ width: 100%;
+}
+
+div#menuControl {
+ position: fixed;
+ top: 0;
+ left: 0;
+
+ width: 100%;
+ height: 3px;
+ background: none;
+
+ z-index: 3;
+}
+
+/* Viewport Clone */
+
+div#viewportClone {
+ display: table;
+ height: 100%;
+ width: 100%;
+ position: fixed;
+ left: 0;
+ top: 0;
+
+ visibility: hidden;
+}
+
+/* Keyboard event target */
+
+textarea#eventTarget {
+ position: absolute;
+
+ /* Hide offscreen */
+ left: 0;
+ top: 0;
+ width: 0;
+ height: 0;
+ opacity: 0;
+
+ overflow: hidden;
+}
+
+/* Touch-specific menu */
+
+div#touchMenu {
+
+ position: absolute;
+ visibility: hidden;
+ z-index: 4;
+
+ white-space: pre;
+ background: black;
+ border: 1px solid silver;
+ padding: 1em;
+ opacity: 0.8;
+
+}
+
+div#touchClipboardDiv {
+
+ position: absolute;
+ visibility: hidden;
+ z-index: 4;
+
+ color: white;
+ background: black;
+ border: 1px solid silver;
+ padding: 1em;
+ opacity: 0.8;
+
+ max-width: 50em;
+
+}
+
+div#touchClipboardDiv h2 {
+ margin: 0;
+ font-size: 1em;
+}
+
+div#touchClipboardDiv textarea {
+ width: 100%;
+}
+
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/styles/keyboard.css
^
|
@@ -0,0 +1,151 @@
+
+/*
+ * 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/>.
+ */
+
+#keyboardContainer {
+ text-align: center;
+
+ position: fixed;
+ left: 0;
+ bottom: 0;
+ width: 100%;
+ margin: 0;
+ padding: 0;
+
+ border-top: 1px solid black;
+ background: #222;
+ opacity: 0.85;
+
+ display: none;
+ z-index: 1;
+}
+
+.guac-keyboard {
+ display: inline-block;
+ width: 100%;
+
+ margin: 0;
+ padding: 0;
+ cursor: default;
+
+ text-align: left;
+ vertical-align: middle;
+}
+
+.guac-keyboard .guac-keyboard-key-container {
+ display: inline-block;
+}
+
+.guac-keyboard .guac-keyboard-key {
+ background: #444;
+ border: 1px outset #888;
+ -moz-border-radius: 0.1em;
+ -webkit-border-radius: 0.1em;
+ -khtml-border-radius: 0.1em;
+ border-radius: 0.1em;
+}
+
+.guac-keyboard .guac-keyboard-cap {
+ color: white;
+ font-family: sans-serif;
+ font-size: 50%;
+ font-weight: lighter;
+ text-align: center;
+ white-space: pre;
+}
+
+.guac-keyboard .guac-keyboard-key:hover {
+ cursor: pointer;
+}
+
+.guac-keyboard .guac-keyboard-key.highlight {
+ background: #666;
+ border-color: #666;
+}
+
+.guac-keyboard.guac-keyboard-modifier-shift .guac-keyboard-key.shift,
+.guac-keyboard.guac-keyboard-modifier-numsym .guac-keyboard-key.numsym {
+ background: #882;
+ border-color: #DD4;
+}
+
+.guac-keyboard.guac-keyboard-modifier-control .guac-keyboard-key.control,
+.guac-keyboard.guac-keyboard-modifier-numsym .guac-keyboard-key.numsym {
+ background: #882;
+ border-color: #DD4;
+}
+
+.guac-keyboard.guac-keyboard-modifier-alt .guac-keyboard-key.alt,
+.guac-keyboard.guac-keyboard-modifier-numsym .guac-keyboard-key.numsym {
+ background: #882;
+ border-color: #DD4;
+}
+
+.guac-keyboard.guac-keyboard-modifier-super .guac-keyboard-key.super,
+.guac-keyboard.guac-keyboard-modifier-numsym .guac-keyboard-key.numsym {
+ background: #882;
+ border-color: #DD4;
+}
+
+.guac-keyboard .guac-keyboard-key.guac-keyboard-pressed {
+ background: #822;
+ border-color: #D44;
+ border-style: inset;
+}
+
+.guac-keyboard .guac-keyboard-row {
+ line-height: 0;
+}
+
+.guac-keyboard .guac-keyboard-column {
+ display: inline-block;
+ text-align: center;
+ vertical-align: top;
+}
+
+.guac-keyboard .guac-keyboard-gap {
+ display: inline-block;
+}
+
+/* Hide keycaps requiring modifiers which are NOT currently active. */
+.guac-keyboard:not(.guac-keyboard-modifier-caps)
+.guac-keyboard-cap.guac-keyboard-requires-caps,
+
+.guac-keyboard:not(.guac-keyboard-modifier-numsym)
+.guac-keyboard-cap.guac-keyboard-requires-numsym,
+
+.guac-keyboard:not(.guac-keyboard-modifier-shift)
+.guac-keyboard-cap.guac-keyboard-requires-shift,
+
+/* Hide keycaps NOT requiring modifiers which ARE currently active, where that
+ modifier is used to determine which cap is displayed for the current key. */
+.guac-keyboard.guac-keyboard-modifier-shift
+.guac-keyboard-key.guac-keyboard-uses-shift
+.guac-keyboard-cap:not(.guac-keyboard-requires-shift),
+
+.guac-keyboard.guac-keyboard-modifier-numsym
+.guac-keyboard-key.guac-keyboard-uses-numsym
+.guac-keyboard-cap:not(.guac-keyboard-requires-numsym),
+
+.guac-keyboard.guac-keyboard-modifier-caps
+.guac-keyboard-key.guac-keyboard-uses-caps
+.guac-keyboard-cap:not(.guac-keyboard-requires-caps) {
+
+ display: none;
+
+}
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/guacamole-0.6.2/styles/login.css
^
|
@@ -0,0 +1,235 @@
+
+/*
+ * 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/>.
+ */
+
+body {
+ background: gray;
+ font-family: sans-serif;
+ padding: 0;
+ margin: 0;
+}
+
+div#login-ui {
+ background: #BCA;
+ height: 100%;
+ width: 100%;
+ position: fixed;
+ left: 0;
+ top: 0;
+ display: table;
+}
+
+p#login-error {
+ text-align: center;
+ background: #FDD;
+ color: red;
+ margin: 0.2em;
+}
+
+div#login-logo {
+ position: relative;
+ bottom: 0;
+ display: inline-block;
+ vertical-align: middle;
+}
+
+div#login-dialog-middle {
+ width: 100%;
+ display: table-cell;
+ vertical-align: middle;
+ text-align: center;
+}
+
+div#login-dialog {
+
+ max-width: 75%;
+ text-align: left;
+
+ display: inline-block;
+}
+
+div#login-dialog h1 {
+ margin-top: 0;
+ margin-bottom: 0em;
+ text-align: center;
+}
+
+div#login-dialog #buttons {
+ padding-top: 0.5em;
+ text-align: right;
+}
+
+div#login-dialog #buttons input,
+div#logout-panel button {
+ background: #9A8;
+ border: 1px solid #676;
+ color: black;
+ padding: 0.25em;
+ padding-right: 1em;
+ padding-left: 1em;
+}
+
+div#login-dialog #buttons input:hover,
+div#logout-panel button:hover {
+ background: #CDB;
+ border: 1px solid #9A8;
+}
+
+div#login-dialog #buttons input:active,
+div#logout-panel button:active {
+ padding-top: 0.35em;
+ padding-left: 1.1em;
+
+ padding-bottom: 0.15em;
+ padding-right: 0.9em;
+}
+
+div#login-dialog #login-fields {
+
+ background: #CDB;
+ vertical-align: middle;
+
+ padding: 1em;
+ border: 1px solid #676;
+
+}
+
+div#login-dialog #login-fields input {
+ border: 1px solid #676;
+}
+
+div#login-dialog #login-fields img.logo {
+ float: left;
+}
+
+div#version-dialog {
+ position: fixed;
+ right: 0;
+ bottom: 0;
+ text-align: right;
+
+ font-style: italic;
+ font-size: 0.75em;
+ color: black;
+ opacity: 0.5;
+
+ padding: 0.25em;
+}
+
+img {
+ border: none;
+}
+
+img#license {
+ float: right;
+ margin: 2px;
+}
+
+div#connection-list-ui {
+ background: #BCA;
+}
+
+div#connection-list-ui table {
+ width: 100%;
+ border-collapse: collapse;
+}
+
+div#connection-list-ui table thead {
+ background: #9A8;
+}
+
+div#connection-list-ui table thead th.protocol {
+ width: 1em;
+ padding: 0.5em;
+}
+
+div#connection-list-ui table thead th.name {
+ text-align: left;
+ padding: 0.5em;
+}
+
+div#connection-list-ui table thead tr {
+ border-top: 1px solid #676;
+ border-bottom: 1px solid gray;
+}
+
+div#connection-list-ui table tbody {
+ background: white;
+}
+
+div#connection-list-ui table tbody tr {
+ border-top: 1px solid gray;
+ border-bottom: 1px solid gray;
+}
+
+div#connection-list-ui table td {
+ padding: 0.25em;
+ text-align: center;
+}
+
+div#connection-list-ui table td.name {
+ text-align: left;
+}
+
+div#connection-list-ui table tbody tr:nth-child(even) { background: #CCC; }
+div#connection-list-ui table tbody tr:nth-child(odd) { background: #EEE; }
+
+div#connection-list-ui table td.description {
+ text-align: left;
+}
+
+div#connection-list-ui h1 {
+
+ margin: 0;
+ padding: 0.5em;
+
+ font-size: 2em;
+ vertical-align: middle;
+ text-align: center;
+
+}
+
+div#connection-list-ui img {
+ vertical-align: middle;
+}
+
+div#logout-panel {
+ padding: 0.25em;
+ text-align: right;
+ float: right;
+}
+
+div#connection-list-ui a[href] {
+ text-decoration: none;
+ color: blue;
+}
+
+div#connection-list-ui a[href]:hover {
+ text-decoration: underline;
+}
+
+.protocol.icon {
+ width: 24px;
+ height: 24px;
+ background-image: url('../images/protocol-icons/tango/video-display.png');
+}
+
+.protocol.icon.ssh {
+ background-image: url('../images/protocol-icons/tango/terminal.png');
+}
+
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/maven-archiver
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/maven-archiver/pom.properties
^
|
@@ -0,0 +1,5 @@
+#Generated by Maven
+#Fri Oct 19 20:56:18 CEST 2012
+version=0.6.2
+groupId=net.sourceforge.guacamole
+artifactId=guacamole
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/surefire
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/war
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/war/work
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/war/work/net.sourceforge.guacamole
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/war/work/net.sourceforge.guacamole/guacamole-common-js
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/war/work/net.sourceforge.guacamole/guacamole-common-js/guacamole-common-js
^
|
+(directory)
|
[-]
[+]
|
Added |
guacamole-0.6.2.tar.bz2/target/war/work/net.sourceforge.guacamole/guacamole-common-js/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/war/work/net.sourceforge.guacamole/guacamole-common-js/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/war/work/net.sourceforge.guacamole/guacamole-common-js/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/war/work/net.sourceforge.guacamole/guacamole-common-js/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/war/work/net.sourceforge.guacamole/guacamole-common-js/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/war/work/net.sourceforge.guacamole/guacamole-common-js/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();
|