From 098a521a4bd3e3bc0e95d9ae4e48bdcded683fb4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 22 Jan 2011 22:08:14 -0800 Subject: [PATCH 001/263] Initial commit --- guacamole-common-js/.gitignore | 2 + guacamole-common-js/COPYING | 661 ++++++++++++++++++ guacamole-common-js/pom.xml | 63 ++ .../src/main/resources/guacamole.js | 601 ++++++++++++++++ .../src/main/resources/keyboard.js | 270 +++++++ .../src/main/resources/keymap.js | 72 ++ .../src/main/resources/layer.js | 142 ++++ .../src/main/resources/mouse.js | 205 ++++++ .../src/main/resources/oskeyboard.js | 487 +++++++++++++ guacamole-common-js/static.xml | 12 + 10 files changed, 2515 insertions(+) create mode 100644 guacamole-common-js/.gitignore create mode 100644 guacamole-common-js/COPYING create mode 100644 guacamole-common-js/pom.xml create mode 100644 guacamole-common-js/src/main/resources/guacamole.js create mode 100644 guacamole-common-js/src/main/resources/keyboard.js create mode 100644 guacamole-common-js/src/main/resources/keymap.js create mode 100644 guacamole-common-js/src/main/resources/layer.js create mode 100644 guacamole-common-js/src/main/resources/mouse.js create mode 100644 guacamole-common-js/src/main/resources/oskeyboard.js create mode 100644 guacamole-common-js/static.xml diff --git a/guacamole-common-js/.gitignore b/guacamole-common-js/.gitignore new file mode 100644 index 000000000..42f4a1a64 --- /dev/null +++ b/guacamole-common-js/.gitignore @@ -0,0 +1,2 @@ +target/ +*~ diff --git a/guacamole-common-js/COPYING b/guacamole-common-js/COPYING new file mode 100644 index 000000000..dba13ed2d --- /dev/null +++ b/guacamole-common-js/COPYING @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + 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. + + 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. + + 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. + + 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. + + 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. + + 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. + + 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. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "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. + + 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. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + 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. + + 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. + + 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. + + 1. Source Code. + + 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. + + 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. + + 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. + + 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. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + 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. + + 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. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + 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. + + 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. + + 4. Conveying Verbatim Copies. + + 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. + + 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. + + 5. Conveying Modified Source Versions. + + 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: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + 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". + + 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. + + 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. + + 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. + + 6. Conveying Non-Source Forms. + + 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: + + 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. + + 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. + + 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. + + 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. + + 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. + + 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. + + 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. + + "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. + + 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). + + 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. + + 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. + + 7. Additional Terms. + + "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. + + 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. + + 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: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + 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 + + 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 + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + 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. + + 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. + + 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. + + 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. + + 8. Termination. + + 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). + + 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. + + 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. + + 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. + + 9. Acceptance Not Required for Having Copies. + + 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. + + 10. Automatic Licensing of Downstream Recipients. + + 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. + + 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. + + 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. + + 11. Patents. + + 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". + + 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. + + 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. + + 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. + + 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. + + 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. + + 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. + + 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. + + 12. No Surrender of Others' Freedom. + + 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. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + 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. + + 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. + + 14. Revised Versions of this License. + + 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. + + 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. + + 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. + + 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. + + 15. Disclaimer of Warranty. + + 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. + + 16. Limitation of Liability. + + 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. + + 17. Interpretation of Sections 15 and 16. + + 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. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + 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. + + 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. + + + Copyright (C) + + 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 . + +Also add information on how to contact you by electronic and paper mail. + + 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. + + 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 +. diff --git a/guacamole-common-js/pom.xml b/guacamole-common-js/pom.xml new file mode 100644 index 000000000..22ef612a3 --- /dev/null +++ b/guacamole-common-js/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + net.sourceforge.guacamole + guacamole-common-js + pom + 0.3.0-SNAPSHOT + guacamole-common-js + http://guacamole.sourceforge.net/ + + + + + + maven-assembly-plugin + + + static.xml + + + + + make-zip + package + + attached + + + + + + + + + + org.apache.maven.wagon + wagon-ssh-external + + + + + + + + guac-dev + http://guac-dev.org/repo + + true + always + fail + + + + + + + guac-dev + ${guac-dev.dist.repo} + + + + diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js new file mode 100644 index 000000000..020e88ac5 --- /dev/null +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -0,0 +1,601 @@ + +/* + * 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 . + */ + +function GuacamoleClient(display) { + + 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 stateChangeHandler = null; + + function setState(state) { + if (state != currentState) { + currentState = state; + if (stateChangeHandler) + stateChangeHandler(currentState); + } + } + + this.setOnStateChangeHandler = function(handler) { + stateChangeHandler = handler; + } + + function isConnected() { + return currentState == STATE_CONNECTED + || currentState == STATE_WAITING; + } + + // Layers + var background = null; + var cursor = null; + + var cursorImage = null; + var cursorHotspotX = 0; + var cursorHotspotY = 0; + + // FIXME: Make object. Clean up. + var cursorRectX = 0; + var cursorRectY = 0; + var cursorRectW = 0; + var cursorRectH = 0; + + var cursorHidden = 0; + + function redrawCursor() { + + // Hide hardware cursor + if (cursorHidden == 0) { + display.className += " guac-hide-cursor"; + cursorHidden = 1; + } + + // Erase old cursor + cursor.clearRect(cursorRectX, cursorRectY, cursorRectW, cursorRectH); + + // Update rect + cursorRectX = mouse.getX() - cursorHotspotX; + cursorRectY = mouse.getY() - cursorHotspotY; + cursorRectW = cursorImage.width; + cursorRectH = cursorImage.height; + + // Draw new cursor + cursor.drawImage(cursorRectX, cursorRectY, cursorImage); + } + + + + + /*****************************************/ + /*** Keyboard ***/ + /*****************************************/ + + var keyboard = new GuacamoleKeyboard(document); + + this.disableKeyboard = function() { + keyboard.setKeyPressedHandler(null); + keyboard.setKeyReleasedHandler(null); + }; + + this.enableKeyboard = function() { + keyboard.setKeyPressedHandler( + function (keysym) { + sendKeyEvent(1, keysym); + } + ); + + keyboard.setKeyReleasedHandler( + function (keysym) { + sendKeyEvent(0, keysym); + } + ); + }; + + // Enable keyboard by default + this.enableKeyboard(); + + function sendKeyEvent(pressed, keysym) { + // Do not send requests if not connected + if (!isConnected()) + return; + + sendMessage("key:" + keysym + "," + pressed + ";"); + } + + this.pressKey = function(keysym) { + sendKeyEvent(1, keysym); + }; + + this.releaseKey = function(keysym) { + sendKeyEvent(0, keysym); + }; + + + /*****************************************/ + /*** Mouse ***/ + /*****************************************/ + + var mouse = new GuacamoleMouse(display); + mouse.setButtonPressedHandler( + function(mouseState) { + sendMouseState(mouseState); + } + ); + + mouse.setButtonReleasedHandler( + function(mouseState) { + sendMouseState(mouseState); + } + ); + + mouse.setMovementHandler( + function(mouseState) { + + // Draw client-side cursor + if (cursorImage != null) { + redrawCursor(); + } + + sendMouseState(mouseState); + } + ); + + + function sendMouseState(mouseState) { + + // Do not send requests if not connected + if (!isConnected()) + return; + + // Build mask + var buttonMask = 0; + if (mouseState.getLeft()) buttonMask |= 1; + if (mouseState.getMiddle()) buttonMask |= 2; + if (mouseState.getRight()) buttonMask |= 4; + if (mouseState.getUp()) buttonMask |= 8; + if (mouseState.getDown()) buttonMask |= 16; + + // Send message + sendMessage("mouse:" + mouseState.getX() + "," + mouseState.getY() + "," + buttonMask + ";"); + } + + var sendingMessages = 0; + var outputMessageBuffer = ""; + + function sendMessage(message) { + + // Add event to queue, restart send loop if finished. + outputMessageBuffer += message; + if (sendingMessages == 0) + sendPendingMessages(); + + } + + function sendPendingMessages() { + + if (outputMessageBuffer.length > 0) { + + sendingMessages = 1; + + var message_xmlhttprequest = new XMLHttpRequest(); + message_xmlhttprequest.open("POST", "inbound"); + message_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + message_xmlhttprequest.setRequestHeader("Content-length", outputMessageBuffer.length); + + // Once response received, send next queued event. + message_xmlhttprequest.onreadystatechange = function() { + if (message_xmlhttprequest.readyState == 4) + sendPendingMessages(); + } + + message_xmlhttprequest.send(outputMessageBuffer); + outputMessageBuffer = ""; // Clear buffer + + } + else + sendingMessages = 0; + + } + + + /*****************************************/ + /*** Clipboard ***/ + /*****************************************/ + + this.setClipboard = function(data) { + + // Do not send requests if not connected + if (!isConnected()) + return; + + sendMessage("clipboard:" + escapeGuacamoleString(data) + ";"); + } + + + function desaturateFilter(data, width, height) { + + for (var i=0; i= 2 && nextRequest == null) + nextRequest = makeRequest(); + + // Parse stream when data is received and when complete. + if (xmlhttprequest.readyState == 3 || + xmlhttprequest.readyState == 4) { + + // Halt on error during request + if (xmlhttprequest.status == 0) { + showError("Request canceled by browser."); + return; + } + else if (xmlhttprequest.status != 200) { + showError("Error during request (HTTP " + xmlhttprequest.status + "): " + xmlhttprequest.statusText); + return; + } + + var current = xmlhttprequest.responseText; + var instructionEnd; + + while ((instructionEnd = current.indexOf(";", startIndex)) != -1) { + + // Start next search at next instruction + startIndex = instructionEnd+1; + + var instruction = current.substr(instructionStart, + instructionEnd - instructionStart); + + instructionStart = startIndex; + + var opcodeEnd = instruction.indexOf(":"); + + var opcode; + var parameters; + if (opcodeEnd == -1) { + opcode = instruction; + parameters = new Array(); + } + else { + opcode = instruction.substr(0, opcodeEnd); + parameters = instruction.substr(opcodeEnd+1).split(","); + } + + // If we're done parsing, handle the next response. + if (opcode.length == 0) { + + if (isConnected()) { + delete xmlhttprequest; + if (nextRequest) + handleResponse(nextRequest); + } + + break; + } + + // Call instruction handler. + doInstruction(opcode, parameters); + } + + // Start search at end of string. + startIndex = current.length; + + delete instruction; + delete parameters; + + } + + } + + xmlhttprequest.onreadystatechange = parseResponse; + parseResponse(); + + } + + + function makeRequest() { + + // Download self + var xmlhttprequest = new XMLHttpRequest(); + xmlhttprequest.open("POST", "outbound"); + xmlhttprequest.send(null); + + return xmlhttprequest; + + } + + function escapeGuacamoleString(str) { + + var escapedString = ""; + + for (var i=0; i. + */ + +function GuacamoleKeyboard(element) { + + /*****************************************/ + /*** Keyboard Handler ***/ + /*****************************************/ + + // Single key state/modifier buffer + var modShift = 0; + var modCtrl = 0; + var modAlt = 0; + + 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) clearInterval(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 null; + + } + + function getKeySymFromCharCode(keyCode) { + + if (keyCode >= 0x0000 && keyCode <= 0x00FF) + return keyCode; + + if (keyCode >= 0x0100 && keyCode <= 0x10FFFF) + return 0x01000000 | keyCode; + + return null; + + } + + function getKeySymFromKeyCode(keyCode) { + + var keysym = null; + if (modShift == 0) 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) { + if (keysym != null && keyPressedHandler) + keyPressedHandler(keysym); + } + + // Sends a single keystroke over the network + function sendKeyReleased(keysym) { + if (keysym != null) + keyReleasedHandler(keysym); + } + + + var KEYDOWN = 1; + var KEYPRESS = 2; + + var keySymSource = null; + + // When key pressed + var keydownCode = null; + element.onkeydown = function(e) { + + // Only intercept if handler set + if (!keyPressedHandler) return true; + + var keynum; + if (window.event) keynum = window.event.keyCode; + else if (e.which) keynum = e.which; + + // Ctrl/Alt/Shift + if (keynum == 16) + modShift = 1; + else if (keynum == 17) + modCtrl = 1; + else if (keynum == 18) + modAlt = 1; + + var keysym = getKeySymFromKeyCode(keynum); + if (keysym) { + // Get keysyms and events from KEYDOWN + keySymSource = KEYDOWN; + } + + // If modifier keys are held down, and we have keyIdentifier + else if ((modCtrl == 1 || modAlt == 1) && e.keyIdentifier) { + + // Get keysym from keyIdentifier + keysym = getKeySymFromKeyIdentifier(modShift, e.keyIdentifier); + + // Get keysyms and events from KEYDOWN + keySymSource = KEYDOWN; + + } + + else + // Get keysyms and events from KEYPRESS + keySymSource = KEYPRESS; + + keydownCode = keynum; + + // Ignore key if we don't need to use KEYPRESS. + // Send key event here + if (keySymSource == KEYDOWN) { + + if (keydownChar[keynum] != keysym) { + + // 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); + } + + return false; + } + + }; + + // When key pressed + element.onkeypress = function(e) { + + // Only intercept if handler set + if (!keyPressedHandler) return true; + + if (keySymSource != KEYPRESS) return false; + + var keynum; + if (window.event) keynum = window.event.keyCode; + else if (e.which) keynum = e.which; + + var keysym = getKeySymFromCharCode(keynum); + if (keysym && keydownChar[keynum] != keysym) { + + // If this button already pressed, release first + var lastKeyDownChar = keydownChar[keydownCode]; + if (lastKeyDownChar) + sendKeyReleased(lastKeyDownChar); + + keydownChar[keydownCode] = keysym; + + // Clear old key repeat, if any. + stopRepeat(); + + // Send key event + sendKeyPressed(keysym); + + // Start repeating (if not a modifier key) after a short delay + repeatKeyTimeoutId = setTimeout(function() { startRepeat(keysym); }, 500); + } + + return false; + }; + + // When key released + element.onkeyup = function(e) { + + // Only intercept if handler set + if (!keyReleasedHandler) return true; + + var keynum; + if (window.event) keynum = window.event.keyCode; + else if (e.which) keynum = e.which; + + // Ctrl/Alt/Shift + if (keynum == 16) + modShift = 0; + else if (keynum == 17) + modCtrl = 0; + else if (keynum == 18) + modAlt = 0; + else + stopRepeat(); + + // Get corresponding character + var lastKeyDownChar = keydownChar[keynum]; + + // Clear character record + keydownChar[keynum] = null; + + // Send release event + sendKeyReleased(lastKeyDownChar); + + return false; + }; + + // When focus is lost, clear modifiers. + var docOnblur = element.onblur; + element.onblur = function() { + modAlt = 0; + modCtrl = 0; + modShift = 0; + if (docOnblur != null) docOnblur(); + }; + + var keyPressedHandler = null; + var keyReleasedHandler = null; + + this.setKeyPressedHandler = function(kh) { keyPressedHandler = kh; }; + this.setKeyReleasedHandler = function(kh) { keyReleasedHandler = kh; }; + +} diff --git a/guacamole-common-js/src/main/resources/keymap.js b/guacamole-common-js/src/main/resources/keymap.js new file mode 100644 index 000000000..016bf5939 --- /dev/null +++ b/guacamole-common-js/src/main/resources/keymap.js @@ -0,0 +1,72 @@ + +/* + * 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 . + */ + + +// Keymap + +var unshiftedKeySym = new Array(); +unshiftedKeySym[8] = 0xFF08; // backspace +unshiftedKeySym[9] = 0xFF09; // tab +unshiftedKeySym[13] = 0xFF0D; // enter +unshiftedKeySym[16] = 0xFFE1; // shift +unshiftedKeySym[17] = 0xFFE3; // ctrl +unshiftedKeySym[18] = 0xFFE9; // alt +unshiftedKeySym[19] = 0xFF13; // pause/break +unshiftedKeySym[20] = 0xFFE5; // caps lock +unshiftedKeySym[27] = 0xFF1B; // escape +unshiftedKeySym[33] = 0xFF55; // page up +unshiftedKeySym[34] = 0xFF56; // page down +unshiftedKeySym[35] = 0xFF57; // end +unshiftedKeySym[36] = 0xFF50; // home +unshiftedKeySym[37] = 0xFF51; // left arrow +unshiftedKeySym[38] = 0xFF52; // up arrow +unshiftedKeySym[39] = 0xFF53; // right arrow +unshiftedKeySym[40] = 0xFF54; // down arrow +unshiftedKeySym[45] = 0xFF63; // insert +unshiftedKeySym[46] = 0xFFFF; // delete +unshiftedKeySym[91] = 0xFFEB; // left window key (super_l) +unshiftedKeySym[92] = 0xFF67; // right window key (menu key?) +unshiftedKeySym[93] = null; // select key +unshiftedKeySym[112] = 0xFFBE; // f1 +unshiftedKeySym[113] = 0xFFBF; // f2 +unshiftedKeySym[114] = 0xFFC0; // f3 +unshiftedKeySym[115] = 0xFFC1; // f4 +unshiftedKeySym[116] = 0xFFC2; // f5 +unshiftedKeySym[117] = 0xFFC3; // f6 +unshiftedKeySym[118] = 0xFFC4; // f7 +unshiftedKeySym[119] = 0xFFC5; // f8 +unshiftedKeySym[120] = 0xFFC6; // f9 +unshiftedKeySym[121] = 0xFFC7; // f10 +unshiftedKeySym[122] = 0xFFC8; // f11 +unshiftedKeySym[123] = 0xFFC9; // f12 +unshiftedKeySym[144] = 0xFF7F; // num lock +unshiftedKeySym[145] = 0xFF14; // scroll lock + +// Shifted versions, IF DIFFERENT FROM UNSHIFTED! +// If any of these are null, the unshifted one will be used. +var shiftedKeySym = new Array(); +shiftedKeySym[18] = 0xFFE7; // alt + +// Constants for keysyms for special keys +var KEYSYM_CTRL = 65507; +var KEYSYM_ALT = 65513; +var KEYSYM_DELETE = 65535; +var KEYSYM_SHIFT = 65505; + + diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js new file mode 100644 index 000000000..d6ac25efa --- /dev/null +++ b/guacamole-common-js/src/main/resources/layer.js @@ -0,0 +1,142 @@ + +/* + * 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 . + */ + +function Layer(width, height) { + + // Off-screen buffer + var display = document.createElement("canvas"); + + display.style.position = "absolute"; + display.style.left = "0px"; + display.style.right = "0px"; + + display.width = width; + display.height = height; + + var displayContext = display.getContext("2d"); + + var readyHandler = null; + var nextUpdateToDraw = 0; + var currentUpdate = 0; + var updates = new Array(); + + // Given an update ID, either call the provided update callback, or + // schedule the update for later. + function setUpdate(updateId, update) { + + // If this update is the next to draw... + if (updateId == nextUpdateToDraw) { + + // Call provided update handler. + update(); + + // Draw all pending updates. + var updateCallback; + while ((updateCallback = updates[++nextUpdateToDraw])) { + updateCallback(); + delete updates[nextUpdateToDraw]; + } + + // If done with updates, call ready handler + if (display.isReady() && readyHandler != null) + readyHandler(); + + } + + // If not next to draw, set callback and wait. + else + updates[updateId] = update; + + } + + display.isReady = function() { + return currentUpdate == nextUpdateToDraw; + } + + display.setReadyHandler = function(handler) { + readyHandler = handler; + } + + + display.drawImage = function(x, y, image) { + var updateId = currentUpdate++; + + setUpdate(updateId, function() { + displayContext.drawImage(image, x, y); + }); + + } + + + display.draw = function(x, y, url) { + var updateId = currentUpdate++; + + var image = new Image(); + image.onload = function() { + setUpdate(updateId, function() { + displayContext.drawImage(image, x, y); + }); + }; + image.src = url; + }; + + + display.copyRect = function(srcx, srcy, w, h, x, y) { + var updateId = currentUpdate++; + + setUpdate(updateId, function() { + displayContext.drawImage(display, srcx, srcy, w, h, x, y, w, h); + }); + + }; + + display.drawRect = function(x, y, w, h, color) { + var updateId = currentUpdate++; + + setUpdate(updateId, function() { + displayContext.fillStyle = color; + displayContext.fillRect(x, y, w, h); + }); + + }; + + display.clearRect = function(x, y, w, h) { + var updateId = currentUpdate++; + + setUpdate(updateId, function() { + displayContext.clearRect(x, y, w, h); + }); + + }; + + display.filter = function(filter) { + var updateId = currentUpdate++; + + setUpdate(updateId, function() { + var imageData = displayContext.getImageData(0, 0, width, height); + filter(imageData.data, width, height); + displayContext.putImageData(imageData, 0, 0); + }); + + }; + + return display; + +} + diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js new file mode 100644 index 000000000..3a1234a0d --- /dev/null +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -0,0 +1,205 @@ + +/* + * 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 . + */ + + +function GuacamoleMouse(element) { + + /*****************************************/ + /*** Mouse Handler ***/ + /*****************************************/ + + + var mouseIndex = 0; + + var mouseLeftButton = 0; + var mouseMiddleButton = 0; + var mouseRightButton = 0; + + var mouseX = 0; + var mouseY = 0; + + var absoluteMouseX = 0; + var absoluteMouseY = 0; + + + function getMouseState(up, down) { + var mouseState = new MouseEvent(mouseX, mouseY, + mouseLeftButton, mouseMiddleButton, mouseRightButton, up, down); + + return mouseState; + } + + + // Block context menu so right-click gets sent properly + element.oncontextmenu = function(e) {return false;}; + + element.onmousemove = function(e) { + + e.stopPropagation(); + + absoluteMouseX = e.pageX; + absoluteMouseY = e.pageY; + + mouseX = absoluteMouseX - element.offsetLeft; + mouseY = absoluteMouseY - element.offsetTop; + + // This is all JUST so we can get the mouse position within the element + var parent = element.offsetParent; + while (parent) { + if (parent.offsetLeft && parent.offsetTop) { + mouseX -= parent.offsetLeft; + mouseY -= parent.offsetTop; + } + parent = parent.offsetParent; + } + + movementHandler(getMouseState(0, 0)); + }; + + + element.onmousedown = function(e) { + + e.stopPropagation(); + + switch (e.button) { + case 0: + mouseLeftButton = 1; + break; + case 1: + mouseMiddleButton = 1; + break; + case 2: + mouseRightButton = 1; + break; + } + + buttonPressedHandler(getMouseState(0, 0)); + }; + + + element.onmouseup = function(e) { + + e.stopPropagation(); + + switch (e.button) { + case 0: + mouseLeftButton = 0; + break; + case 1: + mouseMiddleButton = 0; + break; + case 2: + mouseRightButton = 0; + break; + } + + buttonReleasedHandler(getMouseState(0, 0)); + }; + + // Override selection on mouse event element. + element.onselectstart = function() { + return false; + }; + + // Scroll wheel support + function handleScroll(e) { + + var delta = 0; + if (e.detail) + delta = e.detail; + else if (e.wheelDelta) + delta = -event.wheelDelta; + + // Up + if (delta < 0) { + buttonPressedHandler(getMouseState(1, 0)); + buttonReleasedHandler(getMouseState(0, 0)); + } + + // Down + if (delta > 0) { + buttonPressedHandler(getMouseState(0, 1)); + buttonReleasedHandler(getMouseState(0, 0)); + } + + if (e.preventDefault) + e.preventDefault(); + + e.returnValue = false; + } + + element.addEventListener('DOMMouseScroll', handleScroll, false); + + element.onmousewheel = function(e) { + handleScroll(e); + } + + function MouseEvent(x, y, left, middle, right, up, down) { + + this.getX = function() { + return x; + }; + + this.getY = function() { + return y; + }; + + this.getLeft = function() { + return left; + }; + + this.getMiddle = function() { + return middle; + }; + + this.getRight = function() { + return right; + }; + + this.getUp = function() { + return up; + }; + + this.getDown = function() { + return down; + }; + + this.toString = function() { + return (mouseIndex++) + "," + x + "," + y + "," + left + "," + middle + "," + right + "," + up + "," + down; + }; + + } + + + var buttonPressedHandler = null; + var buttonReleasedHandler = null; + var movementHandler = null; + + this.setButtonPressedHandler = function(mh) {buttonPressedHandler = mh;}; + this.setButtonReleasedHandler = function(mh) {buttonReleasedHandler = mh;}; + this.setMovementHandler = function(mh) {movementHandler = mh;}; + + + this.getX = function() {return mouseX;}; + this.getY = function() {return mouseY;}; + this.getLeftButton = function() {return mouseLeftButton;}; + this.getMiddleButton = function() {return mouseMiddleButton;}; + this.getRightButton = function() {return mouseRightButton;}; + +} diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js new file mode 100644 index 000000000..872bac223 --- /dev/null +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -0,0 +1,487 @@ + +/* + * 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 . + */ + + +function GuacamoleOnScreenKeyboard(url) { + + var tabIndex = 1; + var allKeys = new Array(); + var modifierState = new function() {}; + + function getKeySize(size) { + return (5*size) + "ex"; + } + + function getCapSize(size) { + return (5*size - 0.5) + "ex"; + } + + function clearModifiers() { + + // Send key release events for all pressed modifiers + for (var k=0; k 0) + return true; + + return false; + } + + function toggleModifierPressed(modifier) { + if (isModifierActive(modifier)) + setModifierReleased(modifier); + else + setModifierPressed(modifier); + } + + function refreshAllKeysState() { + for (var k=0; k= 0x0000 && charCode <= 0x00FF) + keysym = charCode; + + else if (charCode >= 0x0100 && charCode <= 0x10FFFF) + keysym = 0x01000000 | charCode; + } + + // Required modifiers for this keycap + var reqMod = null; + if (cap.attributes["if"]) + reqMod = cap.attributes["if"].value.split(","); + + + // Modifier represented by this keycap + var modifier = null; + if (cap.attributes["modifier"]) + modifier = cap.attributes["modifier"].value; + + + // Whether this key is sticky (toggles) + // Currently only valid for modifiers. + var sticky = false; + if (cap.attributes["sticky"] && cap.attributes["sticky"].value == "true") + sticky = true; + + this.getDisplayText = function() { + return cap.textContent; + }; + + this.getKeySym = function() { + return keysym; + }; + + this.getRequiredModifiers = function() { + return reqMod; + }; + + this.getModifier = function() { + return modifier; + }; + + this.isSticky = function() { + return sticky; + }; + + } + + var size = null; + if (key.attributes["size"]) + size = parseFloat(key.attributes["size"].value); + + var caps = key.getElementsByTagName("cap"); + var keycaps = new Array(); + for (var i=0; i can contain or + if (child.tagName == "key") { + var key = new Key(child); + keyboardRow.appendChild(key); + allKeys.push(key); + } + else if (child.tagName == "gap") { + var gap = new Gap(child); + keyboardRow.appendChild(gap); + } + else if (child.tagName == "column") { + var col = new Column(child); + keyboardRow.appendChild(col); + } + + } + + return keyboardRow; + + } + + function Column(col) { + + var keyboardCol = document.createElement("div"); + keyboardCol.className = "col"; + + var align = null; + if (col.attributes["align"]) + align = col.attributes["align"].value; + + var children = col.childNodes; + for (var j=0; j can only contain + if (child.tagName == "row") { + var row = new Row(child); + keyboardCol.appendChild(row); + } + + } + + if (align) + keyboardCol.style.textAlign = align; + + return keyboardCol; + + } + + + + // Create keyboard + var keyboard = document.createElement("div"); + keyboard.className = "keyboard"; + + + // Retrieve keyboard XML + var xmlhttprequest = new XMLHttpRequest(); + xmlhttprequest.open("GET", url, false); + xmlhttprequest.send(null); + + var xml = xmlhttprequest.responseXML; + + if (xml) { + + // Parse document + var root = xml.documentElement; + if (root) { + + var children = root.childNodes; + for (var i=0; i can contain or + if (child.tagName == "row") { + keyboard.appendChild(new Row(child)); + } + else if (child.tagName == "column") { + keyboard.appendChild(new Column(child)); + } + + } + + } + + } + + var keyPressedHandler = null; + var keyReleasedHandler = null; + + keyboard.setKeyPressedHandler = function(kh) { keyPressedHandler = kh; }; + keyboard.setKeyReleasedHandler = function(kh) { keyReleasedHandler = kh; }; + + // Do not allow selection or mouse movement to propagate/register. + keyboard.onselectstart = + keyboard.onmousemove = + keyboard.onmouseup = + keyboard.onmousedown = + function(e) { + e.stopPropagation(); + return false; + }; + + return keyboard; +} + diff --git a/guacamole-common-js/static.xml b/guacamole-common-js/static.xml new file mode 100644 index 000000000..f9b6bdf4c --- /dev/null +++ b/guacamole-common-js/static.xml @@ -0,0 +1,12 @@ + + guacamole-common-js + + zip + + + + src/main/resources + + + + From db00063b36040f55c9f378f9565b0626be98055d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 23 Jan 2011 01:42:37 -0800 Subject: [PATCH 002/263] Moved error style change into hook --- guacamole-common-js/src/main/resources/guacamole.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 020e88ac5..8cf692fc2 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -265,9 +265,6 @@ function GuacamoleClient(display) { disconnect(); - // In case nothing has been rendered yet, use error style - display.className += " guac-error"; - // Show error by desaturating display if (background) background.filter(desaturateFilter); From 77c4c9b3748ff2c43ab17d2df88a38c47abd5659 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 23 Jan 2011 15:22:06 -0800 Subject: [PATCH 003/263] Using new tunnel servlet API --- .../src/main/resources/guacamole.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 8cf692fc2..fc5be607b 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -17,7 +17,11 @@ * along with this program. If not, see . */ -function GuacamoleClient(display) { +function GuacamoleClient(display, tunnelURL) { + + var TUNNEL_CONNECT = tunnelURL + "?connect"; + var TUNNEL_READ = tunnelURL + "?read"; + var TUNNEL_WRITE = tunnelURL + "?write"; var STATE_IDLE = 0; var STATE_CONNECTING = 1; @@ -198,7 +202,7 @@ function GuacamoleClient(display) { sendingMessages = 1; var message_xmlhttprequest = new XMLHttpRequest(); - message_xmlhttprequest.open("POST", "inbound"); + message_xmlhttprequest.open("POST", TUNNEL_WRITE); message_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); message_xmlhttprequest.setRequestHeader("Content-length", outputMessageBuffer.length); @@ -377,7 +381,7 @@ function GuacamoleClient(display) { // Download self var xmlhttprequest = new XMLHttpRequest(); - xmlhttprequest.open("POST", "outbound"); + xmlhttprequest.open("POST", TUNNEL_READ); xmlhttprequest.send(null); return xmlhttprequest; @@ -560,7 +564,7 @@ function GuacamoleClient(display) { // Start tunnel and connect synchronously var connect_xmlhttprequest = new XMLHttpRequest(); - connect_xmlhttprequest.open("POST", "connect", false); + connect_xmlhttprequest.open("POST", TUNNEL_CONNECT, false); connect_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); connect_xmlhttprequest.setRequestHeader("Content-length", 0); connect_xmlhttprequest.send(null); @@ -583,7 +587,7 @@ function GuacamoleClient(display) { // Send disconnect message (synchronously... as necessary until handoff is implemented) var disconnect_xmlhttprequest = new XMLHttpRequest(); - disconnect_xmlhttprequest.open("POST", "inbound", false); + disconnect_xmlhttprequest.open("POST", TUNNEL_WRITE, false); disconnect_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); disconnect_xmlhttprequest.setRequestHeader("Content-length", message.length); disconnect_xmlhttprequest.send(message); From 02d2fc14269de178a56575f39e773215d8148e3f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 23 Jan 2011 17:02:56 -0800 Subject: [PATCH 004/263] Using UTF-8 source encoding. --- guacamole-common-js/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/guacamole-common-js/pom.xml b/guacamole-common-js/pom.xml index 22ef612a3..0d41b78fa 100644 --- a/guacamole-common-js/pom.xml +++ b/guacamole-common-js/pom.xml @@ -9,6 +9,10 @@ guacamole-common-js http://guacamole.sourceforge.net/ + + UTF-8 + + From 56baa32ec781830b0c2188ef92eebb77f9769334 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 24 Jan 2011 14:06:56 -0800 Subject: [PATCH 005/263] Using handler for name message, rather than setting document.title directly (as this is now a JS library) --- guacamole-common-js/src/main/resources/guacamole.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index fc5be607b..131d40280 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -255,6 +255,10 @@ function GuacamoleClient(display, tunnelURL) { } + var nameHandler = null; + this.setNameHandler = function(handler) { + nameHandler = handler; + } var errorHandler = null; this.setErrorHandler = function(handler) { @@ -446,7 +450,7 @@ function GuacamoleClient(display, tunnelURL) { }, "name": function(parameters) { - document.title = unescapeGuacamoleString(parameters[0]); + nameHandler(unescapeGuacamoleString(parameters[0])); }, "clipboard": function(parameters) { From 3d3aad76c9e8a0781717039cdb613d38ef458100 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 12 Feb 2011 01:35:32 -0800 Subject: [PATCH 006/263] Stub implementation of layer/buffer support (initial compat for new version of protocol) --- .../src/main/resources/guacamole.js | 92 ++++++++++--------- .../src/main/resources/layer.js | 14 +-- 2 files changed, 51 insertions(+), 55 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 131d40280..8793293b2 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -50,10 +50,6 @@ function GuacamoleClient(display, tunnelURL) { || currentState == STATE_WAITING; } - // Layers - var background = null; - var cursor = null; - var cursorImage = null; var cursorHotspotX = 0; var cursorHotspotY = 0; @@ -443,6 +439,29 @@ function GuacamoleClient(display, tunnelURL) { } + // Layers + var displayWidth = null; + var displayHeight = null; + var background = null; + var cursor = null; + + function getLayer(index) { + + // FIXME: Stub - does not actually handle layers or the layer index + + if (background == null) { + background = new Layer(displayWidth, displayHeight); + + if (cursor != null) + display.insertBefore(background, cursor); + else + display.appendChild(background); + } + + return background; + + } + var instructionHandlers = { "error": function(parameters) { @@ -459,48 +478,27 @@ function GuacamoleClient(display, tunnelURL) { "size": function(parameters) { - var width = parseInt(parameters[0]); - var height = parseInt(parameters[1]); + displayWidth = parseInt(parameters[0]); + displayHeight = parseInt(parameters[1]); // Update (set) display size - if (display && (background == null || cursor == null)) { - display.style.width = width + "px"; - display.style.height = height + "px"; - - background = new Layer(width, height); - cursor = new Layer(width, height); - - display.appendChild(background); - display.appendChild(cursor); + if (display) { + display.style.width = displayWidth + "px"; + display.style.height = displayHeight + "px"; } - }, - - "rect": function(parameters) { - - var x = parseInt(parameters[0]); - var y = parseInt(parameters[1]); - var w = parseInt(parameters[2]); - var h = parseInt(parameters[3]); - var color = parameters[4]; - - background.drawRect( - x, - y, - w, - h, - color - ); + // Set cursor layer width/height here }, "png": function(parameters) { - var x = parseInt(parameters[0]); - var y = parseInt(parameters[1]); - var data = parameters[2]; + var layer = parseInt(parameters[0]); + var x = parseInt(parameters[1]); + var y = parseInt(parameters[2]); + var data = parameters[3]; - background.draw( + getLayer(layer).draw( x, y, "data:image/png;base64," + data @@ -514,14 +512,17 @@ function GuacamoleClient(display, tunnelURL) { "copy": function(parameters) { - var srcX = parseInt(parameters[0]); - var srcY = parseInt(parameters[1]); - var srcWidth = parseInt(parameters[2]); - var srcHeight = parseInt(parameters[3]); - var dstX = parseInt(parameters[4]); - var dstY = parseInt(parameters[5]); + var srcL = parseInt(parameters[0]); + var srcX = parseInt(parameters[1]); + var srcY = parseInt(parameters[2]); + var srcWidth = parseInt(parameters[3]); + var srcHeight = parseInt(parameters[4]); + var dstL = parseInt(parameters[5]); + var dstX = parseInt(parameters[6]); + var dstY = parseInt(parameters[7]); - background.copyRect( + getLayer(dstL).copyRect( + getLayer(srcL), srcX, srcY, srcWidth, @@ -538,6 +539,11 @@ function GuacamoleClient(display, tunnelURL) { var y = parseInt(parameters[1]); var data = parameters[2]; + if (cursor == null) { + cursor = new Layer(displayWidth, displayHeight); + display.appendChild(cursor); + } + // Start cursor image load var image = new Image(); image.onload = function() { diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index d6ac25efa..380568383 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -97,21 +97,11 @@ function Layer(width, height) { }; - display.copyRect = function(srcx, srcy, w, h, x, y) { + display.copyRect = function(srcLayer, srcx, srcy, w, h, x, y) { var updateId = currentUpdate++; setUpdate(updateId, function() { - displayContext.drawImage(display, srcx, srcy, w, h, x, y, w, h); - }); - - }; - - display.drawRect = function(x, y, w, h, color) { - var updateId = currentUpdate++; - - setUpdate(updateId, function() { - displayContext.fillStyle = color; - displayContext.fillRect(x, y, w, h); + displayContext.drawImage(srcLayer, srcx, srcy, w, h, x, y, w, h); }); }; From 0ad9127a683fe0aa6a78f38ed25f7f887ad7a6ae Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 12 Feb 2011 14:07:12 -0800 Subject: [PATCH 007/263] True layer and buffer support (not stub) --- .../src/main/resources/guacamole.js | 65 +++++++++++++++---- .../src/main/resources/layer.js | 27 +++++--- 2 files changed, 70 insertions(+), 22 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 8793293b2..177bb5afa 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -270,8 +270,9 @@ function GuacamoleClient(display, tunnelURL) { disconnect(); // Show error by desaturating display - if (background) - background.filter(desaturateFilter); + for (var i=0; i Date: Sat, 12 Feb 2011 16:14:29 -0800 Subject: [PATCH 008/263] Added autosize to layer --- .../src/main/resources/guacamole.js | 1 + .../src/main/resources/layer.js | 41 +++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 177bb5afa..5ad4b8f7c 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -459,6 +459,7 @@ function GuacamoleClient(display, tunnelURL) { // Create buffer if necessary if (buffer == null) { buffer = new Layer(0, 0); + buffer.setAutosize(1); buffers[index] = buffer; } diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 9143ca6e3..2614de0ad 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -38,6 +38,32 @@ function Layer(width, height) { display.resize = function(newWidth, newHeight) { if (newWidth != width || newHeight != height) resize(newWidth, newHeight); + }; + + 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); + } resize(width, height); @@ -46,6 +72,11 @@ function Layer(width, height) { var nextUpdateToDraw = 0; var currentUpdate = 0; var updates = new Array(); + var autosize = 0; + + display.setAutosize = function(flag) { + autosize = flag; + }; // Given an update ID, either call the provided update callback, or // schedule the update for later. @@ -78,21 +109,22 @@ function Layer(width, height) { display.isReady = function() { return currentUpdate == nextUpdateToDraw; - } + }; display.setReadyHandler = function(handler) { readyHandler = handler; - } + }; display.drawImage = function(x, y, image) { var updateId = currentUpdate++; setUpdate(updateId, function() { + if (autosize != 0) fitRect(x, y, image.width, image.height); displayContext.drawImage(image, x, y); }); - } + }; display.draw = function(x, y, url) { @@ -101,6 +133,7 @@ function Layer(width, height) { var image = new Image(); image.onload = function() { setUpdate(updateId, function() { + if (autosize != 0) fitRect(x, y, image.width, image.height); displayContext.drawImage(image, x, y); }); }; @@ -112,6 +145,7 @@ function Layer(width, height) { var updateId = currentUpdate++; setUpdate(updateId, function() { + if (autosize != 0) fitRect(x, y, w, h); displayContext.drawImage(srcLayer, srcx, srcy, w, h, x, y, w, h); }); @@ -121,6 +155,7 @@ function Layer(width, height) { var updateId = currentUpdate++; setUpdate(updateId, function() { + if (autosize != 0) fitRect(x, y, w, h); displayContext.clearRect(x, y, w, h); }); From 27a94eb48ae7ddca77c404fddd8df1913b0b9e24 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 12 Feb 2011 18:10:46 -0800 Subject: [PATCH 009/263] Fixed error when layers are missing --- guacamole-common-js/src/main/resources/guacamole.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 5ad4b8f7c..4208eb4fc 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -480,8 +480,10 @@ function GuacamoleClient(display, tunnelURL) { display.innerHTML = ""; // Add existing layers in order - for (var i=0; i Date: Sat, 12 Feb 2011 18:22:39 -0800 Subject: [PATCH 010/263] copyRect should be synchronized with source layer/buffer's updates (as it may not be finished drawing by the time a copy is issued) --- .../src/main/resources/layer.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 2614de0ad..4c29726a2 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -140,13 +140,23 @@ function Layer(width, height) { image.src = url; }; + // Run arbitrary function as soon as currently pending operations complete. + // Future operations will not block this function from being called (unlike + // the ready handler, which requires no pending updates) + display.sync = function(handler) { + var updateId = currentUpdate++; + setUpdate(updateId, handler); + } display.copyRect = function(srcLayer, srcx, srcy, w, h, x, y) { var updateId = currentUpdate++; - - setUpdate(updateId, function() { - if (autosize != 0) fitRect(x, y, w, h); - displayContext.drawImage(srcLayer, srcx, srcy, w, h, x, y, w, h); + + // Synchronize copy operation with source layer + srcLayer.sync(function() { + setUpdate(updateId, function() { + if (autosize != 0) fitRect(x, y, w, h); + displayContext.drawImage(srcLayer, srcx, srcy, w, h, x, y, w, h); + }); }); }; From 25fd42afead495d5b065486b8f92d62f41ed9b60 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 15 Feb 2011 18:46:02 -0800 Subject: [PATCH 011/263] Fixed deadlock in layer --- guacamole-common-js/src/main/resources/layer.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 4c29726a2..b4f3203e2 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -150,14 +150,22 @@ function Layer(width, height) { display.copyRect = function(srcLayer, srcx, srcy, w, h, x, y) { var updateId = currentUpdate++; - - // Synchronize copy operation with source layer - srcLayer.sync(function() { + + function scheduleCopyRect() { setUpdate(updateId, function() { if (autosize != 0) fitRect(x, y, w, h); displayContext.drawImage(srcLayer, srcx, srcy, w, h, x, y, w, h); }); - }); + } + + // If we ARE the source layer, no need to sync. + // Syncing would result in deadlock. + if (display === srcLayer) + scheduleCopyRect(); + + // Otherwise synchronize copy operation with source layer + else + srcLayer.sync(scheduleCopyRect); }; From 299eb56d79f92282c362733948cefc6e5fc99097 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 17 Feb 2011 02:05:36 -0800 Subject: [PATCH 012/263] Adding a layer should not remove ALL contents of display (the on-screen keyboard, for example, is a child of the display) --- .../src/main/resources/guacamole.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 4208eb4fc..d24f5a02b 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -476,18 +476,25 @@ function GuacamoleClient(display, tunnelURL) { layer = new Layer(displayWidth, displayHeight); layers[index] = layer; - // Remove all children - display.innerHTML = ""; - - // Add existing layers in order + // (Re)-add existing layers in order for (var i=0; i Date: Thu, 17 Feb 2011 02:27:49 -0800 Subject: [PATCH 013/263] removeChild(), not removeNode() --- guacamole-common-js/src/main/resources/guacamole.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index d24f5a02b..7cfec8417 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -482,7 +482,7 @@ function GuacamoleClient(display, tunnelURL) { // If already present, remove if (layers[i].parentNode === display) - display.removeNode(layers[i]); + display.removeChild(layers[i]); // Add to end display.appendChild(layers[i]); @@ -492,7 +492,7 @@ function GuacamoleClient(display, tunnelURL) { // Add cursor layer last if (cursor != null) { if (cursor.parentNode === display) - display.removeNode(cursor); + display.removeChild(cursor); display.appendChild(cursor); } From 1693035dc55daf2f17be3cad90e8852c2e2c02ec Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 17 Feb 2011 19:19:05 -0800 Subject: [PATCH 014/263] Removed SNAPSHOT --- guacamole-common-js/pom.xml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/guacamole-common-js/pom.xml b/guacamole-common-js/pom.xml index 0d41b78fa..7307dab95 100644 --- a/guacamole-common-js/pom.xml +++ b/guacamole-common-js/pom.xml @@ -5,7 +5,7 @@ net.sourceforge.guacamole guacamole-common-js pom - 0.3.0-SNAPSHOT + 0.3.0 guacamole-common-js http://guacamole.sourceforge.net/ @@ -49,11 +49,6 @@ guac-dev http://guac-dev.org/repo - - true - always - fail - From bdde602f71814bce3f4e2bb0d71e7a5646cd6dc5 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 18 Feb 2011 23:26:47 -0800 Subject: [PATCH 015/263] FIX: Not all browsers send onreadystatechange for new data (Opera doesn't) --- guacamole-common-js/src/main/resources/guacamole.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 7cfec8417..4c0b14431 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -295,6 +295,7 @@ function GuacamoleClient(display, tunnelURL) { function handleResponse(xmlhttprequest) { + var interval = null; var nextRequest = null; var instructionStart = 0; @@ -310,6 +311,12 @@ function GuacamoleClient(display, tunnelURL) { if (xmlhttprequest.readyState == 3 || xmlhttprequest.readyState == 4) { + // Also poll every 30ms (some browsers don't repeatedly call onreadystatechange for new data) + if (xmlhttprequest.readyState == 3 && interval == null) + interval = setInterval(parseResponse, 30); + else if (xmlhttprequest.readyState == 4 && interval != null) + clearInterval(interval); + // Halt on error during request if (xmlhttprequest.status == 0) { showError("Request canceled by browser."); From 2dfd279e2244d03c34a5b628568d07f97797006e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 18 Feb 2011 23:50:35 -0800 Subject: [PATCH 016/263] Autodetect whether polling should be stopped (whether browser supports multiple readyState==3 events). --- .../src/main/resources/guacamole.js | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 4c0b14431..ffd905396 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -32,6 +32,7 @@ function GuacamoleClient(display, tunnelURL) { var currentState = STATE_IDLE; var stateChangeHandler = null; + var pollResponse = 1; // Default to polling - will be turned off automatically if not needed function setState(state) { if (state != currentState) { @@ -298,6 +299,7 @@ function GuacamoleClient(display, tunnelURL) { var interval = null; var nextRequest = null; + var dataUpdateEvents = 0; var instructionStart = 0; var startIndex = 0; @@ -312,10 +314,12 @@ function GuacamoleClient(display, tunnelURL) { xmlhttprequest.readyState == 4) { // Also poll every 30ms (some browsers don't repeatedly call onreadystatechange for new data) - if (xmlhttprequest.readyState == 3 && interval == null) - interval = setInterval(parseResponse, 30); - else if (xmlhttprequest.readyState == 4 && interval != null) - clearInterval(interval); + if (pollResponse == 1) { + if (xmlhttprequest.readyState == 3 && interval == null) + interval = setInterval(parseResponse, 30); + else if (xmlhttprequest.readyState == 4 && interval != null) + clearInterval(interval); + } // Halt on error during request if (xmlhttprequest.status == 0) { @@ -379,7 +383,29 @@ function GuacamoleClient(display, tunnelURL) { } - xmlhttprequest.onreadystatechange = parseResponse; + // If response polling enabled, attempt to detect if still + // necessary (via wrapping parseResponse()) + if (pollResponse == 1) { + 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) { + pollResponse = 0; + xmlhttprequest.onreadystatechange = parseResponse; + } + } + + parseResponse(); + } + } + + // Otherwise, just parse + else + xmlhttprequest.onreadystatechange = parseResponse; + parseResponse(); } From 4571135a0864520e0ce9d69481281ccd64af4e8a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 20 Feb 2011 13:20:17 -0800 Subject: [PATCH 017/263] More efficient layer implementation (job queue, rather than array + ids... should be less mem) --- .../src/main/resources/layer.js | 102 ++++++++++-------- 1 file changed, 57 insertions(+), 45 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index b4f3203e2..da5606c92 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -69,46 +69,62 @@ function Layer(width, height) { resize(width, height); var readyHandler = null; - var nextUpdateToDraw = 0; - var currentUpdate = 0; var updates = new Array(); var autosize = 0; + function Update(updateHandler) { + + this.setHandler = function(handler) { + updateHandler = handler; + }; + + this.hasHandler = function() { + return updateHandler != null; + }; + + this.handle = function() { + updateHandler(); + } + + } + display.setAutosize = function(flag) { autosize = flag; }; - // Given an update ID, either call the provided update callback, or - // schedule the update for later. - function setUpdate(updateId, update) { - - // If this update is the next to draw... - if (updateId == nextUpdateToDraw) { - - // Call provided update handler. - update(); - - // Draw all pending updates. - var updateCallback; - while ((updateCallback = updates[++nextUpdateToDraw])) { - updateCallback(); - delete updates[nextUpdateToDraw]; - } - - // If done with updates, call ready handler - if (display.isReady() && readyHandler != null) - readyHandler(); - + function reserveJob(handler) { + + // If no pending updates, just call (if available) and exit + if (display.isReady() && handler != null) { + handler(); + return null; } - // If not next to draw, set callback and wait. - else - updates[updateId] = update; + // If updates are pending/executing, schedule a pending update + // and return a reference to it. + var update = new Update(handler); + updates.push(update); + return update; + + } + + function handlePendingUpdates() { + + // Draw all pending updates. + var update; + while ((update = updates[0]).hasHandler()) { + update.handle(); + updates.shift(); + } + + // If done with updates, call ready handler + if (display.isReady() && readyHandler != null) + readyHandler(); } display.isReady = function() { - return currentUpdate == nextUpdateToDraw; + return updates.length == 0; }; display.setReadyHandler = function(handler) { @@ -117,42 +133,44 @@ function Layer(width, height) { display.drawImage = function(x, y, image) { - var updateId = currentUpdate++; - - setUpdate(updateId, function() { + reserveJob(function() { if (autosize != 0) fitRect(x, y, image.width, image.height); displayContext.drawImage(image, x, y); }); - }; display.draw = function(x, y, url) { - var updateId = currentUpdate++; + var update = reserveJob(null); var image = new Image(); image.onload = function() { - setUpdate(updateId, function() { + + update.setHandler(function() { if (autosize != 0) fitRect(x, y, image.width, image.height); displayContext.drawImage(image, x, y); }); + + // As this update originally had no handler and may have blocked + // other updates, handle any blocked updates. + handlePendingUpdates(); + }; image.src = url; + }; // Run arbitrary function as soon as currently pending operations complete. // Future operations will not block this function from being called (unlike // the ready handler, which requires no pending updates) display.sync = function(handler) { - var updateId = currentUpdate++; - setUpdate(updateId, handler); + reserveJob(handler); } display.copyRect = function(srcLayer, srcx, srcy, w, h, x, y) { - var updateId = currentUpdate++; function scheduleCopyRect() { - setUpdate(updateId, function() { + reserveJob(function() { if (autosize != 0) fitRect(x, y, w, h); displayContext.drawImage(srcLayer, srcx, srcy, w, h, x, y, w, h); }); @@ -170,24 +188,18 @@ function Layer(width, height) { }; display.clearRect = function(x, y, w, h) { - var updateId = currentUpdate++; - - setUpdate(updateId, function() { + reserveJob(function() { if (autosize != 0) fitRect(x, y, w, h); displayContext.clearRect(x, y, w, h); }); - }; display.filter = function(filter) { - var updateId = currentUpdate++; - - setUpdate(updateId, function() { + reserveJob(function() { var imageData = displayContext.getImageData(0, 0, width, height); filter(imageData.data, width, height); displayContext.putImageData(imageData, 0, 0); }); - }; return display; From 4d1717146f26b9b1f2ad33e0c14261485dde317f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 20 Feb 2011 13:50:22 -0800 Subject: [PATCH 018/263] Fixed layer positioning. --- guacamole-common-js/src/main/resources/guacamole.js | 9 +++++---- guacamole-common-js/src/main/resources/layer.js | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index ffd905396..8aaef9612 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -34,6 +34,9 @@ function GuacamoleClient(display, tunnelURL) { var stateChangeHandler = null; var pollResponse = 1; // Default to polling - will be turned off automatically if not needed + // Display must be relatively positioned for mouse to be handled properly + display.style.position = "relative"; + function setState(state) { if (state != currentState) { currentState = state; @@ -560,10 +563,8 @@ function GuacamoleClient(display, tunnelURL) { displayHeight = parseInt(parameters[1]); // Update (set) display size - if (display) { - display.style.width = displayWidth + "px"; - display.style.height = displayHeight + "px"; - } + display.style.width = displayWidth + "px"; + display.style.height = displayHeight + "px"; // Set cursor layer width/height if (cursor != null) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index da5606c92..ae5cf2245 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -26,7 +26,7 @@ function Layer(width, height) { function resize(newWidth, newHeight) { display.style.position = "absolute"; display.style.left = "0px"; - display.style.right = "0px"; + display.style.top = "0px"; display.width = newWidth; display.height = newHeight; From 53755b8070d6ea6fe2bdbe1aaffa182532e86f42 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 2 Mar 2011 16:01:03 -0800 Subject: [PATCH 019/263] Extracted tunnel, mouse, and keyboard handling from GuacamoleClient --- .../src/main/resources/guacamole.js | 404 ++---------------- .../src/main/resources/mouse.js | 69 ++- .../src/main/resources/tunnel.js | 266 ++++++++++++ 3 files changed, 327 insertions(+), 412 deletions(-) create mode 100644 guacamole-common-js/src/main/resources/tunnel.js diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 8aaef9612..a4ce995c7 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -14,14 +14,9 @@ * 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 . */ -function GuacamoleClient(display, tunnelURL) { - - var TUNNEL_CONNECT = tunnelURL + "?connect"; - var TUNNEL_READ = tunnelURL + "?read"; - var TUNNEL_WRITE = tunnelURL + "?write"; +function GuacamoleClient(display, tunnel) { var STATE_IDLE = 0; var STATE_CONNECTING = 1; @@ -32,7 +27,8 @@ function GuacamoleClient(display, tunnelURL) { var currentState = STATE_IDLE; var stateChangeHandler = null; - var pollResponse = 1; // Default to polling - will be turned off automatically if not needed + + tunnel.setInstructionHandler(doInstruction); // Display must be relatively positioned for mouse to be handled properly display.style.position = "relative"; @@ -66,7 +62,7 @@ function GuacamoleClient(display, tunnelURL) { var cursorHidden = 0; - function redrawCursor() { + function redrawCursor(x, y) { // Hide hardware cursor if (cursorHidden == 0) { @@ -78,8 +74,8 @@ function GuacamoleClient(display, tunnelURL) { cursor.clearRect(cursorRectX, cursorRectY, cursorRectW, cursorRectH); // Update rect - cursorRectX = mouse.getX() - cursorHotspotX; - cursorRectY = mouse.getY() - cursorHotspotY; + cursorRectX = x - cursorHotspotX; + cursorRectY = y - cursorHotspotY; cursorRectW = cursorImage.width; cursorRectH = cursorImage.height; @@ -87,90 +83,28 @@ function GuacamoleClient(display, tunnelURL) { cursor.drawImage(cursorRectX, cursorRectY, cursorImage); } - - - - /*****************************************/ - /*** Keyboard ***/ - /*****************************************/ - - var keyboard = new GuacamoleKeyboard(document); - - this.disableKeyboard = function() { - keyboard.setKeyPressedHandler(null); - keyboard.setKeyReleasedHandler(null); - }; - - this.enableKeyboard = function() { - keyboard.setKeyPressedHandler( - function (keysym) { - sendKeyEvent(1, keysym); - } - ); - - keyboard.setKeyReleasedHandler( - function (keysym) { - sendKeyEvent(0, keysym); - } - ); - }; - - // Enable keyboard by default - this.enableKeyboard(); - - function sendKeyEvent(pressed, keysym) { + this.sendKeyEvent = function(pressed, keysym) { // Do not send requests if not connected if (!isConnected()) return; - sendMessage("key:" + keysym + "," + pressed + ";"); + tunnel.sendMessage("key:" + keysym + "," + pressed + ";"); } - this.pressKey = function(keysym) { - sendKeyEvent(1, keysym); - }; - - this.releaseKey = function(keysym) { - sendKeyEvent(0, keysym); - }; - - - /*****************************************/ - /*** Mouse ***/ - /*****************************************/ - - var mouse = new GuacamoleMouse(display); - mouse.setButtonPressedHandler( - function(mouseState) { - sendMouseState(mouseState); - } - ); - - mouse.setButtonReleasedHandler( - function(mouseState) { - sendMouseState(mouseState); - } - ); - - mouse.setMovementHandler( - function(mouseState) { - - // Draw client-side cursor - if (cursorImage != null) { - redrawCursor(); - } - - sendMouseState(mouseState); - } - ); - - - function sendMouseState(mouseState) { + this.sendMouseState = function(mouseState) { // Do not send requests if not connected if (!isConnected()) return; + // Draw client-side cursor + if (cursorImage != null) { + redrawCursor( + mouseState.getX(), + mouseState.getY() + ); + } + // Build mask var buttonMask = 0; if (mouseState.getLeft()) buttonMask |= 1; @@ -180,80 +114,19 @@ function GuacamoleClient(display, tunnelURL) { if (mouseState.getDown()) buttonMask |= 16; // Send message - sendMessage("mouse:" + mouseState.getX() + "," + mouseState.getY() + "," + buttonMask + ";"); + tunnel.sendMessage("mouse:" + mouseState.getX() + "," + mouseState.getY() + "," + buttonMask + ";"); } - var sendingMessages = 0; - var outputMessageBuffer = ""; - - function sendMessage(message) { - - // Add event to queue, restart send loop if finished. - outputMessageBuffer += message; - if (sendingMessages == 0) - sendPendingMessages(); - - } - - function sendPendingMessages() { - - if (outputMessageBuffer.length > 0) { - - sendingMessages = 1; - - var message_xmlhttprequest = new XMLHttpRequest(); - message_xmlhttprequest.open("POST", TUNNEL_WRITE); - message_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - message_xmlhttprequest.setRequestHeader("Content-length", outputMessageBuffer.length); - - // Once response received, send next queued event. - message_xmlhttprequest.onreadystatechange = function() { - if (message_xmlhttprequest.readyState == 4) - sendPendingMessages(); - } - - message_xmlhttprequest.send(outputMessageBuffer); - outputMessageBuffer = ""; // Clear buffer - - } - else - sendingMessages = 0; - - } - - - /*****************************************/ - /*** Clipboard ***/ - /*****************************************/ - this.setClipboard = function(data) { // Do not send requests if not connected if (!isConnected()) return; - sendMessage("clipboard:" + escapeGuacamoleString(data) + ";"); + tunnel.sendMessage("clipboard:" + tunnel.escapeGuacamoleString(data) + ";"); } - - function desaturateFilter(data, width, height) { - - for (var i=0; i= 2 && nextRequest == null) - 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 (pollResponse == 1) { - if (xmlhttprequest.readyState == 3 && interval == null) - interval = setInterval(parseResponse, 30); - else if (xmlhttprequest.readyState == 4 && interval != null) - clearInterval(interval); - } - - // Halt on error during request - if (xmlhttprequest.status == 0) { - showError("Request canceled by browser."); - return; - } - else if (xmlhttprequest.status != 200) { - showError("Error during request (HTTP " + xmlhttprequest.status + "): " + xmlhttprequest.statusText); - return; - } - - var current = xmlhttprequest.responseText; - var instructionEnd; - - while ((instructionEnd = current.indexOf(";", startIndex)) != -1) { - - // Start next search at next instruction - startIndex = instructionEnd+1; - - var instruction = current.substr(instructionStart, - instructionEnd - instructionStart); - - instructionStart = startIndex; - - var opcodeEnd = instruction.indexOf(":"); - - var opcode; - var parameters; - if (opcodeEnd == -1) { - opcode = instruction; - parameters = new Array(); - } - else { - opcode = instruction.substr(0, opcodeEnd); - parameters = instruction.substr(opcodeEnd+1).split(","); - } - - // If we're done parsing, handle the next response. - if (opcode.length == 0) { - - if (isConnected()) { - delete xmlhttprequest; - if (nextRequest) - handleResponse(nextRequest); - } - - break; - } - - // Call instruction handler. - doInstruction(opcode, parameters); - } - - // Start search at end of string. - startIndex = current.length; - - delete instruction; - delete parameters; - - } - - } - - // If response polling enabled, attempt to detect if still - // necessary (via wrapping parseResponse()) - if (pollResponse == 1) { - 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) { - pollResponse = 0; - xmlhttprequest.onreadystatechange = parseResponse; - } - } - - parseResponse(); - } - } - - // Otherwise, just parse - else - xmlhttprequest.onreadystatechange = parseResponse; - - parseResponse(); - - } - - - function makeRequest() { - - // Download self - var xmlhttprequest = new XMLHttpRequest(); - xmlhttprequest.open("POST", TUNNEL_READ); - xmlhttprequest.send(null); - - return xmlhttprequest; - - } - - function escapeGuacamoleString(str) { - - var escapedString = ""; - - for (var i=0; i 0) { + + sendingMessages = 1; + + var message_xmlhttprequest = new XMLHttpRequest(); + message_xmlhttprequest.open("POST", TUNNEL_WRITE); + message_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + message_xmlhttprequest.setRequestHeader("Content-length", outputMessageBuffer.length); + + // Once response received, send next queued event. + message_xmlhttprequest.onreadystatechange = function() { + if (message_xmlhttprequest.readyState == 4) + sendPendingMessages(); + } + + message_xmlhttprequest.send(outputMessageBuffer); + outputMessageBuffer = ""; // Clear buffer + + } + else + sendingMessages = 0; + + } + + + function handleResponse(xmlhttprequest) { + + var interval = null; + var nextRequest = null; + + var dataUpdateEvents = 0; + var instructionStart = 0; + var startIndex = 0; + + function parseResponse() { + + // Start next request as soon as possible + if (xmlhttprequest.readyState >= 2 && nextRequest == null) + 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 (pollResponse == 1) { + if (xmlhttprequest.readyState == 3 && interval == null) + interval = setInterval(parseResponse, 30); + else if (xmlhttprequest.readyState == 4 && interval != null) + clearInterval(interval); + } + + // Halt on error during request + if (xmlhttprequest.status == 0) { + showError("Request canceled by browser."); + return; + } + else if (xmlhttprequest.status != 200) { + showError("Error during request (HTTP " + xmlhttprequest.status + "): " + xmlhttprequest.statusText); + return; + } + + var current = xmlhttprequest.responseText; + var instructionEnd; + + while ((instructionEnd = current.indexOf(";", startIndex)) != -1) { + + // Start next search at next instruction + startIndex = instructionEnd+1; + + var instruction = current.substr(instructionStart, + instructionEnd - instructionStart); + + instructionStart = startIndex; + + var opcodeEnd = instruction.indexOf(":"); + + var opcode; + var parameters; + if (opcodeEnd == -1) { + opcode = instruction; + parameters = new Array(); + } + else { + opcode = instruction.substr(0, opcodeEnd); + parameters = instruction.substr(opcodeEnd+1).split(","); + } + + // If we're done parsing, handle the next response. + if (opcode.length == 0) { + + delete xmlhttprequest; + if (nextRequest) + handleResponse(nextRequest); + + break; + } + + // Call instruction handler. + if (instructionHandler != null) + instructionHandler(opcode, parameters); + } + + // Start search at end of string. + startIndex = current.length; + + delete instruction; + delete parameters; + + } + + } + + // If response polling enabled, attempt to detect if still + // necessary (via wrapping parseResponse()) + if (pollResponse == 1) { + 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) { + pollResponse = 0; + xmlhttprequest.onreadystatechange = parseResponse; + } + } + + parseResponse(); + } + } + + // Otherwise, just parse + else + xmlhttprequest.onreadystatechange = parseResponse; + + parseResponse(); + + } + + + function makeRequest() { + + // Download self + var xmlhttprequest = new XMLHttpRequest(); + xmlhttprequest.open("POST", TUNNEL_READ); + xmlhttprequest.send(null); + + return xmlhttprequest; + + } + + function connect() { + + // 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.setRequestHeader("Content-length", 0); + connect_xmlhttprequest.send(null); + + // Start reading data + handleResponse(makeRequest()); + + }; + + // External API + this.connect = connect; + this.sendMessage = sendMessage; + this.setInstructionHandler = function(handler) { + instructionHandler = handler; + } + + this.escapeGuacamoleString = function(str) { + + var escapedString = ""; + + for (var i=0; i Date: Wed, 2 Mar 2011 17:21:26 -0800 Subject: [PATCH 020/263] Fixed error in call to redrawCursor() and layer --- guacamole-common-js/src/main/resources/guacamole.js | 2 +- guacamole-common-js/src/main/resources/layer.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index a4ce995c7..6afc25212 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -302,7 +302,7 @@ function GuacamoleClient(display, tunnel) { cursorImage = image; cursorHotspotX = x; cursorHotspotY = y; - redrawCursor(); + redrawCursor(cursorRectX, cursorRectY); }; image.src = "data:image/png;base64," + data diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index ae5cf2245..8ace45238 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -112,7 +112,7 @@ function Layer(width, height) { // Draw all pending updates. var update; - while ((update = updates[0]).hasHandler()) { + while ((update = updates[0]) != null && update.hasHandler()) { update.handle(); updates.shift(); } From de352e7dff2bbc061e75e2dbc4be8505c318a7ea Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 5 Mar 2011 14:47:50 -0800 Subject: [PATCH 021/263] Added busy handlers for layer, implemented ready instruction handling in client --- .../src/main/resources/guacamole.js | 46 +++++++++++++++++-- .../src/main/resources/layer.js | 11 +++++ 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 6afc25212..cf8e00f57 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -143,6 +143,42 @@ function GuacamoleClient(display, tunnel) { clipboardHandler = handler; }; + var readyCallback = null; + var busyLayers = 0; + + function layerBusy() { busyLayers++; } + function layerReady() { + busyLayers--; + if (readyCallback != null) + readyCallback(); + } + + function sendReady() { + + // If ready, send ready message + if (busyLayers == 0) { + tunnel.sendMessage("ready;"); + } + + // If not ready, queue message for when ready + else if (readyCallback == null) { + readyCallback = function() { + tunnel.sendMessage("ready;"); + readyCallback = null; + } + } + + } + + function getTrackedLayer(w, h) { + var layer = new Layer(w, h); + + layer.setBusyHandler(layerBusy); + layer.setReadyHandler(layerReady); + + return layer; + } + // Layers var displayWidth = 0; var displayHeight = 0; @@ -165,7 +201,7 @@ function GuacamoleClient(display, tunnel) { // Create buffer if necessary if (buffer == null) { - buffer = new Layer(0, 0); + buffer = new Layer(0, 0); // Untracked buffer.setAutosize(1); buffers[index] = buffer; } @@ -180,7 +216,7 @@ function GuacamoleClient(display, tunnel) { if (layer == null) { // Add new layer - layer = new Layer(displayWidth, displayHeight); + layer = getTrackedLayer(displayWidth, displayHeight); layers[index] = layer; // (Re)-add existing layers in order @@ -220,6 +256,10 @@ function GuacamoleClient(display, tunnel) { if (errorHandler) errorHandler(tunnel.unescapeGuacamoleString(parameters[0])); }, + "ready": function(parameters) { + sendReady(); + }, + "name": function(parameters) { if (nameHandler) nameHandler(tunnel.unescapeGuacamoleString(parameters[0])); }, @@ -292,7 +332,7 @@ function GuacamoleClient(display, tunnel) { var data = parameters[2]; if (cursor == null) { - cursor = new Layer(displayWidth, displayHeight); + cursor = getTrackedLayer(displayWidth, displayHeight); display.appendChild(cursor); } diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 8ace45238..b670e96ed 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -68,7 +68,9 @@ function Layer(width, height) { resize(width, height); + var busyHandler = null; var readyHandler = null; + var updates = new Array(); var autosize = 0; @@ -131,6 +133,10 @@ function Layer(width, height) { readyHandler = handler; }; + display.setBusyHandler = function(handler) { + busyHandler = handler; + }; + display.drawImage = function(x, y, image) { reserveJob(function() { @@ -141,6 +147,11 @@ function Layer(width, height) { display.draw = function(x, y, url) { + + // If about to become busy, call busy handler + if (display.isReady() && busyHandler != null) + busyHandler(); + var update = reserveJob(null); var image = new Image(); From 4f656c2e945ec14622a10a0bb8f16bf73426a8f6 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 6 Mar 2011 17:02:18 -0800 Subject: [PATCH 022/263] Revert "Added busy handlers for layer, implemented ready instruction handling in client" This reverts commit 7c3ceb1245a5e2a838811c10599b47b1578a5cf9. --- .../src/main/resources/guacamole.js | 46 ++----------------- .../src/main/resources/layer.js | 11 ----- 2 files changed, 3 insertions(+), 54 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index cf8e00f57..6afc25212 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -143,42 +143,6 @@ function GuacamoleClient(display, tunnel) { clipboardHandler = handler; }; - var readyCallback = null; - var busyLayers = 0; - - function layerBusy() { busyLayers++; } - function layerReady() { - busyLayers--; - if (readyCallback != null) - readyCallback(); - } - - function sendReady() { - - // If ready, send ready message - if (busyLayers == 0) { - tunnel.sendMessage("ready;"); - } - - // If not ready, queue message for when ready - else if (readyCallback == null) { - readyCallback = function() { - tunnel.sendMessage("ready;"); - readyCallback = null; - } - } - - } - - function getTrackedLayer(w, h) { - var layer = new Layer(w, h); - - layer.setBusyHandler(layerBusy); - layer.setReadyHandler(layerReady); - - return layer; - } - // Layers var displayWidth = 0; var displayHeight = 0; @@ -201,7 +165,7 @@ function GuacamoleClient(display, tunnel) { // Create buffer if necessary if (buffer == null) { - buffer = new Layer(0, 0); // Untracked + buffer = new Layer(0, 0); buffer.setAutosize(1); buffers[index] = buffer; } @@ -216,7 +180,7 @@ function GuacamoleClient(display, tunnel) { if (layer == null) { // Add new layer - layer = getTrackedLayer(displayWidth, displayHeight); + layer = new Layer(displayWidth, displayHeight); layers[index] = layer; // (Re)-add existing layers in order @@ -256,10 +220,6 @@ function GuacamoleClient(display, tunnel) { if (errorHandler) errorHandler(tunnel.unescapeGuacamoleString(parameters[0])); }, - "ready": function(parameters) { - sendReady(); - }, - "name": function(parameters) { if (nameHandler) nameHandler(tunnel.unescapeGuacamoleString(parameters[0])); }, @@ -332,7 +292,7 @@ function GuacamoleClient(display, tunnel) { var data = parameters[2]; if (cursor == null) { - cursor = getTrackedLayer(displayWidth, displayHeight); + cursor = new Layer(displayWidth, displayHeight); display.appendChild(cursor); } diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index b670e96ed..8ace45238 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -68,9 +68,7 @@ function Layer(width, height) { resize(width, height); - var busyHandler = null; var readyHandler = null; - var updates = new Array(); var autosize = 0; @@ -133,10 +131,6 @@ function Layer(width, height) { readyHandler = handler; }; - display.setBusyHandler = function(handler) { - busyHandler = handler; - }; - display.drawImage = function(x, y, image) { reserveJob(function() { @@ -147,11 +141,6 @@ function Layer(width, height) { display.draw = function(x, y, url) { - - // If about to become busy, call busy handler - if (display.isReady() && busyHandler != null) - busyHandler(); - var update = reserveJob(null); var image = new Image(); From cfebdb2cf3a1a9f4cc60307d7386cf4ea7cf7b81 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 8 Mar 2011 21:08:59 -0800 Subject: [PATCH 023/263] Added disconnect function to tunnel, added automatic disconnect on error receipt in client. --- .../src/main/resources/guacamole.js | 2 ++ .../src/main/resources/tunnel.js | 31 ++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 6afc25212..2506579ed 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -218,6 +218,7 @@ function GuacamoleClient(display, tunnel) { "error": function(parameters) { if (errorHandler) errorHandler(tunnel.unescapeGuacamoleString(parameters[0])); + disconnect(); }, "name": function(parameters) { @@ -337,6 +338,7 @@ function GuacamoleClient(display, tunnel) { setState(STATE_DISCONNECTING); tunnel.sendMessage("disconnect;"); + tunnel.disconnect(); setState(STATE_DISCONNECTED); } diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index e11bb0b35..fab421fd0 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -22,6 +22,7 @@ function GuacamoleHTTPTunnel(tunnelURL) { var TUNNEL_READ = tunnelURL + "?read"; var TUNNEL_WRITE = tunnelURL + "?write"; + var connected = 0; var pollResponse = 1; // Default to polling - will be turned off automatically if not needed var instructionHandler = null; @@ -30,6 +31,10 @@ function GuacamoleHTTPTunnel(tunnelURL) { function sendMessage(message) { + // Do not attempt to send messages if not connected + if (!connected) + return; + // Add event to queue, restart send loop if finished. outputMessageBuffer += message; if (sendingMessages == 0) @@ -75,6 +80,16 @@ function GuacamoleHTTPTunnel(tunnelURL) { function parseResponse() { + // Do not handle responses if not connected + if (!connected) { + + // Clean up interval if polling + if (interval != null) + clearInterval(interval); + + return; + } + // Start next request as soon as possible if (xmlhttprequest.readyState >= 2 && nextRequest == null) nextRequest = makeRequest(); @@ -92,12 +107,8 @@ function GuacamoleHTTPTunnel(tunnelURL) { } // Halt on error during request - if (xmlhttprequest.status == 0) { - showError("Request canceled by browser."); - return; - } - else if (xmlhttprequest.status != 200) { - showError("Error during request (HTTP " + xmlhttprequest.status + "): " + xmlhttprequest.statusText); + if (xmlhttprequest.status == 0 || xmlhttprequest.status != 200) { + disconnect(); return; } @@ -201,12 +212,18 @@ function GuacamoleHTTPTunnel(tunnelURL) { connect_xmlhttprequest.send(null); // Start reading data + connected = 1; handleResponse(makeRequest()); - }; + } + + function disconnect() { + connected = 0; + } // External API this.connect = connect; + this.disconnect = disconnect; this.sendMessage = sendMessage; this.setInstructionHandler = function(handler) { instructionHandler = handler; From aa0805595a64a180e18a341fde1cfd5bf2bcc714 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 8 Mar 2011 21:42:43 -0800 Subject: [PATCH 024/263] Added missing semicolons, improved state handling --- .../src/main/resources/guacamole.js | 88 +++++++++++++++---- .../src/main/resources/tunnel.js | 83 +++++------------ 2 files changed, 91 insertions(+), 80 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 2506579ed..0d35eaddf 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -43,7 +43,7 @@ function GuacamoleClient(display, tunnel) { this.setOnStateChangeHandler = function(handler) { stateChangeHandler = handler; - } + }; function isConnected() { return currentState == STATE_CONNECTED @@ -89,7 +89,7 @@ function GuacamoleClient(display, tunnel) { return; tunnel.sendMessage("key:" + keysym + "," + pressed + ";"); - } + }; this.sendMouseState = function(mouseState) { @@ -115,7 +115,7 @@ function GuacamoleClient(display, tunnel) { // Send message tunnel.sendMessage("mouse:" + mouseState.getX() + "," + mouseState.getY() + "," + buttonMask + ";"); - } + }; this.setClipboard = function(data) { @@ -123,8 +123,8 @@ function GuacamoleClient(display, tunnel) { if (!isConnected()) return; - tunnel.sendMessage("clipboard:" + tunnel.escapeGuacamoleString(data) + ";"); - } + tunnel.sendMessage("clipboard:" + escapeGuacamoleString(data) + ";"); + }; // Handlers @@ -153,7 +153,7 @@ function GuacamoleClient(display, tunnel) { this.getLayers = function() { return layers; - } + }; function getLayer(index) { @@ -217,16 +217,16 @@ function GuacamoleClient(display, tunnel) { var instructionHandlers = { "error": function(parameters) { - if (errorHandler) errorHandler(tunnel.unescapeGuacamoleString(parameters[0])); + if (errorHandler) errorHandler(unescapeGuacamoleString(parameters[0])); disconnect(); }, "name": function(parameters) { - if (nameHandler) nameHandler(tunnel.unescapeGuacamoleString(parameters[0])); + if (nameHandler) nameHandler(unescapeGuacamoleString(parameters[0])); }, "clipboard": function(parameters) { - if (clipboardHandler) clipboardHandler(tunnel.unescapeGuacamoleString(parameters[0])); + if (clipboardHandler) clipboardHandler(unescapeGuacamoleString(parameters[0])); }, "size": function(parameters) { @@ -319,17 +319,8 @@ function GuacamoleClient(display, tunnel) { handler(parameters); } - - this.connect = function() { - setState(STATE_CONNECTING); - tunnel.connect(); - setState(STATE_WAITING); - - }; - - function disconnect() { // Only attempt disconnection not disconnected. @@ -344,6 +335,67 @@ function GuacamoleClient(display, tunnel) { } + function escapeGuacamoleString(str) { + + var escapedString = ""; + + for (var i=0; i= 2) { - pollResponse = 0; + pollingMode = POLLING_DISABLED; xmlhttprequest.onreadystatechange = parseResponse; } } @@ -212,13 +222,13 @@ function GuacamoleHTTPTunnel(tunnelURL) { connect_xmlhttprequest.send(null); // Start reading data - connected = 1; + currentState = STATE_CONNECTED; handleResponse(makeRequest()); } function disconnect() { - connected = 0; + currentState = STATE_DISCONNECTED; } // External API @@ -227,57 +237,6 @@ function GuacamoleHTTPTunnel(tunnelURL) { this.sendMessage = sendMessage; this.setInstructionHandler = function(handler) { instructionHandler = handler; - } - - this.escapeGuacamoleString = function(str) { - - var escapedString = ""; - - for (var i=0; i Date: Tue, 8 Mar 2011 22:04:15 -0800 Subject: [PATCH 025/263] Removed unnecessary (and often ignored) setting of Content-length header --- guacamole-common-js/src/main/resources/tunnel.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index e605cf809..3ab4bf31f 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -61,7 +61,6 @@ function GuacamoleHTTPTunnel(tunnelURL) { var message_xmlhttprequest = new XMLHttpRequest(); message_xmlhttprequest.open("POST", TUNNEL_WRITE); message_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - message_xmlhttprequest.setRequestHeader("Content-length", outputMessageBuffer.length); // Once response received, send next queued event. message_xmlhttprequest.onreadystatechange = function() { @@ -218,7 +217,6 @@ function GuacamoleHTTPTunnel(tunnelURL) { var connect_xmlhttprequest = new XMLHttpRequest(); connect_xmlhttprequest.open("POST", TUNNEL_CONNECT, false); connect_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - connect_xmlhttprequest.setRequestHeader("Content-length", 0); connect_xmlhttprequest.send(null); // Start reading data From cace921202fbdbf06d92c3d77b6200009c05e6ca Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 11 Mar 2011 19:43:13 -0800 Subject: [PATCH 026/263] Support for sync instruction --- .../src/main/resources/guacamole.js | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 0d35eaddf..e5956d801 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -307,7 +307,38 @@ function GuacamoleClient(display, tunnel) { }; image.src = "data:image/png;base64," + data - } + }, + + "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) + tunnel.sendMessage("sync:" + timestamp + ";"); + + } + + // Count active layers and install sync tracking hook + for (var i=0; i Date: Wed, 30 Mar 2011 00:29:44 -0700 Subject: [PATCH 027/263] Added channel mask. --- .../src/main/resources/guacamole.js | 28 +++++++++++-------- .../src/main/resources/layer.js | 25 +++++++++++++++++ 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index e5956d801..2d2fdce0a 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -246,12 +246,15 @@ function GuacamoleClient(display, tunnel) { "png": function(parameters) { - var layer = parseInt(parameters[0]); - var x = parseInt(parameters[1]); - var y = parseInt(parameters[2]); - var data = parameters[3]; + 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]; - getLayer(layer).draw( + layer.setChannelMask(channelMask); + + layer.draw( x, y, "data:image/png;base64," + data @@ -265,17 +268,20 @@ function GuacamoleClient(display, tunnel) { "copy": function(parameters) { - var srcL = parseInt(parameters[0]); + 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 dstL = parseInt(parameters[5]); - var dstX = parseInt(parameters[6]); - var dstY = parseInt(parameters[7]); + var channelMask = parseInt(parameters[5]); + var dstL = getLayer(parseInt(parameters[6])); + var dstX = parseInt(parameters[7]); + var dstY = parseInt(parameters[8]); - getLayer(dstL).copyRect( - getLayer(srcL), + dstL.setChannelMask(channelMask); + + dstL.copyRect( + srcL, srcX, srcY, srcWidth, diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 8ace45238..5f481b752 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -202,6 +202,31 @@ function Layer(width, height) { }); }; + 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: "source-copy", + /* 0xD NOT IMPLEMENTED */ + 0xE: "source-over", + 0xF: "lighter", + }; + + display.setChannelMask = function(mask) { + reserveJob(function() { + displayContext.globalCompositeOperation = compositeOperation[mask]; + }); + }; + return display; } From 8a6595e2dbd067cc3ff353d3d46b8a4f4ec6d7f6 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 1 Apr 2011 01:58:41 -0700 Subject: [PATCH 028/263] Fixed typo in copy. --- guacamole-common-js/src/main/resources/layer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 5f481b752..7fcae1728 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -215,7 +215,7 @@ function Layer(width, height) { 0x9: "destination-atop", 0xA: "xor", 0xB: "destination-over", - 0xC: "source-copy", + 0xC: "copy", /* 0xD NOT IMPLEMENTED */ 0xE: "source-over", 0xF: "lighter", From 64224d0937405117e3cf5ddc7fb6a08e48cbeea6 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 2 Apr 2011 23:53:30 -0700 Subject: [PATCH 029/263] Fixed copyrect: although synchronization was properly established, draw jobs were not properly reserved in the destination layer, so draw operations would NOT block (synchronized on source only), resulting in draw race conditions. In a copy, the destination layer should block until the source layer is ready. --- .../src/main/resources/layer.js | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 7fcae1728..6921eb490 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -168,22 +168,30 @@ function Layer(width, height) { } display.copyRect = function(srcLayer, srcx, srcy, w, h, x, y) { - - function scheduleCopyRect() { - reserveJob(function() { - if (autosize != 0) fitRect(x, y, w, h); - displayContext.drawImage(srcLayer, srcx, srcy, w, h, x, y, w, h); - }); + + function doCopyRect() { + if (autosize != 0) fitRect(x, y, w, h); + displayContext.drawImage(srcLayer, srcx, srcy, w, h, x, y, w, h); } // If we ARE the source layer, no need to sync. // Syncing would result in deadlock. if (display === srcLayer) - scheduleCopyRect(); + reserveJob(doCopyRect); // Otherwise synchronize copy operation with source layer - else - srcLayer.sync(scheduleCopyRect); + else { + var update = reserveJob(null); + srcLayer.sync(function() { + + update.setHandler(doCopyRect); + + // As this update originally had no handler and may have blocked + // other updates, handle any blocked updates. + handlePendingUpdates(); + + }); + } }; From f6c2d0c88f76b30ea12cf9576444235ae621ef79 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 3 Apr 2011 00:53:00 -0700 Subject: [PATCH 030/263] Fixed potential layer sync issue (if multiple layers are used, and multiple layers are ready, multiply unnecessary sync responses may be sent for a single sync instruction) --- guacamole-common-js/src/main/resources/guacamole.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 2d2fdce0a..4e4831c36 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -333,17 +333,22 @@ function GuacamoleClient(display, tunnel) { } - // Count active layers and install sync tracking hook + // Count active, not-ready layers and install sync tracking hooks for (var i=0; i Date: Fri, 8 Apr 2011 16:28:33 -0700 Subject: [PATCH 031/263] Added support for multiple tunnels (tunnel UUID returned by connect). --- guacamole-common-js/src/main/resources/tunnel.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 3ab4bf31f..70b139de3 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -18,9 +18,11 @@ function GuacamoleHTTPTunnel(tunnelURL) { + var tunnel_uuid; + var TUNNEL_CONNECT = tunnelURL + "?connect"; - var TUNNEL_READ = tunnelURL + "?read"; - var TUNNEL_WRITE = tunnelURL + "?write"; + var TUNNEL_READ = tunnelURL + "?read:"; + var TUNNEL_WRITE = tunnelURL + "?write:"; var STATE_IDLE = 0; var STATE_CONNECTED = 1; @@ -59,7 +61,7 @@ function GuacamoleHTTPTunnel(tunnelURL) { sendingMessages = 1; var message_xmlhttprequest = new XMLHttpRequest(); - message_xmlhttprequest.open("POST", TUNNEL_WRITE); + 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. @@ -204,7 +206,7 @@ function GuacamoleHTTPTunnel(tunnelURL) { // Download self var xmlhttprequest = new XMLHttpRequest(); - xmlhttprequest.open("POST", TUNNEL_READ); + xmlhttprequest.open("POST", TUNNEL_READ + tunnel_uuid); xmlhttprequest.send(null); return xmlhttprequest; @@ -219,6 +221,9 @@ function GuacamoleHTTPTunnel(tunnelURL) { connect_xmlhttprequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); connect_xmlhttprequest.send(null); + // Get UUID from response + tunnel_uuid = connect_xmlhttprequest.responseText; + // Start reading data currentState = STATE_CONNECTED; handleResponse(makeRequest()); From 0eb351e467609037f37a337a11254d5da5a9bb5d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 8 Apr 2011 22:41:31 -0700 Subject: [PATCH 032/263] Error handling, added data submission for connect. --- .../src/main/resources/guacamole.js | 13 ++++++++++--- guacamole-common-js/src/main/resources/tunnel.js | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 4e4831c36..688f22560 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -429,12 +429,19 @@ function GuacamoleClient(display, tunnel) { } this.disconnect = disconnect; - this.connect = function() { + this.connect = function(data) { setState(STATE_CONNECTING); - tunnel.connect(); - setState(STATE_WAITING); + try { + tunnel.connect(data); + } + catch (e) { + setState(STATE_IDLE); + throw e; + } + + setState(STATE_WAITING); }; this.escapeGuacamoleString = escapeGuacamoleString; diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 70b139de3..d5a785ac3 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -213,13 +213,24 @@ function GuacamoleHTTPTunnel(tunnelURL) { } - function connect() { + function connect(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(null); + connect_xmlhttprequest.send(data); + + // If failure, throw error + if (connect_xmlhttprequest.status != 200) { + + var message = connect_xmlhttprequest.getResponseHeader("X-Guacamole-Error-Message"); + if (!message) + message = "Internal error"; + + throw new Error(message); + + } // Get UUID from response tunnel_uuid = connect_xmlhttprequest.responseText; From 00d4cf6858d3c6e71985df564bbaf6065fe84d9f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 26 Apr 2011 12:31:20 -0700 Subject: [PATCH 033/263] Release mouse buttons if mouse leaves browser window. --- guacamole-common-js/src/main/resources/mouse.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 6f422d2ee..fb8600519 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -112,6 +112,21 @@ function GuacamoleMouse(element) { buttonReleasedHandler(getMouseState(0, 0)); }; + element.onmouseout = function(e) { + + e.stopPropagation(); + + // Release all buttons + if (mouseLeftButton || mouseMiddleButton || mouseRightButton) { + mouseLeftButton = 0; + mouseMiddleButton = 0; + mouseRightButton = 0; + + buttonReleasedHandler(getMouseState(0, 0)); + } + + }; + // Override selection on mouse event element. element.onselectstart = function() { return false; From 6f80c9f7305f15df9bb450c2228f885ee4690878 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 17 May 2011 13:32:32 -0700 Subject: [PATCH 034/263] Fixed issue with moving cursor when icon updates. --- guacamole-common-js/src/main/resources/guacamole.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 688f22560..5ab4e8970 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -309,7 +309,10 @@ function GuacamoleClient(display, tunnel) { cursorImage = image; cursorHotspotX = x; cursorHotspotY = y; - redrawCursor(cursorRectX, cursorRectY); + redrawCursor( + cursorRectX + cursorHotspotX, + cursorRectY + cursorHotspotY + ); }; image.src = "data:image/png;base64," + data From 2d7f30ed7b55c7bea9e5d3bfd9973d3018ee8dbe Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 18 May 2011 14:24:45 -0700 Subject: [PATCH 035/263] Fixed initial draw location for new cursors --- guacamole-common-js/src/main/resources/guacamole.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 5ab4e8970..ead548450 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -307,12 +307,14 @@ function GuacamoleClient(display, tunnel) { var image = new Image(); image.onload = function() { cursorImage = image; + + var cursorX = cursorRectX + cursorHotspotX; + var cursorY = cursorRectY + cursorHotspotY; + cursorHotspotX = x; cursorHotspotY = y; - redrawCursor( - cursorRectX + cursorHotspotX, - cursorRectY + cursorHotspotY - ); + + redrawCursor(cursorX, cursorY); }; image.src = "data:image/png;base64," + data From 23ed11a93383499104e03dde54b67ef92ab51b2b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 27 May 2011 13:46:03 -0700 Subject: [PATCH 036/263] Updated version numbers to 0.4.0 --- guacamole-common-js/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/pom.xml b/guacamole-common-js/pom.xml index 7307dab95..0efc46022 100644 --- a/guacamole-common-js/pom.xml +++ b/guacamole-common-js/pom.xml @@ -5,7 +5,7 @@ net.sourceforge.guacamole guacamole-common-js pom - 0.3.0 + 0.4.0 guacamole-common-js http://guacamole.sourceforge.net/ From 567c4a4a11d63cc735aa83a2a6612664938d4053 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 9 Jun 2011 09:25:47 -0700 Subject: [PATCH 037/263] Experimental working touch-based mouse. --- .../src/main/resources/mouse.js | 73 +++++++++++++++++-- 1 file changed, 65 insertions(+), 8 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index fb8600519..745b50c0b 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -46,15 +46,10 @@ function GuacamoleMouse(element) { } - // Block context menu so right-click gets sent properly - element.oncontextmenu = function(e) {return false;}; + function moveMouse(pageX, pageY) { - element.onmousemove = function(e) { - - e.stopPropagation(); - - absoluteMouseX = e.pageX; - absoluteMouseY = e.pageY; + absoluteMouseX = pageX; + absoluteMouseY = pageY; mouseX = absoluteMouseX - element.offsetLeft; mouseY = absoluteMouseY - element.offsetTop; @@ -70,6 +65,68 @@ function GuacamoleMouse(element) { } movementHandler(getMouseState(0, 0)); + + } + + + // Block context menu so right-click gets sent properly + element.oncontextmenu = function(e) {return false;}; + + element.onmousemove = function(e) { + + e.stopPropagation(); + + moveMouse(e.pageX, e.pageY); + + }; + + element.ontouchend = function(e) { + + e.stopPropagation(); + e.preventDefault(); + + // Release all buttons (FIXME: for now...) + if (mouseLeftButton || mouseMiddleButton || mouseRightButton) { + mouseLeftButton = 0; + mouseMiddleButton = 0; + mouseRightButton = 0; + + buttonReleasedHandler(getMouseState(0, 0)); + } + + } + + element.ontouchstart = function(e) { + + e.stopPropagation(); + e.preventDefault(); + + if (e.touches.length == 1) + element.ontouchmove(e); + + else { + + var button = e.touches[0]; + var pointer = e.touches[1]; + + if (pointer.pageX < button.pageX) + mouseLeftButton = 1; + else + mouseRightButton = 1; + + buttonPressedHandler(getMouseState(0, 0)); + } + + }; + + element.ontouchmove = function(e) { + + e.stopPropagation(); + e.preventDefault(); + + var touch = e.touches[0]; + moveMouse(touch.pageX, touch.pageY); + }; From fbce63ea640164be1426300882cef56877a4401b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 3 Jul 2011 15:32:06 -0700 Subject: [PATCH 038/263] Removed keymap (merged into keyboard), fixed JS semicolons, etc. --- .../src/main/resources/guacamole.js | 5 +- .../src/main/resources/keyboard.js | 78 +++++++++++++++---- .../src/main/resources/keymap.js | 72 ----------------- .../src/main/resources/layer.js | 15 +--- 4 files changed, 68 insertions(+), 102 deletions(-) delete mode 100644 guacamole-common-js/src/main/resources/keymap.js diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index ead548450..54153c573 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -54,7 +54,6 @@ function GuacamoleClient(display, tunnel) { var cursorHotspotX = 0; var cursorHotspotY = 0; - // FIXME: Make object. Clean up. var cursorRectX = 0; var cursorRectY = 0; var cursorRectW = 0; @@ -131,7 +130,7 @@ function GuacamoleClient(display, tunnel) { var nameHandler = null; this.setNameHandler = function(handler) { nameHandler = handler; - } + }; var errorHandler = null; this.setErrorHandler = function(handler) { @@ -354,7 +353,7 @@ function GuacamoleClient(display, tunnel) { if (layersToSync == 0) tunnel.sendMessage("sync:" + timestamp + ";"); - }, + } }; diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index b5e6e935c..e0f784db0 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -19,6 +19,52 @@ function GuacamoleKeyboard(element) { + // Keymap + + var unshiftedKeySym = new Array(); + unshiftedKeySym[8] = 0xFF08; // backspace + unshiftedKeySym[9] = 0xFF09; // tab + unshiftedKeySym[13] = 0xFF0D; // enter + unshiftedKeySym[16] = 0xFFE1; // shift + unshiftedKeySym[17] = 0xFFE3; // ctrl + unshiftedKeySym[18] = 0xFFE9; // alt + unshiftedKeySym[19] = 0xFF13; // pause/break + unshiftedKeySym[20] = 0xFFE5; // caps lock + unshiftedKeySym[27] = 0xFF1B; // escape + unshiftedKeySym[33] = 0xFF55; // page up + unshiftedKeySym[34] = 0xFF56; // page down + unshiftedKeySym[35] = 0xFF57; // end + unshiftedKeySym[36] = 0xFF50; // home + unshiftedKeySym[37] = 0xFF51; // left arrow + unshiftedKeySym[38] = 0xFF52; // up arrow + unshiftedKeySym[39] = 0xFF53; // right arrow + unshiftedKeySym[40] = 0xFF54; // down arrow + unshiftedKeySym[45] = 0xFF63; // insert + unshiftedKeySym[46] = 0xFFFF; // delete + unshiftedKeySym[91] = 0xFFEB; // left window key (super_l) + unshiftedKeySym[92] = 0xFF67; // right window key (menu key?) + unshiftedKeySym[93] = null; // select key + unshiftedKeySym[112] = 0xFFBE; // f1 + unshiftedKeySym[113] = 0xFFBF; // f2 + unshiftedKeySym[114] = 0xFFC0; // f3 + unshiftedKeySym[115] = 0xFFC1; // f4 + unshiftedKeySym[116] = 0xFFC2; // f5 + unshiftedKeySym[117] = 0xFFC3; // f6 + unshiftedKeySym[118] = 0xFFC4; // f7 + unshiftedKeySym[119] = 0xFFC5; // f8 + unshiftedKeySym[120] = 0xFFC6; // f9 + unshiftedKeySym[121] = 0xFFC7; // f10 + unshiftedKeySym[122] = 0xFFC8; // f11 + unshiftedKeySym[123] = 0xFFC9; // f12 + unshiftedKeySym[144] = 0xFF7F; // num lock + unshiftedKeySym[145] = 0xFF14; // scroll lock + + // Shifted versions, IF DIFFERENT FROM UNSHIFTED! + // If any of these are null, the unshifted one will be used. + var shiftedKeySym = new Array(); + shiftedKeySym[18] = 0xFFE7; // alt + + /*****************************************/ /*** Keyboard Handler ***/ /*****************************************/ @@ -52,27 +98,27 @@ function GuacamoleKeyboard(element) { function getKeySymFromKeyIdentifier(shifted, keyIdentifier) { - var unicodePrefixLocation = keyIdentifier.indexOf("U+"); - if (unicodePrefixLocation >= 0) { + var unicodePrefixLocation = keyIdentifier.indexOf("U+"); + if (unicodePrefixLocation >= 0) { - var hex = keyIdentifier.substring(unicodePrefixLocation+2); - var codepoint = parseInt(hex, 16); - var typedCharacter; + 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(); + // Convert case if shifted + if (shifted == 0) + typedCharacter = String.fromCharCode(codepoint).toLowerCase(); + else + typedCharacter = String.fromCharCode(codepoint).toUpperCase(); - // Get codepoint - codepoint = typedCharacter.charCodeAt(0); + // Get codepoint + codepoint = typedCharacter.charCodeAt(0); - return getKeySymFromCharCode(codepoint); + return getKeySymFromCharCode(codepoint); - } + } - return null; + return null; } @@ -183,6 +229,8 @@ function GuacamoleKeyboard(element) { return false; } + return true; + }; // When key pressed diff --git a/guacamole-common-js/src/main/resources/keymap.js b/guacamole-common-js/src/main/resources/keymap.js deleted file mode 100644 index 016bf5939..000000000 --- a/guacamole-common-js/src/main/resources/keymap.js +++ /dev/null @@ -1,72 +0,0 @@ - -/* - * 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 . - */ - - -// Keymap - -var unshiftedKeySym = new Array(); -unshiftedKeySym[8] = 0xFF08; // backspace -unshiftedKeySym[9] = 0xFF09; // tab -unshiftedKeySym[13] = 0xFF0D; // enter -unshiftedKeySym[16] = 0xFFE1; // shift -unshiftedKeySym[17] = 0xFFE3; // ctrl -unshiftedKeySym[18] = 0xFFE9; // alt -unshiftedKeySym[19] = 0xFF13; // pause/break -unshiftedKeySym[20] = 0xFFE5; // caps lock -unshiftedKeySym[27] = 0xFF1B; // escape -unshiftedKeySym[33] = 0xFF55; // page up -unshiftedKeySym[34] = 0xFF56; // page down -unshiftedKeySym[35] = 0xFF57; // end -unshiftedKeySym[36] = 0xFF50; // home -unshiftedKeySym[37] = 0xFF51; // left arrow -unshiftedKeySym[38] = 0xFF52; // up arrow -unshiftedKeySym[39] = 0xFF53; // right arrow -unshiftedKeySym[40] = 0xFF54; // down arrow -unshiftedKeySym[45] = 0xFF63; // insert -unshiftedKeySym[46] = 0xFFFF; // delete -unshiftedKeySym[91] = 0xFFEB; // left window key (super_l) -unshiftedKeySym[92] = 0xFF67; // right window key (menu key?) -unshiftedKeySym[93] = null; // select key -unshiftedKeySym[112] = 0xFFBE; // f1 -unshiftedKeySym[113] = 0xFFBF; // f2 -unshiftedKeySym[114] = 0xFFC0; // f3 -unshiftedKeySym[115] = 0xFFC1; // f4 -unshiftedKeySym[116] = 0xFFC2; // f5 -unshiftedKeySym[117] = 0xFFC3; // f6 -unshiftedKeySym[118] = 0xFFC4; // f7 -unshiftedKeySym[119] = 0xFFC5; // f8 -unshiftedKeySym[120] = 0xFFC6; // f9 -unshiftedKeySym[121] = 0xFFC7; // f10 -unshiftedKeySym[122] = 0xFFC8; // f11 -unshiftedKeySym[123] = 0xFFC9; // f12 -unshiftedKeySym[144] = 0xFF7F; // num lock -unshiftedKeySym[145] = 0xFF14; // scroll lock - -// Shifted versions, IF DIFFERENT FROM UNSHIFTED! -// If any of these are null, the unshifted one will be used. -var shiftedKeySym = new Array(); -shiftedKeySym[18] = 0xFFE7; // alt - -// Constants for keysyms for special keys -var KEYSYM_CTRL = 65507; -var KEYSYM_ALT = 65513; -var KEYSYM_DELETE = 65535; -var KEYSYM_SHIFT = 65505; - - diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 6921eb490..775b23683 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -68,7 +68,6 @@ function Layer(width, height) { resize(width, height); - var readyHandler = null; var updates = new Array(); var autosize = 0; @@ -84,7 +83,7 @@ function Layer(width, height) { this.handle = function() { updateHandler(); - } + }; } @@ -117,20 +116,12 @@ function Layer(width, height) { updates.shift(); } - // If done with updates, call ready handler - if (display.isReady() && readyHandler != null) - readyHandler(); - } display.isReady = function() { return updates.length == 0; }; - display.setReadyHandler = function(handler) { - readyHandler = handler; - }; - display.drawImage = function(x, y, image) { reserveJob(function() { @@ -165,7 +156,7 @@ function Layer(width, height) { // the ready handler, which requires no pending updates) display.sync = function(handler) { reserveJob(handler); - } + }; display.copyRect = function(srcLayer, srcx, srcy, w, h, x, y) { @@ -226,7 +217,7 @@ function Layer(width, height) { 0xC: "copy", /* 0xD NOT IMPLEMENTED */ 0xE: "source-over", - 0xF: "lighter", + 0xF: "lighter" }; display.setChannelMask = function(mask) { From 5815f79eef303a7fcf77ec8b91199c17fd62fb4b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 4 Jul 2011 14:25:52 -0700 Subject: [PATCH 039/263] Migrating to traditional JS handlers. --- .../src/main/resources/guacamole.js | 54 +++++++------------ .../src/main/resources/tunnel.js | 31 +++++++---- 2 files changed, 41 insertions(+), 44 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 54153c573..b13a80a56 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -18,6 +18,8 @@ function GuacamoleClient(display, tunnel) { + var guac_client = this; + var STATE_IDLE = 0; var STATE_CONNECTING = 1; var STATE_WAITING = 2; @@ -26,9 +28,8 @@ function GuacamoleClient(display, tunnel) { var STATE_DISCONNECTED = 5; var currentState = STATE_IDLE; - var stateChangeHandler = null; - tunnel.setInstructionHandler(doInstruction); + tunnel.oninstruction = doInstruction; // Display must be relatively positioned for mouse to be handled properly display.style.position = "relative"; @@ -36,15 +37,11 @@ function GuacamoleClient(display, tunnel) { function setState(state) { if (state != currentState) { currentState = state; - if (stateChangeHandler) - stateChangeHandler(currentState); + if (guac_client.onstatechange) + guac_client.onstatechange(currentState); } } - this.setOnStateChangeHandler = function(handler) { - stateChangeHandler = handler; - }; - function isConnected() { return currentState == STATE_CONNECTED || currentState == STATE_WAITING; @@ -82,7 +79,7 @@ function GuacamoleClient(display, tunnel) { cursor.drawImage(cursorRectX, cursorRectY, cursorImage); } - this.sendKeyEvent = function(pressed, keysym) { + guac_client.sendKeyEvent = function(pressed, keysym) { // Do not send requests if not connected if (!isConnected()) return; @@ -90,7 +87,7 @@ function GuacamoleClient(display, tunnel) { tunnel.sendMessage("key:" + keysym + "," + pressed + ";"); }; - this.sendMouseState = function(mouseState) { + guac_client.sendMouseState = function(mouseState) { // Do not send requests if not connected if (!isConnected()) @@ -116,7 +113,7 @@ function GuacamoleClient(display, tunnel) { tunnel.sendMessage("mouse:" + mouseState.getX() + "," + mouseState.getY() + "," + buttonMask + ";"); }; - this.setClipboard = function(data) { + guac_client.setClipboard = function(data) { // Do not send requests if not connected if (!isConnected()) @@ -126,21 +123,10 @@ function GuacamoleClient(display, tunnel) { }; // Handlers - - var nameHandler = null; - this.setNameHandler = function(handler) { - nameHandler = handler; - }; - - var errorHandler = null; - this.setErrorHandler = function(handler) { - errorHandler = handler; - }; - - var clipboardHandler = null; - this.setClipboardHandler = function(handler) { - clipboardHandler = handler; - }; + guac_client.onstatechange = null; + guac_client.onname = null; + guac_client.onerror = null; + guac_client.onclipboard = null; // Layers var displayWidth = 0; @@ -150,7 +136,7 @@ function GuacamoleClient(display, tunnel) { var buffers = new Array(); var cursor = null; - this.getLayers = function() { + guac_client.getLayers = function() { return layers; }; @@ -216,16 +202,16 @@ function GuacamoleClient(display, tunnel) { var instructionHandlers = { "error": function(parameters) { - if (errorHandler) errorHandler(unescapeGuacamoleString(parameters[0])); + if (guac_client.onerror) guac_client.onerror(unescapeGuacamoleString(parameters[0])); disconnect(); }, "name": function(parameters) { - if (nameHandler) nameHandler(unescapeGuacamoleString(parameters[0])); + if (guac_client.onname) guac_client.onname(unescapeGuacamoleString(parameters[0])); }, "clipboard": function(parameters) { - if (clipboardHandler) clipboardHandler(unescapeGuacamoleString(parameters[0])); + if (guac_client.onclipboard) guac_client.onclipboard(unescapeGuacamoleString(parameters[0])); }, "size": function(parameters) { @@ -432,8 +418,8 @@ function GuacamoleClient(display, tunnel) { } - this.disconnect = disconnect; - this.connect = function(data) { + guac_client.disconnect = disconnect; + guac_client.connect = function(data) { setState(STATE_CONNECTING); @@ -448,7 +434,7 @@ function GuacamoleClient(display, tunnel) { setState(STATE_WAITING); }; - this.escapeGuacamoleString = escapeGuacamoleString; - this.unescapeGuacamoleString = unescapeGuacamoleString; + guac_client.escapeGuacamoleString = escapeGuacamoleString; + guac_client.unescapeGuacamoleString = unescapeGuacamoleString; } diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index d5a785ac3..bb89b241f 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -18,6 +18,8 @@ function GuacamoleHTTPTunnel(tunnelURL) { + var tunnel = this; + var tunnel_uuid; var TUNNEL_CONNECT = tunnelURL + "?connect"; @@ -36,11 +38,13 @@ function GuacamoleHTTPTunnel(tunnelURL) { // Default to polling - will be turned off automatically if not needed var pollingMode = POLLING_ENABLED; - var instructionHandler = null; - var sendingMessages = 0; var outputMessageBuffer = ""; + // Handlers + tunnel.onerror = null; + tunnel.oninstruction = null; + function sendMessage(message) { // Do not attempt to send messages if not connected @@ -119,6 +123,16 @@ function GuacamoleHTTPTunnel(tunnelURL) { // Halt on error during request if (xmlhttprequest.status == 0 || xmlhttprequest.status != 200) { + + // Get error message (if any) + var message = xmlhttprequest.getResponseHeader("X-Guacamole-Error-Message"); + if (message) + message = "Internal server error"; + + // Call error handler + if (tunnel.onerror) tunnel.onerror(message); + + // Finish disconnect(); return; } @@ -160,8 +174,8 @@ function GuacamoleHTTPTunnel(tunnelURL) { } // Call instruction handler. - if (instructionHandler != null) - instructionHandler(opcode, parameters); + if (tunnel.oninstruction != null) + tunnel.oninstruction(opcode, parameters); } // Start search at end of string. @@ -246,11 +260,8 @@ function GuacamoleHTTPTunnel(tunnelURL) { } // External API - this.connect = connect; - this.disconnect = disconnect; - this.sendMessage = sendMessage; - this.setInstructionHandler = function(handler) { - instructionHandler = handler; - }; + tunnel.connect = connect; + tunnel.disconnect = disconnect; + tunnel.sendMessage = sendMessage; } From bd477daa2c6ecc5ace6cf0307b45f9113b80dbf5 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 5 Jul 2011 10:16:03 -0700 Subject: [PATCH 040/263] More migration to traditional JS events. --- .../src/main/resources/keyboard.js | 28 ++++------ .../src/main/resources/mouse.js | 54 +++++++++---------- 2 files changed, 38 insertions(+), 44 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index e0f784db0..edbe313fa 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -19,6 +19,8 @@ function GuacamoleKeyboard(element) { + var guac_keyboard = this; + // Keymap var unshiftedKeySym = new Array(); @@ -64,11 +66,6 @@ function GuacamoleKeyboard(element) { var shiftedKeySym = new Array(); shiftedKeySym[18] = 0xFFE7; // alt - - /*****************************************/ - /*** Keyboard Handler ***/ - /*****************************************/ - // Single key state/modifier buffer var modShift = 0; var modCtrl = 0; @@ -150,14 +147,14 @@ function GuacamoleKeyboard(element) { // Sends a single keystroke over the network function sendKeyPressed(keysym) { - if (keysym != null && keyPressedHandler) - keyPressedHandler(keysym); + if (keysym != null && guac_keyboard.onkeydown) + guac_keyboard.onkeydown(keysym); } // Sends a single keystroke over the network function sendKeyReleased(keysym) { - if (keysym != null) - keyReleasedHandler(keysym); + if (keysym != null && guac_keyboard.onkeyup) + guac_keyboard.onkeyup(keysym); } @@ -171,7 +168,7 @@ function GuacamoleKeyboard(element) { element.onkeydown = function(e) { // Only intercept if handler set - if (!keyPressedHandler) return true; + if (!guac_keyboard.onkeydown) return true; var keynum; if (window.event) keynum = window.event.keyCode; @@ -237,7 +234,7 @@ function GuacamoleKeyboard(element) { element.onkeypress = function(e) { // Only intercept if handler set - if (!keyPressedHandler) return true; + if (!guac_keyboard.onkeydown) return true; if (keySymSource != KEYPRESS) return false; @@ -272,7 +269,7 @@ function GuacamoleKeyboard(element) { element.onkeyup = function(e) { // Only intercept if handler set - if (!keyReleasedHandler) return true; + if (!guac_keyboard.onkeyup) return true; var keynum; if (window.event) keynum = window.event.keyCode; @@ -309,10 +306,7 @@ function GuacamoleKeyboard(element) { if (docOnblur != null) docOnblur(); }; - var keyPressedHandler = null; - var keyReleasedHandler = null; - - this.setKeyPressedHandler = function(kh) { keyPressedHandler = kh; }; - this.setKeyReleasedHandler = function(kh) { keyReleasedHandler = kh; }; + guac_keyboard.onkeydown = null; + guac_keyboard.onkeyup = null; } diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index fb8600519..31d5185d0 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -20,12 +20,7 @@ function GuacamoleMouse(element) { - /*****************************************/ - /*** Mouse Handler ***/ - /*****************************************/ - - - var mouseIndex = 0; + var guac_mouse = this; var mouseLeftButton = 0; var mouseMiddleButton = 0; @@ -69,7 +64,8 @@ function GuacamoleMouse(element) { parent = parent.offsetParent; } - movementHandler(getMouseState(0, 0)); + if (guac_mouse.onmousemove) + guac_mouse.onmousemove(getMouseState(0, 0)); }; @@ -89,7 +85,8 @@ function GuacamoleMouse(element) { break; } - buttonPressedHandler(getMouseState(0, 0)); + if (guac_mouse.onmousedown) + guac_mouse.onmousedown(getMouseState(0, 0)); }; @@ -109,7 +106,8 @@ function GuacamoleMouse(element) { break; } - buttonReleasedHandler(getMouseState(0, 0)); + if (guac_mouse.onmouseup) + guac_mouse.onmouseup(getMouseState(0, 0)); }; element.onmouseout = function(e) { @@ -122,7 +120,8 @@ function GuacamoleMouse(element) { mouseMiddleButton = 0; mouseRightButton = 0; - buttonReleasedHandler(getMouseState(0, 0)); + if (guac_mouse.onmouseup) + guac_mouse.onmouseup(getMouseState(0, 0)); } }; @@ -143,14 +142,20 @@ function GuacamoleMouse(element) { // Up if (delta < 0) { - buttonPressedHandler(getMouseState(1, 0)); - buttonReleasedHandler(getMouseState(0, 0)); + if (guac_mouse.onmousedown) + guac_mouse.onmousedown(getMouseState(1, 0)); + + if (guac_mouse.onmouseup) + guac_mouse.onmouseup(getMouseState(0, 0)); } // Down if (delta > 0) { - buttonPressedHandler(getMouseState(0, 1)); - buttonReleasedHandler(getMouseState(0, 0)); + if (guac_mouse.onmousedown) + guac_mouse.onmousedown(getMouseState(0, 1)); + + if (guac_mouse.onmouseup) + guac_mouse.onmouseup(getMouseState(0, 0)); } if (e.preventDefault) @@ -165,20 +170,15 @@ function GuacamoleMouse(element) { handleScroll(e); } - var buttonPressedHandler = null; - var buttonReleasedHandler = null; - var movementHandler = null; + guac_mouse.onmousedown = null; + guac_mouse.onmouseup = null; + guac_mouse.onmousemove = null; - this.setButtonPressedHandler = function(mh) {buttonPressedHandler = mh;}; - this.setButtonReleasedHandler = function(mh) {buttonReleasedHandler = mh;}; - this.setMovementHandler = function(mh) {movementHandler = mh;}; - - - this.getX = function() {return mouseX;}; - this.getY = function() {return mouseY;}; - this.getLeftButton = function() {return mouseLeftButton;}; - this.getMiddleButton = function() {return mouseMiddleButton;}; - this.getRightButton = function() {return mouseRightButton;}; + guac_mouse.getX = function() {return mouseX;}; + guac_mouse.getY = function() {return mouseY;}; + guac_mouse.getLeftButton = function() {return mouseLeftButton;}; + guac_mouse.getMiddleButton = function() {return mouseMiddleButton;}; + guac_mouse.getRightButton = function() {return mouseRightButton;}; } From 3e65c4620442167c08e4a8880bb453e895acf207 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 5 Jul 2011 22:13:45 -0700 Subject: [PATCH 041/263] JSDoc + namespace, some cleanup. --- .../src/main/resources/guacamole.js | 21 +++--- .../src/main/resources/keyboard.js | 5 +- .../src/main/resources/layer.js | 74 ++++++++++++++----- .../src/main/resources/mouse.js | 4 +- .../src/main/resources/oskeyboard.js | 5 +- .../src/main/resources/tunnel.js | 5 +- 6 files changed, 82 insertions(+), 32 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index b13a80a56..371ba73e6 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -16,7 +16,10 @@ * You should have received a copy of the GNU Affero General Public License */ -function GuacamoleClient(display, tunnel) { +// Guacamole namespace +var Guacamole = Guacamole || {}; + +Guacamole.Client = function(display, tunnel) { var guac_client = this; @@ -150,7 +153,7 @@ function GuacamoleClient(display, tunnel) { // Create buffer if necessary if (buffer == null) { - buffer = new Layer(0, 0); + buffer = new Guacamole.Layer(0, 0); buffer.setAutosize(1); buffers[index] = buffer; } @@ -165,7 +168,7 @@ function GuacamoleClient(display, tunnel) { if (layer == null) { // Add new layer - layer = new Layer(displayWidth, displayHeight); + layer = new Guacamole.Layer(displayWidth, displayHeight); layers[index] = layer; // (Re)-add existing layers in order @@ -174,18 +177,18 @@ function GuacamoleClient(display, tunnel) { // If already present, remove if (layers[i].parentNode === display) - display.removeChild(layers[i]); + display.removeChild(layers[i].getCanvas()); // Add to end - display.appendChild(layers[i]); + display.appendChild(layers[i].getCanvas()); } } // Add cursor layer last if (cursor != null) { if (cursor.parentNode === display) - display.removeChild(cursor); - display.appendChild(cursor); + display.removeChild(cursor.getCanvas()); + display.appendChild(cursor.getCanvas()); } } @@ -284,8 +287,8 @@ function GuacamoleClient(display, tunnel) { var data = parameters[2]; if (cursor == null) { - cursor = new Layer(displayWidth, displayHeight); - display.appendChild(cursor); + cursor = new Guacamole.Layer(displayWidth, displayHeight); + display.appendChild(cursor.getCanvas()); } // Start cursor image load diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index edbe313fa..e798f59f7 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -17,7 +17,10 @@ * along with this program. If not, see . */ -function GuacamoleKeyboard(element) { +// Guacamole namespace +var Guacamole = Guacamole || {}; + +Guacamole.Keyboard = function(element) { var guac_keyboard = this; diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 775b23683..16fef960a 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -17,12 +17,40 @@ * along with this program. If not, see . */ -function Layer(width, height) { +// Guacamole namespace +var Guacamole = Guacamole || {}; + +/** + * Abstract ordered drawing surface. Each Layer contains a canvas element and + * provides simple drawing instructions for drawing to that canvas element, + * however unlike the canvas element itself, drawing operations on a Layer are + * guaranteed to run in order, even if such an operation must wait for an image + * to load before completing. + * + * @constructor + * + * @param {Number} width The width of the Layer, in pixels. The canvas element + * backing this Layer will be given this width. + * + * @param {Number} height The height of the Layer, in pixels. The canvas element + * backing this Layer will be given this height. + */ +Guacamole.Layer = function(width, height) { + + var layer = this; // Off-screen buffer var display = document.createElement("canvas"); var displayContext = display.getContext("2d"); + /** + * Returns the canvas element backing this Layer. + * @returns {Element} The canvas element backing this Layer. + */ + this.getCanvas = function() { + return display; + }; + function resize(newWidth, newHeight) { display.style.position = "absolute"; display.style.left = "0px"; @@ -35,7 +63,15 @@ function Layer(width, height) { height = newHeight; } - display.resize = function(newWidth, newHeight) { + /** + * Changes the size of this Layer to the given width and height. Resizing + * is only attempted if the new size provided is actually different from + * the current size. + * + * @param {Number} newWidth The new width to assign to this Layer. + * @param {Number} newHeight The new height to assign to this Layer. + */ + this.resize = function(newWidth, newHeight) { if (newWidth != width || newHeight != height) resize(newWidth, newHeight); }; @@ -87,14 +123,14 @@ function Layer(width, height) { } - display.setAutosize = function(flag) { + this.setAutosize = function(flag) { autosize = flag; }; function reserveJob(handler) { // If no pending updates, just call (if available) and exit - if (display.isReady() && handler != null) { + if (layer.isReady() && handler != null) { handler(); return null; } @@ -118,12 +154,12 @@ function Layer(width, height) { } - display.isReady = function() { + this.isReady = function() { return updates.length == 0; }; - display.drawImage = function(x, y, image) { + this.drawImage = function(x, y, image) { reserveJob(function() { if (autosize != 0) fitRect(x, y, image.width, image.height); displayContext.drawImage(image, x, y); @@ -131,7 +167,7 @@ function Layer(width, height) { }; - display.draw = function(x, y, url) { + this.draw = function(x, y, url) { var update = reserveJob(null); var image = new Image(); @@ -151,14 +187,18 @@ function Layer(width, height) { }; - // Run arbitrary function as soon as currently pending operations complete. - // Future operations will not block this function from being called (unlike - // the ready handler, which requires no pending updates) - display.sync = function(handler) { + /** + * Run an arbitrary function as soon as currently pending operations + * are complete. + * + * @param {function} handler The function to call once all currently + * pending operations are complete. + */ + this.sync = function(handler) { reserveJob(handler); }; - display.copyRect = function(srcLayer, srcx, srcy, w, h, x, y) { + this.copyRect = function(srcLayer, srcx, srcy, w, h, x, y) { function doCopyRect() { if (autosize != 0) fitRect(x, y, w, h); @@ -167,7 +207,7 @@ function Layer(width, height) { // If we ARE the source layer, no need to sync. // Syncing would result in deadlock. - if (display === srcLayer) + if (layer === srcLayer) reserveJob(doCopyRect); // Otherwise synchronize copy operation with source layer @@ -186,14 +226,14 @@ function Layer(width, height) { }; - display.clearRect = function(x, y, w, h) { + this.clearRect = function(x, y, w, h) { reserveJob(function() { if (autosize != 0) fitRect(x, y, w, h); displayContext.clearRect(x, y, w, h); }); }; - display.filter = function(filter) { + this.filter = function(filter) { reserveJob(function() { var imageData = displayContext.getImageData(0, 0, width, height); filter(imageData.data, width, height); @@ -220,13 +260,11 @@ function Layer(width, height) { 0xF: "lighter" }; - display.setChannelMask = function(mask) { + this.setChannelMask = function(mask) { reserveJob(function() { displayContext.globalCompositeOperation = compositeOperation[mask]; }); }; - return display; - } diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 31d5185d0..ec4c7b1a2 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -17,8 +17,10 @@ * along with this program. If not, see . */ +// Guacamole namespace +var Guacamole = Guacamole || {}; -function GuacamoleMouse(element) { +Guacamole.Mouse = function(element) { var guac_mouse = this; diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 872bac223..0e6a9ccef 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -17,10 +17,11 @@ * along with this program. If not, see . */ +// Guacamole namespace +var Guacamole = Guacamole || {}; -function GuacamoleOnScreenKeyboard(url) { +Guacamole.OnScreenKeyboard = function(url) { - var tabIndex = 1; var allKeys = new Array(); var modifierState = new function() {}; diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index bb89b241f..e092088cb 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -16,7 +16,10 @@ * You should have received a copy of the GNU Affero General Public License */ -function GuacamoleHTTPTunnel(tunnelURL) { +// Guacamole namespace +var Guacamole = Guacamole || {}; + +Guacamole.HTTPTunnel = function(tunnelURL) { var tunnel = this; From c7b880d1bc311b0b6b3f0c6c7922d35bb9d26f7d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 5 Jul 2011 23:08:34 -0700 Subject: [PATCH 042/263] More JSDoc. --- .../src/main/resources/guacamole.js | 2 +- .../src/main/resources/layer.js | 108 ++++++++++++++++-- 2 files changed, 98 insertions(+), 12 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 371ba73e6..f4cf49604 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -154,7 +154,7 @@ Guacamole.Client = function(display, tunnel) { // Create buffer if necessary if (buffer == null) { buffer = new Guacamole.Layer(0, 0); - buffer.setAutosize(1); + buffer.autosize = 1; buffers[index] = buffer; } diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 16fef960a..01acafbe0 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -37,9 +37,11 @@ var Guacamole = Guacamole || {}; */ Guacamole.Layer = function(width, height) { + // Reference to this Layer var layer = this; - // Off-screen buffer + // Off-screen buffer (canvas element) and corresponding + // context. var display = document.createElement("canvas"); var displayContext = display.getContext("2d"); @@ -51,6 +53,14 @@ Guacamole.Layer = function(width, height) { return display; }; + /** + * 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) { display.style.position = "absolute"; display.style.left = "0px"; @@ -76,6 +86,22 @@ Guacamole.Layer = function(width, height) { resize(newWidth, newHeight); }; + /** + * 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 @@ -102,10 +128,31 @@ Guacamole.Layer = function(width, height) { } + // Initialize canvas dimensions resize(width, height); + /** + * 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; + var updates = new Array(); - var autosize = 0; function Update(updateHandler) { @@ -123,10 +170,6 @@ Guacamole.Layer = function(width, height) { } - this.setAutosize = function(flag) { - autosize = flag; - }; - function reserveJob(handler) { // If no pending updates, just call (if available) and exit @@ -154,11 +197,25 @@ Guacamole.Layer = function(width, height) { } + /** + * 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 updates.length == 0; }; - + /** + * 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) { reserveJob(function() { if (autosize != 0) fitRect(x, y, image.width, image.height); @@ -166,7 +223,15 @@ Guacamole.Layer = function(width, height) { }); }; - + /** + * 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 update = reserveJob(null); @@ -198,11 +263,32 @@ Guacamole.Layer = function(width, height) { reserveJob(handler); }; - this.copyRect = function(srcLayer, srcx, srcy, w, h, 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.copyRect = function(srcLayer, srcx, srcy, srcw, srch, x, y) { function doCopyRect() { - if (autosize != 0) fitRect(x, y, w, h); - displayContext.drawImage(srcLayer, srcx, srcy, w, h, x, y, w, h); + if (autosize != 0) fitRect(x, y, srcw, srch); + displayContext.drawImage(srcLayer, srcx, srcy, srcw, srch, x, y, srcw, srch); } // If we ARE the source layer, no need to sync. From 086192f4146c9327e5fea98e375c840ef05bee9c Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 6 Jul 2011 13:14:40 -0700 Subject: [PATCH 043/263] More JSDoc, renamed Update to Task, fixed wording. --- .../src/main/resources/layer.js | 158 ++++++++++-------- 1 file changed, 87 insertions(+), 71 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 01acafbe0..db470fa3f 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -37,14 +37,45 @@ var Guacamole = Guacamole || {}; */ Guacamole.Layer = function(width, height) { - // Reference to this Layer + /** + * Reference to this Layer. + * @private + */ var layer = this; - // Off-screen buffer (canvas element) and corresponding - // context. + /** + * 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"); + var tasks = new Array(); + + 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" + }; + /** * Returns the canvas element backing this Layer. * @returns {Element} The canvas element backing this Layer. @@ -128,9 +159,6 @@ Guacamole.Layer = function(width, height) { } - // Initialize canvas dimensions - resize(width, height); - /** * Set to true if this Layer should resize itself to accomodate the * dimensions of any drawing operation, and false (the default) otherwise. @@ -152,47 +180,51 @@ Guacamole.Layer = function(width, height) { */ this.autosize = false; - var updates = new Array(); - - function Update(updateHandler) { - - this.setHandler = function(handler) { - updateHandler = handler; - }; - - this.hasHandler = function() { - return updateHandler != null; - }; - - this.handle = function() { - updateHandler(); - }; - + /** + * 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. + */ + function Task(taskHandler) { + + /** + * The handler this Task is associated with, if any. + * + * @type function + */ + this.handler = taskHandler; + } - function reserveJob(handler) { + function scheduleTask(handler) { - // If no pending updates, just call (if available) and exit + // If no pending tasks, just call (if available) and exit if (layer.isReady() && handler != null) { handler(); return null; } - // If updates are pending/executing, schedule a pending update + // If tasks are pending/executing, schedule a pending task // and return a reference to it. - var update = new Update(handler); - updates.push(update); - return update; + var task = new Task(handler); + tasks.push(task); + return task; } - function handlePendingUpdates() { + function handlePendingTasks() { - // Draw all pending updates. - var update; - while ((update = updates[0]) != null && update.hasHandler()) { - update.handle(); - updates.shift(); + // Draw all pending tasks. + var task; + while ((task = tasks[0]) != null && task.handler) { + task.handler(); + tasks.shift(); } } @@ -204,7 +236,7 @@ Guacamole.Layer = function(width, height) { * @returns {Boolean} true if this Layer is ready, false otherwise. */ this.isReady = function() { - return updates.length == 0; + return tasks.length == 0; }; /** @@ -217,7 +249,7 @@ Guacamole.Layer = function(width, height) { * object - not a URL. */ this.drawImage = function(x, y, image) { - reserveJob(function() { + scheduleTask(function() { if (autosize != 0) fitRect(x, y, image.width, image.height); displayContext.drawImage(image, x, y); }); @@ -233,19 +265,19 @@ Guacamole.Layer = function(width, height) { * @param {String} url The URL of the image to draw. */ this.draw = function(x, y, url) { - var update = reserveJob(null); + var task = scheduleTask(null); var image = new Image(); image.onload = function() { - update.setHandler(function() { + task.handler = function() { if (autosize != 0) fitRect(x, y, image.width, image.height); displayContext.drawImage(image, x, y); - }); + }; - // As this update originally had no handler and may have blocked - // other updates, handle any blocked updates. - handlePendingUpdates(); + // As this task originally had no handler and may have blocked + // other tasks, handle any blocked tasks. + handlePendingTasks(); }; image.src = url; @@ -260,7 +292,7 @@ Guacamole.Layer = function(width, height) { * pending operations are complete. */ this.sync = function(handler) { - reserveJob(handler); + scheduleTask(handler); }; /** @@ -294,18 +326,18 @@ Guacamole.Layer = function(width, height) { // If we ARE the source layer, no need to sync. // Syncing would result in deadlock. if (layer === srcLayer) - reserveJob(doCopyRect); + scheduleTask(doCopyRect); // Otherwise synchronize copy operation with source layer else { - var update = reserveJob(null); + var task = scheduleTask(null); srcLayer.sync(function() { - update.setHandler(doCopyRect); + task.handler = doCopyRect; - // As this update originally had no handler and may have blocked - // other updates, handle any blocked updates. - handlePendingUpdates(); + // As this task originally had no handler and may have blocked + // other tasks, handle any blocked tasks. + handlePendingTasks(); }); } @@ -313,44 +345,28 @@ Guacamole.Layer = function(width, height) { }; this.clearRect = function(x, y, w, h) { - reserveJob(function() { + scheduleTask(function() { if (autosize != 0) fitRect(x, y, w, h); displayContext.clearRect(x, y, w, h); }); }; this.filter = function(filter) { - reserveJob(function() { + scheduleTask(function() { var imageData = displayContext.getImageData(0, 0, width, height); filter(imageData.data, width, height); displayContext.putImageData(imageData, 0, 0); }); }; - 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" - }; - this.setChannelMask = function(mask) { - reserveJob(function() { + scheduleTask(function() { displayContext.globalCompositeOperation = compositeOperation[mask]; }); }; + // Initialize canvas dimensions + resize(width, height); + } From 649d873373898e2d5857e9c1705ef89e17462ffc Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 6 Jul 2011 14:39:50 -0700 Subject: [PATCH 044/263] Finished JSDoc of Layer, more cleanup. --- .../src/main/resources/layer.js | 153 ++++++++++++------ 1 file changed, 107 insertions(+), 46 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index db470fa3f..4033abde8 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -48,6 +48,9 @@ Guacamole.Layer = function(width, height) { * @private */ var display = document.createElement("canvas"); + display.style.position = "absolute"; + display.style.left = "0px"; + display.style.top = "0px"; /** * The 2D display context of the canvas element backing this Layer. @@ -55,8 +58,19 @@ Guacamole.Layer = function(width, height) { */ var displayContext = display.getContext("2d"); + /** + * 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(); + /** + * 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", @@ -76,14 +90,6 @@ Guacamole.Layer = function(width, height) { 0xF: "lighter" }; - /** - * Returns the canvas element backing this Layer. - * @returns {Element} The canvas element backing this Layer. - */ - this.getCanvas = function() { - return display; - }; - /** * Resizes the canvas element backing this Layer without testing the * new size. This function should only be used internally. @@ -93,10 +99,6 @@ Guacamole.Layer = function(width, height) { * @param {Number} newHeight The new height to assign to this Layer. */ function resize(newWidth, newHeight) { - display.style.position = "absolute"; - display.style.left = "0px"; - display.style.top = "0px"; - display.width = newWidth; display.height = newHeight; @@ -104,19 +106,6 @@ Guacamole.Layer = function(width, height) { height = newHeight; } - /** - * Changes the size of this Layer to the given width and height. Resizing - * is only attempted if the new size provided is actually different from - * the current size. - * - * @param {Number} newWidth The new width to assign to this Layer. - * @param {Number} newHeight The new height to assign to this Layer. - */ - this.resize = function(newWidth, newHeight) { - if (newWidth != width || newHeight != height) - resize(newWidth, newHeight); - }; - /** * 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 @@ -159,27 +148,6 @@ Guacamole.Layer = function(width, height) { } - /** - * 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; - /** * 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 @@ -202,6 +170,17 @@ Guacamole.Layer = function(width, height) { } + /** + * 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. + * @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) { // If no pending tasks, just call (if available) and exit @@ -218,6 +197,11 @@ Guacamole.Layer = function(width, height) { } + /** + * Run any Tasks which were pending but are now ready to run and are not + * blocked by other Tasks. + * @private + */ function handlePendingTasks() { // Draw all pending tasks. @@ -229,6 +213,35 @@ Guacamole.Layer = function(width, height) { } + /** + * 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. @@ -239,6 +252,21 @@ Guacamole.Layer = function(width, height) { 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. @@ -344,6 +372,16 @@ Guacamole.Layer = function(width, height) { }; + /** + * Clear the specified rectangle of image data. + * + * @param {Number} x The X coordinate of the upper-left corner of the + * rectangle to clear. + * @param {Number} y The Y coordinate of the upper-left corner of the + * rectangle to clear. + * @param {Number} w The width of the rectangle to clear. + * @param {Number} h The height of the rectangle to clear. + */ this.clearRect = function(x, y, w, h) { scheduleTask(function() { if (autosize != 0) fitRect(x, y, w, h); @@ -351,6 +389,18 @@ Guacamole.Layer = function(width, height) { }); }; + /** + * Provides the given filtering function with a writable snapshot of + * image data and the current width and height of the Layer. + * + * @param {function} filter A function which accepts an array of image + * data (as returned by the canvas element's + * display context's getImageData() function), + * the width of the Layer, and the height of the + * Layer as parameters, in that order. This + * function must accomplish its filtering by + * modifying the given image data array directly. + */ this.filter = function(filter) { scheduleTask(function() { var imageData = displayContext.getImageData(0, 0, width, height); @@ -359,6 +409,17 @@ Guacamole.Layer = function(width, height) { }); }; + /** + * 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]; From 867e64637fa8df8bcd09a9a9f19bffbe9a6a920c Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 6 Jul 2011 15:33:11 -0700 Subject: [PATCH 045/263] Fixed autosize -> layer.autosize. --- guacamole-common-js/src/main/resources/layer.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 4033abde8..02cd28e9d 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -278,7 +278,7 @@ Guacamole.Layer = function(width, height) { */ this.drawImage = function(x, y, image) { scheduleTask(function() { - if (autosize != 0) fitRect(x, y, image.width, image.height); + if (layer.autosize != 0) fitRect(x, y, image.width, image.height); displayContext.drawImage(image, x, y); }); }; @@ -299,7 +299,7 @@ Guacamole.Layer = function(width, height) { image.onload = function() { task.handler = function() { - if (autosize != 0) fitRect(x, y, image.width, image.height); + if (layer.autosize != 0) fitRect(x, y, image.width, image.height); displayContext.drawImage(image, x, y); }; @@ -347,7 +347,7 @@ Guacamole.Layer = function(width, height) { this.copyRect = function(srcLayer, srcx, srcy, srcw, srch, x, y) { function doCopyRect() { - if (autosize != 0) fitRect(x, y, srcw, srch); + if (layer.autosize != 0) fitRect(x, y, srcw, srch); displayContext.drawImage(srcLayer, srcx, srcy, srcw, srch, x, y, srcw, srch); } @@ -384,7 +384,7 @@ Guacamole.Layer = function(width, height) { */ this.clearRect = function(x, y, w, h) { scheduleTask(function() { - if (autosize != 0) fitRect(x, y, w, h); + if (layer.autosize != 0) fitRect(x, y, w, h); displayContext.clearRect(x, y, w, h); }); }; From aea01a5cdb1ed8937f3625191798383c94515d68 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 7 Jul 2011 23:19:19 -0700 Subject: [PATCH 046/263] Better mouse state object, more JSDoc, cleanup. --- .../src/main/resources/guacamole.js | 31 ++- .../src/main/resources/layer.js | 6 +- .../src/main/resources/mouse.js | 193 ++++++++++-------- 3 files changed, 131 insertions(+), 99 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index f4cf49604..7009e7a47 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -99,21 +99,21 @@ Guacamole.Client = function(display, tunnel) { // Draw client-side cursor if (cursorImage != null) { redrawCursor( - mouseState.getX(), - mouseState.getY() + mouseState.x, + mouseState.y ); } // Build mask var buttonMask = 0; - if (mouseState.getLeft()) buttonMask |= 1; - if (mouseState.getMiddle()) buttonMask |= 2; - if (mouseState.getRight()) buttonMask |= 4; - if (mouseState.getUp()) buttonMask |= 8; - if (mouseState.getDown()) buttonMask |= 16; + 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:" + mouseState.getX() + "," + mouseState.getY() + "," + buttonMask + ";"); + tunnel.sendMessage("mouse:" + mouseState.x + "," + mouseState.y + "," + buttonMask + ";"); }; guac_client.setClipboard = function(data) { @@ -169,6 +169,13 @@ Guacamole.Client = function(display, tunnel) { // Add new layer layer = new Guacamole.Layer(displayWidth, displayHeight); + + // Set layer position + var canvas = layer.getCanvas(); + canvas.style.position = "absolute"; + canvas.style.left = "0px"; + canvas.style.top = "0px"; + layers[index] = layer; // (Re)-add existing layers in order @@ -288,7 +295,13 @@ Guacamole.Client = function(display, tunnel) { if (cursor == null) { cursor = new Guacamole.Layer(displayWidth, displayHeight); - display.appendChild(cursor.getCanvas()); + + var canvas = cursor.getCanvas(); + canvas.style.position = "absolute"; + canvas.style.left = "0px"; + canvas.style.top = "0px"; + + display.appendChild(canvas); } // Start cursor image load diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 02cd28e9d..467b4cc66 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -48,9 +48,6 @@ Guacamole.Layer = function(width, height) { * @private */ var display = document.createElement("canvas"); - display.style.position = "absolute"; - display.style.left = "0px"; - display.style.top = "0px"; /** * The 2D display context of the canvas element backing this Layer. @@ -429,5 +426,4 @@ Guacamole.Layer = function(width, height) { // Initialize canvas dimensions resize(width, height); -} - +}; diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index ec4c7b1a2..a8f3a8b97 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -20,54 +20,93 @@ // Guacamole 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. + * + * Touch event support is planned, but currently only in testing (translate + * touch events into mouse events). + * + * @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; - var mouseLeftButton = 0; - var mouseMiddleButton = 0; - var mouseRightButton = 0; + /** + * 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 + ); - var mouseX = 0; - var mouseY = 0; + /** + * 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; - var absoluteMouseX = 0; - var absoluteMouseY = 0; - - - function getMouseState(up, down) { - var mouseState = new MouseEvent(mouseX, mouseY, - mouseLeftButton, mouseMiddleButton, mouseRightButton, up, down); - - return mouseState; - } + /** + * 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; // Block context menu so right-click gets sent properly - element.oncontextmenu = function(e) {return false;}; + element.oncontextmenu = function(e) { + return false; + }; element.onmousemove = function(e) { e.stopPropagation(); - absoluteMouseX = e.pageX; - absoluteMouseY = e.pageY; + var absoluteMouseX = e.pageX; + var absoluteMouseY = e.pageY; - mouseX = absoluteMouseX - element.offsetLeft; - mouseY = absoluteMouseY - element.offsetTop; + guac_mouse.currentState.x = absoluteMouseX - element.offsetLeft; + guac_mouse.currentState.y = absoluteMouseY - element.offsetTop; // This is all JUST so we can get the mouse position within the element var parent = element.offsetParent; while (parent) { if (parent.offsetLeft && parent.offsetTop) { - mouseX -= parent.offsetLeft; - mouseY -= parent.offsetTop; + guac_mouse.currentState.x -= parent.offsetLeft; + guac_mouse.currentState.y -= parent.offsetTop; } parent = parent.offsetParent; } if (guac_mouse.onmousemove) - guac_mouse.onmousemove(getMouseState(0, 0)); + guac_mouse.onmousemove(guac_mouse.currentState); + }; @@ -77,18 +116,19 @@ Guacamole.Mouse = function(element) { switch (e.button) { case 0: - mouseLeftButton = 1; + guac_mouse.currentState.left = true; break; case 1: - mouseMiddleButton = 1; + guac_mouse.currentState.middle = true; break; case 2: - mouseRightButton = 1; + guac_mouse.currentState.right = true; break; } if (guac_mouse.onmousedown) - guac_mouse.onmousedown(getMouseState(0, 0)); + guac_mouse.onmousedown(guac_mouse.currentState); + }; @@ -98,18 +138,19 @@ Guacamole.Mouse = function(element) { switch (e.button) { case 0: - mouseLeftButton = 0; + guac_mouse.currentState.left = false; break; case 1: - mouseMiddleButton = 0; + guac_mouse.currentState.middle = false; break; case 2: - mouseRightButton = 0; + guac_mouse.currentState.right = false; break; } if (guac_mouse.onmouseup) - guac_mouse.onmouseup(getMouseState(0, 0)); + guac_mouse.onmouseup(guac_mouse.currentState); + }; element.onmouseout = function(e) { @@ -117,13 +158,16 @@ Guacamole.Mouse = function(element) { e.stopPropagation(); // Release all buttons - if (mouseLeftButton || mouseMiddleButton || mouseRightButton) { - mouseLeftButton = 0; - mouseMiddleButton = 0; - mouseRightButton = 0; + 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(getMouseState(0, 0)); + guac_mouse.onmouseup(guac_mouse.currentState); } }; @@ -144,20 +188,28 @@ Guacamole.Mouse = function(element) { // Up if (delta < 0) { - if (guac_mouse.onmousedown) - guac_mouse.onmousedown(getMouseState(1, 0)); + if (guac_mouse.onmousedown) { + guac_mouse.currentState.up = true; + guac_mouse.onmousedown(guac_mouse.currentState); + } - if (guac_mouse.onmouseup) - guac_mouse.onmouseup(getMouseState(0, 0)); + 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.onmousedown(getMouseState(0, 1)); - - if (guac_mouse.onmouseup) - guac_mouse.onmouseup(getMouseState(0, 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); + } } if (e.preventDefault) @@ -170,48 +222,19 @@ Guacamole.Mouse = function(element) { element.onmousewheel = function(e) { handleScroll(e); - } - - guac_mouse.onmousedown = null; - guac_mouse.onmouseup = null; - guac_mouse.onmousemove = null; - - guac_mouse.getX = function() {return mouseX;}; - guac_mouse.getY = function() {return mouseY;}; - guac_mouse.getLeftButton = function() {return mouseLeftButton;}; - guac_mouse.getMiddleButton = function() {return mouseMiddleButton;}; - guac_mouse.getRightButton = function() {return mouseRightButton;}; - -} - -function MouseEvent(x, y, left, middle, right, up, down) { - - this.getX = function() { - return x; }; - this.getY = function() { - return y; - }; +}; - this.getLeft = function() { - return left; - }; +Guacamole.Mouse.State = function(x, y, left, middle, right, up, down) { - this.getMiddle = function() { - return middle; - }; + this.x = x; + this.y = y; + this.left = left; + this.middle = middle + this.right = right; + this.up = up; + this.down = down; + +}; - this.getRight = function() { - return right; - }; - - this.getUp = function() { - return up; - }; - - this.getDown = function() { - return down; - }; - -} From 3684bc5522996204b57be26b99c3ce4578026b3b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 7 Jul 2011 23:28:06 -0700 Subject: [PATCH 047/263] Fixed type error in copy rect of Layer. --- guacamole-common-js/src/main/resources/layer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 467b4cc66..7c8c82235 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -345,7 +345,7 @@ Guacamole.Layer = function(width, height) { function doCopyRect() { if (layer.autosize != 0) fitRect(x, y, srcw, srch); - displayContext.drawImage(srcLayer, srcx, srcy, srcw, srch, x, y, srcw, srch); + displayContext.drawImage(srcLayer.getCanvas(), srcx, srcy, srcw, srch, x, y, srcw, srch); } // If we ARE the source layer, no need to sync. From 5ea2be369c73d890bb7d75d109301b5197a64eff Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 7 Jul 2011 23:48:32 -0700 Subject: [PATCH 048/263] Some JSDoc for keyboard, cleaned up keymap. --- .../src/main/resources/keyboard.js | 109 +++++++++++------- 1 file changed, 65 insertions(+), 44 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index e798f59f7..cc1f72695 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -20,54 +20,76 @@ // Guacamole 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; - // Keymap + /** + * 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 + 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 + }; - var unshiftedKeySym = new Array(); - unshiftedKeySym[8] = 0xFF08; // backspace - unshiftedKeySym[9] = 0xFF09; // tab - unshiftedKeySym[13] = 0xFF0D; // enter - unshiftedKeySym[16] = 0xFFE1; // shift - unshiftedKeySym[17] = 0xFFE3; // ctrl - unshiftedKeySym[18] = 0xFFE9; // alt - unshiftedKeySym[19] = 0xFF13; // pause/break - unshiftedKeySym[20] = 0xFFE5; // caps lock - unshiftedKeySym[27] = 0xFF1B; // escape - unshiftedKeySym[33] = 0xFF55; // page up - unshiftedKeySym[34] = 0xFF56; // page down - unshiftedKeySym[35] = 0xFF57; // end - unshiftedKeySym[36] = 0xFF50; // home - unshiftedKeySym[37] = 0xFF51; // left arrow - unshiftedKeySym[38] = 0xFF52; // up arrow - unshiftedKeySym[39] = 0xFF53; // right arrow - unshiftedKeySym[40] = 0xFF54; // down arrow - unshiftedKeySym[45] = 0xFF63; // insert - unshiftedKeySym[46] = 0xFFFF; // delete - unshiftedKeySym[91] = 0xFFEB; // left window key (super_l) - unshiftedKeySym[92] = 0xFF67; // right window key (menu key?) - unshiftedKeySym[93] = null; // select key - unshiftedKeySym[112] = 0xFFBE; // f1 - unshiftedKeySym[113] = 0xFFBF; // f2 - unshiftedKeySym[114] = 0xFFC0; // f3 - unshiftedKeySym[115] = 0xFFC1; // f4 - unshiftedKeySym[116] = 0xFFC2; // f5 - unshiftedKeySym[117] = 0xFFC3; // f6 - unshiftedKeySym[118] = 0xFFC4; // f7 - unshiftedKeySym[119] = 0xFFC5; // f8 - unshiftedKeySym[120] = 0xFFC6; // f9 - unshiftedKeySym[121] = 0xFFC7; // f10 - unshiftedKeySym[122] = 0xFFC8; // f11 - unshiftedKeySym[123] = 0xFFC9; // f12 - unshiftedKeySym[144] = 0xFF7F; // num lock - unshiftedKeySym[145] = 0xFF14; // scroll lock - - // Shifted versions, IF DIFFERENT FROM UNSHIFTED! - // If any of these are null, the unshifted one will be used. - var shiftedKeySym = new Array(); - shiftedKeySym[18] = 0xFFE7; // alt + /** + * 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 + }; // Single key state/modifier buffer var modShift = 0; @@ -76,7 +98,6 @@ Guacamole.Keyboard = function(element) { var keydownChar = new Array(); - // ID of routine repeating keystrokes. -1 = not repeating. var repeatKeyTimeoutId = -1; var repeatKeyIntervalId = -1; From a4d810969d7d9bc22833401eec8864d2503ca0f5 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 8 Jul 2011 09:16:52 -0700 Subject: [PATCH 049/263] Cleanup, JSDoc for keyboard events. --- .../src/main/resources/keyboard.js | 53 ++++++++++++------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index cc1f72695..3dfc31a16 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -36,6 +36,24 @@ Guacamole.Keyboard = function(element) { */ 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. @@ -92,9 +110,9 @@ Guacamole.Keyboard = function(element) { }; // Single key state/modifier buffer - var modShift = 0; - var modCtrl = 0; - var modAlt = 0; + var modShift = false; + var modCtrl = false; + var modAlt = false; var keydownChar = new Array(); @@ -158,7 +176,7 @@ Guacamole.Keyboard = function(element) { function getKeySymFromKeyCode(keyCode) { var keysym = null; - if (modShift == 0) keysym = unshiftedKeySym[keyCode]; + if (!modShift) keysym = unshiftedKeySym[keyCode]; else { keysym = shiftedKeySym[keyCode]; if (keysym == null) keysym = unshiftedKeySym[keyCode]; @@ -200,11 +218,11 @@ Guacamole.Keyboard = function(element) { // Ctrl/Alt/Shift if (keynum == 16) - modShift = 1; + modShift = true; else if (keynum == 17) - modCtrl = 1; + modCtrl = true; else if (keynum == 18) - modAlt = 1; + modAlt = true; var keysym = getKeySymFromKeyCode(keynum); if (keysym) { @@ -213,7 +231,7 @@ Guacamole.Keyboard = function(element) { } // If modifier keys are held down, and we have keyIdentifier - else if ((modCtrl == 1 || modAlt == 1) && e.keyIdentifier) { + else if ((modCtrl || modAlt) && e.keyIdentifier) { // Get keysym from keyIdentifier keysym = getKeySymFromKeyIdentifier(modShift, e.keyIdentifier); @@ -301,11 +319,11 @@ Guacamole.Keyboard = function(element) { // Ctrl/Alt/Shift if (keynum == 16) - modShift = 0; + modShift = false; else if (keynum == 17) - modCtrl = 0; + modCtrl = false; else if (keynum == 18) - modAlt = 0; + modAlt = false; else stopRepeat(); @@ -322,15 +340,10 @@ Guacamole.Keyboard = function(element) { }; // When focus is lost, clear modifiers. - var docOnblur = element.onblur; element.onblur = function() { - modAlt = 0; - modCtrl = 0; - modShift = 0; - if (docOnblur != null) docOnblur(); + modAlt = false; + modCtrl = false; + modShift = false; }; - guac_keyboard.onkeydown = null; - guac_keyboard.onkeyup = null; - -} +}; From 4b4f21e9ab641825abd882a75b296daea405efca Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 9 Jul 2011 09:12:06 -0700 Subject: [PATCH 050/263] More JSDoc and cleanup. --- .../src/main/resources/guacamole.js | 10 ++++ .../src/main/resources/mouse.js | 52 +++++++++++++++++++ .../src/main/resources/oskeyboard.js | 8 +++ .../src/main/resources/tunnel.js | 37 +++++++++++-- 4 files changed, 102 insertions(+), 5 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 7009e7a47..3bff5d0fe 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -19,6 +19,16 @@ // Guacamole 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 {Element} display The display element to add canvas elements to. + * @param {Guacamole.Tunnel} tunnel The tunnel to use to send and receive + * Guacamole instructions. + */ Guacamole.Client = function(display, tunnel) { var guac_client = this; diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index a8f3a8b97..cb2af79cd 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -226,14 +226,66 @@ Guacamole.Mouse = function(element) { }; +/** + * 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) { + /** + * 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; }; diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 0e6a9ccef..34c27810c 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -20,6 +20,14 @@ // Guacamole 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 allKeys = new Array(); diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index e092088cb..d28758909 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -19,6 +19,35 @@ // Guacamole 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() { + + this.connect = function(data) {}; + + this.disconnect = function() {}; + + this.sendMessage = function(message) {}; + + this.onerror = null; + 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) { var tunnel = this; @@ -44,10 +73,6 @@ Guacamole.HTTPTunnel = function(tunnelURL) { var sendingMessages = 0; var outputMessageBuffer = ""; - // Handlers - tunnel.onerror = null; - tunnel.oninstruction = null; - function sendMessage(message) { // Do not attempt to send messages if not connected @@ -267,4 +292,6 @@ Guacamole.HTTPTunnel = function(tunnelURL) { tunnel.disconnect = disconnect; tunnel.sendMessage = sendMessage; -} +}; + +Guacamole.HTTPTunnel.prototype = new Guacamole.Tunnel(); From 0452f36f04f6a8e787ce52d877a347c95d49b5f1 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 10 Jul 2011 20:49:38 -0700 Subject: [PATCH 051/263] Tunnel JSDoc. --- .../src/main/resources/tunnel.js | 65 ++++++++++++++----- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index d28758909..0f33c3e26 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -29,14 +29,47 @@ var Guacamole = Guacamole || {}; * @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 {String} message The message to send to the service on the other + * side of the tunnel. + */ this.sendMessage = function(message) {}; + /** + * 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; }; @@ -50,6 +83,9 @@ Guacamole.Tunnel = function() { */ Guacamole.HTTPTunnel = function(tunnelURL) { + /** + * Reference to this HTTP tunnel. + */ var tunnel = this; var tunnel_uuid; @@ -70,10 +106,10 @@ Guacamole.HTTPTunnel = function(tunnelURL) { // Default to polling - will be turned off automatically if not needed var pollingMode = POLLING_ENABLED; - var sendingMessages = 0; + var sendingMessages = false; var outputMessageBuffer = ""; - function sendMessage(message) { + this.sendMessage = function(message) { // Do not attempt to send messages if not connected if (currentState != STATE_CONNECTED) @@ -81,16 +117,16 @@ Guacamole.HTTPTunnel = function(tunnelURL) { // Add event to queue, restart send loop if finished. outputMessageBuffer += message; - if (sendingMessages == 0) + if (!sendingMessages) sendPendingMessages(); - } + }; function sendPendingMessages() { if (outputMessageBuffer.length > 0) { - sendingMessages = 1; + sendingMessages = true; var message_xmlhttprequest = new XMLHttpRequest(); message_xmlhttprequest.open("POST", TUNNEL_WRITE + tunnel_uuid); @@ -107,7 +143,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) { } else - sendingMessages = 0; + sendingMessages = false; } @@ -161,7 +197,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) { if (tunnel.onerror) tunnel.onerror(message); // Finish - disconnect(); + tunnel.disconnect(); return; } @@ -255,7 +291,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) { } - function connect(data) { + this.connect = function(data) { // Start tunnel and connect synchronously var connect_xmlhttprequest = new XMLHttpRequest(); @@ -281,16 +317,11 @@ Guacamole.HTTPTunnel = function(tunnelURL) { currentState = STATE_CONNECTED; handleResponse(makeRequest()); - } + }; - function disconnect() { + this.disconnect = function() { currentState = STATE_DISCONNECTED; - } - - // External API - tunnel.connect = connect; - tunnel.disconnect = disconnect; - tunnel.sendMessage = sendMessage; + }; }; From b56759139574aec9dfaf23110d03811a3eb2ea49 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 13 Jul 2011 00:17:34 -0700 Subject: [PATCH 052/263] Client now handles tunnel errors. --- guacamole-common-js/src/main/resources/guacamole.js | 5 +++++ guacamole-common-js/src/main/resources/tunnel.js | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 3bff5d0fe..e32c62dbe 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -44,6 +44,11 @@ Guacamole.Client = function(display, tunnel) { tunnel.oninstruction = doInstruction; + tunnel.onerror = function(message) { + if (guac_client.onerror) + guac_client.onerror(message); + }; + // Display must be relatively positioned for mouse to be handled properly display.style.position = "relative"; diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 0f33c3e26..278766e4a 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -169,8 +169,8 @@ Guacamole.HTTPTunnel = function(tunnelURL) { return; } - // Start next request as soon as possible - if (xmlhttprequest.readyState >= 2 && nextRequest == null) + // Start next request as soon as possible IF request was successful + if (xmlhttprequest.readyState >= 2 && nextRequest == null && xmlhttprequest.status == 200) nextRequest = makeRequest(); // Parse stream when data is received and when complete. @@ -185,8 +185,14 @@ Guacamole.HTTPTunnel = function(tunnelURL) { clearInterval(interval); } + // If canceled, stop transfer + if (xmlhttprequest.status == 0) { + tunnel.disconnect(); + return; + } + // Halt on error during request - if (xmlhttprequest.status == 0 || xmlhttprequest.status != 200) { + else if (xmlhttprequest.status != 200) { // Get error message (if any) var message = xmlhttprequest.getResponseHeader("X-Guacamole-Error-Message"); From b5a81afe877d769877af44cd69ea4424730578bf Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 13 Jul 2011 11:09:14 -0700 Subject: [PATCH 053/263] Fixed message generation logic. --- guacamole-common-js/src/main/resources/tunnel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 278766e4a..9d6671f4f 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -196,7 +196,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) { // Get error message (if any) var message = xmlhttprequest.getResponseHeader("X-Guacamole-Error-Message"); - if (message) + if (!message) message = "Internal server error"; // Call error handler From d0155cdf526a4d16c0ee6b8076a7ce60714d17eb Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 21 Jul 2011 15:16:19 -0700 Subject: [PATCH 054/263] Rect and clip instructions. --- .../src/main/resources/guacamole.js | 34 ++++++++++++ .../src/main/resources/layer.js | 53 ++++++++++++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index e32c62dbe..db7ad9b6b 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -302,6 +302,40 @@ Guacamole.Client = function(display, tunnel) { }, + "rect": function(parameters) { + + var channelMask = parseInt(parameters[0]); + var layer = getLayer(parseInt(parameters[1])); + var x = parseInt(parameters[2]); + var y = parseInt(parameters[3]); + var w = parseInt(parameters[4]); + var h = parseInt(parameters[5]); + var r = parseInt(parameters[6]); + var g = parseInt(parameters[7]); + var b = parseInt(parameters[8]); + var a = parseInt(parameters[9]); + + layer.setChannelMask(channelMask); + + layer.drawRect( + x, y, w, h, + r, g, b, a + ); + + }, + + "clip": 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.clipRect(x, y, w, h); + + }, + "cursor": function(parameters) { var x = parseInt(parameters[0]); diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 7c8c82235..64ccd0329 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -54,6 +54,7 @@ Guacamole.Layer = function(width, height) { * @private */ var displayContext = display.getContext("2d"); + displayContext.save(); /** * The queue of all pending Tasks. Tasks will be run in order, with new @@ -204,8 +205,8 @@ Guacamole.Layer = function(width, height) { // Draw all pending tasks. var task; while ((task = tasks[0]) != null && task.handler) { - task.handler(); tasks.shift(); + task.handler(); } } @@ -386,6 +387,56 @@ Guacamole.Layer = function(width, height) { }); }; + /** + * Fill the specified rectangle of image data with the specified color. + * + * @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. + * @param {Number} r The red component of the color of the rectangle. + * @param {Number} g The green component of the color of the rectangle. + * @param {Number} b The blue component of the color of the rectangle. + * @param {Number} a The alpha component of the color of the rectangle. + */ + this.drawRect = function(x, y, w, h, r, g, b, a) { + scheduleTask(function() { + if (layer.autosize != 0) fitRect(x, y, w, h); + displayContext.fillStyle = "rgba(" + + r + "," + g + "," + b + "," + a + ")"; + displayContext.fillRect(x, y, w, h); + }); + }; + + /** + * Clip all future drawing operations by the specified rectangle. + * + * @param {Number} x The X coordinate of the upper-left corner of the + * rectangle to use for the clipping region. + * @param {Number} y The Y coordinate of the upper-left corner of the + * rectangle to use for the clipping region. + * @param {Number} w The width of the rectangle to use for the clipping region. + * @param {Number} h The height of the rectangle to use for the clipping region. + */ + this.clipRect = function(x, y, w, h) { + scheduleTask(function() { + + // Clear any current clipping region + displayContext.restore(); + displayContext.save(); + + if (layer.autosize != 0) fitRect(x, y, w, h); + + // Set new clipping region + displayContext.beginPath(); + displayContext.rect(x, y, w, h); + displayContext.clip(); + + }); + }; + /** * Provides the given filtering function with a writable snapshot of * image data and the current width and height of the Layer. From 6c41eb5aadc0c75c4faa572e79cd942d6d8d209c Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 9 Aug 2011 16:08:18 -0700 Subject: [PATCH 055/263] Alpha for rgba() is from 0.0 to 1.0, not 0 to 255. --- guacamole-common-js/src/main/resources/layer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 64ccd0329..eb0ba7e95 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -405,7 +405,7 @@ Guacamole.Layer = function(width, height) { scheduleTask(function() { if (layer.autosize != 0) fitRect(x, y, w, h); displayContext.fillStyle = "rgba(" - + r + "," + g + "," + b + "," + a + ")"; + + r + "," + g + "," + b + "," + a / 255 + ")"; displayContext.fillRect(x, y, w, h); }); }; From b7a5cc701379f5b683bc96e7ae75548bb760a60a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 18 Aug 2011 18:00:45 -0700 Subject: [PATCH 056/263] Fixed layer resize(), avoid multiple handlePengingTasks() calls --- .../src/main/resources/layer.js | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index eb0ba7e95..3ef8aeba4 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -97,9 +97,36 @@ Guacamole.Layer = function(width, height) { * @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); + + } + + // 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); + width = newWidth; height = newHeight; } @@ -195,6 +222,8 @@ Guacamole.Layer = function(width, height) { } + var tasksInProgress = false; + /** * Run any Tasks which were pending but are now ready to run and are not * blocked by other Tasks. @@ -202,6 +231,11 @@ Guacamole.Layer = function(width, height) { */ function handlePendingTasks() { + if (tasksInProgress) + return; + + tasksInProgress = true; + // Draw all pending tasks. var task; while ((task = tasks[0]) != null && task.handler) { @@ -209,6 +243,8 @@ Guacamole.Layer = function(width, height) { task.handler(); } + tasksInProgress = false; + } /** @@ -475,6 +511,7 @@ Guacamole.Layer = function(width, height) { }; // Initialize canvas dimensions - resize(width, height); + display.width = width; + display.height = height; }; From 1e47ace656f23687c41b83ed74e2d93c4820094c Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 26 Aug 2011 16:44:49 -0700 Subject: [PATCH 057/263] Changed simulated mouse to simulated touchpad. Temporary lack of tap support. --- .../src/main/resources/mouse.js | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 35a68fafc..8fff3cf56 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -113,41 +113,33 @@ Guacamole.Mouse = function(element) { }; + var last_touch_x = 0; + var last_touch_y = 0; + element.ontouchend = function(e) { e.stopPropagation(); e.preventDefault(); - // Release all buttons (FIXME: for now...) - if (mouseLeftButton || mouseMiddleButton || mouseRightButton) { - mouseLeftButton = 0; - mouseMiddleButton = 0; - mouseRightButton = 0; + // TODO: Handle tap-to-click. - buttonReleasedHandler(getMouseState(0, 0)); - } - - } + }; element.ontouchstart = function(e) { e.stopPropagation(); e.preventDefault(); - if (e.touches.length == 1) - element.ontouchmove(e); + // Record initial touch location and time for single-touch movement + // and tap gestures + if (e.touches.length == 1) { - else { - - var button = e.touches[0]; - var pointer = e.touches[1]; + var starting_touch = e.touches[0]; + last_touch_x = starting_touch.pageX; + last_touch_y = starting_touch.pageY; - if (pointer.pageX < button.pageX) - mouseLeftButton = 1; - else - mouseRightButton = 1; + // TODO: Record time (for sake of tap-to-click) - buttonPressedHandler(getMouseState(0, 0)); } }; @@ -157,8 +149,29 @@ Guacamole.Mouse = function(element) { e.stopPropagation(); e.preventDefault(); - var touch = e.touches[0]; - moveMouse(touch.pageX, touch.pageY); + // Handle single-touch movement gesture (touchpad mouse move) + if (e.touches.length == 1) { + + // Get change in touch location + var touch = e.touches[0]; + var delta_x = touch.pageX - last_touch_x; + var delta_y = touch.pageY - last_touch_y; + + // Update mouse location + guac_mouse.currentState.x += delta_x; + guac_mouse.currentState.y += delta_y; + + // FIXME: Prevent mouse from leaving screen + + // Fire movement event, if defined + if (guac_mouse.onmousemove) + guac_mouse.onmousemove(guac_mouse.currentState); + + // Update touch location + last_touch_x = touch.pageX; + last_touch_y = touch.pageY; + + } }; From 98a5f06120e4ec388c19d4bb2a5ceab04cce1db7 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 27 Aug 2011 12:13:10 -0700 Subject: [PATCH 058/263] Tap support, ignore mouse events while touch events are in progress. --- .../src/main/resources/mouse.js | 79 +++++++++++++++---- 1 file changed, 62 insertions(+), 17 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 8fff3cf56..9614c9964 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -107,6 +107,9 @@ Guacamole.Mouse = function(element) { element.onmousemove = function(e) { + // Don't handle if we aren't supposed to + if (gesture_in_progress) return; + e.stopPropagation(); moveMouse(e.pageX, e.pageY); @@ -115,30 +118,60 @@ Guacamole.Mouse = function(element) { var last_touch_x = 0; var last_touch_y = 0; + var last_touch_time = 0; + var pixels_moved = 0; + + var gesture_in_progress = false; element.ontouchend = function(e) { - e.stopPropagation(); - e.preventDefault(); + // If we're handling a gesture + if (gesture_in_progress) { + + e.stopPropagation(); + e.preventDefault(); + + var time = new Date().getTime(); - // TODO: Handle tap-to-click. + // If single tap detected (based on time and distance) + if (time - last_touch_time <= 250 && pixels_moved < 10) { + + // Fire left button down event + guac_mouse.currentState.left = true; + if (guac_mouse.onmousedown) + guac_mouse.onmousedown(guac_mouse.currentState); + + // Fire left button up event + guac_mouse.currentState.left = false; + if (guac_mouse.onmouseup) + guac_mouse.onmouseup(guac_mouse.currentState); + + } + + // Allow mouse events now that touching is over + gesture_in_progress = false; + + } }; element.ontouchstart = function(e) { - e.stopPropagation(); - e.preventDefault(); - // Record initial touch location and time for single-touch movement // and tap gestures if (e.touches.length == 1) { + e.stopPropagation(); + e.preventDefault(); + + // Stop mouse events while touching + gesture_in_progress = true; + var starting_touch = e.touches[0]; last_touch_x = starting_touch.pageX; last_touch_y = starting_touch.pageY; - - // TODO: Record time (for sake of tap-to-click) + last_touch_time = new Date().getTime(); + pixels_moved = 0; } @@ -146,17 +179,20 @@ Guacamole.Mouse = function(element) { element.ontouchmove = function(e) { - e.stopPropagation(); - e.preventDefault(); - // Handle single-touch movement gesture (touchpad mouse move) if (e.touches.length == 1) { + e.stopPropagation(); + e.preventDefault(); + // Get change in touch location var touch = e.touches[0]; var delta_x = touch.pageX - last_touch_x; var delta_y = touch.pageY - last_touch_y; + // Track pixels moved + pixels_moved += Math.abs(delta_x) + Math.abs(delta_y); + // Update mouse location guac_mouse.currentState.x += delta_x; guac_mouse.currentState.y += delta_y; @@ -178,6 +214,9 @@ Guacamole.Mouse = function(element) { element.onmousedown = function(e) { + // Don't handle if we aren't supposed to + if (gesture_in_progress) return; + e.stopPropagation(); switch (e.button) { @@ -200,6 +239,9 @@ Guacamole.Mouse = function(element) { element.onmouseup = function(e) { + // Don't handle if we aren't supposed to + if (gesture_in_progress) return; + e.stopPropagation(); switch (e.button) { @@ -221,6 +263,9 @@ Guacamole.Mouse = function(element) { element.onmouseout = function(e) { + // Don't handle if we aren't supposed to + if (gesture_in_progress) return; + e.stopPropagation(); // Release all buttons @@ -244,7 +289,10 @@ Guacamole.Mouse = function(element) { }; // Scroll wheel support - function handleScroll(e) { + element.onmousewheel = function(e) { + + // Don't handle if we aren't supposed to + if (gesture_in_progress) return; var delta = 0; if (e.detail) @@ -282,14 +330,11 @@ Guacamole.Mouse = function(element) { e.preventDefault(); e.returnValue = false; - } - element.addEventListener('DOMMouseScroll', handleScroll, false); - - element.onmousewheel = function(e) { - handleScroll(e); }; + element.addEventListener('DOMMouseScroll', element.onmousewheel, false); + }; /** From 50ff738cdaa297cafd3004d9126fee6784002bb0 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 29 Aug 2011 14:31:23 -0700 Subject: [PATCH 059/263] Drag support. --- .../src/main/resources/mouse.js | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 9614c9964..211759d77 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -122,6 +122,7 @@ Guacamole.Mouse = function(element) { var pixels_moved = 0; var gesture_in_progress = false; + var click_release_timeout = null; element.ontouchend = function(e) { @@ -133,6 +134,22 @@ Guacamole.Mouse = function(element) { var time = new Date().getTime(); + // If mouse already down, release anad clear timeout + if (guac_mouse.currentState.left) { + + // Fire left button up event + guac_mouse.currentState.left = false; + if (guac_mouse.onmouseup) + guac_mouse.onmouseup(guac_mouse.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 <= 250 && pixels_moved < 10) { @@ -141,16 +158,22 @@ Guacamole.Mouse = function(element) { if (guac_mouse.onmousedown) guac_mouse.onmousedown(guac_mouse.currentState); - // Fire left button up event - guac_mouse.currentState.left = false; - if (guac_mouse.onmouseup) - guac_mouse.onmouseup(guac_mouse.currentState); + // Delay mouse up - mouse up should be canceled if + // touchstart within timeout. + click_release_timeout = window.setTimeout(function() { + + // Fire left button up event + guac_mouse.currentState.left = false; + if (guac_mouse.onmouseup) + guac_mouse.onmouseup(guac_mouse.currentState); + + // Allow mouse events now that touching is over + gesture_in_progress = false; + + }, 250); } - // Allow mouse events now that touching is over - gesture_in_progress = false; - } }; @@ -167,12 +190,21 @@ Guacamole.Mouse = function(element) { // Stop mouse events while touching gesture_in_progress = true; + // Clear timeout, if set + if (click_release_timeout) { + window.clearTimeout(click_release_timeout); + click_release_timeout = null; + } + + // Record touch location and time var starting_touch = e.touches[0]; last_touch_x = starting_touch.pageX; last_touch_y = starting_touch.pageY; last_touch_time = new Date().getTime(); pixels_moved = 0; + // TODO: Handle different buttons + } }; From b6246041dd25002cd9cc99c297cc3bd1762f1899 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 1 Sep 2011 15:39:02 -0700 Subject: [PATCH 060/263] Working initial implementation of websocket tunnel. --- .../src/main/resources/tunnel.js | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 9d6671f4f..2e49d3544 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -332,3 +332,85 @@ Guacamole.HTTPTunnel = function(tunnelURL) { }; 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. + */ + var tunnel = this; + + /** + * The WebSocket used by this tunnel. + */ + var socket = null; + + var TUNNEL_CONNECT = tunnelURL + "?connect"; + + var STATE_IDLE = 0; + var STATE_CONNECTED = 1; + var STATE_DISCONNECTED = 2; + + var currentState = STATE_IDLE; + + this.sendMessage = function(message) { + + // Do not attempt to send messages if not connected + if (currentState != STATE_CONNECTED) + return; + + socket.send(message); + + }; + + this.connect = function(data) { + + // Connect socket + socket = new WebSocket(TUNNEL_CONNECT + "&" + data, "guacamole"); + + socket.onopen = function(event) { + currentState = STATE_CONNECTED; + }; + + socket.onmessage = function(event) { + + var message = event.data; + + var instructions = message.split(";"); + for (var i=0; i Date: Fri, 2 Sep 2011 13:40:58 -0700 Subject: [PATCH 061/263] Automatically handle relative URLs. --- .../src/main/resources/tunnel.js | 44 ++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 2e49d3544..58ee62045 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -353,13 +353,53 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { */ var socket = null; - var TUNNEL_CONNECT = tunnelURL + "?connect"; + /** + * The WebSocket protocol corresponding to the protocol used for the current + * location. + */ + var ws_protocol = { + "http:": "ws:", + "https:": "wss:" + }; 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(message) { @@ -374,7 +414,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { this.connect = function(data) { // Connect socket - socket = new WebSocket(TUNNEL_CONNECT + "&" + data, "guacamole"); + socket = new WebSocket(tunnelURL + "?" + data, "guacamole"); socket.onopen = function(event) { currentState = STATE_CONNECTED; From 5e92911073c4c6805b719bfceeb2b3f47aa0627b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 10 Sep 2011 19:09:17 -0700 Subject: [PATCH 062/263] Support for new instruction format. --- .../src/main/resources/guacamole.js | 38 +----- .../src/main/resources/tunnel.js | 110 ++++++++++++------ 2 files changed, 78 insertions(+), 70 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index db7ad9b6b..0e5a5af1c 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -227,16 +227,16 @@ Guacamole.Client = function(display, tunnel) { var instructionHandlers = { "error": function(parameters) { - if (guac_client.onerror) guac_client.onerror(unescapeGuacamoleString(parameters[0])); + if (guac_client.onerror) guac_client.onerror(parameters[0]); disconnect(); }, "name": function(parameters) { - if (guac_client.onname) guac_client.onname(unescapeGuacamoleString(parameters[0])); + if (guac_client.onname) guac_client.onname(parameters[0]); }, "clipboard": function(parameters) { - if (guac_client.onclipboard) guac_client.onclipboard(unescapeGuacamoleString(parameters[0])); + if (guac_client.onclipboard) guac_client.onclipboard(parameters[0]); }, "size": function(parameters) { @@ -454,35 +454,6 @@ Guacamole.Client = function(display, tunnel) { } - function unescapeGuacamoleString(str) { - - var unescapedString = ""; - - for (var i=0; i= startIndex) { - var instruction = current.substr(instructionStart, - instructionEnd - instructionStart); + // We now have enough data for the element. Parse. + var element = current.substring(startIndex, elementEnd); + var terminator = current.substring(elementEnd, elementEnd+1); - instructionStart = startIndex; + // Add element to array + elements.push(element); - var opcodeEnd = instruction.indexOf(":"); + // 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; - var opcode; - var parameters; - if (opcodeEnd == -1) { - opcode = instruction; - parameters = new Array(); } + + // 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 { - opcode = instruction.substr(0, opcodeEnd); - parameters = instruction.substr(opcodeEnd+1).split(","); - } - - // If we're done parsing, handle the next response. - if (opcode.length == 0) { - - delete xmlhttprequest; - if (nextRequest) - handleResponse(nextRequest); - + startIndex = current.length; break; } - // Call instruction handler. - if (tunnel.oninstruction != null) - tunnel.oninstruction(opcode, parameters); - } - - // Start search at end of string. - startIndex = current.length; - - delete instruction; - delete parameters; + } // end parse loop } From f29a101537501789e01405172b366297319b9a8a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 11 Sep 2011 16:10:38 -0700 Subject: [PATCH 063/263] Partial implementation of new format instructions in output. --- .../src/main/resources/guacamole.js | 34 ++++--------------- .../src/main/resources/tunnel.js | 29 +++++++++++++--- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 0e5a5af1c..ec925f415 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -102,7 +102,7 @@ Guacamole.Client = function(display, tunnel) { if (!isConnected()) return; - tunnel.sendMessage("key:" + keysym + "," + pressed + ";"); + tunnel.sendMessage("key", keysym, pressed); }; guac_client.sendMouseState = function(mouseState) { @@ -128,7 +128,7 @@ Guacamole.Client = function(display, tunnel) { if (mouseState.down) buttonMask |= 16; // Send message - tunnel.sendMessage("mouse:" + mouseState.x + "," + mouseState.y + "," + buttonMask + ";"); + tunnel.sendMessage("mouse", mouseState.x, mouseState.y, buttonMask); }; guac_client.setClipboard = function(data) { @@ -137,7 +137,7 @@ Guacamole.Client = function(display, tunnel) { if (!isConnected()) return; - tunnel.sendMessage("clipboard:" + escapeGuacamoleString(data) + ";"); + tunnel.sendMessage("clipboard", data); }; // Handlers @@ -384,7 +384,7 @@ Guacamole.Client = function(display, tunnel) { // Send sync response when layers are finished if (layersToSync == 0) - tunnel.sendMessage("sync:" + timestamp + ";"); + tunnel.sendMessage("sync", timestamp); } @@ -402,7 +402,7 @@ Guacamole.Client = function(display, tunnel) { // If all layers are ready, then we didn't install any hooks. // Send sync message now, if (layersToSync == 0) - tunnel.sendMessage("sync:" + timestamp + ";"); + tunnel.sendMessage("sync", timestamp); } @@ -425,35 +425,13 @@ Guacamole.Client = function(display, tunnel) { && currentState != STATE_DISCONNECTING) { setState(STATE_DISCONNECTING); - tunnel.sendMessage("disconnect;"); + tunnel.sendMessage("disconnect"); tunnel.disconnect(); setState(STATE_DISCONNECTED); } } - function escapeGuacamoleString(str) { - - var escapedString = ""; - - for (var i=0; i Date: Fri, 16 Sep 2011 06:16:41 +0000 Subject: [PATCH 064/263] Updated comments --- guacamole-common-js/src/main/resources/tunnel.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index ae7a85c69..b4e52f069 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -119,6 +119,13 @@ Guacamole.HTTPTunnel = function(tunnelURL) { if (arguments.length == 0) return; + /** + * Converts the given value to a length/string pair for use as an + * element in a Guacamole instruction. + * + * @param value The value to convert. + * @return {String} The converted value. + */ function getElement(value) { var string = new String(value); return string.length + "." + string; @@ -134,8 +141,10 @@ Guacamole.HTTPTunnel = function(tunnelURL) { // Final terminator message += ";"; - // Add message to buffer, restart send loop if finished. + // Add message to buffer outputMessageBuffer += message; + + // Send if not currently sending if (!sendingMessages) sendPendingMessages(); From 87387c5cb8a0ea6eab19ed8ce5e7614dcfc48d1d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 11 Oct 2011 15:31:01 -0700 Subject: [PATCH 065/263] Code cleanup. --- .../src/main/resources/guacamole.js | 18 ++++++++---------- .../src/main/resources/oskeyboard.js | 3 ++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index ec925f415..d348d64e8 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -42,8 +42,6 @@ Guacamole.Client = function(display, tunnel) { var currentState = STATE_IDLE; - tunnel.oninstruction = doInstruction; - tunnel.onerror = function(message) { if (guac_client.onerror) guac_client.onerror(message); @@ -228,7 +226,7 @@ Guacamole.Client = function(display, tunnel) { "error": function(parameters) { if (guac_client.onerror) guac_client.onerror(parameters[0]); - disconnect(); + guac_client.disconnect(); }, "name": function(parameters) { @@ -409,16 +407,16 @@ Guacamole.Client = function(display, tunnel) { }; - function doInstruction(opcode, parameters) { + tunnel.oninstruction = function(opcode, parameters) { var handler = instructionHandlers[opcode]; if (handler) handler(parameters); - } + }; - function disconnect() { + guac_client.disconnect = function() { // Only attempt disconnection not disconnected. if (currentState != STATE_DISCONNECTED @@ -430,9 +428,8 @@ Guacamole.Client = function(display, tunnel) { setState(STATE_DISCONNECTED); } - } - - guac_client.disconnect = disconnect; + }; + guac_client.connect = function(data) { setState(STATE_CONNECTING); @@ -448,4 +445,5 @@ Guacamole.Client = function(display, tunnel) { setState(STATE_WAITING); }; -} +}; + diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 34c27810c..3783216a6 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -492,5 +492,6 @@ Guacamole.OnScreenKeyboard = function(url) { }; return keyboard; -} + +}; From b3ebfeb2cf670e5a9f9c9d54cd55f870de8a3107 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 4 Nov 2011 15:20:15 -0700 Subject: [PATCH 066/263] Bumped versions to 0.5.0. --- guacamole-common-js/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/pom.xml b/guacamole-common-js/pom.xml index 0efc46022..9fafbfabc 100644 --- a/guacamole-common-js/pom.xml +++ b/guacamole-common-js/pom.xml @@ -5,7 +5,7 @@ net.sourceforge.guacamole guacamole-common-js pom - 0.4.0 + 0.5.0 guacamole-common-js http://guacamole.sourceforge.net/ From 935088d9d4f470a4f755387ca8878fc246b4d0cd Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 4 Dec 2011 17:15:18 -0800 Subject: [PATCH 067/263] Relicensed as Mozilla/LGPL/GPL. --- guacamole-common-js/COPYING | 661 ------------------ guacamole-common-js/LICENSE | 470 +++++++++++++ .../src/main/resources/guacamole.js | 45 +- .../src/main/resources/keyboard.js | 46 +- .../src/main/resources/layer.js | 46 +- .../src/main/resources/mouse.js | 46 +- .../src/main/resources/oskeyboard.js | 46 +- .../src/main/resources/tunnel.js | 45 +- 8 files changed, 662 insertions(+), 743 deletions(-) delete mode 100644 guacamole-common-js/COPYING create mode 100644 guacamole-common-js/LICENSE diff --git a/guacamole-common-js/COPYING b/guacamole-common-js/COPYING deleted file mode 100644 index dba13ed2d..000000000 --- a/guacamole-common-js/COPYING +++ /dev/null @@ -1,661 +0,0 @@ - GNU AFFERO GENERAL PUBLIC LICENSE - Version 3, 19 November 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - 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. - - 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. - - 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. - - 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. - - 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. - - 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. - - 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. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU Affero General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "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. - - 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. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - 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. - - 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. - - 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. - - 1. Source Code. - - 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. - - 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. - - 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. - - 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. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - 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. - - 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. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - 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. - - 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. - - 4. Conveying Verbatim Copies. - - 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. - - 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. - - 5. Conveying Modified Source Versions. - - 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: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - 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". - - 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. - - 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. - - 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. - - 6. Conveying Non-Source Forms. - - 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: - - 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. - - 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. - - 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. - - 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. - - 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. - - 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. - - 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. - - "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. - - 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). - - 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. - - 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. - - 7. Additional Terms. - - "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. - - 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. - - 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: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - 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 - - 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 - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - 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. - - 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. - - 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. - - 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. - - 8. Termination. - - 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). - - 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. - - 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. - - 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. - - 9. Acceptance Not Required for Having Copies. - - 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. - - 10. Automatic Licensing of Downstream Recipients. - - 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. - - 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. - - 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. - - 11. Patents. - - 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". - - 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. - - 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. - - 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. - - 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. - - 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. - - 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. - - 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. - - 12. No Surrender of Others' Freedom. - - 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. - - 13. Remote Network Interaction; Use with the GNU General Public License. - - 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. - - 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. - - 14. Revised Versions of this License. - - 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. - - 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. - - 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. - - 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. - - 15. Disclaimer of Warranty. - - 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. - - 16. Limitation of Liability. - - 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. - - 17. Interpretation of Sections 15 and 16. - - 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. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - 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. - - 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. - - - Copyright (C) - - 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 . - -Also add information on how to contact you by electronic and paper mail. - - 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. - - 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 -. diff --git a/guacamole-common-js/LICENSE b/guacamole-common-js/LICENSE new file mode 100644 index 000000000..7714141d1 --- /dev/null +++ b/guacamole-common-js/LICENSE @@ -0,0 +1,470 @@ + MOZILLA PUBLIC LICENSE + Version 1.1 + + --------------- + +1. Definitions. + + 1.0.1. "Commercial Use" means distribution or otherwise making the + Covered Code available to a third party. + + 1.1. "Contributor" means each entity that creates or contributes to + the creation of Modifications. + + 1.2. "Contributor Version" means the combination of the Original + Code, prior Modifications used by a Contributor, and the Modifications + made by that particular Contributor. + + 1.3. "Covered Code" means the Original Code or Modifications or the + combination of the Original Code and Modifications, in each case + including portions thereof. + + 1.4. "Electronic Distribution Mechanism" means a mechanism generally + accepted in the software development community for the electronic + transfer of data. + + 1.5. "Executable" means Covered Code in any form other than Source + Code. + + 1.6. "Initial Developer" means the individual or entity identified + as the Initial Developer in the Source Code notice required by Exhibit + A. + + 1.7. "Larger Work" means a work which combines Covered Code or + portions thereof with code not governed by the terms of this License. + + 1.8. "License" means this document. + + 1.8.1. "Licensable" means having the right to grant, to the maximum + extent possible, whether at the time of the initial grant or + subsequently acquired, any and all of the rights conveyed herein. + + 1.9. "Modifications" means any addition to or deletion from the + substance or structure of either the Original Code or any previous + Modifications. When Covered Code is released as a series of files, a + Modification is: + A. Any addition to or deletion from the contents of a file + containing Original Code or previous Modifications. + + B. Any new file that contains any part of the Original Code or + previous Modifications. + + 1.10. "Original Code" means Source Code of computer software code + which is described in the Source Code notice required by Exhibit A as + Original Code, and which, at the time of its release under this + License is not already Covered Code governed by this License. + + 1.10.1. "Patent Claims" means any patent claim(s), now owned or + hereafter acquired, including without limitation, method, process, + and apparatus claims, in any patent Licensable by grantor. + + 1.11. "Source Code" means the preferred form of the Covered Code for + making modifications to it, including all modules it contains, plus + any associated interface definition files, scripts used to control + compilation and installation of an Executable, or source code + differential comparisons against either the Original Code or another + well known, available Covered Code of the Contributor's choice. The + Source Code can be in a compressed or archival form, provided the + appropriate decompression or de-archiving software is widely available + for no charge. + + 1.12. "You" (or "Your") means an individual or a legal entity + exercising rights under, and complying with all of the terms of, this + License or a future version of this License issued under Section 6.1. + For legal entities, "You" includes any entity which controls, is + controlled by, or is under common control with You. For purposes of + this definition, "control" means (a) the power, direct or indirect, + to cause the direction or management of such entity, whether by + contract or otherwise, or (b) ownership of more than fifty percent + (50%) of the outstanding shares or beneficial ownership of such + entity. + +2. Source Code License. + + 2.1. The Initial Developer Grant. + The Initial Developer hereby grants You a world-wide, royalty-free, + non-exclusive license, subject to third party intellectual property + claims: + (a) under intellectual property rights (other than patent or + trademark) Licensable by Initial Developer to use, reproduce, + modify, display, perform, sublicense and distribute the Original + Code (or portions thereof) with or without Modifications, and/or + as part of a Larger Work; and + + (b) under Patents Claims infringed by the making, using or + selling of Original Code, to make, have made, use, practice, + sell, and offer for sale, and/or otherwise dispose of the + Original Code (or portions thereof). + + (c) the licenses granted in this Section 2.1(a) and (b) are + effective on the date Initial Developer first distributes + Original Code under the terms of this License. + + (d) Notwithstanding Section 2.1(b) above, no patent license is + granted: 1) for code that You delete from the Original Code; 2) + separate from the Original Code; or 3) for infringements caused + by: i) the modification of the Original Code or ii) the + combination of the Original Code with other software or devices. + + 2.2. Contributor Grant. + Subject to third party intellectual property claims, each Contributor + hereby grants You a world-wide, royalty-free, non-exclusive license + + (a) under intellectual property rights (other than patent or + trademark) Licensable by Contributor, to use, reproduce, modify, + display, perform, sublicense and distribute the Modifications + created by such Contributor (or portions thereof) either on an + unmodified basis, with other Modifications, as Covered Code + and/or as part of a Larger Work; and + + (b) under Patent Claims infringed by the making, using, or + selling of Modifications made by that Contributor either alone + and/or in combination with its Contributor Version (or portions + of such combination), to make, use, sell, offer for sale, have + made, and/or otherwise dispose of: 1) Modifications made by that + Contributor (or portions thereof); and 2) the combination of + Modifications made by that Contributor with its Contributor + Version (or portions of such combination). + + (c) the licenses granted in Sections 2.2(a) and 2.2(b) are + effective on the date Contributor first makes Commercial Use of + the Covered Code. + + (d) Notwithstanding Section 2.2(b) above, no patent license is + granted: 1) for any code that Contributor has deleted from the + Contributor Version; 2) separate from the Contributor Version; + 3) for infringements caused by: i) third party modifications of + Contributor Version or ii) the combination of Modifications made + by that Contributor with other software (except as part of the + Contributor Version) or other devices; or 4) under Patent Claims + infringed by Covered Code in the absence of Modifications made by + that Contributor. + +3. Distribution Obligations. + + 3.1. Application of License. + The Modifications which You create or to which You contribute are + governed by the terms of this License, including without limitation + Section 2.2. The Source Code version of Covered Code may be + distributed only under the terms of this License or a future version + of this License released under Section 6.1, and You must include a + copy of this License with every copy of the Source Code You + distribute. You may not offer or impose any terms on any Source Code + version that alters or restricts the applicable version of this + License or the recipients' rights hereunder. However, You may include + an additional document offering the additional rights described in + Section 3.5. + + 3.2. Availability of Source Code. + Any Modification which You create or to which You contribute must be + made available in Source Code form under the terms of this License + either on the same media as an Executable version or via an accepted + Electronic Distribution Mechanism to anyone to whom you made an + Executable version available; and if made available via Electronic + Distribution Mechanism, must remain available for at least twelve (12) + months after the date it initially became available, or at least six + (6) months after a subsequent version of that particular Modification + has been made available to such recipients. You are responsible for + ensuring that the Source Code version remains available even if the + Electronic Distribution Mechanism is maintained by a third party. + + 3.3. Description of Modifications. + You must cause all Covered Code to which You contribute to contain a + file documenting the changes You made to create that Covered Code and + the date of any change. You must include a prominent statement that + the Modification is derived, directly or indirectly, from Original + Code provided by the Initial Developer and including the name of the + Initial Developer in (a) the Source Code, and (b) in any notice in an + Executable version or related documentation in which You describe the + origin or ownership of the Covered Code. + + 3.4. Intellectual Property Matters + (a) Third Party Claims. + If Contributor has knowledge that a license under a third party's + intellectual property rights is required to exercise the rights + granted by such Contributor under Sections 2.1 or 2.2, + Contributor must include a text file with the Source Code + distribution titled "LEGAL" which describes the claim and the + party making the claim in sufficient detail that a recipient will + know whom to contact. If Contributor obtains such knowledge after + the Modification is made available as described in Section 3.2, + Contributor shall promptly modify the LEGAL file in all copies + Contributor makes available thereafter and shall take other steps + (such as notifying appropriate mailing lists or newsgroups) + reasonably calculated to inform those who received the Covered + Code that new knowledge has been obtained. + + (b) Contributor APIs. + If Contributor's Modifications include an application programming + interface and Contributor has knowledge of patent licenses which + are reasonably necessary to implement that API, Contributor must + also include this information in the LEGAL file. + + (c) Representations. + Contributor represents that, except as disclosed pursuant to + Section 3.4(a) above, Contributor believes that Contributor's + Modifications are Contributor's original creation(s) and/or + Contributor has sufficient rights to grant the rights conveyed by + this License. + + 3.5. Required Notices. + You must duplicate the notice in Exhibit A in each file of the Source + Code. If it is not possible to put such notice in a particular Source + Code file due to its structure, then You must include such notice in a + location (such as a relevant directory) where a user would be likely + to look for such a notice. If You created one or more Modification(s) + You may add your name as a Contributor to the notice described in + Exhibit A. You must also duplicate this License in any documentation + for the Source Code where You describe recipients' rights or ownership + rights relating to Covered Code. You may choose to offer, and to + charge a fee for, warranty, support, indemnity or liability + obligations to one or more recipients of Covered Code. However, You + may do so only on Your own behalf, and not on behalf of the Initial + Developer or any Contributor. You must make it absolutely clear than + any such warranty, support, indemnity or liability obligation is + offered by You alone, and You hereby agree to indemnify the Initial + Developer and every Contributor for any liability incurred by the + Initial Developer or such Contributor as a result of warranty, + support, indemnity or liability terms You offer. + + 3.6. Distribution of Executable Versions. + You may distribute Covered Code in Executable form only if the + requirements of Section 3.1-3.5 have been met for that Covered Code, + and if You include a notice stating that the Source Code version of + the Covered Code is available under the terms of this License, + including a description of how and where You have fulfilled the + obligations of Section 3.2. The notice must be conspicuously included + in any notice in an Executable version, related documentation or + collateral in which You describe recipients' rights relating to the + Covered Code. You may distribute the Executable version of Covered + Code or ownership rights under a license of Your choice, which may + contain terms different from this License, provided that You are in + compliance with the terms of this License and that the license for the + Executable version does not attempt to limit or alter the recipient's + rights in the Source Code version from the rights set forth in this + License. If You distribute the Executable version under a different + license You must make it absolutely clear that any terms which differ + from this License are offered by You alone, not by the Initial + Developer or any Contributor. You hereby agree to indemnify the + Initial Developer and every Contributor for any liability incurred by + the Initial Developer or such Contributor as a result of any such + terms You offer. + + 3.7. Larger Works. + You may create a Larger Work by combining Covered Code with other code + not governed by the terms of this License and distribute the Larger + Work as a single product. In such a case, You must make sure the + requirements of this License are fulfilled for the Covered Code. + +4. Inability to Comply Due to Statute or Regulation. + + If it is impossible for You to comply with any of the terms of this + License with respect to some or all of the Covered Code due to + statute, judicial order, or regulation then You must: (a) comply with + the terms of this License to the maximum extent possible; and (b) + describe the limitations and the code they affect. Such description + must be included in the LEGAL file described in Section 3.4 and must + be included with all distributions of the Source Code. Except to the + extent prohibited by statute or regulation, such description must be + sufficiently detailed for a recipient of ordinary skill to be able to + understand it. + +5. Application of this License. + + This License applies to code to which the Initial Developer has + attached the notice in Exhibit A and to related Covered Code. + +6. Versions of the License. + + 6.1. New Versions. + Netscape Communications Corporation ("Netscape") may publish revised + and/or new versions of the License from time to time. Each version + will be given a distinguishing version number. + + 6.2. Effect of New Versions. + Once Covered Code has been published under a particular version of the + License, You may always continue to use it under the terms of that + version. You may also choose to use such Covered Code under the terms + of any subsequent version of the License published by Netscape. No one + other than Netscape has the right to modify the terms applicable to + Covered Code created under this License. + + 6.3. Derivative Works. + If You create or use a modified version of this License (which you may + only do in order to apply it to code which is not already Covered Code + governed by this License), You must (a) rename Your license so that + the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape", + "MPL", "NPL" or any confusingly similar phrase do not appear in your + license (except to note that your license differs from this License) + and (b) otherwise make it clear that Your version of the license + contains terms which differ from the Mozilla Public License and + Netscape Public License. (Filling in the name of the Initial + Developer, Original Code or Contributor in the notice described in + Exhibit A shall not of themselves be deemed to be modifications of + this License.) + +7. DISCLAIMER OF WARRANTY. + + COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF + DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. + THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE + IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, + YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE + COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER + OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF + ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. + +8. TERMINATION. + + 8.1. This License and the rights granted hereunder will terminate + automatically if You fail to comply with terms herein and fail to cure + such breach within 30 days of becoming aware of the breach. All + sublicenses to the Covered Code which are properly granted shall + survive any termination of this License. Provisions which, by their + nature, must remain in effect beyond the termination of this License + shall survive. + + 8.2. If You initiate litigation by asserting a patent infringement + claim (excluding declatory judgment actions) against Initial Developer + or a Contributor (the Initial Developer or Contributor against whom + You file such action is referred to as "Participant") alleging that: + + (a) such Participant's Contributor Version directly or indirectly + infringes any patent, then any and all rights granted by such + Participant to You under Sections 2.1 and/or 2.2 of this License + shall, upon 60 days notice from Participant terminate prospectively, + unless if within 60 days after receipt of notice You either: (i) + agree in writing to pay Participant a mutually agreeable reasonable + royalty for Your past and future use of Modifications made by such + Participant, or (ii) withdraw Your litigation claim with respect to + the Contributor Version against such Participant. If within 60 days + of notice, a reasonable royalty and payment arrangement are not + mutually agreed upon in writing by the parties or the litigation claim + is not withdrawn, the rights granted by Participant to You under + Sections 2.1 and/or 2.2 automatically terminate at the expiration of + the 60 day notice period specified above. + + (b) any software, hardware, or device, other than such Participant's + Contributor Version, directly or indirectly infringes any patent, then + any rights granted to You by such Participant under Sections 2.1(b) + and 2.2(b) are revoked effective as of the date You first made, used, + sold, distributed, or had made, Modifications made by that + Participant. + + 8.3. If You assert a patent infringement claim against Participant + alleging that such Participant's Contributor Version directly or + indirectly infringes any patent where such claim is resolved (such as + by license or settlement) prior to the initiation of patent + infringement litigation, then the reasonable value of the licenses + granted by such Participant under Sections 2.1 or 2.2 shall be taken + into account in determining the amount or value of any payment or + license. + + 8.4. In the event of termination under Sections 8.1 or 8.2 above, + all end user license agreements (excluding distributors and resellers) + which have been validly granted by You or any distributor hereunder + prior to termination shall survive termination. + +9. LIMITATION OF LIABILITY. + + UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT + (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL + DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE, + OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR + ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY + CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, + WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER + COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN + INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF + LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY + RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW + PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE + EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO + THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. + +10. U.S. GOVERNMENT END USERS. + + The Covered Code is a "commercial item," as that term is defined in + 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer + software" and "commercial computer software documentation," as such + terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 + C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), + all U.S. Government End Users acquire Covered Code with only those + rights set forth herein. + +11. MISCELLANEOUS. + + This License represents the complete agreement concerning subject + matter hereof. If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. This License shall be governed by + California law provisions (except to the extent applicable law, if + any, provides otherwise), excluding its conflict-of-law provisions. + With respect to disputes in which at least one party is a citizen of, + or an entity chartered or registered to do business in the United + States of America, any litigation relating to this License shall be + subject to the jurisdiction of the Federal Courts of the Northern + District of California, with venue lying in Santa Clara County, + California, with the losing party responsible for costs, including + without limitation, court costs and reasonable attorneys' fees and + expenses. The application of the United Nations Convention on + Contracts for the International Sale of Goods is expressly excluded. + Any law or regulation which provides that the language of a contract + shall be construed against the drafter shall not apply to this + License. + +12. RESPONSIBILITY FOR CLAIMS. + + As between Initial Developer and the Contributors, each party is + responsible for claims and damages arising, directly or indirectly, + out of its utilization of rights under this License and You agree to + work with Initial Developer and Contributors to distribute such + responsibility on an equitable basis. Nothing herein is intended or + shall be deemed to constitute any admission of liability. + +13. MULTIPLE-LICENSED CODE. + + Initial Developer may designate portions of the Covered Code as + "Multiple-Licensed". "Multiple-Licensed" means that the Initial + Developer permits you to utilize portions of the Covered Code under + Your choice of the NPL or the alternative licenses, if any, specified + by the Initial Developer in the file described in Exhibit A. + +EXHIBIT A -Mozilla Public License. + + ``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 ______________________________________. + + The Initial Developer of the Original Code is ________________________. + Portions created by ______________________ are Copyright (C) ______ + _______________________. All Rights Reserved. + + Contributor(s): ______________________________________. + + Alternatively, the contents of this file may be used under the terms + of the _____ license (the "[___] License"), in which case the + provisions of [______] License are applicable instead of those + above. If you wish to allow use of your version of this file only + under the terms of the [____] License and not to allow others to use + your version of this file under the MPL, indicate your decision by + deleting the provisions above and replace them with the notice and + other provisions required by the [___] License. If you do not delete + the provisions above, a recipient may use your version of this file + under either the MPL or the [___] License." + + [NOTE: The text of this Exhibit A may differ slightly from the text of + the notices in the Source Code files of the Original Code. You should + use the text of this Exhibit A rather than the text found in the + Original Code Source Code for Your Modifications.] + diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index d348d64e8..b7ca9ab3c 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -1,20 +1,39 @@ -/* - * Guacamole - Clientless Remote Desktop - * Copyright (C) 2010 Michael Jumper +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * - * 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. + * 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/ * - * 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. + * 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. * - * You should have received a copy of the GNU Affero General Public 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 ***** */ // Guacamole namespace var Guacamole = Guacamole || {}; diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 3dfc31a16..4c642c94b 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -1,21 +1,39 @@ -/* - * Guacamole - Clientless Remote Desktop - * Copyright (C) 2010 Michael Jumper +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * - * 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. + * 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/ * - * 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. + * 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. * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ + * 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 ***** */ // Guacamole namespace var Guacamole = Guacamole || {}; diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 3ef8aeba4..bd6af677d 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -1,21 +1,39 @@ -/* - * Guacamole - Clientless Remote Desktop - * Copyright (C) 2010 Michael Jumper +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * - * 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. + * 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/ * - * 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. + * 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. * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ + * 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 ***** */ // Guacamole namespace var Guacamole = Guacamole || {}; diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 211759d77..6f1edf0c5 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -1,21 +1,39 @@ -/* - * Guacamole - Clientless Remote Desktop - * Copyright (C) 2010 Michael Jumper +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * - * 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. + * 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/ * - * 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. + * 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. * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ + * 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 ***** */ // Guacamole namespace var Guacamole = Guacamole || {}; diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 3783216a6..dd37b1271 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -1,21 +1,39 @@ -/* - * Guacamole - Clientless Remote Desktop - * Copyright (C) 2010 Michael Jumper +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * - * 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. + * 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/ * - * 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. + * 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. * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ + * 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 ***** */ // Guacamole namespace var Guacamole = Guacamole || {}; diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index b4e52f069..987752fae 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -1,20 +1,39 @@ -/* - * Guacamole - Clientless Remote Desktop - * Copyright (C) 2010 Michael Jumper +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * - * 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. + * 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/ * - * 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. + * 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. * - * You should have received a copy of the GNU Affero General Public 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 ***** */ // Guacamole namespace var Guacamole = Guacamole || {}; From e362394d106181f133ea026395cb1b4ff83afca0 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 10 Dec 2011 14:31:47 -0800 Subject: [PATCH 068/263] Removing WebSocket tunnel for stable release. It will be back. --- .../src/main/resources/tunnel.js | 122 ------------------ 1 file changed, 122 deletions(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 987752fae..6003ac3a3 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -419,125 +419,3 @@ Guacamole.HTTPTunnel = function(tunnelURL) { }; 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. - */ - var tunnel = this; - - /** - * The WebSocket used by this tunnel. - */ - var socket = null; - - /** - * The WebSocket protocol corresponding to the protocol used for the current - * location. - */ - var ws_protocol = { - "http:": "ws:", - "https:": "wss:" - }; - - 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(message) { - - // Do not attempt to send messages if not connected - if (currentState != STATE_CONNECTED) - return; - - socket.send(message); - - }; - - this.connect = function(data) { - - // Connect socket - socket = new WebSocket(tunnelURL + "?" + data, "guacamole"); - - socket.onopen = function(event) { - currentState = STATE_CONNECTED; - }; - - socket.onmessage = function(event) { - - var message = event.data; - - var instructions = message.split(";"); - for (var i=0; i Date: Sun, 11 Dec 2011 12:04:27 -0800 Subject: [PATCH 069/263] Fix errors in IE due to lack of textContent support. --- guacamole-common-js/src/main/resources/oskeyboard.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index dd37b1271..573b01b13 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -112,6 +112,7 @@ Guacamole.OnScreenKeyboard = function(url) { // Displayed text var displayText = cap.textContent; + if (!displayText) displayText = cap.text; // Keysym var keysym = null; @@ -149,7 +150,7 @@ Guacamole.OnScreenKeyboard = function(url) { sticky = true; this.getDisplayText = function() { - return cap.textContent; + return displayText; }; this.getKeySym = function() { From ece9aa850ec22a229615275aded0544be9f2d4a8 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 11 Dec 2011 12:21:34 -0800 Subject: [PATCH 070/263] Fixes ticket #61 - adds catches where necessary to handle errors thrown only by IE. --- guacamole-common-js/src/main/resources/tunnel.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 6003ac3a3..618734e82 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -223,8 +223,15 @@ Guacamole.HTTPTunnel = function(tunnelURL) { 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 (xmlhttprequest.readyState >= 2 && nextRequest == null && xmlhttprequest.status == 200) + if (xmlhttprequest.readyState >= 2 && nextRequest == null && status == 200) nextRequest = makeRequest(); // Parse stream when data is received and when complete. @@ -261,7 +268,12 @@ Guacamole.HTTPTunnel = function(tunnelURL) { return; } - var current = xmlhttprequest.responseText; + // 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) { From 08d2eb731edadf993a5a9df86b3021639e840f90 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 11 Dec 2011 15:35:56 -0800 Subject: [PATCH 071/263] Added README. --- guacamole-common-js/README | 78 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 guacamole-common-js/README diff --git a/guacamole-common-js/README b/guacamole-common-js/README new file mode 100644 index 000000000..72be5edae --- /dev/null +++ b/guacamole-common-js/README @@ -0,0 +1,78 @@ + +------------------------------------------------------------ + About this README +------------------------------------------------------------ + +This README is intended to provide quick and to-the-point documentation for +technical users intending to compile parts of Guacamole themselves. + +Distribution-specific packages are available from the files section of the main +project page: + + http://sourceforge.net/projects/guacamole/files/ + +Distribution-specific documentation is provided on the Guacamole wiki: + + http://guac-dev.org/ + + +------------------------------------------------------------ + What is guacamole-common-js? +------------------------------------------------------------ + +guacamole-common-js is the core JavaScript library used by the Guacamole web +application. + +guacamole-common-js provides an efficient HTTP tunnel for transporting +protocol data between JavaScript and the web application, as well as an +implementation of a Guacamole protocol client and abstract synchronized +drawing layers. + + +------------------------------------------------------------ + Compiling and installing guacamole-common-js +------------------------------------------------------------ + +guacamole-common-js is built using Maven. Note that this is JavaScript code +and not actually compiled. "Building" guacamole-common-js actually simply +packages it into a redistributable .zip file. This .zip file can be easily +included and expaned into other Maven-based projects (like Guacamole). + +Note that prebuilt versions of guacamole-common-js are available from the +main guac-dev.org Maven repository which is referenced in all Maven +projects in Guacamole. Unless you want to make changes to guacamole-common-js +or you want to use a newer, unreleased version (such as the unstable branch), +you do not need to build this manually. You can let Maven download it for +you when you build Guacamole. + +1) Run mvn package + + $ mvn package + + Maven will download any needed dependencies for building the .zip file. + Once all dependencies have been downloaded, the .zip file will be + created in the target/ subdirectory of the current directory. + +2) Run mvn install + + $ mvn install + + DO NOT RUN THIS AS ROOT! + + Maven will install guacamole-common-js to your user's local Maven + repository where it can be used in future builds. It will not install + into a system-wide repository and does not require root privileges. + + Once installed, building other Maven projects that depend on + guacamole-common-js (such as Guacamole) will be possible. + + +------------------------------------------------------------ + Reporting problems +------------------------------------------------------------ + +Please report any bugs encountered by opening a new ticket at the Trac system +hosted at: + + http://guac-dev.org/trac/ + From 70531a534dea6b2b82ca870ba67d8c49bfbb58fd Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 11 Dec 2011 23:50:28 -0800 Subject: [PATCH 072/263] Added changelog. --- guacamole-common-js/ChangeLog | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 guacamole-common-js/ChangeLog diff --git a/guacamole-common-js/ChangeLog b/guacamole-common-js/ChangeLog new file mode 100644 index 000000000..250fe0ad6 --- /dev/null +++ b/guacamole-common-js/ChangeLog @@ -0,0 +1,18 @@ +2011-12-11 Michael Jumper + + * Implemented improved instruction format + * Fixed errors in IE in on-screen keyboard + * Relicensed as Mozilla/LGPL/GPL + * Touch support (emulates touchpad control of mouse pointer) + * "rect" and "clip" instructions + +2011-07-13 Michael Jumper + + * "sync" instruction + * Channel masks (alpha compositing) + * Multiple tunnel support + +2011-03-02 Michael Jumper + + * Initial release + From 86dc877483209b7887cde957d50cd70dc642974b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 12 Dec 2011 21:26:33 -0800 Subject: [PATCH 073/263] Removed SSH plugin requirement and dist management. --- guacamole-common-js/pom.xml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/guacamole-common-js/pom.xml b/guacamole-common-js/pom.xml index 9fafbfabc..19adef390 100644 --- a/guacamole-common-js/pom.xml +++ b/guacamole-common-js/pom.xml @@ -35,14 +35,6 @@ - - - - org.apache.maven.wagon - wagon-ssh-external - - - @@ -52,11 +44,4 @@ - - - guac-dev - ${guac-dev.dist.repo} - - - From bb5ce4bf325c5bda37935cf09823740850d7a0e4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 12 Dec 2011 21:27:43 -0800 Subject: [PATCH 074/263] Removed unused repo. --- guacamole-common-js/pom.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/guacamole-common-js/pom.xml b/guacamole-common-js/pom.xml index 19adef390..d0e3f1d31 100644 --- a/guacamole-common-js/pom.xml +++ b/guacamole-common-js/pom.xml @@ -37,11 +37,4 @@ - - - guac-dev - http://guac-dev.org/repo - - - From 745a83f0d80961099f6aa23a965ad447d53a2241 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 13 Dec 2011 18:41:20 -0800 Subject: [PATCH 075/263] Fixed typo in README --- guacamole-common-js/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/README b/guacamole-common-js/README index 72be5edae..3929fe4bb 100644 --- a/guacamole-common-js/README +++ b/guacamole-common-js/README @@ -36,7 +36,7 @@ drawing layers. guacamole-common-js is built using Maven. Note that this is JavaScript code and not actually compiled. "Building" guacamole-common-js actually simply packages it into a redistributable .zip file. This .zip file can be easily -included and expaned into other Maven-based projects (like Guacamole). +included and expanded into other Maven-based projects (like Guacamole). Note that prebuilt versions of guacamole-common-js are available from the main guac-dev.org Maven repository which is referenced in all Maven From b4ee710b6f547e7b374f473b95ef7de9f0f88817 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 19 Dec 2011 20:46:46 -0800 Subject: [PATCH 076/263] Prevent mouse from leaving screen when moved via touch events. --- guacamole-common-js/src/main/resources/mouse.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 6f1edf0c5..9c6537c15 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -247,7 +247,17 @@ Guacamole.Mouse = function(element) { guac_mouse.currentState.x += delta_x; guac_mouse.currentState.y += delta_y; - // FIXME: Prevent mouse from leaving screen + // Prevent mouse from leaving screen + + if (guac_mouse.currentState.x < 0) + guac_mouse.currentState.x = 0; + else if (guac_mouse.currentState.x >= element.offsetWidth) + guac_mouse.currentState.x = element.offsetWidth - 1; + + if (guac_mouse.currentState.y < 0) + guac_mouse.currentState.y = 0; + else if (guac_mouse.currentState.y >= element.offsetHeight) + guac_mouse.currentState.y = element.offsetHeight - 1; // Fire movement event, if defined if (guac_mouse.onmousemove) From b4d135c3f1722ac720f07e959a15ca242a6e5213 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 8 Jan 2012 20:20:04 -0800 Subject: [PATCH 077/263] Automatically ping every 5 seconds. --- .../src/main/resources/guacamole.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index b7ca9ab3c..535f9b29a 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -60,6 +60,9 @@ Guacamole.Client = function(display, tunnel) { var STATE_DISCONNECTED = 5; var currentState = STATE_IDLE; + + var currentTimestamp = 0; + var pingInterval = null; tunnel.onerror = function(message) { if (guac_client.onerror) @@ -400,8 +403,10 @@ Guacamole.Client = function(display, tunnel) { layersToSync--; // Send sync response when layers are finished - if (layersToSync == 0) + if (layersToSync == 0) { tunnel.sendMessage("sync", timestamp); + currentTimestamp = timestamp; + } } @@ -418,8 +423,10 @@ Guacamole.Client = function(display, tunnel) { // If all layers are ready, then we didn't install any hooks. // Send sync message now, - if (layersToSync == 0) + if (layersToSync == 0) { tunnel.sendMessage("sync", timestamp); + currentTimestamp = timestamp; + } } @@ -442,9 +449,16 @@ Guacamole.Client = function(display, tunnel) { && 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); + } }; @@ -461,6 +475,11 @@ Guacamole.Client = function(display, tunnel) { throw e; } + // Ping every 5 seconds (ensure connection alive) + pingInterval = window.setInterval(function() { + tunnel.sendMessage("sync", currentTimestamp); + }, 5000); + setState(STATE_WAITING); }; From 6fc6122e678fe88d5f9d607c3f332e1af9e2b8ac Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 8 Jan 2012 23:47:07 -0800 Subject: [PATCH 078/263] Only send sync response if timestamp is changing. --- guacamole-common-js/src/main/resources/guacamole.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 535f9b29a..0a1b72c52 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -404,8 +404,10 @@ Guacamole.Client = function(display, tunnel) { // Send sync response when layers are finished if (layersToSync == 0) { - tunnel.sendMessage("sync", timestamp); - currentTimestamp = timestamp; + if (timestamp != currentTimestamp) { + tunnel.sendMessage("sync", timestamp); + currentTimestamp = timestamp; + } } } @@ -424,8 +426,10 @@ Guacamole.Client = function(display, tunnel) { // If all layers are ready, then we didn't install any hooks. // Send sync message now, if (layersToSync == 0) { - tunnel.sendMessage("sync", timestamp); - currentTimestamp = timestamp; + if (timestamp != currentTimestamp) { + tunnel.sendMessage("sync", timestamp); + currentTimestamp = timestamp; + } } } From 0a4931cb41a8f6e138d2664e28c48cf72f43dfb0 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 10 Jan 2012 11:37:10 -0800 Subject: [PATCH 079/263] Copying from a buffer with no width/height should not fail. Hard exceptions in handlers causes layer task handling to stall. --- guacamole-common-js/src/main/resources/layer.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index bd6af677d..e76206045 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -141,7 +141,7 @@ Guacamole.Layer = function(width, height) { // Redraw old data, if any if (oldData) - displayContext.drawImage(oldData, + displayContext.drawImage(oldData, 0, 0, width, height, 0, 0, width, height); @@ -400,7 +400,10 @@ Guacamole.Layer = function(width, height) { function doCopyRect() { if (layer.autosize != 0) fitRect(x, y, srcw, srch); - displayContext.drawImage(srcLayer.getCanvas(), srcx, srcy, srcw, srch, 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); } // If we ARE the source layer, no need to sync. From e776fbfcec2a7d6fbbb234c2746ff8c9ecf0fd62 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 10 Jan 2012 23:06:28 -0800 Subject: [PATCH 080/263] Fix race condition where the source of a copy operation may be altered before the destination is drawn to (thus the copy may not always copy what we THINK it should be copying, especially if many buffers are repeatedly used and quickly discarded). --- .../src/main/resources/layer.js | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index e76206045..6885f59e6 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -372,7 +372,7 @@ Guacamole.Layer = function(width, height) { * pending operations are complete. */ this.sync = function(handler) { - scheduleTask(handler); + return scheduleTask(handler); }; /** @@ -398,12 +398,18 @@ Guacamole.Layer = function(width, height) { */ this.copyRect = function(srcLayer, srcx, srcy, srcw, srch, x, y) { + var srcCopied = null; + function doCopyRect() { 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); + + // Unblock the copy complete task, if it exists + if (srcCopied != null) + srcCopied.handler = function() {}; } // If we ARE the source layer, no need to sync. @@ -413,8 +419,13 @@ Guacamole.Layer = function(width, height) { // Otherwise synchronize copy operation with source layer else { + + // Task which will be unblocked only when the source layer is ready + // This task will perform the copy var task = scheduleTask(null); - srcLayer.sync(function() { + + // Task which will unblock the drawing task. + var srcReady = srcLayer.sync(function() { task.handler = doCopyRect; @@ -423,6 +434,13 @@ Guacamole.Layer = function(width, height) { handlePendingTasks(); }); + + // Task which will be unblocked only after the copy has + // occurred (this will only be created if the draw task + // was postponed) + if (srcReady != null) + srcCopied = srcLayer.sync(null); + } }; From 028165707812fe5f63e598423e7490cb576618ec Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 12 Jan 2012 10:48:31 -0800 Subject: [PATCH 081/263] Added Task.unblock(), updated block check and update handling mechanism. --- .../src/main/resources/layer.js | 75 ++++++++++--------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 6885f59e6..a8539b01a 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -201,16 +201,34 @@ Guacamole.Layer = function(width, height) { * @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) { - + 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(); + } + } /** @@ -220,21 +238,22 @@ Guacamole.Layer = function(width, height) { * * @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) { + function scheduleTask(handler, blocked) { // If no pending tasks, just call (if available) and exit - if (layer.isReady() && handler != null) { + if (layer.isReady() && !blocked && handler != null) { handler(); return null; } // If tasks are pending/executing, schedule a pending task // and return a reference to it. - var task = new Task(handler); + var task = new Task(handler, blocked); tasks.push(task); return task; @@ -256,9 +275,9 @@ Guacamole.Layer = function(width, height) { // Draw all pending tasks. var task; - while ((task = tasks[0]) != null && task.handler) { + while ((task = tasks[0]) != null && !task.blocked) { tasks.shift(); - task.handler(); + if (task.handler) task.handler(); } tasksInProgress = false; @@ -345,21 +364,14 @@ Guacamole.Layer = function(width, height) { * @param {String} url The URL of the image to draw. */ this.draw = function(x, y, url) { - var task = scheduleTask(null); + + 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 = function() { - - task.handler = function() { - if (layer.autosize != 0) fitRect(x, y, image.width, image.height); - displayContext.drawImage(image, x, y); - }; - - // As this task originally had no handler and may have blocked - // other tasks, handle any blocked tasks. - handlePendingTasks(); - - }; + image.onload = task.unblock; image.src = url; }; @@ -398,7 +410,7 @@ Guacamole.Layer = function(width, height) { */ this.copyRect = function(srcLayer, srcx, srcy, srcw, srch, x, y) { - var srcCopied = null; + var srcLock = null; function doCopyRect() { if (layer.autosize != 0) fitRect(x, y, srcw, srch); @@ -408,8 +420,8 @@ Guacamole.Layer = function(width, height) { displayContext.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch); // Unblock the copy complete task, if it exists - if (srcCopied != null) - srcCopied.handler = function() {}; + if (srcLock != null) + srcLock.unblock(); } // If we ARE the source layer, no need to sync. @@ -422,24 +434,15 @@ Guacamole.Layer = function(width, height) { // Task which will be unblocked only when the source layer is ready // This task will perform the copy - var task = scheduleTask(null); + var task = scheduleTask(doCopyRect, true); // Task which will unblock the drawing task. - var srcReady = srcLayer.sync(function() { - - task.handler = doCopyRect; - - // As this task originally had no handler and may have blocked - // other tasks, handle any blocked tasks. - handlePendingTasks(); - - }); + var srcReady = srcLayer.sync(task.unblock); // Task which will be unblocked only after the copy has // occurred (this will only be created if the draw task // was postponed) - if (srcReady != null) - srcCopied = srcLayer.sync(null); + if (srcReady != null) srcLock = srcLayer.sync(null, true); } From a8de72ac423567b9630d9b39ec94e6b446f9ed0a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 19 Jan 2012 10:39:39 -0800 Subject: [PATCH 082/263] Refactor XML parse, use getElement() instead of overriding DOM. --- .../src/main/resources/oskeyboard.js | 575 +++++------------- 1 file changed, 154 insertions(+), 421 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 573b01b13..84f930cfa 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -48,421 +48,35 @@ var Guacamole = Guacamole || {}; */ Guacamole.OnScreenKeyboard = function(url) { - var allKeys = new Array(); - var modifierState = new function() {}; + // For each child of element, call handler defined in next + function parseChildren(element, next) { - function getKeySize(size) { - return (5*size) + "ex"; - } + var children = root.childNodes; + for (var i=0; i 0) - return true; - - return false; - } - - function toggleModifierPressed(modifier) { - if (isModifierActive(modifier)) - setModifierReleased(modifier); - else - setModifierPressed(modifier); - } - - function refreshAllKeysState() { - for (var k=0; k= 0x0000 && charCode <= 0x00FF) - keysym = charCode; - - else if (charCode >= 0x0100 && charCode <= 0x10FFFF) - keysym = 0x01000000 | charCode; - } - - // Required modifiers for this keycap - var reqMod = null; - if (cap.attributes["if"]) - reqMod = cap.attributes["if"].value.split(","); - - - // Modifier represented by this keycap - var modifier = null; - if (cap.attributes["modifier"]) - modifier = cap.attributes["modifier"].value; - - - // Whether this key is sticky (toggles) - // Currently only valid for modifiers. - var sticky = false; - if (cap.attributes["sticky"] && cap.attributes["sticky"].value == "true") - sticky = true; - - this.getDisplayText = function() { - return displayText; - }; - - this.getKeySym = function() { - return keysym; - }; - - this.getRequiredModifiers = function() { - return reqMod; - }; - - this.getModifier = function() { - return modifier; - }; - - this.isSticky = function() { - return sticky; - }; - - } - - var size = null; - if (key.attributes["size"]) - size = parseFloat(key.attributes["size"].value); - - var caps = key.getElementsByTagName("cap"); - var keycaps = new Array(); - for (var i=0; i can contain or - if (child.tagName == "key") { - var key = new Key(child); - keyboardRow.appendChild(key); - allKeys.push(key); - } - else if (child.tagName == "gap") { - var gap = new Gap(child); - keyboardRow.appendChild(gap); - } - else if (child.tagName == "column") { - var col = new Column(child); - keyboardRow.appendChild(col); - } + throw new Exception( + "Unexpected " + child.tagName + + " within " + element.tagName + ); } - return keyboardRow; - } - function Column(col) { - - var keyboardCol = document.createElement("div"); - keyboardCol.className = "col"; - - var align = null; - if (col.attributes["align"]) - align = col.attributes["align"].value; - - var children = col.childNodes; - for (var j=0; j can only contain - if (child.tagName == "row") { - var row = new Row(child); - keyboardCol.appendChild(row); - } - - } - - if (align) - keyboardCol.style.textAlign = align; - - return keyboardCol; - - } - - - // Create keyboard var keyboard = document.createElement("div"); keyboard.className = "keyboard"; - // Retrieve keyboard XML var xmlhttprequest = new XMLHttpRequest(); xmlhttprequest.open("GET", url, false); @@ -472,34 +86,107 @@ Guacamole.OnScreenKeyboard = function(url) { if (xml) { - // Parse document - var root = xml.documentElement; - if (root) { + function parse_row(e) { + + var row = document.createElement("div"); + row.className = "row"; - var children = root.childNodes; - for (var i=0; i can contain or - if (child.tagName == "row") { - keyboard.appendChild(new Row(child)); - } - else if (child.tagName == "column") { - keyboard.appendChild(new Column(child)); } + + }); - } + return row; } + function parse_column(e) { + + var col = document.createElement("div"); + col.className = "col"; + + var align = col.attributes["align"]; + + if (align) + col.style.textAlign = align.value; + + // Columns can only contain rows + parseChildren(e, { + "row": function(e) { + col.appendChild(parse_row(e)); + } + }); + + return col; + + } + + + // Parse document + parseChildren(xml.documentElement, { + + "keyboard": function parse_keyboard(e) { + + // Get attributes + var keyboard_size = e.attributes["size"]; + + parseChildren(e, { + + "row": function(e) { + keyboard.appendChild(parse_row(e)); + }, + + "column": function(e) { + keyboard.appendChild(parse_column(e)); + } + + }); + + } // end keyboard + + }); + } - var keyPressedHandler = null; - var keyReleasedHandler = null; - - keyboard.setKeyPressedHandler = function(kh) { keyPressedHandler = kh; }; - keyboard.setKeyReleasedHandler = function(kh) { keyReleasedHandler = kh; }; - // Do not allow selection or mouse movement to propagate/register. keyboard.onselectstart = keyboard.onmousemove = @@ -510,7 +197,53 @@ Guacamole.OnScreenKeyboard = function(url) { return false; }; - return keyboard; + + this.onkeypressed = null; + this.onkeyreleased = null; + + this.getElement = function() { + return keyboard; + }; }; +Guacamole.OnScreenKeyboard.Key = function() { + + /** + * Width of the key, relative to the size of the keyboard. + */ + this.size = 1; + + /** + * Whether this key is currently pressed. + */ + this.pressed = false; + + /** + * An associative map of all caps by modifier. + */ + this.caps = {}; + +} + +Guacamole.OnScreenKeyboard.Cap = function(text, keycode, modifier) { + + /** + * Modifier represented by this keycap + */ + this.modifier = 0; + + /** + * The text to be displayed within this keycap + */ + this.text = text; + + /** + * The keycode this cap sends when its associated key is pressed/released + */ + this.keycode = keycode; + + // Set modifier if provided + if (modifier) this.modifier = modifier; + +} From 4482fc45303c8484faa8b48f9739161b663281f4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 19 Jan 2012 11:19:02 -0800 Subject: [PATCH 083/263] Fixed parsing. --- .../src/main/resources/oskeyboard.js | 64 ++++++++++++------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 84f930cfa..e0c2d69aa 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -51,11 +51,17 @@ Guacamole.OnScreenKeyboard = function(url) { // For each child of element, call handler defined in next function parseChildren(element, next) { - var children = root.childNodes; + var children = element.childNodes; for (var i=0; i Date: Thu, 19 Jan 2012 11:22:49 -0800 Subject: [PATCH 084/263] Set key size, improve class names. --- .../src/main/resources/oskeyboard.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index e0c2d69aa..30a5de9d6 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -81,7 +81,7 @@ Guacamole.OnScreenKeyboard = function(url) { // Create keyboard var keyboard = document.createElement("div"); - keyboard.className = "keyboard"; + keyboard.className = "guacamole-keyboard"; // Retrieve keyboard XML var xmlhttprequest = new XMLHttpRequest(); @@ -95,7 +95,7 @@ Guacamole.OnScreenKeyboard = function(url) { function parse_row(e) { var row = document.createElement("div"); - row.className = "row"; + row.className = "guacamole-keyboard-row"; parseChildren(e, { @@ -110,9 +110,10 @@ Guacamole.OnScreenKeyboard = function(url) { // Create element var gap = document.createElement("div"); - gap.className = "gap"; + gap.className = "guacamole-keyboard-gap"; gap.textContent = " "; + // Set gap size if (gap_size) gap.style.width = gap.style.height = parseFloat(gap_size.value) + "em"; @@ -128,9 +129,15 @@ Guacamole.OnScreenKeyboard = function(url) { // Create element var key = document.createElement("div"); - key.className = "key"; + key.className = "guacamole-keyboard-key"; key.textContent = "K"; + // Set key size + if (key_size) { + key.style.width = parseFloat(key_size.value) + "em"; + key.style.height = "1em"; + } + parseChildren(e, { "cap": function cap(e) { @@ -164,7 +171,7 @@ Guacamole.OnScreenKeyboard = function(url) { function parse_column(e) { var col = document.createElement("div"); - col.className = "col"; + col.className = "guacamole-keyboard-column"; var align = col.attributes["align"]; From eac56704879496c33716138f007edaac7fe9d893 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 19 Jan 2012 11:47:41 -0800 Subject: [PATCH 085/263] Fixed style and positioning. --- .../src/main/resources/oskeyboard.js | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 30a5de9d6..304f3eb40 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -92,6 +92,10 @@ Guacamole.OnScreenKeyboard = function(url) { if (xml) { + var width = 640; + var size = 20; + var unit = width / size; + function parse_row(e) { var row = document.createElement("div"); @@ -116,7 +120,7 @@ Guacamole.OnScreenKeyboard = function(url) { // Set gap size if (gap_size) gap.style.width = gap.style.height = - parseFloat(gap_size.value) + "em"; + parseFloat(gap_size.value)*unit + "px"; row.appendChild(gap); @@ -124,19 +128,27 @@ Guacamole.OnScreenKeyboard = function(url) { "key": function parse_key(e) { + // Get attributes var key_size = e.attributes["size"]; + // Create container element + var key_container = document.createElement("div"); + key_container.style.display = "inline-block"; + key_container.style.fontSize = unit + "px"; + key_container.style.lineHeight = unit + "px"; + key_container.style.height = unit + "px"; + // Create element var key = document.createElement("div"); key.className = "guacamole-keyboard-key"; - key.textContent = "K"; + key_container.appendChild(key); // Set key size - if (key_size) { - key.style.width = parseFloat(key_size.value) + "em"; - key.style.height = "1em"; - } + if (key_size) + key_container.style.width = parseFloat(key_size.value)*unit + "px"; + else + key_container.style.width = unit + "px"; parseChildren(e, { "cap": function cap(e) { @@ -158,7 +170,7 @@ Guacamole.OnScreenKeyboard = function(url) { } }); - row.appendChild(key); + row.appendChild(key_container); } From 7ddc68e70700bb2a07b597c5e2772db40e03e5fd Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 19 Jan 2012 12:07:53 -0800 Subject: [PATCH 086/263] Style key containers, add line-height. --- guacamole-common-js/src/main/resources/oskeyboard.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 304f3eb40..a06226fd6 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -134,10 +134,11 @@ Guacamole.OnScreenKeyboard = function(url) { // Create container element var key_container = document.createElement("div"); + key_container.className = "guacamole-keyboard-key-container"; key_container.style.display = "inline-block"; key_container.style.fontSize = unit + "px"; - key_container.style.lineHeight = unit + "px"; key_container.style.height = unit + "px"; + key_container.style.lineHeight = unit + "px"; // Create element var key = document.createElement("div"); From 1a88b26c98c1466a86cac8b5c35075b3f879b6e9 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 19 Jan 2012 14:25:42 -0800 Subject: [PATCH 087/263] Improved placement and available classes. --- .../src/main/resources/oskeyboard.js | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index a06226fd6..68b47e2cd 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -115,7 +115,6 @@ Guacamole.OnScreenKeyboard = function(url) { // Create element var gap = document.createElement("div"); gap.className = "guacamole-keyboard-gap"; - gap.textContent = " "; // Set gap size if (gap_size) @@ -132,24 +131,23 @@ Guacamole.OnScreenKeyboard = function(url) { // Get attributes var key_size = e.attributes["size"]; - // Create container element - var key_container = document.createElement("div"); - key_container.className = "guacamole-keyboard-key-container"; - key_container.style.display = "inline-block"; - key_container.style.fontSize = unit + "px"; - key_container.style.height = unit + "px"; - key_container.style.lineHeight = unit + "px"; - // Create element - var key = document.createElement("div"); - key.className = "guacamole-keyboard-key"; - key_container.appendChild(key); + var key_element = document.createElement("div"); + key_element.className = "guacamole-keyboard-key"; + key_element.style.fontSize = unit + "px"; + key_element.style.height = unit + "px"; + key_element.style.lineHeight = unit + "px"; + + // Create cap + var cap_element = document.createElement("div"); + cap_element.className = "guacamole-keyboard-cap"; + key_element.appendChild(cap_element); // Set key size if (key_size) - key_container.style.width = parseFloat(key_size.value)*unit + "px"; + key_element.style.width = parseFloat(key_size.value)*unit + "px"; else - key_container.style.width = unit + "px"; + key_element.style.width = unit + "px"; parseChildren(e, { "cap": function cap(e) { @@ -165,13 +163,13 @@ Guacamole.OnScreenKeyboard = function(url) { // If no requirements, then show cap by default if (!required) { - key.textContent = content; + cap_element.textContent = content; } } }); - row.appendChild(key_container); + row.appendChild(key_element); } From 80795f656fb0d8acd1d828f36df3a62826d24108 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 19 Jan 2012 15:05:53 -0800 Subject: [PATCH 088/263] Resizable elements. --- .../src/main/resources/oskeyboard.js | 55 ++++++++++++++----- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 68b47e2cd..5fde1e226 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -48,6 +48,25 @@ var Guacamole = Guacamole || {}; */ Guacamole.OnScreenKeyboard = function(url) { + var scaledElements = []; + + 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) { @@ -92,10 +111,6 @@ Guacamole.OnScreenKeyboard = function(url) { if (xml) { - var width = 640; - var size = 20; - var unit = width / size; - function parse_row(e) { var row = document.createElement("div"); @@ -117,10 +132,11 @@ Guacamole.OnScreenKeyboard = function(url) { gap.className = "guacamole-keyboard-gap"; // Set gap size + var gap_units = 1; if (gap_size) - gap.style.width = gap.style.height = - parseFloat(gap_size.value)*unit + "px"; + gap_units = parseFloat(gap_size.value); + scaledElements.push(new ScaledElement(gap, gap_units, gap_units)); row.appendChild(gap); }, @@ -134,9 +150,6 @@ Guacamole.OnScreenKeyboard = function(url) { // Create element var key_element = document.createElement("div"); key_element.className = "guacamole-keyboard-key"; - key_element.style.fontSize = unit + "px"; - key_element.style.height = unit + "px"; - key_element.style.lineHeight = unit + "px"; // Create cap var cap_element = document.createElement("div"); @@ -144,10 +157,9 @@ Guacamole.OnScreenKeyboard = function(url) { key_element.appendChild(cap_element); // Set key size + var key_units = 1; if (key_size) - key_element.style.width = parseFloat(key_size.value)*unit + "px"; - else - key_element.style.width = unit + "px"; + key_units = parseFloat(key_size.value); parseChildren(e, { "cap": function cap(e) { @@ -169,6 +181,7 @@ Guacamole.OnScreenKeyboard = function(url) { } }); + scaledElements.push(new ScaledElement(key_element, key_units, 1, true)); row.appendChild(key_element); } @@ -207,7 +220,10 @@ Guacamole.OnScreenKeyboard = function(url) { throw new Error("Root element must be keyboard"); // Get attributes - var keyboard_size = keyboard_element.attributes["size"]; + if (!keyboard_element.attributes["size"]) + throw new Error("size attribute is required for keyboard"); + + var keyboard_size = parseFloat(keyboard_element.attributes["size"].value); parseChildren(keyboard_element, { @@ -241,6 +257,19 @@ Guacamole.OnScreenKeyboard = function(url) { return keyboard; }; + this.resize = function(width) { + + // Get pixel size of a unit + var unit = width / keyboard_size; + + // Resize all scaled elements + for (var i=0; i Date: Fri, 20 Jan 2012 13:57:32 -0800 Subject: [PATCH 089/263] Store caps by modifier in keys within central key array. --- .../src/main/resources/oskeyboard.js | 97 ++++++++++++++++--- 1 file changed, 83 insertions(+), 14 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 5fde1e226..285c6f9f6 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -49,6 +49,29 @@ var Guacamole = Guacamole || {}; Guacamole.OnScreenKeyboard = function(url) { var scaledElements = []; + + var modifiers = {}; + var currentModifier = 1; + + // Returns a unique power-of-two value for the modifier with the + // given name. The same value will be returned for the same modifier. + function getModifier(name) { + + var value = modifiers[name]; + if (!value) { + + // Get current modifier, advance to next + value = currentModifier; + currentModifier <<= 1; + + // Store value of this modifier + modifiers[name] = value; + + } + + return value; + + } function ScaledElement(element, width, height, scaleFont) { @@ -56,11 +79,11 @@ Guacamole.OnScreenKeyboard = function(url) { this.height = height; this.scale = function(pixels) { - element.style.width = width * pixels + "px"; - element.style.height = height * pixels + "px"; + element.style.width = Math.floor(width * pixels) + "px"; + element.style.height = Math.floor(height * pixels) + "px"; if (scaleFont) { - element.style.lineHeight = height * pixels + "px"; + element.style.lineHeight = Math.floor(height * pixels) + "px"; element.style.fontSize = pixels + "px"; } } @@ -143,7 +166,6 @@ Guacamole.OnScreenKeyboard = function(url) { "key": function parse_key(e) { - // Get attributes var key_size = e.attributes["size"]; @@ -151,18 +173,23 @@ Guacamole.OnScreenKeyboard = function(url) { var key_element = document.createElement("div"); key_element.className = "guacamole-keyboard-key"; - // Create cap + // Create cap element var cap_element = document.createElement("div"); cap_element.className = "guacamole-keyboard-cap"; key_element.appendChild(cap_element); + // Create key + var key = new Guacamole.OnScreenKeyboard.Key(cap_element); + // Set key size var key_units = 1; if (key_size) key_units = parseFloat(key_size.value); + key.size = key_units; + parseChildren(e, { - "cap": function cap(e) { + "cap": function parse_cap(e) { // Get attributes var required = e.attributes["if"]; @@ -173,17 +200,36 @@ Guacamole.OnScreenKeyboard = function(url) { // Get content of key cap var content = e.textContent; - // If no requirements, then show cap by default - if (!required) { - cap_element.textContent = content; + // Create cap + var cap = new Guacamole.OnScreenKeyboard.Cap(content, + keysym ? keysym.value : null); + + // Get modifier value + var modifierValue = 0; + if (required) { + + // Get modifier value for specified comma-delimited + // list of required modifiers. + var requirements = required.value.split(","); + for (var i=0; i Date: Fri, 20 Jan 2012 22:33:14 -0800 Subject: [PATCH 090/263] Better classname assignment for keycaps, restructure of keyboard (keyboard/key-container(s)/key/cap(s)). --- .../src/main/resources/oskeyboard.js | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 285c6f9f6..6d30a8b77 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -172,14 +172,14 @@ Guacamole.OnScreenKeyboard = function(url) { // Create element var key_element = document.createElement("div"); key_element.className = "guacamole-keyboard-key"; - - // Create cap element - var cap_element = document.createElement("div"); - cap_element.className = "guacamole-keyboard-cap"; - key_element.appendChild(cap_element); + + // Position keys using container div + var key_container_element = document.createElement("div"); + key_container_element.className = "guacamole-keyboard-key-container"; + key_container_element.appendChild(key_element); // Create key - var key = new Guacamole.OnScreenKeyboard.Key(cap_element); + var key = new Guacamole.OnScreenKeyboard.Key(); // Set key size var key_units = 1; @@ -204,6 +204,12 @@ Guacamole.OnScreenKeyboard = function(url) { var cap = new Guacamole.OnScreenKeyboard.Cap(content, keysym ? keysym.value : null); + // Create cap element + var cap_element = document.createElement("div"); + cap_element.className = "guacamole-keyboard-cap"; + cap_element.textContent = content; + key_element.appendChild(cap_element); + // Get modifier value var modifierValue = 0; if (required) { @@ -213,6 +219,7 @@ Guacamole.OnScreenKeyboard = function(url) { var requirements = required.value.split(","); for (var i=0; i Date: Sat, 21 Jan 2012 12:06:43 -0800 Subject: [PATCH 091/263] Initial version of onclick for keys, improved classes. --- .../src/main/resources/oskeyboard.js | 59 ++++++++++++------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 6d30a8b77..a1d442f48 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -12,7 +12,7 @@ * for the specific language governing rights and limitations under the * License. * - * The Original Code is guacamole-common-js. + * The Original Code is guac-common-js. * * The Initial Developer of the Original Code is * Michael Jumper. @@ -48,6 +48,8 @@ var Guacamole = Guacamole || {}; */ Guacamole.OnScreenKeyboard = function(url) { + var on_screen_keyboard = this; + var scaledElements = []; var modifiers = {}; @@ -123,7 +125,7 @@ Guacamole.OnScreenKeyboard = function(url) { // Create keyboard var keyboard = document.createElement("div"); - keyboard.className = "guacamole-keyboard"; + keyboard.className = "guac-keyboard"; // Retrieve keyboard XML var xmlhttprequest = new XMLHttpRequest(); @@ -137,7 +139,7 @@ Guacamole.OnScreenKeyboard = function(url) { function parse_row(e) { var row = document.createElement("div"); - row.className = "guacamole-keyboard-row"; + row.className = "guac-keyboard-row"; parseChildren(e, { @@ -152,7 +154,7 @@ Guacamole.OnScreenKeyboard = function(url) { // Create element var gap = document.createElement("div"); - gap.className = "guacamole-keyboard-gap"; + gap.className = "guac-keyboard-gap"; // Set gap size var gap_units = 1; @@ -171,11 +173,11 @@ Guacamole.OnScreenKeyboard = function(url) { // Create element var key_element = document.createElement("div"); - key_element.className = "guacamole-keyboard-key"; + key_element.className = "guac-keyboard-key"; // Position keys using container div var key_container_element = document.createElement("div"); - key_container_element.className = "guacamole-keyboard-key-container"; + key_container_element.className = "guac-keyboard-key-container"; key_container_element.appendChild(key_element); // Create key @@ -203,10 +205,13 @@ Guacamole.OnScreenKeyboard = function(url) { // Create cap var cap = new Guacamole.OnScreenKeyboard.Cap(content, keysym ? keysym.value : null); + + if (modifier) + cap.modifier = modifier.value; // Create cap element var cap_element = document.createElement("div"); - cap_element.className = "guacamole-keyboard-cap"; + cap_element.className = "guac-keyboard-cap"; cap_element.textContent = content; key_element.appendChild(cap_element); @@ -219,7 +224,8 @@ Guacamole.OnScreenKeyboard = function(url) { var requirements = required.value.split(","); for (var i=0; i Date: Sat, 21 Jan 2012 12:53:18 -0800 Subject: [PATCH 092/263] Toggle modifier pressed states. --- .../src/main/resources/oskeyboard.js | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index a1d442f48..48d9989b5 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -243,13 +243,30 @@ Guacamole.OnScreenKeyboard = function(url) { // Set up click handler for key key_element.onclick = function() { + // Toggle pressed state + key.pressed = !key.pressed; + // Get current cap based on modifier state var cap = key.getCap(on_screen_keyboard.modifiers); // Update modifier state if (cap.modifier) { - on_screen_keyboard.modifiers |= getModifier(cap.modifier); - keyboard.classList.add("guac-keyboard-modifier-" + cap.modifier); + + // Construct classname for modifier + var modifierClass = "guac-keyboard-modifier-" + cap.modifier; + + // Activate modifier if pressed + if (key.pressed) { + on_screen_keyboard.modifiers |= getModifier(cap.modifier); + keyboard.classList.add(modifierClass); + } + + // Deactivate if not pressed + else { + on_screen_keyboard.modifiers &= ~getModifier(cap.modifier); + keyboard.classList.remove(modifierClass); + } + } // TODO: Send key event From 53683c90d241ce5004825eae1557e46c3f8c44d4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 21 Jan 2012 12:53:59 -0800 Subject: [PATCH 093/263] Only modifier states should toggle. --- guacamole-common-js/src/main/resources/oskeyboard.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 48d9989b5..476f7ea11 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -243,15 +243,15 @@ Guacamole.OnScreenKeyboard = function(url) { // Set up click handler for key key_element.onclick = function() { - // Toggle pressed state - key.pressed = !key.pressed; - // Get current cap based on modifier state var cap = key.getCap(on_screen_keyboard.modifiers); // Update modifier state if (cap.modifier) { + // Toggle pressed state + key.pressed = !key.pressed; + // Construct classname for modifier var modifierClass = "guac-keyboard-modifier-" + cap.modifier; From c210444fac8aa5da4855de679f4757e997465192 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 21 Jan 2012 12:58:44 -0800 Subject: [PATCH 094/263] Track pressed state for modifiers globally. Do not track pressed state of non-modifiers. --- .../src/main/resources/oskeyboard.js | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 476f7ea11..2c095fb59 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -249,23 +249,20 @@ Guacamole.OnScreenKeyboard = function(url) { // Update modifier state if (cap.modifier) { - // Toggle pressed state - key.pressed = !key.pressed; - // Construct classname for modifier var modifierClass = "guac-keyboard-modifier-" + cap.modifier; + var modifierFlag = getModifier(cap.modifier); + + // Toggle modifier state + on_screen_keyboard.modifiers ^= modifierFlag; // Activate modifier if pressed - if (key.pressed) { - on_screen_keyboard.modifiers |= getModifier(cap.modifier); + if (on_screen_keyboard.modifiers & modifierFlag) keyboard.classList.add(modifierClass); - } // Deactivate if not pressed - else { - on_screen_keyboard.modifiers &= ~getModifier(cap.modifier); + else keyboard.classList.remove(modifierClass); - } } @@ -374,11 +371,6 @@ Guacamole.OnScreenKeyboard.Key = function() { */ this.size = 1; - /** - * Whether this key is currently pressed. - */ - this.pressed = false; - /** * An associative map of all caps by modifier. */ From aa5b07761e1ac2e2104271d3f9d76829c03101b6 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 23 Jan 2012 10:04:27 -0800 Subject: [PATCH 095/263] Use pressed classname for pressed keys. --- guacamole-common-js/src/main/resources/oskeyboard.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 2c095fb59..5d3fa0275 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -241,7 +241,10 @@ Guacamole.OnScreenKeyboard = function(url) { row.appendChild(key_container_element); // Set up click handler for key - key_element.onclick = function() { + key_element.onmousedown = + key_element.ontouchstart = function() { + + key_element.classList.add("guac-keyboard-pressed"); // Get current cap based on modifier state var cap = key.getCap(on_screen_keyboard.modifiers); @@ -270,6 +273,11 @@ Guacamole.OnScreenKeyboard = function(url) { }; + key_element.onmouseup = + key_element.ontouchend = function() { + key_element.classList.remove("guac-keyboard-pressed"); + }; + } }); From 5ca6a2cacf49aa934b72f1f75ef3f1165dab9dbd Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 23 Jan 2012 10:41:39 -0800 Subject: [PATCH 096/263] Support for user-defined classes in keyboard XML. --- guacamole-common-js/src/main/resources/oskeyboard.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 5d3fa0275..61b6f534f 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -170,11 +170,16 @@ Guacamole.OnScreenKeyboard = function(url) { // Get attributes var key_size = e.attributes["size"]; + var key_class = e.attributes["class"]; // Create element var key_element = document.createElement("div"); key_element.className = "guac-keyboard-key"; + // Append class if specified + if (key_class) + key_element.className += " " + key_class.value; + // Position keys using container div var key_container_element = document.createElement("div"); key_container_element.className = "guac-keyboard-key-container"; @@ -198,6 +203,7 @@ Guacamole.OnScreenKeyboard = function(url) { var modifier = e.attributes["modifier"]; var keysym = e.attributes["keysym"]; var sticky = e.attributes["sticky"]; + var cap_class = e.attributes["class"]; // Get content of key cap var content = e.textContent; @@ -215,6 +221,10 @@ Guacamole.OnScreenKeyboard = function(url) { cap_element.textContent = content; key_element.appendChild(cap_element); + // Append class if specified + if (cap_class) + cap_element.className += " " + cap_class.value; + // Get modifier value var modifierValue = 0; if (required) { From 08c3a8344a1d824ae09444ee648b3c76ac0e5cd4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 23 Jan 2012 10:51:12 -0800 Subject: [PATCH 097/263] Release key on mouse out. --- guacamole-common-js/src/main/resources/oskeyboard.js | 1 + 1 file changed, 1 insertion(+) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 61b6f534f..b329f65f3 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -284,6 +284,7 @@ Guacamole.OnScreenKeyboard = function(url) { }; key_element.onmouseup = + key_element.onmouseout = key_element.ontouchend = function() { key_element.classList.remove("guac-keyboard-pressed"); }; From ff6ca004dbb764d1e9793d1078de259d1296f01c Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 23 Jan 2012 13:48:30 -0800 Subject: [PATCH 098/263] Round to nearest tenth, rather than integer. --- guacamole-common-js/src/main/resources/oskeyboard.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index b329f65f3..91f32417a 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -81,11 +81,11 @@ Guacamole.OnScreenKeyboard = function(url) { this.height = height; this.scale = function(pixels) { - element.style.width = Math.floor(width * pixels) + "px"; - element.style.height = Math.floor(height * pixels) + "px"; + element.style.width = (width * pixels) + "px"; + element.style.height = (height * pixels) + "px"; if (scaleFont) { - element.style.lineHeight = Math.floor(height * pixels) + "px"; + element.style.lineHeight = (height * pixels) + "px"; element.style.fontSize = pixels + "px"; } } @@ -369,7 +369,7 @@ Guacamole.OnScreenKeyboard = function(url) { this.resize = function(width) { // Get pixel size of a unit - var unit = Math.floor(width / keyboard_size); + var unit = Math.floor(width * 10 / keyboard_size) / 10; // Resize all scaled elements for (var i=0; i Date: Mon, 23 Jan 2012 15:14:47 -0800 Subject: [PATCH 099/263] Add call for key events, refactor to onkeydown and onkeyup. --- .../src/main/resources/oskeyboard.js | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 91f32417a..69d71a4b9 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -208,9 +208,24 @@ Guacamole.OnScreenKeyboard = function(url) { // Get content of key cap var content = e.textContent; + // Get keysym + var real_keysym = null; + if (keysym) + real_keysym = parseInt(keysym.value); + + // 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, - keysym ? keysym.value : null); + var cap = new Guacamole.OnScreenKeyboard.Cap(content, real_keysym); if (modifier) cap.modifier = modifier.value; @@ -279,14 +294,23 @@ Guacamole.OnScreenKeyboard = function(url) { } - // TODO: Send key event + if (on_screen_keyboard.onkeydown && cap.keysym) + on_screen_keyboard.onkeydown(cap.keysym); }; key_element.onmouseup = key_element.onmouseout = key_element.ontouchend = function() { + + // Get current cap based on modifier state + var cap = key.getCap(on_screen_keyboard.modifiers); + key_element.classList.remove("guac-keyboard-pressed"); + + if (on_screen_keyboard.onkeyup && cap.keysym) + on_screen_keyboard.onkeyup(cap.keysym); + }; } @@ -359,8 +383,8 @@ Guacamole.OnScreenKeyboard = function(url) { */ this.modifiers = 0; - this.onkeypressed = null; - this.onkeyreleased = null; + this.onkeydown = null; + this.onkeyup = null; this.getElement = function() { return keyboard; From 4aef4fe8043eac59ad8e04c3e7edded8fbd9a7f3 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 23 Jan 2012 15:18:16 -0800 Subject: [PATCH 100/263] Added DTD for keyboard XML. --- guacamole-common-js/doc/guacamole-osk.dtd | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 guacamole-common-js/doc/guacamole-osk.dtd diff --git a/guacamole-common-js/doc/guacamole-osk.dtd b/guacamole-common-js/doc/guacamole-osk.dtd new file mode 100644 index 000000000..e3a468980 --- /dev/null +++ b/guacamole-common-js/doc/guacamole-osk.dtd @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + From 692186f0c9162731a992740024176c4cf95fdf7e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 23 Jan 2012 15:24:35 -0800 Subject: [PATCH 101/263] Track pressed status of keys. Only release/press keys if not already in that status. --- .../src/main/resources/oskeyboard.js | 71 ++++++++++++------- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 69d71a4b9..8fc3b3692 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -269,47 +269,65 @@ Guacamole.OnScreenKeyboard = function(url) { key_element.onmousedown = key_element.ontouchstart = function() { - key_element.classList.add("guac-keyboard-pressed"); + // Press key if not yet pressed + if (!key.pressed) { - // Get current cap based on modifier state - var cap = key.getCap(on_screen_keyboard.modifiers); + key_element.classList.add("guac-keyboard-pressed"); - // Update modifier state - if (cap.modifier) { + // Get current cap based on modifier state + var cap = key.getCap(on_screen_keyboard.modifiers); - // Construct classname for modifier - var modifierClass = "guac-keyboard-modifier-" + cap.modifier; - var modifierFlag = getModifier(cap.modifier); + // Update modifier state + if (cap.modifier) { - // Toggle modifier state - on_screen_keyboard.modifiers ^= modifierFlag; + // Construct classname for modifier + var modifierClass = "guac-keyboard-modifier-" + cap.modifier; + var modifierFlag = getModifier(cap.modifier); - // Activate modifier if pressed - if (on_screen_keyboard.modifiers & modifierFlag) - keyboard.classList.add(modifierClass); + // Toggle modifier state + on_screen_keyboard.modifiers ^= modifierFlag; - // Deactivate if not pressed - else - keyboard.classList.remove(modifierClass); + // Activate modifier if pressed + if (on_screen_keyboard.modifiers & modifierFlag) + keyboard.classList.add(modifierClass); + + // Deactivate if not pressed + else + keyboard.classList.remove(modifierClass); + + } + + // Send key event + if (on_screen_keyboard.onkeydown && cap.keysym) + on_screen_keyboard.onkeydown(cap.keysym); + + // Mark key as pressed + key.pressed = true; } - if (on_screen_keyboard.onkeydown && cap.keysym) - on_screen_keyboard.onkeydown(cap.keysym); - }; key_element.onmouseup = key_element.onmouseout = key_element.ontouchend = function() { - // Get current cap based on modifier state - var cap = key.getCap(on_screen_keyboard.modifiers); + // Release key if currently pressed + if (key.pressed) { - key_element.classList.remove("guac-keyboard-pressed"); + // Get current cap based on modifier state + var cap = key.getCap(on_screen_keyboard.modifiers); - if (on_screen_keyboard.onkeyup && cap.keysym) - on_screen_keyboard.onkeyup(cap.keysym); + key_element.classList.remove("guac-keyboard-pressed"); + + // Send key event + if (on_screen_keyboard.onkeyup && cap.keysym) + on_screen_keyboard.onkeyup(cap.keysym); + + // Mark key as released + key.pressed = false; + + } }; @@ -409,6 +427,11 @@ 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. */ From 8cc8ad9e5eef60aad041d3748cbfbc734de99a42 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 24 Jan 2012 22:56:53 -0800 Subject: [PATCH 102/263] Handle events via addEventListener(). This solves an issue with touch events firing twice (they were firing once for bubble and once for capture). With addEventListener(), they fire once. --- .../src/main/resources/oskeyboard.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 8fc3b3692..d940a9f4b 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -266,8 +266,7 @@ Guacamole.OnScreenKeyboard = function(url) { row.appendChild(key_container_element); // Set up click handler for key - key_element.onmousedown = - key_element.ontouchstart = function() { + function press(e) { // Press key if not yet pressed if (!key.pressed) { @@ -306,11 +305,14 @@ Guacamole.OnScreenKeyboard = function(url) { } + e.preventDefault(); + }; - key_element.onmouseup = - key_element.onmouseout = - key_element.ontouchend = function() { + key_element.addEventListener("mousedown", press, true); + key_element.addEventListener("touchstart", press, true); + + function release(e) { // Release key if currently pressed if (key.pressed) { @@ -329,8 +331,14 @@ Guacamole.OnScreenKeyboard = function(url) { } + e.preventDefault(); + }; + key_element.addEventListener("mouseup", release, true); + key_element.addEventListener("mouseout", release, true); + key_element.addEventListener("touchend", release, true); + } }); From 684dcdd33fb8ebd694b4e060971b5d5a166a607a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 26 Jan 2012 11:48:19 -0800 Subject: [PATCH 103/263] Properly block source layer until copy to destination is complete. --- .../src/main/resources/layer.js | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index a8539b01a..64ee9a75b 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -410,6 +410,7 @@ Guacamole.Layer = function(width, height) { */ this.copyRect = function(srcLayer, srcx, srcy, srcw, srch, x, y) { + var drawComplete = false; var srcLock = null; function doCopyRect() { @@ -419,9 +420,12 @@ Guacamole.Layer = function(width, height) { if (srcCanvas.width != 0 && srcCanvas.height != 0) displayContext.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch); - // Unblock the copy complete task, if it exists + // Unblock the source layer now that draw is complete if (srcLock != null) srcLock.unblock(); + + // Flag operation as done + drawComplete = true; } // If we ARE the source layer, no need to sync. @@ -432,17 +436,19 @@ Guacamole.Layer = function(width, height) { // Otherwise synchronize copy operation with source layer else { - // Task which will be unblocked only when the source layer is ready - // This task will perform the copy + // Currently blocked draw task var task = scheduleTask(doCopyRect, true); - // Task which will unblock the drawing task. - var srcReady = srcLayer.sync(task.unblock); + // Unblock draw task once source layer is ready + srcLayer.sync(task.unblock); - // Task which will be unblocked only after the copy has - // occurred (this will only be created if the draw task - // was postponed) - if (srcReady != null) srcLock = srcLayer.sync(null, true); + // Block source layer until draw completes + // Note that the draw MAY have already been performed at this point, + // in which case creating a lock on the source layer will lead to + // deadlock (the draw task has already run and will thus never + // clear the lock) + if (!drawComplete) + srcLock = srcLayer.sync(null, true); } From 0209bf448a42018d4f15dd01e5ae25050c34d0db Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 30 Jan 2012 00:53:13 -0800 Subject: [PATCH 104/263] Synchronize layers properly in copy. --- guacamole-common-js/src/main/resources/layer.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 64ee9a75b..ee986a5e0 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -246,8 +246,8 @@ Guacamole.Layer = function(width, height) { function scheduleTask(handler, blocked) { // If no pending tasks, just call (if available) and exit - if (layer.isReady() && !blocked && handler != null) { - handler(); + if (layer.isReady() && !blocked) { + if (handler) handler(); return null; } @@ -382,10 +382,9 @@ Guacamole.Layer = function(width, height) { * * @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 = function(handler) { - return scheduleTask(handler); - }; + this.sync = scheduleTask; /** * Copy a rectangle of image data from one Layer to this Layer. This From 902cef5db68ecda6550b52b086becf1602c397c7 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 9 Feb 2012 10:01:55 -0800 Subject: [PATCH 105/263] Must only check response if readyState >= 2. --- guacamole-common-js/src/main/resources/tunnel.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 618734e82..ec3e47510 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -223,6 +223,9 @@ Guacamole.HTTPTunnel = function(tunnelURL) { return; } + // Do not parse response yet if not ready + if (xmlhttprequest.readyState < 2) return; + // Attempt to read status var status; try { status = xmlhttprequest.status; } @@ -231,7 +234,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) { catch (e) { status = 200; } // Start next request as soon as possible IF request was successful - if (xmlhttprequest.readyState >= 2 && nextRequest == null && status == 200) + if (nextRequest == null && status == 200) nextRequest = makeRequest(); // Parse stream when data is received and when complete. From 776054e33b7cccd7aaee1e462f32c49a3ab5c589 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 9 Feb 2012 10:43:25 -0800 Subject: [PATCH 106/263] Correct description of touch support. --- guacamole-common-js/src/main/resources/mouse.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 9c6537c15..26cefa093 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -44,8 +44,8 @@ var Guacamole = Guacamole || {}; * mouse events into a non-browser-specific event provided by the * Guacamole.Mouse instance. * - * Touch event support is planned, but currently only in testing (translate - * touch events into mouse events). + * 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 mouse events. From ceca1570b08db5d6a811ee164d8e0bf228d71d4a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 11 Feb 2012 22:00:18 -0800 Subject: [PATCH 107/263] Modify to support new size instruction format (stub). --- guacamole-common-js/src/main/resources/guacamole.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 0a1b72c52..129d469ad 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -261,8 +261,9 @@ Guacamole.Client = function(display, tunnel) { "size": function(parameters) { - displayWidth = parseInt(parameters[0]); - displayHeight = parseInt(parameters[1]); + var layer = getLayer(parseInt(parameters[0])); /* FIXME: Implement */ + displayWidth = parseInt(parameters[1]); + displayHeight = parseInt(parameters[2]); // Update (set) display size display.style.width = displayWidth + "px"; From 2b342c38641148553bd846b699c7028448c5cdec Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 14 Feb 2012 20:46:48 -0800 Subject: [PATCH 108/263] Initial support for move instruction and layer containers. --- .../src/main/resources/guacamole.js | 297 ++++++++++++------ 1 file changed, 202 insertions(+), 95 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 129d469ad..e126348fe 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -38,17 +38,17 @@ // Guacamole 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 {Element} display The display element to add canvas elements to. * @param {Guacamole.Tunnel} tunnel The tunnel to use to send and receive * Guacamole instructions. */ -Guacamole.Client = function(display, tunnel) { +Guacamole.Client = function(tunnel) { var guac_client = this; @@ -64,14 +64,36 @@ Guacamole.Client = function(display, tunnel) { var currentTimestamp = 0; var pingInterval = null; + var displayWidth = 0; + var displayHeight = 0; + + // Create display + var display = document.createElement("div"); + display.style.position = "relative"; + display.style.width = displayWidth + "px"; + display.style.height = displayHeight + "px"; + + // Create default layer + var default_layer_container = new Guacamole.Client.LayerContainer(displayWidth, displayHeight); + + // Create cursor layer + var cursor = new Guacamole.Client.LayerContainer(displayWidth, displayHeight); + + // Add default layer and cursor to display + display.appendChild(default_layer_container.getElement()); + display.appendChild(cursor.getElement()); + + // 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); }; - // Display must be relatively positioned for mouse to be handled properly - display.style.position = "relative"; - function setState(state) { if (state != currentState) { currentState = state; @@ -115,8 +137,13 @@ Guacamole.Client = function(display, tunnel) { // Draw new cursor cursor.drawImage(cursorRectX, cursorRectY, cursorImage); + } + guac_client.getDisplay = function() { + return display; + }; + guac_client.sendKeyEvent = function(pressed, keysym) { // Do not send requests if not connected if (!isConnected()) @@ -167,80 +194,54 @@ Guacamole.Client = function(display, tunnel) { guac_client.onclipboard = null; // Layers - var displayWidth = 0; - var displayHeight = 0; + function getBufferLayer(index) { - var layers = new Array(); - var buffers = new Array(); - var cursor = null; + index = -1 - index; + var buffer = buffers[index]; - guac_client.getLayers = function() { - return layers; - }; + // 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"; + + // 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); - // If negative index, use buffer - if (index < 0) { - - 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; - } - - // If non-negative, use visible layer - else { - - var layer = layers[index]; - if (layer == null) { - - // Add new layer - layer = new Guacamole.Layer(displayWidth, displayHeight); - - // Set layer position - var canvas = layer.getCanvas(); - canvas.style.position = "absolute"; - canvas.style.left = "0px"; - canvas.style.top = "0px"; - - layers[index] = layer; - - // (Re)-add existing layers in order - for (var i=0; i= 0) { - // Set cursor layer width/height - if (cursor != null) - cursor.resize(displayWidth, displayHeight); + // 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"; + + // Set cursor layer width/height + if (cursor != null) + cursor.resize(displayWidth, displayHeight); + + } + + } // end if layer (not buffer) + + }, + + "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).getElement(); + var parent = getLayerContainer(parent_index).getElement(); + + // Set parent if necessary + if (!(layer_container.parentNode === parent)) + parent.appendChild(layer_container); + + // Move layer + layer_container.style.left = x + "px"; + layer_container.style.top = y + "px"; + layer_container.style.zIndex = z; + + } }, @@ -363,17 +409,6 @@ Guacamole.Client = function(display, tunnel) { var y = parseInt(parameters[1]); var data = parameters[2]; - if (cursor == null) { - cursor = new Guacamole.Layer(displayWidth, displayHeight); - - var canvas = cursor.getCanvas(); - canvas.style.position = "absolute"; - canvas.style.left = "0px"; - canvas.style.top = "0px"; - - display.appendChild(canvas); - } - // Start cursor image load var image = new Image(); image.onload = function() { @@ -416,7 +451,7 @@ Guacamole.Client = function(display, tunnel) { // Count active, not-ready layers and install sync tracking hooks for (var i=0; i Date: Tue, 14 Feb 2012 21:11:38 -0800 Subject: [PATCH 109/263] Move cursor layer, rather than redrawing cursor image. --- .../src/main/resources/guacamole.js | 64 +++++++------------ 1 file changed, 23 insertions(+), 41 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index e126348fe..946197880 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -75,9 +75,17 @@ Guacamole.Client = function(tunnel) { // Create default layer var default_layer_container = new Guacamole.Client.LayerContainer(displayWidth, displayHeight); + 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"; // Create cursor layer - var cursor = new Guacamole.Client.LayerContainer(displayWidth, displayHeight); + var cursor = new Guacamole.Client.LayerContainer(0, 0); + 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()); @@ -107,18 +115,14 @@ Guacamole.Client = function(tunnel) { || currentState == STATE_WAITING; } - var cursorImage = null; var cursorHotspotX = 0; var cursorHotspotY = 0; - var cursorRectX = 0; - var cursorRectY = 0; - var cursorRectW = 0; - var cursorRectH = 0; - var cursorHidden = 0; - function redrawCursor(x, y) { + function moveCursor(x, y) { + + var element = cursor.getElement(); // Hide hardware cursor if (cursorHidden == 0) { @@ -126,17 +130,9 @@ Guacamole.Client = function(tunnel) { cursorHidden = 1; } - // Erase old cursor - cursor.clearRect(cursorRectX, cursorRectY, cursorRectW, cursorRectH); - // Update rect - cursorRectX = x - cursorHotspotX; - cursorRectY = y - cursorHotspotY; - cursorRectW = cursorImage.width; - cursorRectH = cursorImage.height; - - // Draw new cursor - cursor.drawImage(cursorRectX, cursorRectY, cursorImage); + element.style.left = (x - cursorHotspotX) + "px"; + element.style.top = (y - cursorHotspotY) + "px"; } @@ -158,13 +154,11 @@ Guacamole.Client = function(tunnel) { if (!isConnected()) return; - // Draw client-side cursor - if (cursorImage != null) { - redrawCursor( - mouseState.x, - mouseState.y - ); - } + // Update client-side cursor + moveCursor( + mouseState.x, + mouseState.y + ); // Build mask var buttonMask = 0; @@ -405,24 +399,12 @@ Guacamole.Client = function(tunnel) { "cursor": function(parameters) { - var x = parseInt(parameters[0]); - var y = parseInt(parameters[1]); + cursorHotspotX = parseInt(parameters[0]); + cursorHotspotY = parseInt(parameters[1]); var data = parameters[2]; - // Start cursor image load - var image = new Image(); - image.onload = function() { - cursorImage = image; - - var cursorX = cursorRectX + cursorHotspotX; - var cursorY = cursorRectY + cursorHotspotY; - - cursorHotspotX = x; - cursorHotspotY = y; - - redrawCursor(cursorX, cursorY); - }; - image.src = "data:image/png;base64," + data + // Draw cursor to cursor layer + cursor.draw(0, 0, "data:image/png;base64," + data); }, From 8cd1b3a857c954a64caa45918a0952bf5409f541 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 14 Feb 2012 22:58:52 -0800 Subject: [PATCH 110/263] Added pre-defined channel mask constants. Setting cursor layer to Guacamole.Layer.SRC. --- .../src/main/resources/guacamole.js | 5 ++ .../src/main/resources/layer.js | 70 +++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 946197880..6c650ac6c 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -75,6 +75,8 @@ Guacamole.Client = function(tunnel) { // 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"; @@ -82,6 +84,9 @@ Guacamole.Client = function(tunnel) { // 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"; diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index ee986a5e0..fe93e2b63 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -38,6 +38,76 @@ // Guacamole namespace var Guacamole = Guacamole || {}; +/** + * 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; + /** * Abstract ordered drawing surface. Each Layer contains a canvas element and * provides simple drawing instructions for drawing to that canvas element, From 663a3544ce969b4841d862f8e3cb09bc9de95397 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 14 Feb 2012 23:07:39 -0800 Subject: [PATCH 111/263] Wrong location for declaration. --- .../src/main/resources/layer.js | 141 +++++++++--------- 1 file changed, 71 insertions(+), 70 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index fe93e2b63..8ec163394 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -38,76 +38,6 @@ // Guacamole namespace var Guacamole = Guacamole || {}; -/** - * 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; - /** * Abstract ordered drawing surface. Each Layer contains a canvas element and * provides simple drawing instructions for drawing to that canvas element, @@ -632,3 +562,74 @@ Guacamole.Layer = function(width, height) { 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; + From f6bf6c4aaa8ab2906e6dc38fadecb23f497cd38f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 15 Feb 2012 10:10:49 -0800 Subject: [PATCH 112/263] Support for new buffered cursor instruction. --- .../src/main/resources/guacamole.js | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 6c650ac6c..3881c154f 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -282,10 +282,6 @@ Guacamole.Client = function(tunnel) { display.style.width = displayWidth + "px"; display.style.height = displayHeight + "px"; - // Set cursor layer width/height - if (cursor != null) - cursor.resize(displayWidth, displayHeight); - } } // end if layer (not buffer) @@ -406,10 +402,27 @@ Guacamole.Client = function(tunnel) { cursorHotspotX = parseInt(parameters[0]); cursorHotspotY = parseInt(parameters[1]); - var data = parameters[2]; + 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.draw(0, 0, "data:image/png;base64," + data); + cursor.getLayer().copyRect( + srcL, + srcX, + srcY, + srcWidth, + srcHeight, + 0, + 0 + ); + + // FIXME: Update cursor position when hotspot changes }, From ebc5caac284624cb65bd1ff57ef8abe759f9bb43 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 15 Feb 2012 10:17:27 -0800 Subject: [PATCH 113/263] Application should hide cursor. Do not require CSS class definitions. --- guacamole-common-js/src/main/resources/guacamole.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 3881c154f..a9fcbed40 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -123,18 +123,10 @@ Guacamole.Client = function(tunnel) { var cursorHotspotX = 0; var cursorHotspotY = 0; - var cursorHidden = 0; - function moveCursor(x, y) { var element = cursor.getElement(); - // Hide hardware cursor - if (cursorHidden == 0) { - display.className += " guac-hide-cursor"; - cursorHidden = 1; - } - // Update rect element.style.left = (x - cursorHotspotX) + "px"; element.style.top = (y - cursorHotspotY) + "px"; From 3019b4d5cdc6024b5fd1c28ea01bd5ce198edef2 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 15 Feb 2012 12:26:56 -0800 Subject: [PATCH 114/263] Layer should preserve composite operation through resize. --- guacamole-common-js/src/main/resources/layer.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 8ec163394..a38ffe892 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -116,7 +116,6 @@ Guacamole.Layer = function(width, height) { */ function resize(newWidth, newHeight) { - // Only preserve old data if width/height are both non-zero var oldData = null; if (width != 0 && height != 0) { @@ -135,6 +134,9 @@ Guacamole.Layer = function(width, height) { } + // Preserve composite operation + var oldCompositeOperation = displayContext.globalCompositeOperation; + // Resize canvas display.width = newWidth; display.height = newHeight; @@ -145,8 +147,12 @@ Guacamole.Layer = function(width, height) { 0, 0, width, height, 0, 0, width, height); + // Restore composite operation + displayContext.globalCompositeOperation = oldCompositeOperation; + width = newWidth; height = newHeight; + } /** From 5c92d65234962f76b2071de5dd391faec19f47e7 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 20 Feb 2012 12:48:26 -0800 Subject: [PATCH 115/263] Implement dispose instruction. --- .../src/main/resources/guacamole.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index a9fcbed40..7f474ac83 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -308,6 +308,32 @@ Guacamole.Client = function(tunnel) { }, + "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. + + }, + "png": function(parameters) { var channelMask = parseInt(parameters[0]); From 3f2a79fd0f7cabf3db8bf76b0759948d4216f012 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 22 Feb 2012 15:14:27 -0800 Subject: [PATCH 116/263] Use addEventListener() for mouse, fix handling of mouseout. --- .../src/main/resources/mouse.js | 85 ++++++++++--------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 26cefa093..8cb597967 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -97,6 +97,12 @@ Guacamole.Mouse = function(element) { */ this.onmousemove = null; + function cancelEvent(e) { + e.stopPropagation(); + if (e.preventDefault) e.preventDefault(); + e.returnValue = false; + } + function moveMouse(pageX, pageY) { guac_mouse.currentState.x = pageX - element.offsetLeft; @@ -119,20 +125,20 @@ Guacamole.Mouse = function(element) { // Block context menu so right-click gets sent properly - element.oncontextmenu = function(e) { - return false; - }; + element.addEventListener("contextmenu", function(e) { + cancelEvent(e); + }, false); - element.onmousemove = function(e) { + element.addEventListener("mousemove", function(e) { // Don't handle if we aren't supposed to if (gesture_in_progress) return; - e.stopPropagation(); + cancelEvent(e); moveMouse(e.pageX, e.pageY); - }; + }, false); var last_touch_x = 0; var last_touch_y = 0; @@ -142,13 +148,12 @@ Guacamole.Mouse = function(element) { var gesture_in_progress = false; var click_release_timeout = null; - element.ontouchend = function(e) { + element.addEventListener("touchend", function(e) { // If we're handling a gesture if (gesture_in_progress) { - e.stopPropagation(); - e.preventDefault(); + cancelEvent(e); var time = new Date().getTime(); @@ -194,16 +199,15 @@ Guacamole.Mouse = function(element) { } - }; + }, false); - element.ontouchstart = function(e) { + element.addEventListener("touchstart", function(e) { // Record initial touch location and time for single-touch movement // and tap gestures if (e.touches.length == 1) { - e.stopPropagation(); - e.preventDefault(); + cancelEvent(e); // Stop mouse events while touching gesture_in_progress = true; @@ -225,15 +229,14 @@ Guacamole.Mouse = function(element) { } - }; + }, false); - element.ontouchmove = function(e) { + element.addEventListener("touchmove", function(e) { // Handle single-touch movement gesture (touchpad mouse move) if (e.touches.length == 1) { - e.stopPropagation(); - e.preventDefault(); + cancelEvent(e); // Get change in touch location var touch = e.touches[0]; @@ -269,15 +272,15 @@ Guacamole.Mouse = function(element) { } - }; + }, false); - element.onmousedown = function(e) { + element.addEventListener("mousedown", function(e) { // Don't handle if we aren't supposed to if (gesture_in_progress) return; - e.stopPropagation(); + cancelEvent(e); switch (e.button) { case 0: @@ -294,15 +297,15 @@ Guacamole.Mouse = function(element) { if (guac_mouse.onmousedown) guac_mouse.onmousedown(guac_mouse.currentState); - }; + }, false); - element.onmouseup = function(e) { + element.addEventListener("mouseup", function(e) { // Don't handle if we aren't supposed to if (gesture_in_progress) return; - e.stopPropagation(); + cancelEvent(e); switch (e.button) { case 0: @@ -319,14 +322,25 @@ Guacamole.Mouse = function(element) { if (guac_mouse.onmouseup) guac_mouse.onmouseup(guac_mouse.currentState); - }; + }, false); - element.onmouseout = function(e) { + element.addEventListener("mouseout", function(e) { // Don't handle if we aren't supposed to if (gesture_in_progress) return; - e.stopPropagation(); + // 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 @@ -341,15 +355,15 @@ Guacamole.Mouse = function(element) { guac_mouse.onmouseup(guac_mouse.currentState); } - }; + }, true); // Override selection on mouse event element. - element.onselectstart = function() { - return false; - }; + element.addEventListener("selectstart", function(e) { + cancelEvent(e); + }, false); // Scroll wheel support - element.onmousewheel = function(e) { + element.addEventListener('DOMMouseScroll', function(e) { // Don't handle if we aren't supposed to if (gesture_in_progress) return; @@ -386,14 +400,9 @@ Guacamole.Mouse = function(element) { } } - if (e.preventDefault) - e.preventDefault(); + cancelEvent(e); - e.returnValue = false; - - }; - - element.addEventListener('DOMMouseScroll', element.onmousewheel, false); + }, false); }; From 27ec480ccb9fa09c5ec0786c8eb2fe0da805f5af Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 22 Feb 2012 15:23:10 -0800 Subject: [PATCH 117/263] No capture for anything. --- guacamole-common-js/src/main/resources/mouse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 8cb597967..7d01d7b68 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -355,7 +355,7 @@ Guacamole.Mouse = function(element) { guac_mouse.onmouseup(guac_mouse.currentState); } - }, true); + }, false); // Override selection on mouse event element. element.addEventListener("selectstart", function(e) { From 4e91f312ed7d8aefee2dc7e7488e9b98af867209 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 23 Feb 2012 10:23:36 -0800 Subject: [PATCH 118/263] Fix mousewheel support. --- guacamole-common-js/src/main/resources/mouse.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 7d01d7b68..f648602ba 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -363,7 +363,7 @@ Guacamole.Mouse = function(element) { }, false); // Scroll wheel support - element.addEventListener('DOMMouseScroll', function(e) { + function mousewheel_handler(e) { // Don't handle if we aren't supposed to if (gesture_in_progress) return; @@ -402,7 +402,9 @@ Guacamole.Mouse = function(element) { cancelEvent(e); - }, false); + } + element.addEventListener('DOMMouseScroll', mousewheel_handler, false); + element.addEventListener('mousewheel', mousewheel_handler, false); }; From d1496d7375cb6ca422690522d88a85065f17d73d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 23 Feb 2012 11:22:15 -0800 Subject: [PATCH 119/263] Update cursor position when cursor image/hotspot is updated. --- guacamole-common-js/src/main/resources/guacamole.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 7f474ac83..ea5f87508 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -123,6 +123,9 @@ Guacamole.Client = function(tunnel) { var cursorHotspotX = 0; var cursorHotspotY = 0; + var cursorX = 0; + var cursorY = 0; + function moveCursor(x, y) { var element = cursor.getElement(); @@ -131,6 +134,10 @@ Guacamole.Client = function(tunnel) { element.style.left = (x - cursorHotspotX) + "px"; element.style.top = (y - cursorHotspotY) + "px"; + // Update stored position + cursorX = x; + cursorY = y; + } guac_client.getDisplay = function() { @@ -440,7 +447,8 @@ Guacamole.Client = function(tunnel) { 0 ); - // FIXME: Update cursor position when hotspot changes + // Update cursor position (hotspot may have changed) + moveCursor(cursorX, cursorY); }, From aedc40691ed64a6623a524a9d505eb9db5250cfd Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 23 Feb 2012 13:27:08 -0800 Subject: [PATCH 120/263] Bumped version to 0.6.0 --- guacamole-common-js/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/pom.xml b/guacamole-common-js/pom.xml index d0e3f1d31..5e8ee9a9b 100644 --- a/guacamole-common-js/pom.xml +++ b/guacamole-common-js/pom.xml @@ -5,7 +5,7 @@ net.sourceforge.guacamole guacamole-common-js pom - 0.5.0 + 0.6.0 guacamole-common-js http://guacamole.sourceforge.net/ From 7011f650c5223b30999db668d2e1d82f806db44e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 27 Feb 2012 11:20:25 -0800 Subject: [PATCH 121/263] Implement raster operations as transfer functions, rename setChannelMask to setCompositeOperation, supporting both channel masks and binary raster operations. --- .../src/main/resources/layer.js | 68 ++++++++++++++++--- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index a38ffe892..790fd013d 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -74,6 +74,12 @@ Guacamole.Layer = function(width, height) { var displayContext = display.getContext("2d"); displayContext.save(); + /** + * The function to apply when drawing arbitrary source pixels over + * destination pixels. + */ + var transferFunction = null; + /** * 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 @@ -106,6 +112,36 @@ Guacamole.Layer = function(width, height) { 0xF: "lighter" }; + /** + * Map of all Guacamole binary raster operations to transfer functions. + * @private + */ + var binaryCompositeTransferFunction = { + + 0x10: function (src, dst) { return 0x00; }, /* BLACK */ + 0x1F: function (src, dst) { return 0xFF; }, /* WHITE */ + + 0x13: function (src, dst) { return src; }, /* SRC */ + 0x15: function (src, dst) { return dst; }, /* DEST */ + 0x1C: function (src, dst) { return ~src; }, /* NSRC */ + 0x1A: function (src, dst) { return ~dst; }, /* NDEST */ + + 0x11: function (src, dst) { return src & dst; }, /* AND */ + 0x1E: function (src, dst) { return ~(src & dst); }, /* NAND */ + + 0x17: function (src, dst) { return src | dst; }, /* OR */ + 0x18: function (src, dst) { return ~(src | dst); }, /* NOR */ + + 0x16: function (src, dst) { return src ^ dst; }, /* XOR */ + 0x19: function (src, dst) { return ~(src ^ dst); }, /* XNOR */ + + 0x14: function (src, dst) { return ~src & dst; }, /* AND inverted source */ + 0x1D: function (src, dst) { return ~src | dst; }, /* OR inverted source */ + 0x12: function (src, dst) { return src & ~dst; }, /* AND inverted destination */ + 0x1B: function (src, dst) { return src | ~dst; } /* OR inverted destination */ + + }; + /** * Resizes the canvas element backing this Layer without testing the * new size. This function should only be used internally. @@ -547,19 +583,35 @@ Guacamole.Layer = function(width, height) { }; /** - * 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, + * Sets the composite operation for future operations on this Layer. This + * operation is either a channel mask, or the ID of a binary raster + * operation. + * + * 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. + * @param {Number} operation The composite operation (channel mask or binary + * raster operation) for future operations on this + * Layer. */ - this.setChannelMask = function(mask) { + this.setCompositeOperation = function(operation) { scheduleTask(function() { - displayContext.globalCompositeOperation = compositeOperation[mask]; + + // If channel mask, set composite operation only + if (operation <= 0xF) { + displayContext.globalCompositeOperation = compositeOperation[operation]; + transferFunction = null; + } + + // Otherwise, set binary raster operation + else { + displayContext.globalCompositeOperation = "source-over"; + transferFunction = binaryCompositeTransferFunction[operation]; + } + }); }; From 6bfa0d7ea177cd9ffff14e5af132e99e78a7322b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 27 Feb 2012 11:35:02 -0800 Subject: [PATCH 122/263] Use transfer function within copy, if set. --- .../src/main/resources/layer.js | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 790fd013d..2938f76ac 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -458,8 +458,29 @@ Guacamole.Layer = function(width, height) { 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); + if (srcCanvas.width != 0 && srcCanvas.height != 0) { + + // Just copy if no transfer function + if (!transferFunction) + displayContext.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch); + + // Otherwise, copy via transfer function + else { + + // 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 Date: Mon, 27 Feb 2012 11:41:28 -0800 Subject: [PATCH 123/263] Use composite operation instead of channel mask. --- guacamole-common-js/src/main/resources/guacamole.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index ea5f87508..345a9724d 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -84,7 +84,7 @@ Guacamole.Client = function(tunnel) { // Create cursor layer var cursor = new Guacamole.Client.LayerContainer(0, 0); - cursor.getLayer().setChannelMask(Guacamole.Layer.SRC); + cursor.getLayer().setCompositeOperation(Guacamole.Layer.SRC); // Position cursor layer var cursor_element = cursor.getElement(); @@ -349,7 +349,7 @@ Guacamole.Client = function(tunnel) { var y = parseInt(parameters[3]); var data = parameters[4]; - layer.setChannelMask(channelMask); + layer.setCompositeOperation(channelMask); layer.draw( x, @@ -375,7 +375,7 @@ Guacamole.Client = function(tunnel) { var dstX = parseInt(parameters[7]); var dstY = parseInt(parameters[8]); - dstL.setChannelMask(channelMask); + dstL.setCompositeOperation(channelMask); dstL.copyRect( srcL, @@ -402,7 +402,7 @@ Guacamole.Client = function(tunnel) { var b = parseInt(parameters[8]); var a = parseInt(parameters[9]); - layer.setChannelMask(channelMask); + layer.setCompositeOperation(channelMask); layer.drawRect( x, y, w, h, From 02e1333e5876804852c067b0a6d08bd4e04c1d4e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 27 Feb 2012 12:23:38 -0800 Subject: [PATCH 124/263] Initial refactor of raster operations to real transfer functions. --- .../src/main/resources/guacamole.js | 63 ++++++- .../src/main/resources/layer.js | 166 +++++++++--------- 2 files changed, 146 insertions(+), 83 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 345a9724d..0d3dde78f 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -67,6 +67,36 @@ Guacamole.Client = function(tunnel) { var displayWidth = 0; var displayHeight = 0; + /** + * Map of all Guacamole binary raster operations to transfer functions. + * @private + */ + var transferFunctions = { + + 0x10: function (src, dst) { return 0x00; }, /* BLACK */ + 0x1F: function (src, dst) { return 0xFF; }, /* WHITE */ + + 0x13: function (src, dst) { return src; }, /* SRC */ + 0x15: function (src, dst) { return dst; }, /* DEST */ + 0x1C: function (src, dst) { return ~src; }, /* NSRC */ + 0x1A: function (src, dst) { return ~dst; }, /* NDEST */ + + 0x11: function (src, dst) { return src & dst; }, /* AND */ + 0x1E: function (src, dst) { return ~(src & dst); }, /* NAND */ + + 0x17: function (src, dst) { return src | dst; }, /* OR */ + 0x18: function (src, dst) { return ~(src | dst); }, /* NOR */ + + 0x16: function (src, dst) { return src ^ dst; }, /* XOR */ + 0x19: function (src, dst) { return ~(src ^ dst); }, /* XNOR */ + + 0x14: function (src, dst) { return ~src & dst; }, /* AND inverted source */ + 0x1D: function (src, dst) { return ~src | dst; }, /* OR inverted source */ + 0x12: function (src, dst) { return src & ~dst; }, /* AND inverted destination */ + 0x1B: function (src, dst) { return src | ~dst; } /* OR inverted destination */ + + }; + // Create display var display = document.createElement("div"); display.style.position = "relative"; @@ -84,7 +114,7 @@ Guacamole.Client = function(tunnel) { // Create cursor layer var cursor = new Guacamole.Client.LayerContainer(0, 0); - cursor.getLayer().setCompositeOperation(Guacamole.Layer.SRC); + cursor.getLayer().setChannelMask(Guacamole.Layer.SRC); // Position cursor layer var cursor_element = cursor.getElement(); @@ -349,7 +379,7 @@ Guacamole.Client = function(tunnel) { var y = parseInt(parameters[3]); var data = parameters[4]; - layer.setCompositeOperation(channelMask); + layer.setChannelMask(channelMask); layer.draw( x, @@ -375,7 +405,7 @@ Guacamole.Client = function(tunnel) { var dstX = parseInt(parameters[7]); var dstY = parseInt(parameters[8]); - dstL.setCompositeOperation(channelMask); + dstL.setChannelMask(channelMask); dstL.copyRect( srcL, @@ -389,6 +419,31 @@ Guacamole.Client = function(tunnel) { }, + "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 = transferFunctions[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 + ); + + }, + "rect": function(parameters) { var channelMask = parseInt(parameters[0]); @@ -402,7 +457,7 @@ Guacamole.Client = function(tunnel) { var b = parseInt(parameters[8]); var a = parseInt(parameters[9]); - layer.setCompositeOperation(channelMask); + layer.setChannelMask(channelMask); layer.drawRect( x, y, w, h, diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 2938f76ac..32faa322c 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -74,12 +74,6 @@ Guacamole.Layer = function(width, height) { var displayContext = display.getContext("2d"); displayContext.save(); - /** - * The function to apply when drawing arbitrary source pixels over - * destination pixels. - */ - var transferFunction = null; - /** * 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 @@ -112,36 +106,6 @@ Guacamole.Layer = function(width, height) { 0xF: "lighter" }; - /** - * Map of all Guacamole binary raster operations to transfer functions. - * @private - */ - var binaryCompositeTransferFunction = { - - 0x10: function (src, dst) { return 0x00; }, /* BLACK */ - 0x1F: function (src, dst) { return 0xFF; }, /* WHITE */ - - 0x13: function (src, dst) { return src; }, /* SRC */ - 0x15: function (src, dst) { return dst; }, /* DEST */ - 0x1C: function (src, dst) { return ~src; }, /* NSRC */ - 0x1A: function (src, dst) { return ~dst; }, /* NDEST */ - - 0x11: function (src, dst) { return src & dst; }, /* AND */ - 0x1E: function (src, dst) { return ~(src & dst); }, /* NAND */ - - 0x17: function (src, dst) { return src | dst; }, /* OR */ - 0x18: function (src, dst) { return ~(src | dst); }, /* NOR */ - - 0x16: function (src, dst) { return src ^ dst; }, /* XOR */ - 0x19: function (src, dst) { return ~(src ^ dst); }, /* XNOR */ - - 0x14: function (src, dst) { return ~src & dst; }, /* AND inverted source */ - 0x1D: function (src, dst) { return ~src | dst; }, /* OR inverted source */ - 0x12: function (src, dst) { return src & ~dst; }, /* AND inverted destination */ - 0x1B: function (src, dst) { return src | ~dst; } /* OR inverted destination */ - - }; - /** * Resizes the canvas element backing this Layer without testing the * new size. This function should only be used internally. @@ -428,6 +392,86 @@ Guacamole.Layer = function(width, height) { */ 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) { + + var drawComplete = false; + var srcLock = null; + + function doTransfer() { + 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 Date: Mon, 27 Feb 2012 12:36:25 -0800 Subject: [PATCH 125/263] Actually DRAW image data. --- guacamole-common-js/src/main/resources/layer.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 32faa322c..d1cbd06b9 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -436,6 +436,9 @@ Guacamole.Layer = function(width, height) { dst.data[i+3] = 0xFF; // Assume output opaque } + // Draw image data + displayContext.putImageData(dst, x, y); + } // Unblock the source layer now that draw is complete From 5eb316a3ba2befffd4b1f1aebcacf98ae9ee6a52 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 27 Feb 2012 13:23:07 -0800 Subject: [PATCH 126/263] Transfer functions on abstract pixels. --- .../src/main/resources/guacamole.js | 150 ++++++++++++++---- .../src/main/resources/layer.js | 69 +++++++- 2 files changed, 183 insertions(+), 36 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 0d3dde78f..b3a0b33b5 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -67,36 +67,6 @@ Guacamole.Client = function(tunnel) { var displayWidth = 0; var displayHeight = 0; - /** - * Map of all Guacamole binary raster operations to transfer functions. - * @private - */ - var transferFunctions = { - - 0x10: function (src, dst) { return 0x00; }, /* BLACK */ - 0x1F: function (src, dst) { return 0xFF; }, /* WHITE */ - - 0x13: function (src, dst) { return src; }, /* SRC */ - 0x15: function (src, dst) { return dst; }, /* DEST */ - 0x1C: function (src, dst) { return ~src; }, /* NSRC */ - 0x1A: function (src, dst) { return ~dst; }, /* NDEST */ - - 0x11: function (src, dst) { return src & dst; }, /* AND */ - 0x1E: function (src, dst) { return ~(src & dst); }, /* NAND */ - - 0x17: function (src, dst) { return src | dst; }, /* OR */ - 0x18: function (src, dst) { return ~(src | dst); }, /* NOR */ - - 0x16: function (src, dst) { return src ^ dst; }, /* XOR */ - 0x19: function (src, dst) { return ~(src ^ dst); }, /* XNOR */ - - 0x14: function (src, dst) { return ~src & dst; }, /* AND inverted source */ - 0x1D: function (src, dst) { return ~src | dst; }, /* OR inverted source */ - 0x12: function (src, dst) { return src & ~dst; }, /* AND inverted destination */ - 0x1B: function (src, dst) { return src | ~dst; } /* OR inverted destination */ - - }; - // Create display var display = document.createElement("div"); display.style.position = "relative"; @@ -426,7 +396,7 @@ Guacamole.Client = function(tunnel) { var srcY = parseInt(parameters[2]); var srcWidth = parseInt(parameters[3]); var srcHeight = parseInt(parameters[4]); - var transferFunction = transferFunctions[parameters[5]]; + var transferFunction = Guacamole.Client.DefaultTransferFunction[parameters[5]]; var dstL = getLayer(parseInt(parameters[6])); var dstX = parseInt(parameters[7]); var dstY = parseInt(parameters[8]); @@ -677,4 +647,120 @@ Guacamole.Client.LayerContainer = function(width, height) { return div; }; -}; \ No newline at end of file +}; + +/** + * 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 = ~src.red; + dst.green = ~src.green; + dst.blue = ~src.blue; + dst.alpha = src.alpha; + }, + + /* Invert DEST */ + 0xA: function (src, dst) { + dst.red = ~dst.red; + dst.green = ~dst.green; + dst.blue = ~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 = ~( src.red & dst.red); + dst.green = ~( src.green & dst.green); + dst.blue = ~( 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 = ~( src.red | dst.red); + dst.green = ~( src.green | dst.green); + dst.blue = ~( 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 = ~( src.red ^ dst.red); + dst.green = ~( src.green ^ dst.green); + dst.blue = ~( src.blue ^ dst.blue); + }, + + /* AND inverted source */ + 0x4: function (src, dst) { + dst.red = (~src.red & dst.red); + dst.green = (~src.green & dst.green); + dst.blue = (~src.blue & dst.blue); + }, + + /* OR inverted source */ + 0xD: function (src, dst) { + dst.red = (~src.red | dst.red); + dst.green = (~src.green | dst.green); + dst.blue = (~src.blue | dst.blue); + }, + + /* AND inverted destination */ + 0x2: function (src, dst) { + dst.red = ( src.red & ~dst.red); + dst.green = ( src.green & ~dst.green); + dst.blue = ( src.blue & ~dst.blue); + }, + + /* OR inverted destination */ + 0xB: function (src, dst) { + dst.red = ( src.red | ~dst.red); + dst.green = ( src.green | ~dst.green); + dst.blue = ( src.blue | ~dst.blue); + } + +}; diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index d1cbd06b9..709d3aeeb 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -430,10 +430,32 @@ Guacamole.Layer = function(width, height) { // Apply transfer for each pixel for (var i=0; i Date: Wed, 29 Feb 2012 13:34:11 -0800 Subject: [PATCH 127/263] Only use classList.add() and classList.remove() if classList is supported. --- .../src/main/resources/oskeyboard.js | 61 +++++++++++++++++-- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index d940a9f4b..6cbef3efd 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -55,6 +55,55 @@ Guacamole.OnScreenKeyboard = function(url) { var modifiers = {}; var currentModifier = 1; + // 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; + + } + ); + + }; + + } + // Returns a unique power-of-two value for the modifier with the // given name. The same value will be returned for the same modifier. function getModifier(name) { @@ -249,8 +298,8 @@ Guacamole.OnScreenKeyboard = function(url) { var requirements = required.value.split(","); for (var i=0; i Date: Thu, 1 Mar 2012 16:00:07 -0800 Subject: [PATCH 128/263] Fix OSK to work in IE9+ --- .../src/main/resources/oskeyboard.js | 54 +++++++------------ 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 6cbef3efd..ba7ea720f 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -198,17 +198,14 @@ Guacamole.OnScreenKeyboard = function(url) { "gap": function parse_gap(e) { - // Get attributes - var gap_size = e.attributes["size"]; - // Create element var gap = document.createElement("div"); gap.className = "guac-keyboard-gap"; // Set gap size var gap_units = 1; - if (gap_size) - gap_units = parseFloat(gap_size.value); + if (e.getAttribute("size")) + gap_units = parseFloat(e.getAttribute("size")); scaledElements.push(new ScaledElement(gap, gap_units, gap_units)); row.appendChild(gap); @@ -217,17 +214,13 @@ Guacamole.OnScreenKeyboard = function(url) { "key": function parse_key(e) { - // Get attributes - var key_size = e.attributes["size"]; - var key_class = e.attributes["class"]; - // Create element var key_element = document.createElement("div"); key_element.className = "guac-keyboard-key"; // Append class if specified - if (key_class) - key_element.className += " " + key_class.value; + if (e.getAttribute("class")) + key_element.className += " " + e.getAttribute("class"); // Position keys using container div var key_container_element = document.createElement("div"); @@ -239,28 +232,23 @@ Guacamole.OnScreenKeyboard = function(url) { // Set key size var key_units = 1; - if (key_size) - key_units = parseFloat(key_size.value); + if (e.getAttribute("size")) + key_units = parseFloat(e.getAttribute("size")); key.size = key_units; parseChildren(e, { "cap": function parse_cap(e) { - // Get attributes - var required = e.attributes["if"]; - var modifier = e.attributes["modifier"]; - var keysym = e.attributes["keysym"]; - var sticky = e.attributes["sticky"]; - var cap_class = e.attributes["class"]; + // TODO: Handle "sticky" attribute // Get content of key cap - var content = e.textContent; + var content = e.textContent || e.text; // Get keysym var real_keysym = null; - if (keysym) - real_keysym = parseInt(keysym.value); + 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) { @@ -276,8 +264,8 @@ Guacamole.OnScreenKeyboard = function(url) { // Create cap var cap = new Guacamole.OnScreenKeyboard.Cap(content, real_keysym); - if (modifier) - cap.modifier = modifier.value; + if (e.getAttribute("modifier")) + cap.modifier = e.getAttribute("modifier"); // Create cap element var cap_element = document.createElement("div"); @@ -286,16 +274,16 @@ Guacamole.OnScreenKeyboard = function(url) { key_element.appendChild(cap_element); // Append class if specified - if (cap_class) - cap_element.className += " " + cap_class.value; + if (e.getAttribute("class")) + cap_element.className += " " + e.getAttribute("class"); // Get modifier value var modifierValue = 0; - if (required) { + if (e.getAttribute("if")) { // Get modifier value for specified comma-delimited // list of required modifiers. - var requirements = required.value.split(","); + var requirements = e.getAttribute("if").split(","); for (var i=0; i Date: Mon, 5 Mar 2012 12:07:45 -0500 Subject: [PATCH 129/263] JS bitwise operators use all 32-bits, added mask to keep bitwise NOT to 8-bits --- .../src/main/resources/guacamole.js | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index b3a0b33b5..aee7faeaf 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -680,17 +680,17 @@ Guacamole.Client.DefaultTransferFunction = { /* Invert SRC */ 0xC: function (src, dst) { - dst.red = ~src.red; - dst.green = ~src.green; - dst.blue = ~src.blue; + 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 = ~dst.red; - dst.green = ~dst.green; - dst.blue = ~dst.blue; + dst.red = 0xFF & ~dst.red; + dst.green = 0xFF & ~dst.green; + dst.blue = 0xFF & ~dst.blue; }, /* AND */ @@ -702,9 +702,9 @@ Guacamole.Client.DefaultTransferFunction = { /* NAND */ 0xE: function (src, dst) { - dst.red = ~( src.red & dst.red); - dst.green = ~( src.green & dst.green); - dst.blue = ~( src.blue & dst.blue); + dst.red = 0xFF & ~( src.red & dst.red); + dst.green = 0xFF & ~( src.green & dst.green); + dst.blue = 0xFF & ~( src.blue & dst.blue); }, /* OR */ @@ -716,9 +716,9 @@ Guacamole.Client.DefaultTransferFunction = { /* NOR */ 0x8: function (src, dst) { - dst.red = ~( src.red | dst.red); - dst.green = ~( src.green | dst.green); - dst.blue = ~( src.blue | dst.blue); + dst.red = 0xFF & ~( src.red | dst.red); + dst.green = 0xFF & ~( src.green | dst.green); + dst.blue = 0xFF & ~( src.blue | dst.blue); }, /* XOR */ @@ -730,37 +730,37 @@ Guacamole.Client.DefaultTransferFunction = { /* XNOR */ 0x9: function (src, dst) { - dst.red = ~( src.red ^ dst.red); - dst.green = ~( src.green ^ dst.green); - dst.blue = ~( src.blue ^ dst.blue); + 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 = (~src.red & dst.red); - dst.green = (~src.green & dst.green); - dst.blue = (~src.blue & dst.blue); + 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 = (~src.red | dst.red); - dst.green = (~src.green | dst.green); - dst.blue = (~src.blue | dst.blue); + 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 = ( src.red & ~dst.red); - dst.green = ( src.green & ~dst.green); - dst.blue = ( src.blue & ~dst.blue); + 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 = ( src.red | ~dst.red); - dst.green = ( src.green | ~dst.green); - dst.blue = ( src.blue | ~dst.blue); + dst.red = 0xFF & ( src.red | ~dst.red); + dst.green = 0xFF & ( src.green | ~dst.green); + dst.blue = 0xFF & ( src.blue | ~dst.blue); } }; From 9f8fedcf4792e5994beaed6612369012c9969189 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 5 Mar 2012 12:18:15 -0800 Subject: [PATCH 130/263] Adding Matt Hortman to list of contributors. --- guacamole-common-js/src/main/resources/guacamole.js | 1 + 1 file changed, 1 insertion(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index aee7faeaf..88f4dbae7 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -20,6 +20,7 @@ * 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 From fded6d28737d427efc162092bc5b6beea7e917cf Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 7 Mar 2012 21:38:47 -0800 Subject: [PATCH 131/263] Revert "Removing WebSocket tunnel for stable release. It will be back." This reverts commit 31a7ce3912ebed5d6fee8b5d400b982b2e87cbfd. --- .../src/main/resources/tunnel.js | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index ec3e47510..99a87d36f 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -434,3 +434,125 @@ Guacamole.HTTPTunnel = function(tunnelURL) { }; 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. + */ + var tunnel = this; + + /** + * The WebSocket used by this tunnel. + */ + var socket = null; + + /** + * The WebSocket protocol corresponding to the protocol used for the current + * location. + */ + var ws_protocol = { + "http:": "ws:", + "https:": "wss:" + }; + + 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(message) { + + // Do not attempt to send messages if not connected + if (currentState != STATE_CONNECTED) + return; + + socket.send(message); + + }; + + this.connect = function(data) { + + // Connect socket + socket = new WebSocket(tunnelURL + "?" + data, "guacamole"); + + socket.onopen = function(event) { + currentState = STATE_CONNECTED; + }; + + socket.onmessage = function(event) { + + var message = event.data; + + var instructions = message.split(";"); + for (var i=0; i Date: Fri, 9 Mar 2012 12:27:16 -0800 Subject: [PATCH 132/263] Implemented WebSocketTunnel. --- .../src/main/resources/tunnel.js | 86 ++++++++++++++++--- 1 file changed, 74 insertions(+), 12 deletions(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 99a87d36f..50d596948 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -503,12 +503,38 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { } - this.sendMessage = function(message) { + 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. + * + * @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 Date: Fri, 9 Mar 2012 14:56:41 -0800 Subject: [PATCH 133/263] Implement tunnel onerror() for WebSocket. --- guacamole-common-js/src/main/resources/tunnel.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 50d596948..79343da97 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -548,6 +548,13 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { currentState = STATE_CONNECTED; }; + socket.onerror = function(event) { + + // Call error handler + if (tunnel.onerror) tunnel.onerror(event.data); + + }; + socket.onmessage = function(event) { var message = event.data; From 90876a47d67168e7aa3127a2c4ab707826d43314 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 9 Mar 2012 15:53:54 -0800 Subject: [PATCH 134/263] Implement ChainedTunnel, which wraps an arbitrary list of tunnels, using each in order if a tunnel fails. --- .../src/main/resources/tunnel.js | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 79343da97..835f9f56f 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -464,6 +464,20 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { "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; @@ -548,6 +562,14 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { 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 @@ -625,3 +647,77 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { Guacamole.WebSocketTunnel.prototype = new Guacamole.Tunnel(); + +Guacamole.ChainedTunnel = function() { + + var chained_tunnel = this; + var current_tunnel = null; + + var connect_data; + var tunnels = []; + + // Load all tunnels into array + for (var i=0; i Date: Fri, 9 Mar 2012 16:00:23 -0800 Subject: [PATCH 135/263] Only chain to next tunnel if no instructions received. Pass through errors otherwise. --- guacamole-common-js/src/main/resources/tunnel.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 835f9f56f..3a0a481c4 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -674,7 +674,16 @@ Guacamole.ChainedTunnel = function() { // 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 From 0d95a5b5b82619833535065121ff0564f6ef3079 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 9 Mar 2012 16:11:16 -0800 Subject: [PATCH 136/263] JSDoc, remove useless onerror initialization. --- .../src/main/resources/tunnel.js | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 3a0a481c4..4719649c9 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -648,12 +648,38 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { Guacamole.WebSocketTunnel.prototype = new Guacamole.Tunnel(); -Guacamole.ChainedTunnel = function() { +/** + * 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) { + /** + */ var chained_tunnel = this; + + /** + * The currently wrapped tunnel, if any. + */ var current_tunnel = null; + /** + * Data passed in via connect(), to be used for + * wrapped calls to other tunnels' connect() functions. + */ var connect_data; + + /** + * Array of all tunnels passed to this ChainedTunnel through the + * constructor arguments. + */ var tunnels = []; // Load all tunnels into array @@ -725,8 +751,6 @@ Guacamole.ChainedTunnel = function() { }; - this.onerror = null; - }; Guacamole.ChainedTunnel.prototype = new Guacamole.Tunnel(); From 10b192b677730cb8404191fdeca8e8cdfdf3c7de Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 9 Mar 2012 16:12:12 -0800 Subject: [PATCH 137/263] Fixed comment on self reference. --- guacamole-common-js/src/main/resources/tunnel.js | 1 + 1 file changed, 1 insertion(+) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 4719649c9..5b5a167aa 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -662,6 +662,7 @@ Guacamole.WebSocketTunnel.prototype = new Guacamole.Tunnel(); Guacamole.ChainedTunnel = function(tunnel_chain) { /** + * Reference to this chained tunnel. */ var chained_tunnel = this; From b11445e8dd717c73c2a5e3713324cfb7e8e6b7dc Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 9 Mar 2012 16:27:22 -0800 Subject: [PATCH 138/263] Errors thrown by connect() of a chained tunnel should be resent to onerror() if caught within ChainedTunnel.attach(). --- guacamole-common-js/src/main/resources/tunnel.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 5b5a167aa..8729b8ab8 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -729,8 +729,19 @@ Guacamole.ChainedTunnel = function(tunnel_chain) { }; - // Attempt connection - current_tunnel.connect(connect_data); + try { + + // Attempt connection + current_tunnel.connect(connect_data); + + } + catch (e) { + + // Call error handler of current tunnel on error + current_tunnel.onerror(e.message); + + } + } From 4c4b2de6543f2669583c28be91f90a8b0dca76f8 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 9 Mar 2012 16:38:17 -0800 Subject: [PATCH 139/263] For OSK modifiers, call keydown/keyup events only on press, calling keydown if modifier activated, and keyup if modifier deactivated. Do not call keyup on release if key is a modifier. --- .../src/main/resources/oskeyboard.js | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index ba7ea720f..dc5833a89 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -324,17 +324,31 @@ Guacamole.OnScreenKeyboard = function(url) { on_screen_keyboard.modifiers ^= modifierFlag; // Activate modifier if pressed - if (on_screen_keyboard.modifiers & modifierFlag) + if (on_screen_keyboard.modifiers & modifierFlag) { + addClass(keyboard, modifierClass); + + // Send key event + if (on_screen_keyboard.onkeydown && cap.keysym) + on_screen_keyboard.onkeydown(cap.keysym); + + } // Deactivate if not pressed - else + else { + removeClass(keyboard, modifierClass); + + // Send key event + if (on_screen_keyboard.onkeyup && cap.keysym) + on_screen_keyboard.onkeyup(cap.keysym); + + } } - // Send key event - if (on_screen_keyboard.onkeydown && 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 @@ -346,9 +360,6 @@ Guacamole.OnScreenKeyboard = function(url) { }; - key_element.addEventListener("mousedown", press, true); - key_element.addEventListener("touchstart", press, true); - function release(e) { // Release key if currently pressed @@ -359,8 +370,8 @@ Guacamole.OnScreenKeyboard = function(url) { removeClass(key_element, "guac-keyboard-pressed"); - // Send key event - if (on_screen_keyboard.onkeyup && cap.keysym) + // 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 @@ -372,6 +383,9 @@ Guacamole.OnScreenKeyboard = function(url) { }; + 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); From aa1e46779109a96fccdfd601473ba67d3c9c0684 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 11 Mar 2012 20:16:36 -0700 Subject: [PATCH 140/263] Refactor rect, rename copyRect -> copy, add several necessary operations, remove unused functions. --- .../src/main/resources/guacamole.js | 34 +-- .../src/main/resources/layer.js | 203 +++++++++++++----- 2 files changed, 159 insertions(+), 78 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 88f4dbae7..0cbf024ea 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -378,7 +378,7 @@ Guacamole.Client = function(tunnel) { dstL.setChannelMask(channelMask); - dstL.copyRect( + dstL.copy( srcL, srcX, srcY, @@ -417,35 +417,21 @@ Guacamole.Client = function(tunnel) { "rect": function(parameters) { - var channelMask = parseInt(parameters[0]); - var layer = getLayer(parseInt(parameters[1])); - var x = parseInt(parameters[2]); - var y = parseInt(parameters[3]); - var w = parseInt(parameters[4]); - var h = parseInt(parameters[5]); - var r = parseInt(parameters[6]); - var g = parseInt(parameters[7]); - var b = parseInt(parameters[8]); - var a = parseInt(parameters[9]); - - layer.setChannelMask(channelMask); - - layer.drawRect( - x, y, w, h, - r, g, b, a - ); - - }, - - "clip": 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.clipRect(x, y, w, h); + layer.rect(x, y, w, h); + + }, + + "clip": function(parameters) { + + var layer = getLayer(parseInt(parameters[0])); + + layer.clip(); }, diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 709d3aeeb..faac6ff26 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -72,7 +72,6 @@ Guacamole.Layer = function(width, height) { * @private */ var displayContext = display.getContext("2d"); - displayContext.save(); /** * The queue of all pending Tasks. Tasks will be run in order, with new @@ -82,6 +81,17 @@ Guacamole.Layer = function(width, height) { */ var tasks = new Array(); + /** + * Whether a new path should be started with the next path drawing + * operations. + */ + var pathClosed = true; + + /** + * The number of states on the state stack. + */ + var stackSize = 0; + /** * Map of all Guacamole channel masks to HTML5 canvas composite operation * names. Not all channel mask combinations are currently implemented. @@ -518,12 +528,12 @@ Guacamole.Layer = function(width, height) { * @param {Number} x The destination X coordinate. * @param {Number} y The destination Y coordinate. */ - this.copyRect = function(srcLayer, srcx, srcy, srcw, srch, x, y) { + this.copy = function(srcLayer, srcx, srcy, srcw, srch, x, y) { var drawComplete = false; var srcLock = null; - function doCopyRect() { + function doCopy() { if (layer.autosize != 0) fitRect(x, y, srcw, srch); var srcCanvas = srcLayer.getCanvas(); @@ -541,13 +551,13 @@ Guacamole.Layer = function(width, height) { // If we ARE the source layer, no need to sync. // Syncing would result in deadlock. if (layer === srcLayer) - scheduleTask(doCopyRect); + scheduleTask(doCopy); // Otherwise synchronize copy operation with source layer else { // Currently blocked draw task - var task = scheduleTask(doCopyRect, true); + var task = scheduleTask(doCopy, true); // Unblock draw task once source layer is ready srcLayer.sync(task.unblock); @@ -565,24 +575,32 @@ Guacamole.Layer = function(width, height) { }; /** - * Clear the specified rectangle of image data. + * Add the specified cubic bezier point to the current path. * - * @param {Number} x The X coordinate of the upper-left corner of the - * rectangle to clear. - * @param {Number} y The Y coordinate of the upper-left corner of the - * rectangle to clear. - * @param {Number} w The width of the rectangle to clear. - * @param {Number} h The height of the rectangle to clear. + * @param {Number} x The X coordinate of the point to draw. + * @param {Number} y The Y coordinate of the point to draw. + * @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. */ - this.clearRect = function(x, y, w, h) { + this.path = function(x, y, cp1x, cp1y, cp2x, cp2y) { scheduleTask(function() { - if (layer.autosize != 0) fitRect(x, y, w, h); - displayContext.clearRect(x, y, w, h); + + // 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, y); + }); }; /** - * Fill the specified rectangle of image data with the specified color. + * Add the specified rectangle to the current path. * * @param {Number} x The X coordinate of the upper-left corner of the * rectangle to draw. @@ -590,64 +608,141 @@ Guacamole.Layer = function(width, height) { * rectangle to draw. * @param {Number} w The width of the rectangle to draw. * @param {Number} h The height of the rectangle to draw. - * @param {Number} r The red component of the color of the rectangle. - * @param {Number} g The green component of the color of the rectangle. - * @param {Number} b The blue component of the color of the rectangle. - * @param {Number} a The alpha component of the color of the rectangle. */ - this.drawRect = function(x, y, w, h, r, g, b, a) { + 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.fillStyle = "rgba(" - + r + "," + g + "," + b + "," + a / 255 + ")"; - displayContext.fillRect(x, y, w, h); + displayContext.rect(x, y, w, h); + }); }; /** - * Clip all future drawing operations by the specified rectangle. - * - * @param {Number} x The X coordinate of the upper-left corner of the - * rectangle to use for the clipping region. - * @param {Number} y The Y coordinate of the upper-left corner of the - * rectangle to use for the clipping region. - * @param {Number} w The width of the rectangle to use for the clipping region. - * @param {Number} h The height of the rectangle to use for the clipping region. + * 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.clipRect = function(x, y, w, h) { + this.clip = function() { scheduleTask(function() { - // Clear any current clipping region - displayContext.restore(); - displayContext.save(); - - if (layer.autosize != 0) fitRect(x, y, w, h); - // Set new clipping region - displayContext.beginPath(); - displayContext.rect(x, y, w, h); displayContext.clip(); + // Path now implicitly closed + pathClosed = true; + }); }; /** - * Provides the given filtering function with a writable snapshot of - * image data and the current width and height of the Layer. + * 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 {function} filter A function which accepts an array of image - * data (as returned by the canvas element's - * display context's getImageData() function), - * the width of the Layer, and the height of the - * Layer as parameters, in that order. This - * function must accomplish its filtering by - * modifying the given image data array directly. + * @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.filter = function(filter) { + this.strokeColor = function(r, g, b, a) { scheduleTask(function() { - var imageData = displayContext.getImageData(0, 0, width, height); - filter(imageData.data, width, height); - displayContext.putImageData(imageData, 0, 0); + + // Stroke with color + 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; + + }); + }; + + /** + * 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--; + } + + // Clear transform + displayContext.setTransform( + 1, 0, 0, + 0, 1, 0 + /*0, 0, 1*/ + ); + + // Clear path + displayContext.beginPath(); + pathClosed = false; + }); }; From 56facdb6b2fac92cff65b5ea3ad8b874c855fda8 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 11 Mar 2012 21:00:08 -0700 Subject: [PATCH 141/263] Implemented remaining operations as possible. --- .../src/main/resources/layer.js | 250 ++++++++++++------ 1 file changed, 175 insertions(+), 75 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index faac6ff26..f78e519b4 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -300,6 +300,68 @@ Guacamole.Layer = function(width, height) { } + /** + * 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. + * + * @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. @@ -424,11 +486,8 @@ Guacamole.Layer = function(width, height) { * destination. */ this.transfer = function(srcLayer, srcx, srcy, srcw, srch, x, y, transferFunction) { + scheduleTaskSynced(srcLayer, function() { - var drawComplete = false; - var srcLock = null; - - function doTransfer() { if (layer.autosize != 0) fitRect(x, y, srcw, srch); var srcCanvas = srcLayer.getCanvas(); @@ -473,38 +532,7 @@ Guacamole.Layer = function(width, height) { } - // Unblock the source layer now that draw is complete - if (srcLock != null) - srcLock.unblock(); - - // Flag operation as done - drawComplete = true; - } - - // If we ARE the source layer, no need to sync. - // Syncing would result in deadlock. - if (layer === srcLayer) - scheduleTask(doTransfer); - - // Otherwise synchronize copy operation with source layer - else { - - // Currently blocked draw task - var task = scheduleTask(doTransfer, true); - - // Unblock draw task once source layer is ready - srcLayer.sync(task.unblock); - - // Block source layer until draw completes - // Note that the draw MAY have already been performed at this point, - // in which case creating a lock on the source layer will lead to - // deadlock (the draw task has already run and will thus never - // clear the lock) - if (!drawComplete) - srcLock = srcLayer.sync(null, true); - - } - + }); }; /** @@ -529,49 +557,14 @@ Guacamole.Layer = function(width, height) { * @param {Number} y The destination Y coordinate. */ this.copy = function(srcLayer, srcx, srcy, srcw, srch, x, y) { - - var drawComplete = false; - var srcLock = null; - - function doCopy() { + 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); - // Unblock the source layer now that draw is complete - if (srcLock != null) - srcLock.unblock(); - - // Flag operation as done - drawComplete = true; - } - - // If we ARE the source layer, no need to sync. - // Syncing would result in deadlock. - if (layer === srcLayer) - scheduleTask(doCopy); - - // Otherwise synchronize copy operation with source layer - else { - - // Currently blocked draw task - var task = scheduleTask(doCopy, true); - - // Unblock draw task once source layer is ready - srcLayer.sync(task.unblock); - - // Block source layer until draw completes - // Note that the draw MAY have already been performed at this point, - // in which case creating a lock on the source layer will lead to - // deadlock (the draw task has already run and will thus never - // clear the lock) - if (!drawComplete) - srcLock = srcLayer.sync(null, true); - - } - + }); }; /** @@ -648,15 +641,23 @@ Guacamole.Layer = function(width, height) { * 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(r, g, b, a) { + 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(); @@ -666,7 +667,6 @@ Guacamole.Layer = function(width, height) { }); }; - /** * Fills the current path with the specified color. The current path * is implicitly closed. The current path can continue to be reused @@ -691,6 +691,66 @@ Guacamole.Layer = function(width, height) { }); }; + /** + * 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. */ @@ -746,6 +806,31 @@ Guacamole.Layer = function(width, height) { }); }; + /** + * Applies the given affine transform (defined with three 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() { + + // Clear transform + displayContext.transform( + a, b, c, + d, e, f + /*0, 0, 1*/ + ); + + }); + }; + + /** * Sets the channel mask for future operations on this Layer. * @@ -764,6 +849,21 @@ Guacamole.Layer = function(width, height) { }); }; + /** + * 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; From 87cf3940c68f3b8a1f73029d24cfa47990c81263 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 11 Mar 2012 21:10:07 -0700 Subject: [PATCH 142/263] Implement cfill. --- .../src/main/resources/guacamole.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 0cbf024ea..51ed16ca7 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -435,6 +435,21 @@ Guacamole.Client = function(tunnel) { }, + "cfill": function(parameters) { + + var channelMask = parseInt(parameters[0]); + var layer = getLayer(parseInt(parameters[1])); + var r = getLayer(parseInt(parameters[2])); + var g = getLayer(parseInt(parameters[3])); + var b = getLayer(parseInt(parameters[4])); + var a = getLayer(parseInt(parameters[5])); + + layer.setChannelMask(channelMask); + + layer.fillColor(r, g, b, a); + + }, + "cursor": function(parameters) { cursorHotspotX = parseInt(parameters[0]); From ead3811df6cc10873d9e32f8cff227cf6e5d15a8 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 11 Mar 2012 21:17:16 -0700 Subject: [PATCH 143/263] Accidentally used getLayer() in RGBA component ints. --- guacamole-common-js/src/main/resources/guacamole.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 51ed16ca7..e49b155ae 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -439,10 +439,10 @@ Guacamole.Client = function(tunnel) { var channelMask = parseInt(parameters[0]); var layer = getLayer(parseInt(parameters[1])); - var r = getLayer(parseInt(parameters[2])); - var g = getLayer(parseInt(parameters[3])); - var b = getLayer(parseInt(parameters[4])); - var a = getLayer(parseInt(parameters[5])); + var r = parseInt(parameters[2]); + var g = parseInt(parameters[3]); + var b = parseInt(parameters[4]); + var a = parseInt(parameters[5]); layer.setChannelMask(channelMask); From 66d3973cdc1891a7d798cc9f76ef6465f06bac7f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 11 Mar 2012 21:30:00 -0700 Subject: [PATCH 144/263] Fix reset() to properly reset EVERYTHING. --- guacamole-common-js/src/main/resources/layer.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index f78e519b4..c7754c3ee 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -72,6 +72,7 @@ Guacamole.Layer = function(width, height) { * @private */ var displayContext = display.getContext("2d"); + displayContext.save(); /** * The queue of all pending Tasks. Tasks will be run in order, with new @@ -89,6 +90,10 @@ Guacamole.Layer = function(width, height) { /** * 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. */ var stackSize = 0; @@ -788,16 +793,13 @@ Guacamole.Layer = function(width, height) { // Clear stack while (stackSize > 0) { - displaycontext.restore(); + displayContext.restore(); stackSize--; } - // Clear transform - displayContext.setTransform( - 1, 0, 0, - 0, 1, 0 - /*0, 0, 1*/ - ); + // Restore to initial state + displayContext.restore(); + displayContext.save(); // Clear path displayContext.beginPath(); From 6cb68f86cf19125d7e8fac28f4ec3a18ac6efb4c Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 11 Mar 2012 21:33:39 -0700 Subject: [PATCH 145/263] Fix cursor - copyRect() has been renamed to copy(). --- guacamole-common-js/src/main/resources/guacamole.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index e49b155ae..d4a52ba35 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -464,7 +464,7 @@ Guacamole.Client = function(tunnel) { cursor.resize(srcWidth, srcHeight); // Draw cursor to cursor layer - cursor.getLayer().copyRect( + cursor.getLayer().copy( srcL, srcX, srcY, From e63b7108f3e5b37136c9743a950b3d53293d568b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 11 Mar 2012 21:48:06 -0700 Subject: [PATCH 146/263] Implement reset instruction. --- guacamole-common-js/src/main/resources/guacamole.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index d4a52ba35..434d16d44 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -426,7 +426,15 @@ Guacamole.Client = function(tunnel) { layer.rect(x, y, w, h); }, + + "reset": function(parameters) { + var layer = getLayer(parseInt(parameters[0])); + + layer.reset(); + + }, + "clip": function(parameters) { var layer = getLayer(parseInt(parameters[0])); From b363f958b0a7e1af629a79100e695b3daaac9137 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 11 Mar 2012 21:59:19 -0700 Subject: [PATCH 147/263] Alphabetized instruction set for future instruction-adding convenience. --- .../src/main/resources/guacamole.js | 276 +++++++++--------- 1 file changed, 138 insertions(+), 138 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 434d16d44..9f96ddaf6 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -246,48 +246,119 @@ Guacamole.Client = function(tunnel) { var instructionHandlers = { - "error": function(parameters) { - if (guac_client.onerror) guac_client.onerror(parameters[0]); - guac_client.disconnect(); + "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); + }, - "name": function(parameters) { - if (guac_client.onname) guac_client.onname(parameters[0]); + "clip": function(parameters) { + + var layer = getLayer(parseInt(parameters[0])); + + layer.clip(); + }, "clipboard": function(parameters) { if (guac_client.onclipboard) guac_client.onclipboard(parameters[0]); }, - "size": function(parameters) { + "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 + ); + + }, + + "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); + + }, + + "dispose": function(parameters) { + var layer_index = parseInt(parameters[0]); - var width = parseInt(parameters[1]); - var height = parseInt(parameters[2]); - // Only valid for layers (buffers auto-resize) - if (layer_index >= 0) { + // If visible layer, remove from parent + if (layer_index > 0) { - // Resize layer - var layer_container = getLayerContainer(layer_index); - layer_container.resize(width, height); + // Get container element + var layer_container = getLayerContainer(layer_index).getElement(); - // If layer is default, resize display - if (layer_index == 0) { + // Remove from parent + layer_container.parentNode.removeChild(layer_container); - displayWidth = width; - displayHeight = height; + // Delete reference + delete layers[layer_index]; - // Update (set) display size - display.style.width = displayWidth + "px"; - display.style.height = displayHeight + "px"; + } - } + // If buffer, just delete reference + else if (layer_index < 0) + delete buffers[-1 - layer_index]; - } // end if layer (not buffer) + // Attempting to dispose the root layer currently has no effect. }, + "error": function(parameters) { + if (guac_client.onerror) guac_client.onerror(parameters[0]); + guac_client.disconnect(); + }, + "move": function(parameters) { var layer_index = parseInt(parameters[0]); @@ -316,30 +387,8 @@ Guacamole.Client = function(tunnel) { }, - "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. - + "name": function(parameters) { + if (guac_client.onname) guac_client.onname(parameters[0]); }, "png": function(parameters) { @@ -364,57 +413,6 @@ Guacamole.Client = function(tunnel) { }, - "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 - ); - - }, - - "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 - ); - - }, - "rect": function(parameters) { var layer = getLayer(parseInt(parameters[0])); @@ -435,55 +433,32 @@ Guacamole.Client = function(tunnel) { }, - "clip": function(parameters) { + "size": function(parameters) { - var layer = getLayer(parseInt(parameters[0])); + var layer_index = parseInt(parameters[0]); + var width = parseInt(parameters[1]); + var height = parseInt(parameters[2]); - layer.clip(); + // Only valid for layers (buffers auto-resize) + if (layer_index >= 0) { - }, + // Resize layer + var layer_container = getLayerContainer(layer_index); + layer_container.resize(width, height); - "cfill": function(parameters) { + // If layer is default, resize display + if (layer_index == 0) { - 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]); + displayWidth = width; + displayHeight = height; - layer.setChannelMask(channelMask); + // Update (set) display size + display.style.width = displayWidth + "px"; + display.style.height = displayHeight + "px"; - layer.fillColor(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); + } // end if layer (not buffer) }, @@ -529,6 +504,31 @@ Guacamole.Client = function(tunnel) { } } + }, + + "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 + ); + } }; From 6cffafad6abe87d12912dff6e5a7c71234716ca2 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 11 Mar 2012 22:13:10 -0700 Subject: [PATCH 148/263] Reset internal stack state when stack automatically reset from resize. --- guacamole-common-js/src/main/resources/layer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index c7754c3ee..4f87547d6 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -168,6 +168,10 @@ Guacamole.Layer = function(width, height) { width = newWidth; height = newHeight; + // Acknowledge reset of stack (happens on resize of canvas) + stackSize = 0; + displayContext.save(); + } /** From 5b902e669cab36117d58141d8e074ada882a9333 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 11 Mar 2012 22:21:54 -0700 Subject: [PATCH 149/263] Buffers should be resizable, too. --- .../src/main/resources/guacamole.js | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 9f96ddaf6..385e3dd66 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -439,26 +439,21 @@ Guacamole.Client = function(tunnel) { var width = parseInt(parameters[1]); var height = parseInt(parameters[2]); - // Only valid for layers (buffers auto-resize) - if (layer_index >= 0) { + // Resize layer + var layer_container = getLayerContainer(layer_index); + layer_container.resize(width, height); - // Resize layer - var layer_container = getLayerContainer(layer_index); - layer_container.resize(width, height); + // If layer is default, resize display + if (layer_index == 0) { - // If layer is default, resize display - if (layer_index == 0) { + displayWidth = width; + displayHeight = height; - displayWidth = width; - displayHeight = height; + // Update (set) display size + display.style.width = displayWidth + "px"; + display.style.height = displayHeight + "px"; - // Update (set) display size - display.style.width = displayWidth + "px"; - display.style.height = displayHeight + "px"; - - } - - } // end if layer (not buffer) + } }, From 88e897dcd254451d195344251231b88e9ca14590 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 12 Mar 2012 17:04:29 -0700 Subject: [PATCH 150/263] Refactored to more reasonable path operations. --- .../src/main/resources/layer.js | 128 ++++++++++++++++-- 1 file changed, 119 insertions(+), 9 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 4f87547d6..4d48983be 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -577,16 +577,12 @@ Guacamole.Layer = function(width, height) { }; /** - * Add the specified cubic bezier point to the current path. + * 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. - * @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. */ - this.path = function(x, y, cp1x, cp1y, cp2x, cp2y) { + this.moveTo = function(x, y) { scheduleTask(function() { // Start a new path if current path is closed @@ -596,7 +592,96 @@ Guacamole.Layer = function(width, height) { } if (layer.autosize != 0) fitRect(x, y, 0, 0); - displayContext.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, y); + 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. Drawing direction is + * determined by the start and end angles. To draw clockwise, ensure + * the end angle is greater than the start angle. To draw counterclockwise, + * ensure the end angle is less than the start angle. + * + * @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. + */ + this.arc = function(x, y, radius, startAngle, endAngle) { + 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, endAngle < startAngle); + + }); + }; + + /** + * 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; }); }; @@ -813,7 +898,32 @@ Guacamole.Layer = function(width, height) { }; /** - * Applies the given affine transform (defined with three values from the + * 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. @@ -826,7 +936,7 @@ Guacamole.Layer = function(width, height) { this.transform = function(a, b, c, d, e, f) { scheduleTask(function() { - // Clear transform + // Apply transform displayContext.transform( a, b, c, d, e, f From c25a4edab7bee3991cc731cd4a984fc6a246cb85 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 12 Mar 2012 17:27:42 -0700 Subject: [PATCH 151/263] Implement start, line, and curve instructions. --- .../src/main/resources/guacamole.js | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 385e3dd66..b7328bad6 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -68,6 +68,24 @@ Guacamole.Client = function(tunnel) { var displayWidth = 0; var displayHeight = 0; + /** + * Translation from Guacamole protocol line caps to Layer line caps. + */ + var lineCap = { + 0: "butt", + 1: "round", + 2: "square" + }; + + /** + * Translation from Guacamole protocol line caps to Layer line caps. + */ + var lineJoin = { + 0: "bevel", + 1: "miter", + 2: "round" + }; + // Create display var display = document.createElement("div"); display.style.position = "relative"; @@ -299,6 +317,24 @@ Guacamole.Client = function(tunnel) { }, + "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]); @@ -359,6 +395,16 @@ Guacamole.Client = function(tunnel) { guac_client.disconnect(); }, + "line": function(parameters) { + + var layer = getLayer(parseInt(parameters[0])); + var x = parseInt(parameters[1]); + var y = parseInt(parameters[2]); + + layer.lineTo(x, y); + + }, + "move": function(parameters) { var layer_index = parseInt(parameters[0]); @@ -456,6 +502,16 @@ Guacamole.Client = function(tunnel) { } }, + + "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) { From 3435edf4d6bea2d0fc13cbf2fdeb441b2d54b6d7 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 12 Mar 2012 17:37:04 -0700 Subject: [PATCH 152/263] Implemented close, curve, arc. --- .../src/main/resources/guacamole.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index b7328bad6..f998bdfbd 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -264,6 +264,19 @@ Guacamole.Client = function(tunnel) { 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]); + + layer.arc(x, y, radius, startAngle, endAngle); + + }, + "cfill": function(parameters) { var channelMask = parseInt(parameters[0]); @@ -291,6 +304,14 @@ Guacamole.Client = function(tunnel) { 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])); @@ -364,6 +385,20 @@ Guacamole.Client = function(tunnel) { }, + "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]); From 4b3b2966f5d3e239c899206e24aeaec186cb030a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 12 Mar 2012 17:39:18 -0700 Subject: [PATCH 153/263] Implemented lfill, lstroke. --- .../src/main/resources/guacamole.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index f998bdfbd..7af0da379 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -430,6 +430,18 @@ Guacamole.Client = function(tunnel) { guac_client.disconnect(); }, + "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])); @@ -440,6 +452,18 @@ Guacamole.Client = function(tunnel) { }, + "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]); From b540cc0427d7f2805738d61b8eaf8670db53b3dd Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 12 Mar 2012 17:42:44 -0700 Subject: [PATCH 154/263] Implement identity, transform. --- .../src/main/resources/guacamole.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 7af0da379..100a75c77 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -430,6 +430,18 @@ Guacamole.Client = function(tunnel) { guac_client.disconnect(); }, + "identity": function(parameters) { + + var layer = getLayer(parseInt(parameters[0])); + + layer.setTransform( + 1, 0, 0, + 0, 1, 0 + /*0, 0, 1*/ + ); + + }, + "lfill": function(parameters) { var channelMask = parseInt(parameters[0]); @@ -639,6 +651,20 @@ Guacamole.Client = function(tunnel) { 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); + } }; From fc716d7d9a76a610d45e21c77c91e2552afdd2f3 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 12 Mar 2012 23:25:23 -0700 Subject: [PATCH 155/263] Implement distort, shade. --- .../src/main/resources/guacamole.js | 60 +++++++++++++++++-- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 100a75c77..d950895ca 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -425,6 +425,40 @@ Guacamole.Client = function(tunnel) { }, + "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.style.transform = + layer_container.style.WebkitTransform = + layer_container.style.MozTransform = + layer_container.style.OTransform = + layer_container.style.msTransform = + + /* a c e + * b d f + * 0 0 1 + */ + + "matrix(" + a + "," + b + "," + c + "," + d + "," + e + "," + f + ")"; + + } + + }, + "error": function(parameters) { if (guac_client.onerror) guac_client.onerror(parameters[0]); guac_client.disconnect(); @@ -434,11 +468,7 @@ Guacamole.Client = function(tunnel) { var layer = getLayer(parseInt(parameters[0])); - layer.setTransform( - 1, 0, 0, - 0, 1, 0 - /*0, 0, 1*/ - ); + layer.setTransform(1, 0, 0, 1, 0, 0); }, @@ -549,7 +579,25 @@ Guacamole.Client = function(tunnel) { layer.reset(); }, - + + "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]); From c91efb51ec0f92745338bf5c5b4b349062992085 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 12 Mar 2012 23:58:07 -0700 Subject: [PATCH 156/263] Implemented push and pop. --- .../src/main/resources/guacamole.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index d950895ca..817f5ba38 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -560,6 +560,22 @@ Guacamole.Client = function(tunnel) { }, + "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])); From 02500bf96ba34ee39076be97c5f4d61f55c5dbe3 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 13 Mar 2012 00:29:21 -0700 Subject: [PATCH 157/263] Layers should clip contents. --- guacamole-common-js/src/main/resources/guacamole.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 817f5ba38..55b71ba68 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -100,6 +100,7 @@ Guacamole.Client = function(tunnel) { 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); @@ -241,6 +242,7 @@ Guacamole.Client = function(tunnel) { 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); From 6df9fe2871883b4212da16d85dfdabff0e63536d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 13 Mar 2012 12:12:59 -0700 Subject: [PATCH 158/263] Implement set instruction. --- .../src/main/resources/guacamole.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 55b71ba68..0e2181b27 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -264,6 +264,21 @@ Guacamole.Client = function(tunnel) { } + /** + * Handlers for all defined layer properties. + */ + var layerPropertyHandlers = { + + "miter-limit": function(layer, value) { + layer.setMiterLimit(parseFloat(value)); + } + + }; + + /** + * Handlers for all instruction opcodes receivable by a Guacamole protocol + * client. + */ var instructionHandlers = { "arc": function(parameters) { @@ -597,6 +612,19 @@ Guacamole.Client = function(tunnel) { 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) { From cc6c2671accb1231a35088a7c4be20ece8c8d0aa Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 13 Mar 2012 18:59:57 -0700 Subject: [PATCH 159/263] Refactor arc to include drawing direction. --- guacamole-common-js/src/main/resources/guacamole.js | 3 ++- guacamole-common-js/src/main/resources/layer.js | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 0e2181b27..4cd95d0a8 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -289,8 +289,9 @@ Guacamole.Client = function(tunnel) { 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); + layer.arc(x, y, radius, startAngle, endAngle, negative != 0); }, diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 4d48983be..8358fbbf9 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -619,10 +619,7 @@ Guacamole.Layer = function(width, height) { }; /** - * Add the specified arc to the current path. Drawing direction is - * determined by the start and end angles. To draw clockwise, ensure - * the end angle is greater than the start angle. To draw counterclockwise, - * ensure the end angle is less than the start angle. + * 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. @@ -631,8 +628,10 @@ Guacamole.Layer = function(width, height) { * @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) { + this.arc = function(x, y, radius, startAngle, endAngle, negative) { scheduleTask(function() { // Start a new path if current path is closed @@ -642,7 +641,7 @@ Guacamole.Layer = function(width, height) { } if (layer.autosize != 0) fitRect(x, y, 0, 0); - displayContext.arc(x, y, radius, startAngle, endAngle, endAngle < startAngle); + displayContext.arc(x, y, radius, startAngle, endAngle, negative); }); }; From 431d38d21fd90f1497abdab00421f917a112e70b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 14 Mar 2012 16:18:11 -0700 Subject: [PATCH 160/263] Properly handle errors on write as well as read. --- .../src/main/resources/tunnel.js | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 8729b8ab8..b81c418d3 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -181,8 +181,17 @@ Guacamole.HTTPTunnel = function(tunnelURL) { // Once response received, send next queued event. message_xmlhttprequest.onreadystatechange = function() { - if (message_xmlhttprequest.readyState == 4) - sendPendingMessages(); + 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); @@ -195,6 +204,22 @@ Guacamole.HTTPTunnel = function(tunnelURL) { } + function handleHTTPTunnelError(xmlhttprequest) { + + // Get error message (if any) + var message = xmlhttprequest.getResponseHeader("X-Guacamole-Error-Message"); + if (!message) + message = "Internal server error"; + + // Call error handler + if (tunnel.onerror) tunnel.onerror(message); + + // Finish + tunnel.disconnect(); + + } + + function handleResponse(xmlhttprequest) { var interval = null; @@ -257,17 +282,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) { // Halt on error during request else if (xmlhttprequest.status != 200) { - - // Get error message (if any) - var message = xmlhttprequest.getResponseHeader("X-Guacamole-Error-Message"); - if (!message) - message = "Internal server error"; - - // Call error handler - if (tunnel.onerror) tunnel.onerror(message); - - // Finish - tunnel.disconnect(); + handleHTTPTunnelError(xmlhttprequest); return; } From fccfe52a198820bf7497a186de7861a818919e6b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 19 Mar 2012 15:11:05 -0700 Subject: [PATCH 161/263] In chained tunnel, clear handlers in old tunnel when new tunnel is taking over. --- guacamole-common-js/src/main/resources/tunnel.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index b81c418d3..a35d0070b 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -707,6 +707,12 @@ Guacamole.ChainedTunnel = function(tunnel_chain) { */ 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; From 7522c3a853f6531fcebef376d526356446245d24 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 20 Mar 2012 10:14:49 -0700 Subject: [PATCH 162/263] Fix ticket #114 - mouse position calculated incorrectly. --- guacamole-common-js/src/main/resources/mouse.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index f648602ba..a193f6771 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -111,10 +111,13 @@ Guacamole.Mouse = function(element) { // This is all JUST so we can get the mouse position within the element var parent = element.offsetParent; while (parent) { - if (parent.offsetLeft && parent.offsetTop) { + + if (parent.offsetLeft) guac_mouse.currentState.x -= parent.offsetLeft; + + if (parent.offsetTop) guac_mouse.currentState.y -= parent.offsetTop; - } + parent = parent.offsetParent; } From 8ad557cf31755c392f1003acb16455990f59ea4a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 22 Mar 2012 17:28:24 -0700 Subject: [PATCH 163/263] Use screenX/screenY for touch. --- guacamole-common-js/src/main/resources/mouse.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index a193f6771..547f51722 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -223,8 +223,8 @@ Guacamole.Mouse = function(element) { // Record touch location and time var starting_touch = e.touches[0]; - last_touch_x = starting_touch.pageX; - last_touch_y = starting_touch.pageY; + last_touch_x = starting_touch.screenX; + last_touch_y = starting_touch.screenY; last_touch_time = new Date().getTime(); pixels_moved = 0; @@ -243,8 +243,8 @@ Guacamole.Mouse = function(element) { // Get change in touch location var touch = e.touches[0]; - var delta_x = touch.pageX - last_touch_x; - var delta_y = touch.pageY - last_touch_y; + var delta_x = touch.screenX - last_touch_x; + var delta_y = touch.screenY - last_touch_y; // Track pixels moved pixels_moved += Math.abs(delta_x) + Math.abs(delta_y); @@ -270,8 +270,8 @@ Guacamole.Mouse = function(element) { guac_mouse.onmousemove(guac_mouse.currentState); // Update touch location - last_touch_x = touch.pageX; - last_touch_y = touch.pageY; + last_touch_x = touch.screenX; + last_touch_y = touch.screenY; } From e6249fbf5bd628f19d466eac5e75c84d2b58fef1 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 24 Mar 2012 16:57:58 -0700 Subject: [PATCH 164/263] Do not use X-Guacamole-Error-Message - use status code only. --- .../src/main/resources/tunnel.js | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index a35d0070b..f44110d44 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -203,13 +203,22 @@ Guacamole.HTTPTunnel = function(tunnelURL) { } + function getHTTPTunnelErrorMessage(xmlhttprequest) { + + var status = xmlhttprequest.status; + + if (status >= 200 && status <= 299) return "Success"; + if (status >= 400 && status <= 499) return "Unauthorized"; + if (status >= 500 && status <= 599) return "Connection lost"; + + return "Unknown error"; + + } function handleHTTPTunnelError(xmlhttprequest) { - // Get error message (if any) - var message = xmlhttprequest.getResponseHeader("X-Guacamole-Error-Message"); - if (!message) - message = "Internal server error"; + // Get error message + var message = getHTTPTunnelErrorMessage(xmlhttprequest); // Call error handler if (tunnel.onerror) tunnel.onerror(message); @@ -424,13 +433,8 @@ Guacamole.HTTPTunnel = function(tunnelURL) { // If failure, throw error if (connect_xmlhttprequest.status != 200) { - - var message = connect_xmlhttprequest.getResponseHeader("X-Guacamole-Error-Message"); - if (!message) - message = "Internal error"; - + var message = getHTTPTunnelErrorMessage(connect_xmlhttprequest); throw new Error(message); - } // Get UUID from response From b80ede52a4fb7fe4c00cd1dfac2f4c76a1ecef6a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 24 Mar 2012 19:13:32 -0700 Subject: [PATCH 165/263] Generic error messages from status codes. --- guacamole-common-js/src/main/resources/tunnel.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index f44110d44..a06c2b4f7 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -207,10 +207,15 @@ Guacamole.HTTPTunnel = function(tunnelURL) { var status = xmlhttprequest.status; - if (status >= 200 && status <= 299) return "Success"; - if (status >= 400 && status <= 499) return "Unauthorized"; - if (status >= 500 && status <= 599) return "Connection lost"; + // Special cases + if (status == 200) return "Success"; + if (status == 403) return "Unauthorized"; + if (status == 404) return "Connection does not exist"; + // Internal server errors + if (status >= 500 && status <= 599) return "Server error"; + + // Otherwise, unknown return "Unknown error"; } From d4aabf013bd9601ea46def8216df348184d6f943 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 25 Mar 2012 13:36:01 -0700 Subject: [PATCH 166/263] Assume space cap if blank (blank caps would otherwise not render, and IE trims the contents of XML tags, which breaks the OSK spacebar). --- guacamole-common-js/src/main/resources/oskeyboard.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index dc5833a89..1f8c08360 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -244,6 +244,10 @@ Guacamole.OnScreenKeyboard = function(url) { // 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; From 3b7b8382a368c985090d77ab7849c77d60472efd Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 25 Mar 2012 17:56:33 -0700 Subject: [PATCH 167/263] Add error for status code of 0. --- guacamole-common-js/src/main/resources/tunnel.js | 1 + 1 file changed, 1 insertion(+) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index a06c2b4f7..39709d864 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -208,6 +208,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) { 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 does not exist"; From 631ec6120eb2b6349573014e9d1f5db33cd3d171 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 25 Mar 2012 23:03:54 -0700 Subject: [PATCH 168/263] Change "Connection does not exist" to more user-friendly error. --- guacamole-common-js/src/main/resources/tunnel.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 39709d864..87155ebe5 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -211,8 +211,20 @@ Guacamole.HTTPTunnel = function(tunnelURL) { if (status == 0) return "Disconnected"; if (status == 200) return "Success"; if (status == 403) return "Unauthorized"; - if (status == 404) return "Connection does not exist"; - + 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"; From e8ee79a5b0a4b2f2ac1f1dfdc9f51c836a304fd7 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 26 Mar 2012 18:51:16 -0700 Subject: [PATCH 169/263] Fixed project URL. --- guacamole-common-js/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/pom.xml b/guacamole-common-js/pom.xml index 5e8ee9a9b..e3606aaba 100644 --- a/guacamole-common-js/pom.xml +++ b/guacamole-common-js/pom.xml @@ -7,7 +7,7 @@ pom 0.6.0 guacamole-common-js - http://guacamole.sourceforge.net/ + http://guac-dev.org/ UTF-8 From eca34b24fb64a695e2b6586ebd6c189e167fd321 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 29 Mar 2012 10:05:38 -0700 Subject: [PATCH 170/263] Allow user of API to decide whether keyboard events are canceled. --- .../src/main/resources/keyboard.js | 153 ++++++++++-------- 1 file changed, 82 insertions(+), 71 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 4c642c94b..3d4180a5d 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -60,8 +60,11 @@ Guacamole.Keyboard = function(element) { * * @event * @param {Number} keysym The keysym of the key being pressed. + * @returns {Boolean} true if the originating event of this keypress should + * be allowed through to the browser, false or undefined + * otherwise. */ - this.onkeydown = null; + this.onkeydown = null; /** * Fired whenever the user releases a key with the element associated @@ -69,8 +72,11 @@ Guacamole.Keyboard = function(element) { * * @event * @param {Number} keysym The keysym of the key being released. + * @returns {Boolean} true if the originating event of this key release + * should be allowed through to the browser, false or + * undefined otherwise. */ - this.onkeyup = null; + this.onkeyup = null; /** * Map of known JavaScript keycodes which do not map to typable characters @@ -127,10 +133,10 @@ Guacamole.Keyboard = function(element) { 18: 0xFFE7 // alt }; - // Single key state/modifier buffer - var modShift = false; - var modCtrl = false; - var modAlt = false; + // Single key state/modifier buffer + var modShift = false; + var modCtrl = false; + var modAlt = false; var keydownChar = new Array(); @@ -138,19 +144,19 @@ Guacamole.Keyboard = function(element) { var repeatKeyTimeoutId = -1; var repeatKeyIntervalId = -1; - // Starts repeating keystrokes - function startRepeat(keySym) { - repeatKeyIntervalId = setInterval(function() { + // Starts repeating keystrokes + function startRepeat(keySym) { + repeatKeyIntervalId = setInterval(function() { sendKeyReleased(keySym); sendKeyPressed(keySym); }, 50); - } + } - // Stops repeating keystrokes - function stopRepeat() { - if (repeatKeyTimeoutId != -1) clearInterval(repeatKeyTimeoutId); - if (repeatKeyIntervalId != -1) clearInterval(repeatKeyIntervalId); - } + // Stops repeating keystrokes + function stopRepeat() { + if (repeatKeyTimeoutId != -1) clearInterval(repeatKeyTimeoutId); + if (repeatKeyIntervalId != -1) clearInterval(repeatKeyIntervalId); + } function getKeySymFromKeyIdentifier(shifted, keyIdentifier) { @@ -194,8 +200,8 @@ Guacamole.Keyboard = function(element) { function getKeySymFromKeyCode(keyCode) { var keysym = null; - if (!modShift) keysym = unshiftedKeySym[keyCode]; - else { + if (!modShift) keysym = unshiftedKeySym[keyCode]; + else { keysym = shiftedKeySym[keyCode]; if (keysym == null) keysym = unshiftedKeySym[keyCode]; } @@ -205,17 +211,19 @@ Guacamole.Keyboard = function(element) { } - // Sends a single keystroke over the network - function sendKeyPressed(keysym) { - if (keysym != null && guac_keyboard.onkeydown) - guac_keyboard.onkeydown(keysym); - } + // Sends a single keystroke over the network + function sendKeyPressed(keysym) { + if (keysym != null && guac_keyboard.onkeydown) + return guac_keyboard.onkeydown(keysym) != false; + return true; + } - // Sends a single keystroke over the network - function sendKeyReleased(keysym) { - if (keysym != null && guac_keyboard.onkeyup) - guac_keyboard.onkeyup(keysym); - } + // Sends a single keystroke over the network + function sendKeyReleased(keysym) { + if (keysym != null && guac_keyboard.onkeyup) + return guac_keyboard.onkeyup(keysym) != false; + return true; + } var KEYDOWN = 1; @@ -223,24 +231,24 @@ Guacamole.Keyboard = function(element) { var keySymSource = null; - // When key pressed + // When key pressed var keydownCode = null; - element.onkeydown = function(e) { + element.onkeydown = function(e) { // Only intercept if handler set if (!guac_keyboard.onkeydown) return true; - var keynum; - if (window.event) keynum = window.event.keyCode; - else if (e.which) keynum = e.which; + var keynum; + if (window.event) keynum = window.event.keyCode; + else if (e.which) keynum = e.which; - // Ctrl/Alt/Shift - if (keynum == 16) - modShift = true; - else if (keynum == 17) - modCtrl = true; - else if (keynum == 18) - modAlt = true; + // Ctrl/Alt/Shift + if (keynum == 16) + modShift = true; + else if (keynum == 17) + modCtrl = true; + else if (keynum == 18) + modAlt = true; var keysym = getKeySymFromKeyCode(keynum); if (keysym) { @@ -269,11 +277,13 @@ Guacamole.Keyboard = function(element) { // Send key event here if (keySymSource == KEYDOWN) { + var returnValue = true; + if (keydownChar[keynum] != keysym) { // Send event keydownChar[keynum] = keysym; - sendKeyPressed(keysym); + returnValue = sendKeyPressed(keysym); // Clear old key repeat, if any. stopRepeat(); @@ -283,14 +293,14 @@ Guacamole.Keyboard = function(element) { repeatKeyTimeoutId = setTimeout(function() { startRepeat(keysym); }, 500); } - return false; + return returnValue; } return true; - }; + }; - // When key pressed + // When key pressed element.onkeypress = function(e) { // Only intercept if handler set @@ -298,10 +308,11 @@ Guacamole.Keyboard = function(element) { if (keySymSource != KEYPRESS) return false; - var keynum; - if (window.event) keynum = window.event.keyCode; - else if (e.which) keynum = e.which; + var keynum; + if (window.event) keynum = window.event.keyCode; + else if (e.which) keynum = e.which; + var returnValue = true; var keysym = getKeySymFromCharCode(keynum); if (keysym && keydownChar[keynum] != keysym) { @@ -316,32 +327,33 @@ Guacamole.Keyboard = function(element) { stopRepeat(); // Send key event - sendKeyPressed(keysym); + returnValue = sendKeyPressed(keysym); // Start repeating (if not a modifier key) after a short delay repeatKeyTimeoutId = setTimeout(function() { startRepeat(keysym); }, 500); } - return false; - }; + return returnValue; - // When key released - element.onkeyup = function(e) { + }; + + // When key released + element.onkeyup = function(e) { // Only intercept if handler set if (!guac_keyboard.onkeyup) return true; - var keynum; - if (window.event) keynum = window.event.keyCode; - else if (e.which) keynum = e.which; - - // Ctrl/Alt/Shift - if (keynum == 16) - modShift = false; - else if (keynum == 17) - modCtrl = false; - else if (keynum == 18) - modAlt = false; + var keynum; + if (window.event) keynum = window.event.keyCode; + else if (e.which) keynum = e.which; + + // Ctrl/Alt/Shift + if (keynum == 16) + modShift = false; + else if (keynum == 17) + modCtrl = false; + else if (keynum == 18) + modAlt = false; else stopRepeat(); @@ -352,16 +364,15 @@ Guacamole.Keyboard = function(element) { keydownChar[keynum] = null; // Send release event - sendKeyReleased(lastKeyDownChar); + return sendKeyReleased(lastKeyDownChar); - return false; - }; + }; - // When focus is lost, clear modifiers. - element.onblur = function() { - modAlt = false; - modCtrl = false; - modShift = false; - }; + // When focus is lost, clear modifiers. + element.onblur = function() { + modAlt = false; + modCtrl = false; + modShift = false; + }; }; From 8c7b883d55904b918d1c759fd8765ef634dfadd6 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 29 Mar 2012 17:42:34 -0700 Subject: [PATCH 171/263] Fixed regression with key repeat. --- .../src/main/resources/keyboard.js | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 3d4180a5d..07e4dcf99 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -277,13 +277,11 @@ Guacamole.Keyboard = function(element) { // Send key event here if (keySymSource == KEYDOWN) { - var returnValue = true; - if (keydownChar[keynum] != keysym) { // Send event keydownChar[keynum] = keysym; - returnValue = sendKeyPressed(keysym); + var returnValue = sendKeyPressed(keysym); // Clear old key repeat, if any. stopRepeat(); @@ -291,9 +289,16 @@ Guacamole.Keyboard = function(element) { // Start repeating (if not a modifier key) after a short delay if (keynum != 16 && keynum != 17 && keynum != 18) repeatKeyTimeoutId = setTimeout(function() { startRepeat(keysym); }, 500); + + // Use return code provided by handler + return returnValue; + } - return returnValue; + // Default to canceling event if no keypress is being sent, but + // source of events is keydown. + return false; + } return true; @@ -312,7 +317,6 @@ Guacamole.Keyboard = function(element) { if (window.event) keynum = window.event.keyCode; else if (e.which) keynum = e.which; - var returnValue = true; var keysym = getKeySymFromCharCode(keynum); if (keysym && keydownChar[keynum] != keysym) { @@ -327,13 +331,17 @@ Guacamole.Keyboard = function(element) { stopRepeat(); // Send key event - returnValue = sendKeyPressed(keysym); + var returnValue = sendKeyPressed(keysym); // Start repeating (if not a modifier key) after a short delay repeatKeyTimeoutId = setTimeout(function() { startRepeat(keysym); }, 500); + + return returnValue; } - return returnValue; + // Default to canceling event if no keypress is being sent, but + // source of events is keypress. + return false; }; From b0196b89f122e5e5b45a1efab512ae7dc0b37d8e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 29 Mar 2012 23:11:13 -0700 Subject: [PATCH 172/263] Partial cleanup, track and expose key and modifier states. --- .../src/main/resources/keyboard.js | 87 +++++++++++++------ 1 file changed, 60 insertions(+), 27 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 07e4dcf99..fd8134191 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -133,10 +133,35 @@ Guacamole.Keyboard = function(element) { 18: 0xFFE7 // alt }; - // Single key state/modifier buffer - var modShift = false; - var modCtrl = false; - var modAlt = false; + /** + * 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(); @@ -200,7 +225,7 @@ Guacamole.Keyboard = function(element) { function getKeySymFromKeyCode(keyCode) { var keysym = null; - if (!modShift) keysym = unshiftedKeySym[keyCode]; + if (!guac_keyboard.modifiers.shift) keysym = unshiftedKeySym[keyCode]; else { keysym = shiftedKeySym[keyCode]; if (keysym == null) keysym = unshiftedKeySym[keyCode]; @@ -213,16 +238,30 @@ Guacamole.Keyboard = function(element) { // 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) return guac_keyboard.onkeydown(keysym) != false; + return true; + } // 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) return guac_keyboard.onkeyup(keysym) != false; + return true; + } @@ -243,32 +282,29 @@ Guacamole.Keyboard = function(element) { else if (e.which) keynum = e.which; // Ctrl/Alt/Shift - if (keynum == 16) - modShift = true; - else if (keynum == 17) - modCtrl = true; - else if (keynum == 18) - modAlt = true; + 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; + // If keysym is defined for given key code, key events can come from + // KEYDOWN. var keysym = getKeySymFromKeyCode(keynum); - if (keysym) { - // Get keysyms and events from KEYDOWN + if (keysym) keySymSource = KEYDOWN; - } - // If modifier keys are held down, and we have keyIdentifier - else if ((modCtrl || modAlt) && e.keyIdentifier) { + // Otherwise, if modifier keys are held down, try to get from keyIdentifier + else if ((guac_keyboard.modifiers.ctrl || guac_keyboard.modifiers.alt) && e.keyIdentifier) { // Get keysym from keyIdentifier - keysym = getKeySymFromKeyIdentifier(modShift, e.keyIdentifier); + keysym = getKeySymFromKeyIdentifier(guac_keyboard.modifiers.shift, e.keyIdentifier); // Get keysyms and events from KEYDOWN keySymSource = KEYDOWN; } + // Otherwise, resort to KEYPRESS else - // Get keysyms and events from KEYPRESS keySymSource = KEYPRESS; keydownCode = keynum; @@ -356,12 +392,9 @@ Guacamole.Keyboard = function(element) { else if (e.which) keynum = e.which; // Ctrl/Alt/Shift - if (keynum == 16) - modShift = false; - else if (keynum == 17) - modCtrl = false; - else if (keynum == 18) - modAlt = false; + 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(); @@ -378,9 +411,9 @@ Guacamole.Keyboard = function(element) { // When focus is lost, clear modifiers. element.onblur = function() { - modAlt = false; - modCtrl = false; - modShift = false; + guac_keyboard.modifiers.alt = false; + guac_keyboard.modifiers.ctrl = false; + guac_keyboard.modifiers.shift = false; }; }; From fa961438844f9bea943d8a8dc69c7fdff8352940 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 29 Mar 2012 23:48:45 -0700 Subject: [PATCH 173/263] Move layers using translation via matrices - do not use CSS top/left. --- .../src/main/resources/guacamole.js | 101 ++++++++++++++---- 1 file changed, 78 insertions(+), 23 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 4cd95d0a8..4c5c99710 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -148,11 +148,8 @@ Guacamole.Client = function(tunnel) { function moveCursor(x, y) { - var element = cursor.getElement(); - - // Update rect - element.style.left = (x - cursorHotspotX) + "px"; - element.style.top = (y - cursorHotspotY) + "px"; + // Move cursor layer + cursor.translate(x - cursorHotspotX, y - cursorHotspotY); // Update stored position cursorX = x; @@ -460,18 +457,7 @@ Guacamole.Client = function(tunnel) { var layer_container = getLayerContainer(layer_index).getElement(); // Set layer transform - layer_container.style.transform = - layer_container.style.WebkitTransform = - layer_container.style.MozTransform = - layer_container.style.OTransform = - layer_container.style.msTransform = - - /* a c e - * b d f - * 0 0 1 - */ - - "matrix(" + a + "," + b + "," + c + "," + d + "," + e + "," + f + ")"; + layer_container.transform(a, b, c, d, e, f); } @@ -536,17 +522,17 @@ Guacamole.Client = function(tunnel) { if (layer_index > 0 && parent_index >= 0) { // Get container element - var layer_container = getLayerContainer(layer_index).getElement(); + 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.parentNode === parent)) - parent.appendChild(layer_container); + if (!(layer_container_element.parentNode === parent)) + parent.appendChild(layer_container_element); // Move layer - layer_container.style.left = x + "px"; - layer_container.style.top = y + "px"; - layer_container.style.zIndex = z; + layer_container.translate(x, y); + layer_container_element.style.zIndex = z; } @@ -888,6 +874,75 @@ Guacamole.Client.LayerContainer = function(width, height) { return div; }; + /** + * The translation component of this LayerContainer's transform. + */ + var translate = "translate(0px, 0px)"; // (0, 0) + + /** + * The arbitrary matrix component of this LayerContainer's transform. + */ + 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. + */ + layer_container.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. + */ + layer_container.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; + + }; + }; /** From ed3d12fbcecf9b646024b06e24fd958c99207515 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 30 Mar 2012 22:48:22 -0700 Subject: [PATCH 174/263] Implement right and middle-click. --- .../src/main/resources/mouse.js | 92 ++++++++++--------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 547f51722..f7cfb123e 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -143,28 +143,38 @@ Guacamole.Mouse = function(element) { }, false); + 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) { - // If we're handling a gesture - if (gesture_in_progress) { + // If we're handling a gesture AND this is the last touch + if (gesture_in_progress && e.touches.length == 1) { cancelEvent(e); var time = new Date().getTime(); - // If mouse already down, release anad clear timeout - if (guac_mouse.currentState.left) { + // Get corresponding mouse button + var button = touch_buttons[touch_count]; - // Fire left button up event - guac_mouse.currentState.left = false; + // If mouse already down, release anad clear timeout + if (guac_mouse.currentState[button]) { + + // Fire button up event + guac_mouse.currentState[button] = false; if (guac_mouse.onmouseup) guac_mouse.onmouseup(guac_mouse.currentState); @@ -179,8 +189,8 @@ Guacamole.Mouse = function(element) { // If single tap detected (based on time and distance) if (time - last_touch_time <= 250 && pixels_moved < 10) { - // Fire left button down event - guac_mouse.currentState.left = true; + // Fire button down event + guac_mouse.currentState[button] = true; if (guac_mouse.onmousedown) guac_mouse.onmousedown(guac_mouse.currentState); @@ -188,8 +198,8 @@ Guacamole.Mouse = function(element) { // touchstart within timeout. click_release_timeout = window.setTimeout(function() { - // Fire left button up event - guac_mouse.currentState.left = false; + // Fire button up event + guac_mouse.currentState[button] = false; if (guac_mouse.onmouseup) guac_mouse.onmouseup(guac_mouse.currentState); @@ -206,7 +216,10 @@ Guacamole.Mouse = function(element) { element.addEventListener("touchstart", function(e) { - // Record initial touch location and time for single-touch movement + // Track number of touches, but no more than three + touch_count = Math.max(e.touches.length, 3); + + // Record initial touch location and time for touch movement // and tap gestures if (e.touches.length == 1) { @@ -228,52 +241,45 @@ Guacamole.Mouse = function(element) { last_touch_time = new Date().getTime(); pixels_moved = 0; - // TODO: Handle different buttons - } }, false); element.addEventListener("touchmove", function(e) { - // Handle single-touch movement gesture (touchpad mouse move) - if (e.touches.length == 1) { + cancelEvent(e); - cancelEvent(e); + // Get change in touch location + var touch = e.touches[0]; + var delta_x = touch.screenX - last_touch_x; + var delta_y = touch.screenY - last_touch_y; - // Get change in touch location - var touch = e.touches[0]; - var delta_x = touch.screenX - last_touch_x; - var delta_y = touch.screenY - last_touch_y; + // Track pixels moved + pixels_moved += Math.abs(delta_x) + Math.abs(delta_y); - // Track pixels moved - pixels_moved += Math.abs(delta_x) + Math.abs(delta_y); + // Update mouse location + guac_mouse.currentState.x += delta_x; + guac_mouse.currentState.y += delta_y; - // Update mouse location - guac_mouse.currentState.x += delta_x; - guac_mouse.currentState.y += delta_y; + // Prevent mouse from leaving screen - // Prevent mouse from leaving screen + if (guac_mouse.currentState.x < 0) + guac_mouse.currentState.x = 0; + else if (guac_mouse.currentState.x >= element.offsetWidth) + guac_mouse.currentState.x = element.offsetWidth - 1; - if (guac_mouse.currentState.x < 0) - guac_mouse.currentState.x = 0; - else if (guac_mouse.currentState.x >= element.offsetWidth) - guac_mouse.currentState.x = element.offsetWidth - 1; + if (guac_mouse.currentState.y < 0) + guac_mouse.currentState.y = 0; + else if (guac_mouse.currentState.y >= element.offsetHeight) + guac_mouse.currentState.y = element.offsetHeight - 1; - if (guac_mouse.currentState.y < 0) - guac_mouse.currentState.y = 0; - else if (guac_mouse.currentState.y >= element.offsetHeight) - guac_mouse.currentState.y = element.offsetHeight - 1; + // Fire movement event, if defined + if (guac_mouse.onmousemove) + guac_mouse.onmousemove(guac_mouse.currentState); - // Fire movement event, if defined - if (guac_mouse.onmousemove) - guac_mouse.onmousemove(guac_mouse.currentState); - - // Update touch location - last_touch_x = touch.screenX; - last_touch_y = touch.screenY; - - } + // Update touch location + last_touch_x = touch.screenX; + last_touch_y = touch.screenY; }, false); From e22296bbff509621adbad69a1d45b873256280a8 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 30 Mar 2012 22:59:46 -0700 Subject: [PATCH 175/263] Check for last touch by verifying touch length 0, not 1. Fix wrong use of max() (should be min). --- guacamole-common-js/src/main/resources/mouse.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index f7cfb123e..066c65bde 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -161,7 +161,7 @@ Guacamole.Mouse = function(element) { element.addEventListener("touchend", function(e) { // If we're handling a gesture AND this is the last touch - if (gesture_in_progress && e.touches.length == 1) { + if (gesture_in_progress && e.touches.length == 0) { cancelEvent(e); @@ -217,7 +217,7 @@ Guacamole.Mouse = function(element) { element.addEventListener("touchstart", function(e) { // Track number of touches, but no more than three - touch_count = Math.max(e.touches.length, 3); + touch_count = Math.min(e.touches.length, 3); // Record initial touch location and time for touch movement // and tap gestures From 5e2858a4138900575da273c05d9ccd2dd7d9dd52 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 30 Mar 2012 23:12:19 -0700 Subject: [PATCH 176/263] Move all thresholds into properties, implement scrollwheel via touch. --- .../src/main/resources/mouse.js | 94 +++++++++++++++---- 1 file changed, 74 insertions(+), 20 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 066c65bde..d1217d47f 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -58,6 +58,24 @@ Guacamole.Mouse = function(element) { */ var guac_mouse = this; + /** + * The number of pixels a touch must move for it to be considered a scroll + * wheel event. + */ + this.scrollThreshold = 20; + + /** + * 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; + /** * 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 @@ -187,7 +205,8 @@ Guacamole.Mouse = function(element) { } // If single tap detected (based on time and distance) - if (time - last_touch_time <= 250 && pixels_moved < 10) { + if (time - last_touch_time <= guac_mouse.clickTimingThreshold + && pixels_moved < guac_mouse.clickMoveThreshold) { // Fire button down event guac_mouse.currentState[button] = true; @@ -206,7 +225,7 @@ Guacamole.Mouse = function(element) { // Allow mouse events now that touching is over gesture_in_progress = false; - }, 250); + }, guac_mouse.clickTimingThreshold); } @@ -257,29 +276,64 @@ Guacamole.Mouse = function(element) { // Track pixels moved pixels_moved += Math.abs(delta_x) + Math.abs(delta_y); - // Update mouse location - guac_mouse.currentState.x += delta_x; - guac_mouse.currentState.y += delta_y; + // If only one touch involved, this is mouse move + if (touch_count == 1) { - // Prevent mouse from leaving screen + // Update mouse location + guac_mouse.currentState.x += delta_x; + guac_mouse.currentState.y += delta_y; - if (guac_mouse.currentState.x < 0) - guac_mouse.currentState.x = 0; - else if (guac_mouse.currentState.x >= element.offsetWidth) - guac_mouse.currentState.x = element.offsetWidth - 1; + // Prevent mouse from leaving screen - if (guac_mouse.currentState.y < 0) - guac_mouse.currentState.y = 0; - else if (guac_mouse.currentState.y >= element.offsetHeight) - guac_mouse.currentState.y = element.offsetHeight - 1; + if (guac_mouse.currentState.x < 0) + guac_mouse.currentState.x = 0; + else if (guac_mouse.currentState.x >= element.offsetWidth) + guac_mouse.currentState.x = element.offsetWidth - 1; - // Fire movement event, if defined - if (guac_mouse.onmousemove) - guac_mouse.onmousemove(guac_mouse.currentState); + if (guac_mouse.currentState.y < 0) + guac_mouse.currentState.y = 0; + else if (guac_mouse.currentState.y >= element.offsetHeight) + guac_mouse.currentState.y = element.offsetHeight - 1; - // Update touch location - last_touch_x = touch.screenX; - last_touch_y = touch.screenY; + // Fire movement event, if defined + if (guac_mouse.onmousemove) + guac_mouse.onmousemove(guac_mouse.currentState); + + // Update touch location + last_touch_x = touch.screenX; + last_touch_y = touch.screenY; + + } + + // Otherwise, interpret as scrollwheel + else { + + // If change in location passes threshold for scroll + if (Math.abs(delta_y) >= guac_mouse.scrollThreshold) { + + // Decide button based on Y movement direction + var button; + if (delta_y > 0) button = "down"; + else button = "up"; + + // Fire button down event + guac_mouse.currentState[button] = true; + if (guac_mouse.onmousedown) + guac_mouse.onmousedown(guac_mouse.currentState); + + // Fire button up event + guac_mouse.currentState[button] = false; + if (guac_mouse.onmouseup) + guac_mouse.onmouseup(guac_mouse.currentState); + + // Only update touch location after a scroll has been + // detected + last_touch_x = touch.screenX; + last_touch_y = touch.screenY; + + } + + } }, false); From dcf55cbd7554de6fb58dc578872d96db37389690 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 1 Apr 2012 01:07:14 -0700 Subject: [PATCH 177/263] Add scale function, use bounding div for main display element, such that the display can be scaled independently of the surrounding div, which provides the layout. --- .../src/main/resources/guacamole.js | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 4c5c99710..43bd16520 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -67,6 +67,7 @@ Guacamole.Client = function(tunnel) { var displayWidth = 0; var displayHeight = 0; + var displayScale = 1; /** * Translation from Guacamole protocol line caps to Layer line caps. @@ -86,12 +87,26 @@ Guacamole.Client = function(tunnel) { 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); @@ -116,6 +131,9 @@ Guacamole.Client = function(tunnel) { 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]; @@ -158,7 +176,7 @@ Guacamole.Client = function(tunnel) { } guac_client.getDisplay = function() { - return display; + return bounds; }; guac_client.sendKeyEvent = function(pressed, keysym) { @@ -651,6 +669,10 @@ Guacamole.Client = function(tunnel) { 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"; + } }, @@ -801,6 +823,24 @@ Guacamole.Client = function(tunnel) { setState(STATE_WAITING); }; + guac_client.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"; + + }; + }; From 818f081bb54451c67167ca7875d5f26d5dd87308 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 1 Apr 2012 18:20:18 -0700 Subject: [PATCH 178/263] Set scroll and click thresholds relative to screen pixel density (if readable) and size of gesture. --- .../src/main/resources/mouse.js | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index d1217d47f..547579325 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -59,10 +59,10 @@ Guacamole.Mouse = function(element) { var guac_mouse = this; /** - * The number of pixels a touch must move for it to be considered a scroll - * wheel event. + * The distance a two-finger touch must move per scrollwheel event, relative + * to the distance between the two touches. */ - this.scrollThreshold = 20; + this.scrollThreshold = 0.5; /** * The maximum number of milliseconds to wait for a touch to end for the @@ -74,7 +74,7 @@ Guacamole.Mouse = function(element) { * The maximum number of pixels to allow a touch to move for the gesture to * be considered a click. */ - this.clickMoveThreshold = 10; + this.clickMoveThreshold = 10 * (window.displayPixelRatio || 1); /** * The current mouse state. The properties of this state are updated when @@ -166,6 +166,7 @@ Guacamole.Mouse = function(element) { var last_touch_y = 0; var last_touch_time = 0; var pixels_moved = 0; + var touch_distance = 0; var touch_buttons = { 1: "left", @@ -262,6 +263,12 @@ Guacamole.Mouse = function(element) { } + else if (e.touches.length == 2) { + var diff_x = e.touches[0].screenX - e.touches[1].screenX; + var diff_y = e.touches[0].screenY - e.touches[1].screenY; + touch_distance = Math.sqrt(diff_x*diff_x + diff_y*diff_y); + } + }, false); element.addEventListener("touchmove", function(e) { @@ -305,11 +312,11 @@ Guacamole.Mouse = function(element) { } - // Otherwise, interpret as scrollwheel - else { + // Interpret two-finger touch as scrollwheel + else if (touch_count == 2) { // If change in location passes threshold for scroll - if (Math.abs(delta_y) >= guac_mouse.scrollThreshold) { + if (Math.abs(delta_y) >= touch_distance * guac_mouse.scrollThreshold) { // Decide button based on Y movement direction var button; From ff20799b29a487f53f5819809b0d1e6e395adaba Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 1 Apr 2012 18:52:06 -0700 Subject: [PATCH 179/263] Provide means of retrieving scale. --- guacamole-common-js/src/main/resources/guacamole.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 43bd16520..204b606d2 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -841,8 +841,11 @@ Guacamole.Client = function(tunnel) { }; -}; + guac_client.getScale = function() { + return displayScale; + }; +}; /** * Simple container for Guacamole.Layer, allowing layers to be easily From f6868b866135e70728db0ca30e34eaaeb77b39ca Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 1 Apr 2012 18:52:49 -0700 Subject: [PATCH 180/263] "device" not "display" (typo). Switch back to two-finger scroll. --- .../src/main/resources/mouse.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 547579325..006c332cc 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -59,10 +59,10 @@ Guacamole.Mouse = function(element) { var guac_mouse = this; /** - * The distance a two-finger touch must move per scrollwheel event, relative - * to the distance between the two touches. + * The distance a two-finger touch must move per scrollwheel event, in + * pixels. */ - this.scrollThreshold = 0.5; + this.scrollThreshold = 20 * (window.devicePixelRatio || 1); /** * The maximum number of milliseconds to wait for a touch to end for the @@ -74,7 +74,7 @@ Guacamole.Mouse = function(element) { * The maximum number of pixels to allow a touch to move for the gesture to * be considered a click. */ - this.clickMoveThreshold = 10 * (window.displayPixelRatio || 1); + this.clickMoveThreshold = 10 * (window.devicePixelRatio || 1); /** * The current mouse state. The properties of this state are updated when @@ -263,12 +263,6 @@ Guacamole.Mouse = function(element) { } - else if (e.touches.length == 2) { - var diff_x = e.touches[0].screenX - e.touches[1].screenX; - var diff_y = e.touches[0].screenY - e.touches[1].screenY; - touch_distance = Math.sqrt(diff_x*diff_x + diff_y*diff_y); - } - }, false); element.addEventListener("touchmove", function(e) { @@ -312,11 +306,11 @@ Guacamole.Mouse = function(element) { } - // Interpret two-finger touch as scrollwheel + // Interpret two-finger swipe as scrollwheel else if (touch_count == 2) { // If change in location passes threshold for scroll - if (Math.abs(delta_y) >= touch_distance * guac_mouse.scrollThreshold) { + if (Math.abs(delta_y) >= guac_mouse.scrollThreshold) { // Decide button based on Y movement direction var button; From 9e1d2b24429ba923ef670aad803a18276d7b071b Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 3 Apr 2012 02:18:47 -0700 Subject: [PATCH 181/263] Fix iPad synchronization issue (ticket #90). --- .../src/main/resources/layer.js | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 8358fbbf9..ceb2618bf 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -74,6 +74,19 @@ Guacamole.Layer = function(width, height) { var displayContext = display.getContext("2d"); displayContext.save(); + /** + * A temporary canvas element whose contents can be relied on only + * through the duration of an operation. + * @private + */ + var temp = document.createElement("canvas"); + + /** + * The 2D display context of the temporary canvas element. + * @private + */ + var tempContext = temp.getContext("2d"); + /** * 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 @@ -400,6 +413,15 @@ Guacamole.Layer = function(width, height) { return display; }; + /** + * Returns the display context of the canvas element backing this layer. + * @returns {CanvasRenderingContext2D} The display context of the canvas + * element backing this layer. + */ + this.getContext = function() { + return displayContext; + }; + /** * Returns whether this Layer is ready. A Layer is ready if it has no * pending operations and no operations in-progress. @@ -570,8 +592,23 @@ Guacamole.Layer = function(width, height) { 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); + if (srcCanvas.width != 0 && srcCanvas.height != 0) { + + // Copy source data into temporary canvas (drawing from + // source canvas directly can cause the operation to be + // performed lazily by the underlying Canvas implementation, + // which undermines the sychronization built into these + // layers). + temp.width = srcw; + temp.height = srch; + tempContext.putImageData( + srcLayer.getContext().getImageData(srcx, srcy, srcw, srch), + 0, 0); + + // Draw from temporary canvas + displayContext.drawImage(temp, 0, 0, srcw, srch, x, y, srcw, srch); + + } }); }; From 6e835dacdce2cb20b671d808988aae8ac59d8bb0 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 3 Apr 2012 02:35:32 -0700 Subject: [PATCH 182/263] More efficient blocking, leveraging the now-necessary image data copy. --- .../src/main/resources/layer.js | 47 +++++++++++++++---- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index ceb2618bf..48452c534 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -588,29 +588,58 @@ Guacamole.Layer = function(width, height) { * @param {Number} y The destination Y coordinate. */ this.copy = function(srcLayer, srcx, srcy, srcw, srch, x, y) { - scheduleTaskSynced(srcLayer, function() { + + // If we are copying from ourselves, perform simple drawImage() copy. + // No other synchronization is necessary. + if (srcLayer === this) { + + scheduleTask(function() { + if (layer.autosize != 0) fitRect(x, y, srcw, srch); + displayContext.drawImage(srcLayer.getCanvas(), srcx, srcy, srcw, srch, x, y, srcw, srch); + }); + + return; + } + + // Note that source image data MUST be retrieved with getImageData() + // rather than drawing directly using the source canvas as an + // argument to drawImage(). This is because Canvas implementations may + // implement drawImage() lazily, which can cause rendering issues if + // the source canvas is updated before drawImage() is actually + // performed. Retrieving the actual underlying pixel data with + // getImageData() ensures that the image data is truly available. + + // Will contain image data once source layer is ready + var data; + + // Draw image data from the source layer any time after the + // source layer is ready (the copied image data will be stored + // such that the source layer can continue unimpeded). + var task = scheduleTask(function() { + if (layer.autosize != 0) fitRect(x, y, srcw, srch); var srcCanvas = srcLayer.getCanvas(); if (srcCanvas.width != 0 && srcCanvas.height != 0) { - // Copy source data into temporary canvas (drawing from - // source canvas directly can cause the operation to be - // performed lazily by the underlying Canvas implementation, - // which undermines the sychronization built into these - // layers). + // Copy image data onto temporary canvas temp.width = srcw; temp.height = srch; - tempContext.putImageData( - srcLayer.getContext().getImageData(srcx, srcy, srcw, srch), - 0, 0); + tempContext.putImageData(data, 0, 0); // Draw from temporary canvas displayContext.drawImage(temp, 0, 0, srcw, srch, x, y, srcw, srch); } + }, true); + + // When source layer is ready, pull data, and unblock draw task + srcLayer.sync(function() { + data = srcLayer.getContext().getImageData(srcx, srcy, srcw, srch); + task.unblock(); }); + }; /** From 041f22563cc434317af9daf24151bc966a02b2c8 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 5 Apr 2012 15:29:55 -0700 Subject: [PATCH 183/263] Revert fixes for iPad #90 due to performance regression - can avoid bug in libguac-client-rdp and friends until it is fixed upstream. --- .../src/main/resources/layer.js | 72 +------------------ 1 file changed, 3 insertions(+), 69 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 48452c534..8358fbbf9 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -74,19 +74,6 @@ Guacamole.Layer = function(width, height) { var displayContext = display.getContext("2d"); displayContext.save(); - /** - * A temporary canvas element whose contents can be relied on only - * through the duration of an operation. - * @private - */ - var temp = document.createElement("canvas"); - - /** - * The 2D display context of the temporary canvas element. - * @private - */ - var tempContext = temp.getContext("2d"); - /** * 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 @@ -413,15 +400,6 @@ Guacamole.Layer = function(width, height) { return display; }; - /** - * Returns the display context of the canvas element backing this layer. - * @returns {CanvasRenderingContext2D} The display context of the canvas - * element backing this layer. - */ - this.getContext = function() { - return displayContext; - }; - /** * Returns whether this Layer is ready. A Layer is ready if it has no * pending operations and no operations in-progress. @@ -588,58 +566,14 @@ Guacamole.Layer = function(width, height) { * @param {Number} y The destination Y coordinate. */ this.copy = function(srcLayer, srcx, srcy, srcw, srch, x, y) { - - // If we are copying from ourselves, perform simple drawImage() copy. - // No other synchronization is necessary. - if (srcLayer === this) { - - scheduleTask(function() { - if (layer.autosize != 0) fitRect(x, y, srcw, srch); - displayContext.drawImage(srcLayer.getCanvas(), srcx, srcy, srcw, srch, x, y, srcw, srch); - }); - - return; - } - - // Note that source image data MUST be retrieved with getImageData() - // rather than drawing directly using the source canvas as an - // argument to drawImage(). This is because Canvas implementations may - // implement drawImage() lazily, which can cause rendering issues if - // the source canvas is updated before drawImage() is actually - // performed. Retrieving the actual underlying pixel data with - // getImageData() ensures that the image data is truly available. - - // Will contain image data once source layer is ready - var data; - - // Draw image data from the source layer any time after the - // source layer is ready (the copied image data will be stored - // such that the source layer can continue unimpeded). - var task = scheduleTask(function() { - + scheduleTaskSynced(srcLayer, function() { if (layer.autosize != 0) fitRect(x, y, srcw, srch); var srcCanvas = srcLayer.getCanvas(); - if (srcCanvas.width != 0 && srcCanvas.height != 0) { + if (srcCanvas.width != 0 && srcCanvas.height != 0) + displayContext.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch); - // Copy image data onto temporary canvas - temp.width = srcw; - temp.height = srch; - tempContext.putImageData(data, 0, 0); - - // Draw from temporary canvas - displayContext.drawImage(temp, 0, 0, srcw, srch, x, y, srcw, srch); - - } - - }, true); - - // When source layer is ready, pull data, and unblock draw task - srcLayer.sync(function() { - data = srcLayer.getContext().getImageData(srcx, srcy, srcw, srch); - task.unblock(); }); - }; /** From eaa233520c01a07d860df0db4f6ca35777a11a59 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 6 Apr 2012 12:38:24 -0700 Subject: [PATCH 184/263] Calculate mouse position including scroll of overflow elements (cannot rely on pageX/Y). --- guacamole-common-js/src/main/resources/mouse.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 006c332cc..dbd4c2a2b 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -121,20 +121,17 @@ Guacamole.Mouse = function(element) { e.returnValue = false; } - function moveMouse(pageX, pageY) { + function moveMouse(clientX, clientY) { - guac_mouse.currentState.x = pageX - element.offsetLeft; - guac_mouse.currentState.y = pageY - element.offsetTop; + guac_mouse.currentState.x = clientX - element.offsetLeft; + guac_mouse.currentState.y = clientY - element.offsetTop; // This is all JUST so we can get the mouse position within the element var parent = element.offsetParent; while (parent) { - if (parent.offsetLeft) - guac_mouse.currentState.x -= parent.offsetLeft; - - if (parent.offsetTop) - guac_mouse.currentState.y -= parent.offsetTop; + guac_mouse.currentState.x -= parent.offsetLeft - parent.scrollLeft; + guac_mouse.currentState.y -= parent.offsetTop - parent.scrollTop; parent = parent.offsetParent; } @@ -157,7 +154,7 @@ Guacamole.Mouse = function(element) { cancelEvent(e); - moveMouse(e.pageX, e.pageY); + moveMouse(e.clientX, e.clientY); }, false); From df595d46ec6ac1cc789cd678786de5eb18371df7 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 8 Apr 2012 21:22:09 -0700 Subject: [PATCH 185/263] Avoid crazy accelerating autoscroll by using clientX/clientY instead of screenX/screenY. --- guacamole-common-js/src/main/resources/mouse.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index dbd4c2a2b..86672c97a 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -253,8 +253,8 @@ Guacamole.Mouse = function(element) { // Record touch location and time var starting_touch = e.touches[0]; - last_touch_x = starting_touch.screenX; - last_touch_y = starting_touch.screenY; + last_touch_x = starting_touch.clientX; + last_touch_y = starting_touch.clientY; last_touch_time = new Date().getTime(); pixels_moved = 0; @@ -268,8 +268,8 @@ Guacamole.Mouse = function(element) { // Get change in touch location var touch = e.touches[0]; - var delta_x = touch.screenX - last_touch_x; - var delta_y = touch.screenY - last_touch_y; + 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); @@ -298,8 +298,8 @@ Guacamole.Mouse = function(element) { guac_mouse.onmousemove(guac_mouse.currentState); // Update touch location - last_touch_x = touch.screenX; - last_touch_y = touch.screenY; + last_touch_x = touch.clientX; + last_touch_y = touch.clientY; } @@ -326,8 +326,8 @@ Guacamole.Mouse = function(element) { // Only update touch location after a scroll has been // detected - last_touch_x = touch.screenX; - last_touch_y = touch.screenY; + last_touch_x = touch.clientX; + last_touch_y = touch.clientY; } From 47b9e435597ca5d4d91ba2494252661a7a4014e4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 8 Apr 2012 21:51:00 -0700 Subject: [PATCH 186/263] Mouse acceleration. --- guacamole-common-js/src/main/resources/mouse.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 86672c97a..8613ce9bc 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -277,9 +277,15 @@ Guacamole.Mouse = function(element) { // 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_mouse.currentState.x += delta_x; - guac_mouse.currentState.y += delta_y; + guac_mouse.currentState.x += delta_x*scale; + guac_mouse.currentState.y += delta_y*scale; // Prevent mouse from leaving screen From 5e0c6d8c51b391a08e245d4fc0cfded668c6fcb1 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 8 Apr 2012 21:51:35 -0700 Subject: [PATCH 187/263] Only send integer coordinates in mouse events. --- guacamole-common-js/src/main/resources/guacamole.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 204b606d2..b68413714 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -208,7 +208,7 @@ Guacamole.Client = function(tunnel) { if (mouseState.down) buttonMask |= 16; // Send message - tunnel.sendMessage("mouse", mouseState.x, mouseState.y, buttonMask); + tunnel.sendMessage("mouse", Math.floor(mouseState.x), Math.floor(mouseState.y), buttonMask); }; guac_client.setClipboard = function(data) { From b2bcaef6816d315da4e02a641ae186d185519cbc Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 9 Apr 2012 13:57:58 -0700 Subject: [PATCH 188/263] Fix non-left mouse button clicks (there may not be one touchstart event per touch). Fix setting/resetting of `gesture_in_progress` flag. --- .../src/main/resources/mouse.js | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 8613ce9bc..1c681745f 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -163,7 +163,6 @@ Guacamole.Mouse = function(element) { var last_touch_y = 0; var last_touch_time = 0; var pixels_moved = 0; - var touch_distance = 0; var touch_buttons = { 1: "left", @@ -176,11 +175,11 @@ Guacamole.Mouse = function(element) { element.addEventListener("touchend", function(e) { + cancelEvent(e); + // If we're handling a gesture AND this is the last touch if (gesture_in_progress && e.touches.length == 0) { - cancelEvent(e); - var time = new Date().getTime(); // Get corresponding mouse button @@ -220,37 +219,41 @@ Guacamole.Mouse = function(element) { if (guac_mouse.onmouseup) guac_mouse.onmouseup(guac_mouse.currentState); - // Allow mouse events now that touching is over + // Gesture now over gesture_in_progress = false; - + }, guac_mouse.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) { + cancelEvent(e); + // 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 (e.touches.length == 1) { - - cancelEvent(e); + if (!gesture_in_progress) { // Stop mouse events while touching gesture_in_progress = true; - // Clear timeout, if set - if (click_release_timeout) { - window.clearTimeout(click_release_timeout); - click_release_timeout = null; - } - // Record touch location and time var starting_touch = e.touches[0]; last_touch_x = starting_touch.clientX; From 63685aa048a4488bb1b645a3c9b660758baa93bf Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 10 Apr 2012 22:53:30 -0700 Subject: [PATCH 189/263] Position mouse cursor only at integer coordinates. --- guacamole-common-js/src/main/resources/guacamole.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index b68413714..71679c084 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -195,8 +195,8 @@ Guacamole.Client = function(tunnel) { // Update client-side cursor moveCursor( - mouseState.x, - mouseState.y + Math.floor(mouseState.x), + Math.floor(mouseState.y) ); // Build mask From 76fd31bd53d20d4f9439923a615b497e5b4704df Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 1 May 2012 14:33:31 -0700 Subject: [PATCH 190/263] Properly offset mouse by document scroll amount (Firefox/Chrome, etc. inconsistency) - fixes ticket #124. --- guacamole-common-js/src/main/resources/mouse.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 1c681745f..8fd1d6a5e 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -128,14 +128,20 @@ Guacamole.Mouse = function(element) { // This is all JUST so we can get the mouse position within the element var parent = element.offsetParent; - while (parent) { - + while (parent && !(parent === document.body)) { guac_mouse.currentState.x -= parent.offsetLeft - parent.scrollLeft; guac_mouse.currentState.y -= parent.offsetTop - parent.scrollTop; parent = parent.offsetParent; } + // Offset by document scroll amount + var documentScrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft; + var documentScrollTop = document.body.scrollTop || document.documentElement.scrollTop; + + guac_mouse.currentState.x -= parent.offsetLeft - documentScrollLeft; + guac_mouse.currentState.y -= parent.offsetTop - documentScrollTop; + if (guac_mouse.onmousemove) guac_mouse.onmousemove(guac_mouse.currentState); From f5515d67529ee7d9f8218769f83c7520dc757a0e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 4 May 2012 18:46:20 -0700 Subject: [PATCH 191/263] Updated ChangeLog --- guacamole-common-js/ChangeLog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/guacamole-common-js/ChangeLog b/guacamole-common-js/ChangeLog index 250fe0ad6..62eaab587 100644 --- a/guacamole-common-js/ChangeLog +++ b/guacamole-common-js/ChangeLog @@ -1,3 +1,10 @@ +2012-05-04 Michael Jumper + + * Improved iPad and touch device support + * Improved touch support + * Implemented new drawing instructions + * Nestable layers + 2011-12-11 Michael Jumper * Implemented improved instruction format From d6b1985396da2b333d938fc05d688ed74875ebf4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 14 May 2012 09:17:15 -0700 Subject: [PATCH 192/263] Defer handling of keypress via JS event queue. --- .../src/main/resources/keyboard.js | 126 ++++++++---------- 1 file changed, 52 insertions(+), 74 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index fd8134191..08597ff68 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -265,13 +265,44 @@ Guacamole.Keyboard = function(element) { } - var KEYDOWN = 1; - var KEYPRESS = 2; + var keydown_code = null; - var keySymSource = null; + var deferred_keypress = null; + var keydown_keysym = null; + var keypress_keysym = null; + + function fireKeyPress() { + + // 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; + + } // When key pressed - var keydownCode = null; element.onkeydown = function(e) { // Only intercept if handler set @@ -286,58 +317,22 @@ Guacamole.Keyboard = function(element) { else if (keynum == 17) guac_keyboard.modifiers.ctrl = true; else if (keynum == 18) guac_keyboard.modifiers.alt = true; - // If keysym is defined for given key code, key events can come from - // KEYDOWN. - var keysym = getKeySymFromKeyCode(keynum); - if (keysym) - keySymSource = KEYDOWN; + // Try to get keysym from keycode + keydown_keysym = getKeySymFromKeyCode(keynum); - // Otherwise, if modifier keys are held down, try to get from keyIdentifier - else if ((guac_keyboard.modifiers.ctrl || guac_keyboard.modifiers.alt) && e.keyIdentifier) { + // Also try to get get keysym from keyIdentifier + if (e.keyIdentifier) + keydown_keysym = getKeySymFromKeyIdentifier(guac_keyboard.modifiers.shift, e.keyIdentifier); - // Get keysym from keyIdentifier - keysym = getKeySymFromKeyIdentifier(guac_keyboard.modifiers.shift, e.keyIdentifier); + // Set keycode which will be associated with any future keypress + keydown_code = keynum; - // Get keysyms and events from KEYDOWN - keySymSource = KEYDOWN; + // Defer handling of event until after any other pending + // key events. + if (!deferred_keypress) + deferred_keypress = window.setTimeout(fireKeyPress, 0); - } - - // Otherwise, resort to KEYPRESS - else - keySymSource = KEYPRESS; - - keydownCode = keynum; - - // Ignore key if we don't need to use KEYPRESS. - // Send key event here - if (keySymSource == KEYDOWN) { - - if (keydownChar[keynum] != keysym) { - - // Send event - keydownChar[keynum] = keysym; - var returnValue = 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); - - // Use return code provided by handler - return returnValue; - - } - - // Default to canceling event if no keypress is being sent, but - // source of events is keydown. - return false; - - } - - return true; + return false; }; @@ -353,30 +348,13 @@ Guacamole.Keyboard = function(element) { if (window.event) keynum = window.event.keyCode; else if (e.which) keynum = e.which; - var keysym = getKeySymFromCharCode(keynum); - if (keysym && keydownChar[keynum] != keysym) { + keypress_keysym = getKeySymFromCharCode(keynum); - // If this button already pressed, release first - var lastKeyDownChar = keydownChar[keydownCode]; - if (lastKeyDownChar) - sendKeyReleased(lastKeyDownChar); + // Defer handling of event until after any other pending + // key events. + if (!deferred_keypress) + deferred_keypress = window.setTimeout(fireKeyPress, 0); - keydownChar[keydownCode] = keysym; - - // Clear old key repeat, if any. - stopRepeat(); - - // Send key event - var returnValue = sendKeyPressed(keysym); - - // Start repeating (if not a modifier key) after a short delay - repeatKeyTimeoutId = setTimeout(function() { startRepeat(keysym); }, 500); - - return returnValue; - } - - // Default to canceling event if no keypress is being sent, but - // source of events is keypress. return false; }; From 0abc6b3562d16b4d05d598ab992fd69468c046f2 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 14 May 2012 10:15:43 -0700 Subject: [PATCH 193/263] Add keyidentifier map. --- .../src/main/resources/keyboard.js | 84 ++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 08597ff68..526af2f82 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -122,6 +122,88 @@ Guacamole.Keyboard = function(element) { 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 @@ -206,7 +288,7 @@ Guacamole.Keyboard = function(element) { } - return null; + return keyidentifier_keysym[keyIdentifier]; } From d3f5d003ea3703e2721e516ca87ad6f42b16d301 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 14 May 2012 13:21:43 -0700 Subject: [PATCH 194/263] Only cancel keydown if not typable. Release Ctrl and Alt if actually typing a character via keypress (if they are not functioning as Ctrl or Alt). Cancel keydown if Ctrl or Alt (but not both) are held, even if we expect the character to be typable. --- .../src/main/resources/keyboard.js | 52 ++++++++++++++++--- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 526af2f82..6787af8c3 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -381,6 +381,29 @@ Guacamole.Keyboard = function(element) { // 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 (codepoint <= 0x1F) return false; + if (codepoint >= 0x7F && codepoint <= 0x9F) return false; + + // Otherwise, typable + return true; } @@ -388,7 +411,7 @@ Guacamole.Keyboard = function(element) { element.onkeydown = function(e) { // Only intercept if handler set - if (!guac_keyboard.onkeydown) return true; + if (!guac_keyboard.onkeydown) return; var keynum; if (window.event) keynum = window.event.keyCode; @@ -403,8 +426,22 @@ Guacamole.Keyboard = function(element) { keydown_keysym = getKeySymFromKeyCode(keynum); // Also try to get get keysym from keyIdentifier - if (e.keyIdentifier) - keydown_keysym = getKeySymFromKeyIdentifier(guac_keyboard.modifiers.shift, e.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)) + e.preventDefault(); + + } // Set keycode which will be associated with any future keypress keydown_code = keynum; @@ -414,8 +451,6 @@ Guacamole.Keyboard = function(element) { if (!deferred_keypress) deferred_keypress = window.setTimeout(fireKeyPress, 0); - return false; - }; // When key pressed @@ -424,14 +459,17 @@ Guacamole.Keyboard = function(element) { // Only intercept if handler set if (!guac_keyboard.onkeydown) return true; - if (keySymSource != KEYPRESS) return false; - 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 (keypress involved) + // then release Ctrl and Alt (if pressed) + if (guac_keyboard.modifiers.ctrl) sendKeyReleased(0xFFE3); + if (guac_keyboard.modifiers.alt) sendKeyReleased(0xFFE9); + // Defer handling of event until after any other pending // key events. if (!deferred_keypress) From b8ad66ab6e77ac8b3345519c3ce75482ae944971 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 14 May 2012 13:44:17 -0700 Subject: [PATCH 195/263] Only release ctrl/alt in keypress handler if character is not a control character. Beware that this causes a regression in Firefox as it sends keypress for Alt+combinations and Ctrl+combinations even though they will not type anything. --- .../src/main/resources/keyboard.js | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 6787af8c3..c60759e9e 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -292,13 +292,22 @@ Guacamole.Keyboard = function(element) { } - function getKeySymFromCharCode(keyCode) { + function isControlCharacter(codepoint) { + return codepoint <= 0x1F || (codepoint >= 0x7F && codepoint <= 0x9F); + } - if (keyCode >= 0x0000 && keyCode <= 0x00FF) - return keyCode; + function getKeySymFromCharCode(codepoint) { - if (keyCode >= 0x0100 && keyCode <= 0x10FFFF) - return 0x01000000 | keyCode; + // 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; @@ -399,8 +408,7 @@ Guacamole.Keyboard = function(element) { var codepoint = parseInt(hex, 16); // If control character, not typable - if (codepoint <= 0x1F) return false; - if (codepoint >= 0x7F && codepoint <= 0x9F) return false; + if (isControlCharacter(codepoint)) return false; // Otherwise, typable return true; @@ -465,10 +473,12 @@ Guacamole.Keyboard = function(element) { keypress_keysym = getKeySymFromCharCode(keynum); - // If event identified as a typable character (keypress involved) + // If event identified as a typable character // then release Ctrl and Alt (if pressed) - if (guac_keyboard.modifiers.ctrl) sendKeyReleased(0xFFE3); - if (guac_keyboard.modifiers.alt) sendKeyReleased(0xFFE9); + if (!isControlCharacter(keynum)) { + if (guac_keyboard.modifiers.ctrl) sendKeyReleased(0xFFE3); + if (guac_keyboard.modifiers.alt) sendKeyReleased(0xFFE9); + } // Defer handling of event until after any other pending // key events. From 49fa2723a9e4bb1a1dcdc147f39bbeadf7a4143f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 14 May 2012 13:54:44 -0700 Subject: [PATCH 196/263] Only send release for ctrl+alt when both are pressed (we assume Ctrl+Alt == AltGr in the context of keypress). --- guacamole-common-js/src/main/resources/keyboard.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index c60759e9e..142d7ac7f 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -473,11 +473,11 @@ Guacamole.Keyboard = function(element) { keypress_keysym = getKeySymFromCharCode(keynum); - // If event identified as a typable character - // then release Ctrl and Alt (if pressed) - if (!isControlCharacter(keynum)) { - if (guac_keyboard.modifiers.ctrl) sendKeyReleased(0xFFE3); - if (guac_keyboard.modifiers.alt) sendKeyReleased(0xFFE9); + // 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); } // Defer handling of event until after any other pending From 0399689177a898b263fe2986b02e5e0d90b657d0 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 16 May 2012 00:52:16 -0700 Subject: [PATCH 197/263] Ignore unknown key events. --- .../src/main/resources/keyboard.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 142d7ac7f..eb2523d87 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -425,6 +425,12 @@ Guacamole.Keyboard = function(element) { if (window.event) keynum = window.event.keyCode; else if (e.which) keynum = e.which; + // Ignore any unknown key events + if (keynum == 0) { + e.preventDefault(); + return; + } + // Ctrl/Alt/Shift if (keynum == 16) guac_keyboard.modifiers.shift = true; else if (keynum == 17) guac_keyboard.modifiers.ctrl = true; @@ -465,7 +471,7 @@ Guacamole.Keyboard = function(element) { element.onkeypress = function(e) { // Only intercept if handler set - if (!guac_keyboard.onkeydown) return true; + if (!guac_keyboard.onkeydown) return; var keynum; if (window.event) keynum = window.event.keyCode; @@ -485,20 +491,24 @@ Guacamole.Keyboard = function(element) { if (!deferred_keypress) deferred_keypress = window.setTimeout(fireKeyPress, 0); - return false; - }; // When key released element.onkeyup = function(e) { // Only intercept if handler set - if (!guac_keyboard.onkeyup) return true; + if (!guac_keyboard.onkeyup) return; + + e.preventDefault(); var keynum; if (window.event) keynum = window.event.keyCode; else if (e.which) keynum = e.which; + // Ignore any unknown key events + if (keynum == 0) + return; + // Ctrl/Alt/Shift if (keynum == 16) guac_keyboard.modifiers.shift = false; else if (keynum == 17) guac_keyboard.modifiers.ctrl = false; @@ -513,7 +523,7 @@ Guacamole.Keyboard = function(element) { keydownChar[keynum] = null; // Send release event - return sendKeyReleased(lastKeyDownChar); + sendKeyReleased(lastKeyDownChar); }; From 685f07ed752e435febd308be18199acb7b260b4c Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 16 May 2012 10:36:37 -0700 Subject: [PATCH 198/263] Don't wait for keypress if keycode well defined. Define space via keycode (some browsers interpret "space" as scroll down). --- guacamole-common-js/src/main/resources/keyboard.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index eb2523d87..d1d222452 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -93,6 +93,7 @@ Guacamole.Keyboard = function(element) { 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 @@ -439,6 +440,11 @@ Guacamole.Keyboard = function(element) { // Try to get keysym from keycode keydown_keysym = getKeySymFromKeyCode(keynum); + // If key is known from keycode, prevent default + if (keydown_keysym) + e.preventDefault(); + + // Also try to get get keysym from keyIdentifier if (e.keyIdentifier) { From aa7c38be3206cfadffd21e6c67833aac4fef2dfe Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 16 May 2012 10:40:06 -0700 Subject: [PATCH 199/263] Should be using clearTimeout(), not clearInterval() for timeout. --- guacamole-common-js/src/main/resources/keyboard.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index d1d222452..af19c2697 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -262,7 +262,7 @@ Guacamole.Keyboard = function(element) { // Stops repeating keystrokes function stopRepeat() { - if (repeatKeyTimeoutId != -1) clearInterval(repeatKeyTimeoutId); + if (repeatKeyTimeoutId != -1) clearTimeout(repeatKeyTimeoutId); if (repeatKeyIntervalId != -1) clearInterval(repeatKeyIntervalId); } @@ -511,10 +511,6 @@ Guacamole.Keyboard = function(element) { if (window.event) keynum = window.event.keyCode; else if (e.which) keynum = e.which; - // Ignore any unknown key events - if (keynum == 0) - return; - // Ctrl/Alt/Shift if (keynum == 16) guac_keyboard.modifiers.shift = false; else if (keynum == 17) guac_keyboard.modifiers.ctrl = false; From a650a4a6ecb7a02872d921ad3a99611a8955d472 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 16 May 2012 13:36:28 -0700 Subject: [PATCH 200/263] As keydown/keypress are handled via deferred setTimeout(), so should keyup (otherwise, there's a race condition that keyup might happen before the deferred handling of keydown/keypress, and the key might be effectively stuck down or in a repeating state). --- .../src/main/resources/keyboard.js | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index af19c2697..4f957164f 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -511,21 +511,27 @@ Guacamole.Keyboard = function(element) { 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(); + // Defer handling of keyup (otherwise, keyup may happen before + // deferred handling of keydown/keypress). + window.setTimeout(function() { - // Get corresponding character - var lastKeyDownChar = keydownChar[keynum]; + // 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(); - // Clear character record - keydownChar[keynum] = null; + // Get corresponding character + var lastKeyDownChar = keydownChar[keynum]; - // Send release event - sendKeyReleased(lastKeyDownChar); + // Clear character record + keydownChar[keynum] = null; + + // Send release event + sendKeyReleased(lastKeyDownChar); + + }, 0); }; From 6cc12e88f9fccc92f19c83f47f0a59aef3bd42b5 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 16 May 2012 13:38:28 -0700 Subject: [PATCH 201/263] preventDefault() in keypress, too. --- guacamole-common-js/src/main/resources/keyboard.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 4f957164f..fe2e777b3 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -444,7 +444,6 @@ Guacamole.Keyboard = function(element) { if (keydown_keysym) e.preventDefault(); - // Also try to get get keysym from keyIdentifier if (e.keyIdentifier) { @@ -479,6 +478,8 @@ Guacamole.Keyboard = function(element) { // Only intercept if handler set if (!guac_keyboard.onkeydown) return; + e.preventDefault(); + var keynum; if (window.event) keynum = window.event.keyCode; else if (e.which) keynum = e.which; From 88e2a7d500ec90b32215cee0a5edb250b87a8ad9 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 16 May 2012 15:32:46 -0700 Subject: [PATCH 202/263] Renamed deferred handler. --- guacamole-common-js/src/main/resources/keyboard.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index fe2e777b3..82a85c52c 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -363,7 +363,7 @@ Guacamole.Keyboard = function(element) { var keydown_keysym = null; var keypress_keysym = null; - function fireKeyPress() { + function handleKeyEvents() { // Prefer keysym from keypress var keysym = keypress_keysym || keydown_keysym; @@ -468,7 +468,7 @@ Guacamole.Keyboard = function(element) { // Defer handling of event until after any other pending // key events. if (!deferred_keypress) - deferred_keypress = window.setTimeout(fireKeyPress, 0); + deferred_keypress = window.setTimeout(handleKeyEvents, 0); }; @@ -496,7 +496,7 @@ Guacamole.Keyboard = function(element) { // Defer handling of event until after any other pending // key events. if (!deferred_keypress) - deferred_keypress = window.setTimeout(fireKeyPress, 0); + deferred_keypress = window.setTimeout(handleKeyEvents, 0); }; From 03486264d16319dad6f0b1a43bc3307034570285 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 17 May 2012 00:23:52 -0700 Subject: [PATCH 203/263] Implement size for buffers. --- .../src/main/resources/guacamole.js | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 71679c084..1cf3b942c 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -655,24 +655,35 @@ Guacamole.Client = function(tunnel) { var width = parseInt(parameters[1]); var height = parseInt(parameters[2]); - // Resize layer - var layer_container = getLayerContainer(layer_index); - layer_container.resize(width, height); + // If not buffer, resize layer and container + if (layer_index >= 0) { - // If layer is default, resize display - if (layer_index == 0) { + // Resize layer + var layer_container = getLayerContainer(layer_index); + layer_container.resize(width, height); - displayWidth = width; - displayHeight = height; + // If layer is default, resize display + if (layer_index == 0) { - // Update (set) display size - display.style.width = displayWidth + "px"; - display.style.height = displayHeight + "px"; + displayWidth = width; + displayHeight = height; - // Update bounds size - bounds.style.width = (displayWidth*displayScale) + "px"; - bounds.style.height = (displayHeight*displayScale) + "px"; + // 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); } }, From 8f8b41fe8b09d22ba930b9cf8daa2b325916d7ae Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 20 Jun 2012 22:46:53 -0700 Subject: [PATCH 204/263] Use timeout only as failsafe. Send key events immediately when we know we will handle via keypress or keydown. --- .../src/main/resources/keyboard.js | 62 ++++++++++--------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 82a85c52c..a059847ee 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -432,6 +432,8 @@ Guacamole.Keyboard = function(element) { return; } + var expect_keypress = true; + // Ctrl/Alt/Shift if (keynum == 16) guac_keyboard.modifiers.shift = true; else if (keynum == 17) guac_keyboard.modifiers.ctrl = true; @@ -442,7 +444,7 @@ Guacamole.Keyboard = function(element) { // If key is known from keycode, prevent default if (keydown_keysym) - e.preventDefault(); + expect_keypress = false; // Also try to get get keysym from keyIdentifier if (e.keyIdentifier) { @@ -458,17 +460,25 @@ Guacamole.Keyboard = function(element) { if (!isTypable(e.keyIdentifier) || ( guac_keyboard.modifiers.ctrl && !guac_keyboard.modifiers.alt) || (!guac_keyboard.modifiers.ctrl && guac_keyboard.modifiers.alt)) - e.preventDefault(); + expect_keypress = false; } // Set keycode which will be associated with any future keypress keydown_code = keynum; - // Defer handling of event until after any other pending - // key events. - if (!deferred_keypress) - deferred_keypress = window.setTimeout(handleKeyEvents, 0); + // 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(); + } }; @@ -493,10 +503,12 @@ Guacamole.Keyboard = function(element) { sendKeyReleased(0xFFE9); } - // Defer handling of event until after any other pending - // key events. - if (!deferred_keypress) - deferred_keypress = window.setTimeout(handleKeyEvents, 0); + // Clear timeout, if any + if (deferred_keypress) + window.clearTimeout(deferred_keypress); + + // Handle event with all aggregated data + handleKeyEvents(); }; @@ -512,27 +524,21 @@ Guacamole.Keyboard = function(element) { if (window.event) keynum = window.event.keyCode; else if (e.which) keynum = e.which; - // Defer handling of keyup (otherwise, keyup may happen before - // deferred handling of keydown/keypress). - window.setTimeout(function() { + // 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(); - // 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]; - // Get corresponding character - var lastKeyDownChar = keydownChar[keynum]; + // Clear character record + keydownChar[keynum] = null; - // Clear character record - keydownChar[keynum] = null; - - // Send release event - sendKeyReleased(lastKeyDownChar); - - }, 0); + // Send release event + sendKeyReleased(lastKeyDownChar); }; From 078322f8083e86947479fac02511e98c8f4d84eb Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 27 Jul 2012 13:21:45 -0700 Subject: [PATCH 205/263] Do not handle keypress if we already handled the event in keydown. --- guacamole-common-js/src/main/resources/keyboard.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index a059847ee..474c42be6 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -357,6 +357,7 @@ Guacamole.Keyboard = function(element) { } + var expect_keypress = true; var keydown_code = null; var deferred_keypress = null; @@ -432,7 +433,7 @@ Guacamole.Keyboard = function(element) { return; } - var expect_keypress = true; + expect_keypress = true; // Ctrl/Alt/Shift if (keynum == 16) guac_keyboard.modifiers.shift = true; @@ -490,6 +491,10 @@ Guacamole.Keyboard = function(element) { 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; From afdc4ed536e9da28fc4733e2336063151e8fbed4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 21 May 2012 17:39:41 -0700 Subject: [PATCH 206/263] Split Guacamole.Mouse into Guacamole.Mouse (mouse event handling) and Guacamole.Mouse.Touchpad (touch event translation handling). --- .../src/main/resources/mouse.js | 357 ++++++++++-------- 1 file changed, 201 insertions(+), 156 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 8fd1d6a5e..72ccb02a8 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -44,9 +44,6 @@ var Guacamole = Guacamole || {}; * mouse events into a non-browser-specific event provided by the * Guacamole.Mouse instance. * - * 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 mouse events. */ @@ -58,24 +55,6 @@ Guacamole.Mouse = function(element) { */ var guac_mouse = 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 @@ -155,15 +134,213 @@ Guacamole.Mouse = function(element) { element.addEventListener("mousemove", function(e) { - // Don't handle if we aren't supposed to - if (gesture_in_progress) return; - cancelEvent(e); moveMouse(e.clientX, e.clientY); }, false); + element.addEventListener("mousedown", function(e) { + + cancelEvent(e); + + 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); + + 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); + + // 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 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. + * @private + */ + var guac_mouse = 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 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; + + function cancelEvent(e) { + e.stopPropagation(); + if (e.preventDefault) e.preventDefault(); + e.returnValue = false; + } + var touch_count = 0; var last_touch_x = 0; var last_touch_y = 0; @@ -350,138 +527,6 @@ Guacamole.Mouse = function(element) { }, false); - - element.addEventListener("mousedown", function(e) { - - // Don't handle if we aren't supposed to - if (gesture_in_progress) return; - - cancelEvent(e); - - 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) { - - // Don't handle if we aren't supposed to - if (gesture_in_progress) return; - - cancelEvent(e); - - 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) { - - // Don't handle if we aren't supposed to - if (gesture_in_progress) return; - - // 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); - - // Scroll wheel support - function mousewheel_handler(e) { - - // Don't handle if we aren't supposed to - if (gesture_in_progress) return; - - 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); - }; /** From 6800bd73290d50b7677495b438e0d7b589526d08 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 22 May 2012 00:09:23 -0700 Subject: [PATCH 207/263] Cleaned up Guacamole.Mouse.Touchpad and docs. --- .../src/main/resources/mouse.js | 99 ++++++++++--------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 72ccb02a8..a0c39797e 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -273,10 +273,10 @@ Guacamole.Mouse = function(element) { Guacamole.Mouse.Touchpad = function(element) { /** - * Reference to this Guacamole.Mouse. + * Reference to this Guacamole.Mouse.Touchpad. * @private */ - var guac_mouse = this; + var guac_touchpad = this; /** * The distance a two-finger touch must move per scrollwheel event, in @@ -309,8 +309,10 @@ Guacamole.Mouse.Touchpad = function(element) { ); /** - * Fired whenever the user presses a mouse button down over the element - * associated with this Guacamole.Mouse. + * 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. @@ -318,8 +320,10 @@ Guacamole.Mouse.Touchpad = function(element) { this.onmousedown = null; /** - * Fired whenever the user releases a mouse button down over the element - * associated with this Guacamole.Mouse. + * 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. @@ -327,20 +331,14 @@ Guacamole.Mouse.Touchpad = function(element) { this.onmouseup = null; /** - * Fired whenever the user moves the mouse over the element associated with - * this Guacamole.Mouse. + * 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; - function cancelEvent(e) { - e.stopPropagation(); - if (e.preventDefault) e.preventDefault(); - e.returnValue = false; - } - var touch_count = 0; var last_touch_x = 0; var last_touch_y = 0; @@ -358,7 +356,8 @@ Guacamole.Mouse.Touchpad = function(element) { element.addEventListener("touchend", function(e) { - cancelEvent(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) { @@ -369,12 +368,12 @@ Guacamole.Mouse.Touchpad = function(element) { var button = touch_buttons[touch_count]; // If mouse already down, release anad clear timeout - if (guac_mouse.currentState[button]) { + if (guac_touchpad.currentState[button]) { // Fire button up event - guac_mouse.currentState[button] = false; - if (guac_mouse.onmouseup) - guac_mouse.onmouseup(guac_mouse.currentState); + guac_touchpad.currentState[button] = false; + if (guac_touchpad.onmouseup) + guac_touchpad.onmouseup(guac_touchpad.currentState); // Clear timeout, if set if (click_release_timeout) { @@ -385,27 +384,27 @@ Guacamole.Mouse.Touchpad = function(element) { } // If single tap detected (based on time and distance) - if (time - last_touch_time <= guac_mouse.clickTimingThreshold - && pixels_moved < guac_mouse.clickMoveThreshold) { + if (time - last_touch_time <= guac_touchpad.clickTimingThreshold + && pixels_moved < guac_touchpad.clickMoveThreshold) { // Fire button down event - guac_mouse.currentState[button] = true; - if (guac_mouse.onmousedown) - guac_mouse.onmousedown(guac_mouse.currentState); + 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_mouse.currentState[button] = false; - if (guac_mouse.onmouseup) - guac_mouse.onmouseup(guac_mouse.currentState); + guac_touchpad.currentState[button] = false; + if (guac_touchpad.onmouseup) + guac_touchpad.onmouseup(guac_touchpad.currentState); // Gesture now over gesture_in_progress = false; - }, guac_mouse.clickTimingThreshold); + }, guac_touchpad.clickTimingThreshold); } @@ -419,7 +418,8 @@ Guacamole.Mouse.Touchpad = function(element) { element.addEventListener("touchstart", function(e) { - cancelEvent(e); + e.stopPropagation(); + e.preventDefault(); // Track number of touches, but no more than three touch_count = Math.min(e.touches.length, 3); @@ -450,7 +450,8 @@ Guacamole.Mouse.Touchpad = function(element) { element.addEventListener("touchmove", function(e) { - cancelEvent(e); + e.stopPropagation(); + e.preventDefault(); // Get change in touch location var touch = e.touches[0]; @@ -470,24 +471,24 @@ Guacamole.Mouse.Touchpad = function(element) { var scale = 1 + velocity; // Update mouse location - guac_mouse.currentState.x += delta_x*scale; - guac_mouse.currentState.y += delta_y*scale; + guac_touchpad.currentState.x += delta_x*scale; + guac_touchpad.currentState.y += delta_y*scale; // Prevent mouse from leaving screen - if (guac_mouse.currentState.x < 0) - guac_mouse.currentState.x = 0; - else if (guac_mouse.currentState.x >= element.offsetWidth) - guac_mouse.currentState.x = element.offsetWidth - 1; + 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_mouse.currentState.y < 0) - guac_mouse.currentState.y = 0; - else if (guac_mouse.currentState.y >= element.offsetHeight) - guac_mouse.currentState.y = element.offsetHeight - 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_mouse.onmousemove) - guac_mouse.onmousemove(guac_mouse.currentState); + if (guac_touchpad.onmousemove) + guac_touchpad.onmousemove(guac_touchpad.currentState); // Update touch location last_touch_x = touch.clientX; @@ -499,7 +500,7 @@ Guacamole.Mouse.Touchpad = function(element) { else if (touch_count == 2) { // If change in location passes threshold for scroll - if (Math.abs(delta_y) >= guac_mouse.scrollThreshold) { + if (Math.abs(delta_y) >= guac_touchpad.scrollThreshold) { // Decide button based on Y movement direction var button; @@ -507,14 +508,14 @@ Guacamole.Mouse.Touchpad = function(element) { else button = "up"; // Fire button down event - guac_mouse.currentState[button] = true; - if (guac_mouse.onmousedown) - guac_mouse.onmousedown(guac_mouse.currentState); + guac_touchpad.currentState[button] = true; + if (guac_touchpad.onmousedown) + guac_touchpad.onmousedown(guac_touchpad.currentState); // Fire button up event - guac_mouse.currentState[button] = false; - if (guac_mouse.onmouseup) - guac_mouse.onmouseup(guac_mouse.currentState); + 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 From 1c363ec37bc781583a3f2f73c4736b57953a25de Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 22 May 2012 01:39:53 -0700 Subject: [PATCH 208/263] Stubbed out Guacamole.Mouse.Touchscreen. --- .../src/main/resources/mouse.js | 100 +++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index a0c39797e..124fca7e6 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -262,7 +262,7 @@ Guacamole.Mouse = function(element) { /** - * Provides cross-browser touch event translation for a given element. + * 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). @@ -530,6 +530,104 @@ Guacamole.Mouse.Touchpad = function(element) { }; +/** + * 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) { + + e.stopPropagation(); + e.preventDefault(); + + // TODO: STUB + + }, false); + + element.addEventListener("touchstart", function(e) { + + e.stopPropagation(); + e.preventDefault(); + + // TODO: STUB + + }, false); + + element.addEventListener("touchmove", function(e) { + + e.stopPropagation(); + e.preventDefault(); + + // TODO: STUB + + }, false); + +}; + /** * Simple container for properties describing the state of a mouse. * From 0da51499fe738137d544476fa347077873bbda5c Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 22 May 2012 11:12:44 -0700 Subject: [PATCH 209/263] First basic absolute pointer implementation. --- .../src/main/resources/mouse.js | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 124fca7e6..6b39a0a27 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -604,7 +604,9 @@ Guacamole.Mouse.Touchscreen = function(element) { e.stopPropagation(); e.preventDefault(); - // TODO: STUB + // 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); @@ -613,7 +615,17 @@ Guacamole.Mouse.Touchscreen = function(element) { e.stopPropagation(); e.preventDefault(); - // TODO: STUB + // Get touch + var touch = e.touches[0]; + + // Update state + guac_touchscreen.currentstate.x = touch.clientX; + guac_touchscreen.currentstate.y = touch.clientY; + + // Fire press event, if defined + if (guac_touchscreen.onmousedown) + guac_touchscreen.onmousedown(guac_touchscreen.currentState); + }, false); @@ -622,7 +634,16 @@ Guacamole.Mouse.Touchscreen = function(element) { e.stopPropagation(); e.preventDefault(); - // TODO: STUB + // Get touch + var touch = e.touches[0]; + + // Update state + guac_touchscreen.currentstate.x = touch.clientX; + guac_touchscreen.currentstate.y = touch.clientY; + + // Fire movement event, if defined + if (guac_touchscreen.onmousemove) + guac_touchscreen.onmousemove(guac_touchscreen.currentState); }, false); From 50567d401beadb7dacdac155ca6fc6f185bd551a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 22 May 2012 11:26:40 -0700 Subject: [PATCH 210/263] Fix setting of state within touchscreen events. --- guacamole-common-js/src/main/resources/mouse.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 6b39a0a27..96a18bbec 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -604,6 +604,9 @@ Guacamole.Mouse.Touchscreen = function(element) { 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); @@ -619,8 +622,9 @@ Guacamole.Mouse.Touchscreen = function(element) { var touch = e.touches[0]; // Update state - guac_touchscreen.currentstate.x = touch.clientX; - guac_touchscreen.currentstate.y = touch.clientY; + guac_touchscreen.currentState.left = true; + guac_touchscreen.currentState.x = touch.clientX; + guac_touchscreen.currentState.y = touch.clientY; // Fire press event, if defined if (guac_touchscreen.onmousedown) @@ -638,8 +642,8 @@ Guacamole.Mouse.Touchscreen = function(element) { var touch = e.touches[0]; // Update state - guac_touchscreen.currentstate.x = touch.clientX; - guac_touchscreen.currentstate.y = touch.clientY; + guac_touchscreen.currentState.x = touch.clientX; + guac_touchscreen.currentState.y = touch.clientY; // Fire movement event, if defined if (guac_touchscreen.onmousemove) From 2f6dbde5da5d0f8421a5183847f78655b065859e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 29 Jul 2012 17:13:33 -0700 Subject: [PATCH 211/263] Use event-queue heuristics to detect and ignore mouse events caused by touch events. --- .../src/main/resources/mouse.js | 75 ++++++++++++++++++- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 96a18bbec..bf2c6d5f4 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -94,6 +94,39 @@ Guacamole.Mouse = function(element) { */ this.onmousemove = null; + /** + * Zero-delay timeout set when mouse events are fired, and canceled when + * touch events are detected, in order to prevent touch events registering + * as mouse events (some browsers will do this). + */ + var deferred_mouse_event = null; + + /** + * Flag which, when set to true, will cause all mouse events to be + * ignored. Used to temporarily ignore events when generated by + * touch events, and not by a mouse. + */ + var ignore_mouse = false; + + /** + * Forces all mouse events to be ignored until the event queue is flushed. + */ + function ignorePendingMouseEvents() { + + // Cancel deferred event + if (deferred_mouse_event) { + window.clearTimeout(deferred_mouse_event); + deferred_mouse_event = null; + } + + // Ignore all other events until end of event loop + ignore_mouse = true; + window.setTimeout(function() { + ignore_mouse = false; + }, 0); + + } + function cancelEvent(e) { e.stopPropagation(); if (e.preventDefault) e.preventDefault(); @@ -122,7 +155,10 @@ Guacamole.Mouse = function(element) { guac_mouse.currentState.y -= parent.offsetTop - documentScrollTop; if (guac_mouse.onmousemove) - guac_mouse.onmousemove(guac_mouse.currentState); + deferred_mouse_event = window.setTimeout(function() { + guac_mouse.onmousemove(guac_mouse.currentState); + deferred_mouse_event = null; + }, 0); } @@ -136,6 +172,13 @@ Guacamole.Mouse = function(element) { cancelEvent(e); + // If artificial event detected, ignore currently pending events + if (deferred_mouse_event) + ignorePendingMouseEvents(); + + if (ignore_mouse) + return; + moveMouse(e.clientX, e.clientY); }, false); @@ -144,6 +187,13 @@ Guacamole.Mouse = function(element) { cancelEvent(e); + // If artificial event detected, ignore currently pending events + if (deferred_mouse_event) + ignorePendingMouseEvents(); + + if (ignore_mouse) + return; + switch (e.button) { case 0: guac_mouse.currentState.left = true; @@ -157,7 +207,10 @@ Guacamole.Mouse = function(element) { } if (guac_mouse.onmousedown) - guac_mouse.onmousedown(guac_mouse.currentState); + deferred_mouse_event = window.setTimeout(function() { + guac_mouse.onmousedown(guac_mouse.currentState); + deferred_mouse_event = null; + }, 0); }, false); @@ -165,6 +218,13 @@ Guacamole.Mouse = function(element) { cancelEvent(e); + // If artificial event detected, ignore currently pending events + if (deferred_mouse_event) + ignorePendingMouseEvents(); + + if (ignore_mouse) + return; + switch (e.button) { case 0: guac_mouse.currentState.left = false; @@ -178,7 +238,10 @@ Guacamole.Mouse = function(element) { } if (guac_mouse.onmouseup) - guac_mouse.onmouseup(guac_mouse.currentState); + deferred_mouse_event = window.setTimeout(function() { + guac_mouse.onmouseup(guac_mouse.currentState); + deferred_mouse_event = null; + }, 0); }, false); @@ -217,6 +280,12 @@ Guacamole.Mouse = function(element) { cancelEvent(e); }, false); + + // Ignore all pending mouse events when touch events are the apparent source + element.addEventListener("touchmove", ignorePendingMouseEvents, false); + element.addEventListener("touchstart", ignorePendingMouseEvents, false); + element.addEventListener("touchend", ignorePendingMouseEvents, false); + // Scroll wheel support function mousewheel_handler(e) { From 182f8e891afce8318f696ca92cbc5d5200e86803 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 29 Jul 2012 17:27:47 -0700 Subject: [PATCH 212/263] Ignore absolute touch events if more than one touch. --- guacamole-common-js/src/main/resources/mouse.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index bf2c6d5f4..d23c8f7b2 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -670,6 +670,10 @@ Guacamole.Mouse.Touchscreen = function(element) { element.addEventListener("touchend", function(e) { + // Ignore if more than one touch + if (e.touches.length + e.changedTouches.length != 1) + return; + e.stopPropagation(); e.preventDefault(); @@ -684,6 +688,10 @@ Guacamole.Mouse.Touchscreen = function(element) { element.addEventListener("touchstart", function(e) { + // Ignore if more than one touch + if (e.touches.length != 1) + return; + e.stopPropagation(); e.preventDefault(); @@ -704,6 +712,10 @@ Guacamole.Mouse.Touchscreen = function(element) { element.addEventListener("touchmove", function(e) { + // Ignore if more than one touch + if (e.touches.length != 1) + return; + e.stopPropagation(); e.preventDefault(); From 3e8d14e6992d6c6a67824fe50b884b94dfbfbe8f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 29 Jul 2012 20:57:45 -0700 Subject: [PATCH 213/263] Clean up handling of viewport-relative coordinates. Modify absolute touch support to properly handle scrolled viewport. --- .../src/main/resources/mouse.js | 84 +++++++++++-------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index d23c8f7b2..b954fd305 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -133,36 +133,6 @@ Guacamole.Mouse = function(element) { e.returnValue = false; } - function moveMouse(clientX, clientY) { - - guac_mouse.currentState.x = clientX - element.offsetLeft; - guac_mouse.currentState.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_mouse.currentState.x -= parent.offsetLeft - parent.scrollLeft; - guac_mouse.currentState.y -= parent.offsetTop - parent.scrollTop; - - parent = parent.offsetParent; - } - - // Offset by document scroll amount - var documentScrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft; - var documentScrollTop = document.body.scrollTop || document.documentElement.scrollTop; - - guac_mouse.currentState.x -= parent.offsetLeft - documentScrollLeft; - guac_mouse.currentState.y -= parent.offsetTop - documentScrollTop; - - if (guac_mouse.onmousemove) - deferred_mouse_event = window.setTimeout(function() { - guac_mouse.onmousemove(guac_mouse.currentState); - deferred_mouse_event = null; - }, 0); - - } - - // Block context menu so right-click gets sent properly element.addEventListener("contextmenu", function(e) { cancelEvent(e); @@ -179,7 +149,13 @@ Guacamole.Mouse = function(element) { if (ignore_mouse) return; - moveMouse(e.clientX, e.clientY); + guac_mouse.currentState.fromClientPosition(element, e.clientX, e.clientY); + + if (guac_mouse.onmousemove) + deferred_mouse_event = window.setTimeout(function() { + guac_mouse.onmousemove(guac_mouse.currentState); + deferred_mouse_event = null; + }, 0); }, false); @@ -700,8 +676,7 @@ Guacamole.Mouse.Touchscreen = function(element) { // Update state guac_touchscreen.currentState.left = true; - guac_touchscreen.currentState.x = touch.clientX; - guac_touchscreen.currentState.y = touch.clientY; + guac_touchscreen.currentState.fromClientPosition(element, touch.clientX, touch.clientY); // Fire press event, if defined if (guac_touchscreen.onmousedown) @@ -723,8 +698,7 @@ Guacamole.Mouse.Touchscreen = function(element) { var touch = e.touches[0]; // Update state - guac_touchscreen.currentState.x = touch.clientX; - guac_touchscreen.currentState.y = touch.clientY; + guac_touchscreen.currentState.fromClientPosition(element, touch.clientX, touch.clientY); // Fire movement event, if defined if (guac_touchscreen.onmousemove) @@ -750,6 +724,12 @@ Guacamole.Mouse.Touchscreen = function(element) { */ 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 @@ -795,6 +775,40 @@ Guacamole.Mouse.State = function(x, y, left, middle, right, up, down) { * @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; + } + + // Offset by document scroll amount + 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; + + }; + }; From e90eec79e466b4c4822a5e7ac68a8639d3b8153d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 30 Jul 2012 15:00:45 -0700 Subject: [PATCH 214/263] Simpler heuristic for handling touch-generated mouse events (disable handling of mouse events upon receipt of a touch event until a specified number of mousemove events have been received). --- .../src/main/resources/mouse.js | 76 +++++-------------- 1 file changed, 20 insertions(+), 56 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index b954fd305..857cef31b 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -55,6 +55,12 @@ Guacamole.Mouse = function(element) { */ 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 @@ -95,37 +101,10 @@ Guacamole.Mouse = function(element) { this.onmousemove = null; /** - * Zero-delay timeout set when mouse events are fired, and canceled when - * touch events are detected, in order to prevent touch events registering - * as mouse events (some browsers will do this). + * Counter of mouse events to ignore. This decremented by mousemove, and + * while non-zero, mouse events will have no effect. */ - var deferred_mouse_event = null; - - /** - * Flag which, when set to true, will cause all mouse events to be - * ignored. Used to temporarily ignore events when generated by - * touch events, and not by a mouse. - */ - var ignore_mouse = false; - - /** - * Forces all mouse events to be ignored until the event queue is flushed. - */ - function ignorePendingMouseEvents() { - - // Cancel deferred event - if (deferred_mouse_event) { - window.clearTimeout(deferred_mouse_event); - deferred_mouse_event = null; - } - - // Ignore all other events until end of event loop - ignore_mouse = true; - window.setTimeout(function() { - ignore_mouse = false; - }, 0); - - } + var ignore_mouse = 0; function cancelEvent(e) { e.stopPropagation(); @@ -142,20 +121,16 @@ Guacamole.Mouse = function(element) { cancelEvent(e); - // If artificial event detected, ignore currently pending events - if (deferred_mouse_event) - ignorePendingMouseEvents(); - - if (ignore_mouse) + // If ignoring events, decrement counter + if (ignore_mouse) { + ignore_mouse--; return; + } guac_mouse.currentState.fromClientPosition(element, e.clientX, e.clientY); if (guac_mouse.onmousemove) - deferred_mouse_event = window.setTimeout(function() { - guac_mouse.onmousemove(guac_mouse.currentState); - deferred_mouse_event = null; - }, 0); + guac_mouse.onmousemove(guac_mouse.currentState); }, false); @@ -163,10 +138,7 @@ Guacamole.Mouse = function(element) { cancelEvent(e); - // If artificial event detected, ignore currently pending events - if (deferred_mouse_event) - ignorePendingMouseEvents(); - + // Do not handle if ignoring events if (ignore_mouse) return; @@ -183,10 +155,7 @@ Guacamole.Mouse = function(element) { } if (guac_mouse.onmousedown) - deferred_mouse_event = window.setTimeout(function() { - guac_mouse.onmousedown(guac_mouse.currentState); - deferred_mouse_event = null; - }, 0); + guac_mouse.onmousedown(guac_mouse.currentState); }, false); @@ -194,10 +163,7 @@ Guacamole.Mouse = function(element) { cancelEvent(e); - // If artificial event detected, ignore currently pending events - if (deferred_mouse_event) - ignorePendingMouseEvents(); - + // Do not handle if ignoring events if (ignore_mouse) return; @@ -214,10 +180,7 @@ Guacamole.Mouse = function(element) { } if (guac_mouse.onmouseup) - deferred_mouse_event = window.setTimeout(function() { - guac_mouse.onmouseup(guac_mouse.currentState); - deferred_mouse_event = null; - }, 0); + guac_mouse.onmouseup(guac_mouse.currentState); }, false); @@ -256,8 +219,9 @@ Guacamole.Mouse = function(element) { 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); From ce0bade000111c401c273c065c4d45ca984b4d07 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 1 Aug 2012 11:33:39 -0700 Subject: [PATCH 215/263] Only take parent into account if actually relevant to positioning. --- guacamole-common-js/src/main/resources/mouse.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 857cef31b..55f99b1ea 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -765,12 +765,15 @@ Guacamole.Mouse.State = function(x, y, left, middle, right, up, down) { parent = parent.offsetParent; } - // Offset by document scroll amount - var documentScrollLeft = document.body.scrollLeft || document.documentElement.scrollLeft; - var documentScrollTop = document.body.scrollTop || document.documentElement.scrollTop; + // 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; + guac_state.x -= parent.offsetLeft - documentScrollLeft; + guac_state.y -= parent.offsetTop - documentScrollTop; + } }; From d5e1b88cdc7e1e516c97181c1ff9d417de261be4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 2 Aug 2012 00:53:22 -0700 Subject: [PATCH 216/263] Use addEventListener(), only ignore key event if truly unknown (might have keyIdentifiier, but no keycode). --- .../src/main/resources/keyboard.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 474c42be6..8c0d3ab2f 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -418,7 +418,7 @@ Guacamole.Keyboard = function(element) { } // When key pressed - element.onkeydown = function(e) { + element.addEventListener("keydown", function(e) { // Only intercept if handler set if (!guac_keyboard.onkeydown) return; @@ -428,7 +428,7 @@ Guacamole.Keyboard = function(element) { else if (e.which) keynum = e.which; // Ignore any unknown key events - if (keynum == 0) { + if (keynum == 0 && !e.keyIdentifier) { e.preventDefault(); return; } @@ -481,10 +481,10 @@ Guacamole.Keyboard = function(element) { handleKeyEvents(); } - }; + }, true); // When key pressed - element.onkeypress = function(e) { + element.addEventListener("keypress", function(e) { // Only intercept if handler set if (!guac_keyboard.onkeydown) return; @@ -515,10 +515,10 @@ Guacamole.Keyboard = function(element) { // Handle event with all aggregated data handleKeyEvents(); - }; + }, true); // When key released - element.onkeyup = function(e) { + element.addEventListener("keyup", function(e) { // Only intercept if handler set if (!guac_keyboard.onkeyup) return; @@ -545,13 +545,13 @@ Guacamole.Keyboard = function(element) { // Send release event sendKeyReleased(lastKeyDownChar); - }; + }, true); // When focus is lost, clear modifiers. - element.onblur = function() { + element.addEventListener("blur", function() { guac_keyboard.modifiers.alt = false; guac_keyboard.modifiers.ctrl = false; guac_keyboard.modifiers.shift = false; - }; + }, true); }; From 21fb1e92bb968ebfdaa202a5a80355411016c954 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 11 Aug 2012 12:52:30 -0700 Subject: [PATCH 217/263] Fix jsdoc, add missing documentation. --- .../src/main/resources/guacamole.js | 102 ++++++++++++++---- .../src/main/resources/keyboard.js | 19 ++-- .../src/main/resources/layer.js | 9 +- .../src/main/resources/mouse.js | 6 +- .../src/main/resources/oskeyboard.js | 94 +++++++++++++--- .../src/main/resources/tunnel.js | 20 +++- 6 files changed, 202 insertions(+), 48 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 1cf3b942c..d566a3dee 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -36,7 +36,10 @@ * * ***** END LICENSE BLOCK ***** */ -// Guacamole namespace +/** + * Namespace for all Guacamole JavaScript objects. + * @namespace + */ var Guacamole = Guacamole || {}; @@ -71,6 +74,7 @@ Guacamole.Client = function(tunnel) { /** * Translation from Guacamole protocol line caps to Layer line caps. + * @private */ var lineCap = { 0: "butt", @@ -80,6 +84,7 @@ Guacamole.Client = function(tunnel) { /** * Translation from Guacamole protocol line caps to Layer line caps. + * @private */ var lineJoin = { 0: "bevel", @@ -175,11 +180,27 @@ Guacamole.Client = function(tunnel) { } - guac_client.getDisplay = function() { + /** + * 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; }; - guac_client.sendKeyEvent = function(pressed, keysym) { + /** + * 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; @@ -187,7 +208,14 @@ Guacamole.Client = function(tunnel) { tunnel.sendMessage("key", keysym, pressed); }; - guac_client.sendMouseState = function(mouseState) { + /** + * 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()) @@ -211,7 +239,12 @@ Guacamole.Client = function(tunnel) { tunnel.sendMessage("mouse", Math.floor(mouseState.x), Math.floor(mouseState.y), buttonMask); }; - guac_client.setClipboard = function(data) { + /** + * 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()) @@ -220,11 +253,38 @@ Guacamole.Client = function(tunnel) { tunnel.sendMessage("clipboard", data); }; - // Handlers - guac_client.onstatechange = null; - guac_client.onname = null; - guac_client.onerror = null; - guac_client.onclipboard = null; + /** + * 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) { @@ -281,6 +341,7 @@ Guacamole.Client = function(tunnel) { /** * Handlers for all defined layer properties. + * @private */ var layerPropertyHandlers = { @@ -293,6 +354,7 @@ Guacamole.Client = function(tunnel) { /** * Handlers for all instruction opcodes receivable by a Guacamole protocol * client. + * @private */ var instructionHandlers = { @@ -793,7 +855,7 @@ Guacamole.Client = function(tunnel) { }; - guac_client.disconnect = function() { + this.disconnect = function() { // Only attempt disconnection not disconnected. if (currentState != STATE_DISCONNECTED @@ -814,7 +876,7 @@ Guacamole.Client = function(tunnel) { }; - guac_client.connect = function(data) { + this.connect = function(data) { setState(STATE_CONNECTING); @@ -834,7 +896,7 @@ Guacamole.Client = function(tunnel) { setState(STATE_WAITING); }; - guac_client.scale = function(scale) { + this.scale = function(scale) { display.style.transform = display.style.WebkitTransform = @@ -852,7 +914,7 @@ Guacamole.Client = function(tunnel) { }; - guac_client.getScale = function() { + this.getScale = function() { return displayScale; }; @@ -901,7 +963,7 @@ Guacamole.Client.LayerContainer = function(width, height) { * @param {Number} width The new width to assign to this Layer. * @param {Number} height The new height to assign to this Layer. */ - layer_container.resize = function(width, height) { + this.resize = function(width, height) { // Resize layer layer.resize(width, height); @@ -916,7 +978,7 @@ Guacamole.Client.LayerContainer = function(width, height) { * Returns the Layer contained within this LayerContainer. * @returns {Guacamole.Layer} The Layer contained within this LayerContainer. */ - layer_container.getLayer = function() { + this.getLayer = function() { return layer; }; @@ -924,17 +986,19 @@ Guacamole.Client.LayerContainer = function(width, height) { * Returns the element containing the Layer within this LayerContainer. * @returns {Element} The element containing the Layer within this LayerContainer. */ - layer_container.getElement = function() { + 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 @@ -945,7 +1009,7 @@ Guacamole.Client.LayerContainer = function(width, height) { * @param {Number} x The X coordinate to move to. * @param {Number} y The Y coordinate to move to. */ - layer_container.translate = function(x, y) { + this.translate = function(x, y) { // Generate translation translate = "translate(" @@ -974,7 +1038,7 @@ Guacamole.Client.LayerContainer = function(width, height) { * @param {Number} e The fifth value in the affine transform's matrix. * @param {Number} f The sixth value in the affine transform's matrix. */ - layer_container.transform = function(a, b, c, d, e, f) { + this.transform = function(a, b, c, d, e, f) { // Generate matrix transformation matrix = diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 8c0d3ab2f..8c08f39c5 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -35,7 +35,10 @@ * * ***** END LICENSE BLOCK ***** */ -// Guacamole namespace +/** + * Namespace for all Guacamole JavaScript objects. + * @namespace + */ var Guacamole = Guacamole || {}; /** @@ -60,9 +63,6 @@ Guacamole.Keyboard = function(element) { * * @event * @param {Number} keysym The keysym of the key being pressed. - * @returns {Boolean} true if the originating event of this keypress should - * be allowed through to the browser, false or undefined - * otherwise. */ this.onkeydown = null; @@ -72,9 +72,6 @@ Guacamole.Keyboard = function(element) { * * @event * @param {Number} keysym The keysym of the key being released. - * @returns {Boolean} true if the originating event of this key release - * should be allowed through to the browser, false or - * undefined otherwise. */ this.onkeyup = null; @@ -336,9 +333,7 @@ Guacamole.Keyboard = function(element) { // Send key event if (keysym != null && guac_keyboard.onkeydown) - return guac_keyboard.onkeydown(keysym) != false; - - return true; + guac_keyboard.onkeydown(keysym); } @@ -350,9 +345,7 @@ Guacamole.Keyboard = function(element) { // Send key event if (keysym != null && guac_keyboard.onkeyup) - return guac_keyboard.onkeyup(keysym) != false; - - return true; + guac_keyboard.onkeyup(keysym); } diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 8358fbbf9..e6052e76f 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -35,7 +35,10 @@ * * ***** END LICENSE BLOCK ***** */ -// Guacamole namespace +/** + * Namespace for all Guacamole JavaScript objects. + * @namespace + */ var Guacamole = Guacamole || {}; /** @@ -85,6 +88,7 @@ Guacamole.Layer = function(width, height) { /** * Whether a new path should be started with the next path drawing * operations. + * @private */ var pathClosed = true; @@ -94,6 +98,8 @@ Guacamole.Layer = function(width, height) { * 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; @@ -323,6 +329,7 @@ Guacamole.Layer = function(width, height) { * 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. diff --git a/guacamole-common-js/src/main/resources/mouse.js b/guacamole-common-js/src/main/resources/mouse.js index 55f99b1ea..9dc2f222b 100644 --- a/guacamole-common-js/src/main/resources/mouse.js +++ b/guacamole-common-js/src/main/resources/mouse.js @@ -35,7 +35,10 @@ * * ***** END LICENSE BLOCK ***** */ -// Guacamole namespace +/** + * Namespace for all Guacamole JavaScript objects. + * @namespace + */ var Guacamole = Guacamole || {}; /** @@ -103,6 +106,7 @@ Guacamole.Mouse = function(element) { /** * 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; diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 1f8c08360..3acebdb63 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -35,7 +35,10 @@ * * ***** END LICENSE BLOCK ***** */ -// Guacamole namespace +/** + * Namespace for all Guacamole JavaScript objects. + * @namespace + */ var Guacamole = Guacamole || {}; /** @@ -50,24 +53,48 @@ Guacamole.OnScreenKeyboard = function(url) { var on_screen_keyboard = this; + /** + * State of all modifiers. This is the bitwise OR of all active modifier + * values. + * + * @private + */ + var modifiers = 0; + var scaledElements = []; var modifiers = {}; var currentModifier = 1; - // Function for adding a class to an element + /** + * 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; - // Function for removing a class from an element + /** + * 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); }; @@ -77,6 +104,7 @@ Guacamole.OnScreenKeyboard = function(url) { // Otherwise, implement own else { + /** @ignore */ addClass = function(element, classname) { // Simply add new class @@ -84,6 +112,7 @@ Guacamole.OnScreenKeyboard = function(url) { }; + /** @ignore */ removeClass = function(element, classname) { // Filter out classes with given name @@ -315,7 +344,7 @@ Guacamole.OnScreenKeyboard = function(url) { addClass(key_element, "guac-keyboard-pressed"); // Get current cap based on modifier state - var cap = key.getCap(on_screen_keyboard.modifiers); + var cap = key.getCap(modifiers); // Update modifier state if (cap.modifier) { @@ -325,10 +354,10 @@ Guacamole.OnScreenKeyboard = function(url) { var modifierFlag = getModifier(cap.modifier); // Toggle modifier state - on_screen_keyboard.modifiers ^= modifierFlag; + modifiers ^= modifierFlag; // Activate modifier if pressed - if (on_screen_keyboard.modifiers & modifierFlag) { + if (modifiers & modifierFlag) { addClass(keyboard, modifierClass); @@ -370,7 +399,7 @@ Guacamole.OnScreenKeyboard = function(url) { if (key.pressed) { // Get current cap based on modifier state - var cap = key.getCap(on_screen_keyboard.modifiers); + var cap = key.getCap(modifiers); removeClass(key_element, "guac-keyboard-pressed"); @@ -458,17 +487,37 @@ Guacamole.OnScreenKeyboard = function(url) { }; /** - * State of all modifiers. + * Fired whenever the user presses a key on this Guacamole.OnScreenKeyboard. + * + * @event + * @param {Number} keysym The keysym of the key being pressed. */ - this.modifiers = 0; - 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 @@ -484,6 +533,15 @@ Guacamole.OnScreenKeyboard = function(url) { }; + +/** + * 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; @@ -516,8 +574,20 @@ Guacamole.OnScreenKeyboard.Key = function() { 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) { /** @@ -538,4 +608,4 @@ Guacamole.OnScreenKeyboard.Cap = function(text, keysym, modifier) { // Set modifier if provided if (modifier) this.modifier = modifier; -} +}; diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 87155ebe5..4f75ea3f6 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -35,7 +35,10 @@ * * ***** END LICENSE BLOCK ***** */ -// Guacamole namespace +/** + * Namespace for all Guacamole JavaScript objects. + * @namespace + */ var Guacamole = Guacamole || {}; /** @@ -104,6 +107,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) { /** * Reference to this HTTP tunnel. + * @private */ var tunnel = this; @@ -142,6 +146,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) { * 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. */ @@ -484,17 +489,20 @@ 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:", @@ -568,6 +576,7 @@ Guacamole.WebSocketTunnel = function(tunnelURL) { * 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. */ @@ -700,23 +709,27 @@ 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 = []; @@ -725,7 +738,10 @@ Guacamole.ChainedTunnel = function(tunnel_chain) { tunnels.push(arguments[i]); /** - * Sets the current tunnel + * Sets the current tunnel. + * + * @private + * @param {Guacamole.Tunnel} tunnel The tunnel to set as the current tunnel. */ function attach(tunnel) { From 05c7031d8e1ffd5dfd1f1279eca39b56d620ea29 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 11 Aug 2012 14:12:47 -0700 Subject: [PATCH 218/263] Update version number, update changelog --- guacamole-common-js/ChangeLog | 12 ++++++++++++ guacamole-common-js/pom.xml | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/ChangeLog b/guacamole-common-js/ChangeLog index 62eaab587..c1cb0911f 100644 --- a/guacamole-common-js/ChangeLog +++ b/guacamole-common-js/ChangeLog @@ -1,3 +1,15 @@ +2012-08-11 Michael Jumper + + * Improve documentation + +2012-08-02 Michael Jumper + + * Fix keyboard event handling + +2012-08-01 Michael Jumper + + * Implement absolute touch device emulation + 2012-05-04 Michael Jumper * Improved iPad and touch device support diff --git a/guacamole-common-js/pom.xml b/guacamole-common-js/pom.xml index e3606aaba..8105af4ab 100644 --- a/guacamole-common-js/pom.xml +++ b/guacamole-common-js/pom.xml @@ -5,7 +5,7 @@ net.sourceforge.guacamole guacamole-common-js pom - 0.6.0 + 0.6.1 guacamole-common-js http://guac-dev.org/ From 2c73b682d1f8c3263d6ee13c6fcaf775340d532f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 27 Sep 2012 21:05:38 -0700 Subject: [PATCH 219/263] Fix variable naming conflict (ticket #191). Fix other warnings. --- .../src/main/resources/oskeyboard.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index 3acebdb63..f5e72d2b2 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -63,8 +63,8 @@ Guacamole.OnScreenKeyboard = function(url) { var scaledElements = []; - var modifiers = {}; - var currentModifier = 1; + var modifier_masks = {}; + var next_mask = 1; /** * Adds a class to an element. @@ -135,17 +135,17 @@ Guacamole.OnScreenKeyboard = function(url) { // Returns a unique power-of-two value for the modifier with the // given name. The same value will be returned for the same modifier. - function getModifier(name) { + function getModifierMask(name) { - var value = modifiers[name]; + var value = modifier_masks[name]; if (!value) { // Get current modifier, advance to next - value = currentModifier; - currentModifier <<= 1; + value = next_mask; + next_mask <<= 1; // Store value of this modifier - modifiers[name] = value; + modifier_masks[name] = value; } @@ -318,7 +318,7 @@ Guacamole.OnScreenKeyboard = function(url) { // list of required modifiers. var requirements = e.getAttribute("if").split(","); for (var i=0; i Date: Mon, 15 Oct 2012 10:42:03 -0700 Subject: [PATCH 220/263] Update ChangeLog, bump version. --- guacamole-common-js/ChangeLog | 4 ++++ guacamole-common-js/pom.xml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/ChangeLog b/guacamole-common-js/ChangeLog index c1cb0911f..8b47d6718 100644 --- a/guacamole-common-js/ChangeLog +++ b/guacamole-common-js/ChangeLog @@ -1,3 +1,7 @@ +2012-09-27 Michael Jumper + + * Fix variable naming conflict (ticket #191) + 2012-08-11 Michael Jumper * Improve documentation diff --git a/guacamole-common-js/pom.xml b/guacamole-common-js/pom.xml index 8105af4ab..55fb3e1f6 100644 --- a/guacamole-common-js/pom.xml +++ b/guacamole-common-js/pom.xml @@ -5,7 +5,7 @@ net.sourceforge.guacamole guacamole-common-js pom - 0.6.1 + 0.6.2 guacamole-common-js http://guac-dev.org/ From d0c582b5e88e999c6cfd99b907809fd6df6f69b1 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 16 Oct 2012 14:13:18 -0700 Subject: [PATCH 221/263] Add unique integer to end of request (fix #201). --- guacamole-common-js/src/main/resources/tunnel.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 4f75ea3f6..812ee897d 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -434,12 +434,16 @@ Guacamole.HTTPTunnel = function(tunnelURL) { } + /** + * Arbitrary integer, unique for each tunnel read request. + */ + var request_id = 0; function makeRequest() { - // Download self + // Make request, increment request ID var xmlhttprequest = new XMLHttpRequest(); - xmlhttprequest.open("POST", TUNNEL_READ + tunnel_uuid); + xmlhttprequest.open("GET", TUNNEL_READ + tunnel_uuid + ":" + (request_id++)); xmlhttprequest.send(null); return xmlhttprequest; From b77e78deb5f488feacf594494caf66f2e1486cf4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 16 Oct 2012 18:17:55 -0700 Subject: [PATCH 222/263] Update ChangeLog --- guacamole-common-js/ChangeLog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/guacamole-common-js/ChangeLog b/guacamole-common-js/ChangeLog index 8b47d6718..f2c396ea1 100644 --- a/guacamole-common-js/ChangeLog +++ b/guacamole-common-js/ChangeLog @@ -1,3 +1,7 @@ +2012-10-16 Michael Jumper + + * Fix stream inefficiency bug (ticket #201) + 2012-09-27 Michael Jumper * Fix variable naming conflict (ticket #191) From f2f6173c7d63180d45e3b7610c147d11cfd73a00 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 20 Oct 2012 19:33:53 -0700 Subject: [PATCH 223/263] Implemented Guacamole.Parser --- .../src/main/resources/guacamole.js | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index d566a3dee..22564b9bc 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -42,6 +42,131 @@ */ var Guacamole = Guacamole || {}; +/** + * Simple Guacamole protocol parser that invokes an oninstruction event when + * full instructions are available from data received via receive(). + * + * @constructor + */ +Guacamole.Parser = function() { + + /** + * Reference to this parser. + * @private + */ + var parser = this; + + /** + * Current buffer of received data. This buffer grows until a full + * element is available. After a full element is available, that element + * is flushed into the element buffer. + * + * @priate + */ + var buffer = ""; + + /** + * Buffer of all received, complete elements. After an entire instruction + * is read, this buffer is flushed, and a new instruction begins. + * + * @priate + */ + var element_buffer = []; + + // The location of the last element's terminator + var element_end = -1; + + // Where to start the next length search or the next element + var start_index = 0; + + this.receive = function(packet) { + + // Truncate buffer as necessary + if (start_index > 4096) { + + buffer = buffer.substring(start_index); + + // Reset parse relative to truncation + element_end -= start_index; + start_index = 0; + + } + + // Append data to buffer + buffer += packet; + + // While search is within currently received data + while (element_end < buffer.length) { + + // If we are waiting for element data + if (element_end >= start_index) { + + // We now have enough data for the element. Parse. + var element = buffer.substring(start_index, element_end); + var terminator = buffer.substring(element_end, element_end+1); + + // Add element to array + element_buffer.push(element); + + // If last element, handle instruction + if (terminator == ";") { + + // Get opcode + var opcode = element_buffer.shift(); + + // Call instruction handler. + if (parser.oninstruction != null) + parser.oninstruction(opcode, element_buffer); + + // Clear elements + element_buffer.length = 0; + + } + + // Start searching for length at character after + // element terminator + start_index = element_end + 1; + + } + + // Search for end of length + var length_end = buffer.indexOf(".", start_index); + if (length_end != -1) { + + // Parse length + var length = parseInt(buffer.substring(element_end+1, length_end)); + + // Calculate start of element + start_index = length_end + 1; + + // Calculate location of element terminator + element_end = start_index + length; + + } + + // If no period yet, continue search when more data + // is received + else { + start_index = buffer.length; + break; + } + + } // end parse loop + + }; + + /** + * 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 protocol client. Given a display element and {@link Guacamole.Tunnel}, From 9b9981acc3f9b636f16857e7467cb7cd0faa9155 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 20 Oct 2012 20:09:13 -0700 Subject: [PATCH 224/263] Implement nest instruction. --- .../src/main/resources/guacamole.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 22564b9bc..a1a196062 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -270,6 +270,9 @@ Guacamole.Client = function(tunnel) { // No initial buffers var buffers = []; + // No initial parsers + var parsers = []; + tunnel.onerror = function(message) { if (guac_client.onerror) guac_client.onerror(message); @@ -464,6 +467,21 @@ Guacamole.Client = function(tunnel) { } + function getParser(index) { + + var parser = parsers[index]; + + // If parser not yet created, create it, and tie to the + // oninstruction handler of the tunnel. + if (parser == null) { + parser = parsers[index] = new Guacamole.Parser(); + parser.oninstruction = tunnel.oninstruction; + } + + return parser; + + } + /** * Handlers for all defined layer properties. * @private @@ -747,6 +765,11 @@ Guacamole.Client = function(tunnel) { if (guac_client.onname) guac_client.onname(parameters[0]); }, + "nest": function(parameters) { + var parser = getParser(parseInt(parameters[0])); + parser.receive(parameters[1]); + }, + "png": function(parameters) { var channelMask = parseInt(parameters[0]); From 6026b14a0f57a941e7c1a41be92d60d4aab78603 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 21 Oct 2012 15:48:07 -0700 Subject: [PATCH 225/263] Add audio/video/size event functions. --- .../src/main/resources/guacamole.js | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index a1a196062..7ffbefe7f 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -320,6 +320,52 @@ Guacamole.Client = function(tunnel) { return bounds; }; + /** + * Sends a supported audio mimetype. + * + * @param {String} mimetype The supported mimetype to send. + */ + this.sendAudioMimetype = function(mimetype) { + + // Do not send requests if not connected + if (!isConnected()) + return; + + tunnel.sendMessage("audio", mimetype); + + }; + + /** + * Sends a supported video mimetype. + * + * @param {String} mimetype The supported mimetype to send. + */ + this.sendVideoMimetype = function(mimetype) { + + // Do not send requests if not connected + if (!isConnected()) + return; + + tunnel.sendMessage("video", mimetype); + + }; + + /** + * Sends the current size of the screen. + * + * @param {Number} width The width of the screen. + * @param {Number} height The height of the screen. + */ + this.sendSize = function(width, height) { + + // Do not send requests if not connected + if (!isConnected()) + return; + + tunnel.sendMessage("size", width, height); + + }; + /** * Sends a key event having the given properties as if the user * pressed or released a key. From 2bd982fe83ea87b23b386ee15572d6f3c5e7191f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 23 Oct 2012 00:47:15 -0700 Subject: [PATCH 226/263] Bump version. --- guacamole-common-js/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/pom.xml b/guacamole-common-js/pom.xml index 55fb3e1f6..aee81f5a6 100644 --- a/guacamole-common-js/pom.xml +++ b/guacamole-common-js/pom.xml @@ -5,7 +5,7 @@ net.sourceforge.guacamole guacamole-common-js pom - 0.6.2 + 0.7.0 guacamole-common-js http://guac-dev.org/ From 3b9adefa4a5e04c340e03da46c3e5ec209dcf82f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 23 Oct 2012 11:02:54 -0700 Subject: [PATCH 227/263] Switch from WAITING to CONNECTED on first sync, rather than first png. --- guacamole-common-js/src/main/resources/guacamole.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 7ffbefe7f..6076a5f3b 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -832,10 +832,6 @@ Guacamole.Client = function(tunnel) { "data:image/png;base64," + data ); - // If received first update, no longer waiting. - if (currentState == STATE_WAITING) - setState(STATE_CONNECTED); - }, "pop": function(parameters) { @@ -996,6 +992,10 @@ Guacamole.Client = function(tunnel) { } } + // If received first update, no longer waiting. + if (currentState == STATE_WAITING) + setState(STATE_CONNECTED); + }, "transfer": function(parameters) { From 61abcc639b63619da99d382e2026de7a4f2dd764 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 24 Oct 2012 00:08:16 -0700 Subject: [PATCH 228/263] Add Guacamole.AudioChannel, --- .../src/main/resources/audio.js | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 guacamole-common-js/src/main/resources/audio.js diff --git a/guacamole-common-js/src/main/resources/audio.js b/guacamole-common-js/src/main/resources/audio.js new file mode 100644 index 000000000..3cb0841a3 --- /dev/null +++ b/guacamole-common-js/src/main/resources/audio.js @@ -0,0 +1,144 @@ + +/* ***** 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 audio channel which queues and plays arbitrary audio data. + * @constructor + */ +Guacamole.AudioChannel = function() { + + /** + * Reference to this AudioChannel. + * @private + */ + var channel = this; + + /** + * Packet queue. + */ + var packets = []; + + /** + * Whether this channel is currently playing sound. + */ + var playing = false; + + /** + * Advances to the next audio packet, if any, and plays it. + */ + function advance() { + + // If packets remain, play next + if (packets.length != 0) { + var packet = packets.shift(); + packet.play(); + window.setTimeout(advance, packet.duration); + } + + // Otherwise, no longer playing + else + playing = false; + + } + + /** + * Queues up the given data for playing by this channel once all previously + * queued data has been played. If no data has been queued, the data will + * play immediately. + * + * @param {String} mimetype The mimetype of the data provided. + * @param {Number} duration The duration of the data provided, in + * milliseconds. + * @param {String} data The base64-encoded data to play. + */ + this.play = function(mimetype, duration, data) { + + var packet = + new Guacamole.AudioChannel.Packet(mimetype, duration, data); + + // If currently playing sound, add packet to queue + if (playing) + packets.push(packet); + + // Otherwise, play now, flag channel as playing + else { + playing = true; + packet.play(); + window.setTimeout(advance, packet.duration); + } + + }; + +}; + +/** + * Abstract representation of an audio packet. + * + * @constructor + * + * @param {String} mimetype The mimetype of the data contained by this packet. + * @param {Number} duration The duration of the data contained by this packet. + * @param {String} data The base64-encoded sound data contained by this packet. + */ +Guacamole.AudioChannel.Packet = function(mimetype, duration, data) { + + // Build data URI + var data_uri = "data:" + mimetype + ";base64," + data; + + // Create audio element to house and play the data + var audio = new Audio(); + audio.src = data_uri; + + /** + * The duration of this packet, in milliseconds. + */ + this.duration = duration; + + /** + * Plays the sound data contained by this packet immediately. + */ + this.play = function() { + audio.play(); + }; + +}; From 56495c7cfabcdd2bb9612eae625ef3af5f13f846 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 24 Oct 2012 00:18:43 -0700 Subject: [PATCH 229/263] Implement audio instruction. --- .../src/main/resources/guacamole.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 6076a5f3b..5ffaee0a9 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -273,6 +273,9 @@ Guacamole.Client = function(tunnel) { // No initial parsers var parsers = []; + // No initial audio channels + var audio_channels = []; + tunnel.onerror = function(message) { if (guac_client.onerror) guac_client.onerror(message); @@ -528,6 +531,18 @@ Guacamole.Client = function(tunnel) { } + function getAudioChannel(index) { + + var audio_channel = audio_channels[index]; + + // If audio channel not yet created, create it + if (audio_channel == null) + audio_channel = audio_channels[index] = new Guacamole.AudioChannel(); + + return audio_channel; + + } + /** * Handlers for all defined layer properties. * @private @@ -561,6 +576,17 @@ Guacamole.Client = function(tunnel) { }, + "audio": function(parameters) { + + var channel = getAudioChannel(parseInt(parameters[0])); + var mimetype = parameters[1]; + var duration = parseInt(parameters[2]); + var data = parameters[3]; + + channel.play(mimetype, duration, data); + + }, + "cfill": function(parameters) { var channelMask = parseInt(parameters[0]); From ea6764743f5df51a95e291811947afa381eedc1d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 24 Oct 2012 10:52:53 -0700 Subject: [PATCH 230/263] Add width/height getters, add onresize event. --- .../src/main/resources/guacamole.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 5ffaee0a9..e2384c52e 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -463,6 +463,16 @@ Guacamole.Client = function(tunnel) { */ this.onclipboard = null; + /** + * Fired when the default layer (and thus the entire Guacamole display) + * is resized. + * + * @event + * @param {Number} width The new width of the Guacamole display. + * @param {Number} height The new height of the Guacamole display. + */ + this.onresize = null; + // Layers function getBufferLayer(index) { @@ -954,6 +964,10 @@ Guacamole.Client = function(tunnel) { bounds.style.width = (displayWidth*displayScale) + "px"; bounds.style.height = (displayHeight*displayScale) + "px"; + // Call resize event handler if defined + if (guac_client.onresize) + guac_client.onresize(width, height); + } } @@ -1134,6 +1148,14 @@ Guacamole.Client = function(tunnel) { }; + this.getWidth = function() { + return displayWidth; + }; + + this.getHeight = function() { + return displayHeight; + }; + this.getScale = function() { return displayScale; }; From ec0ea40b5813d8459c37cecd8cbefbeeef98dde0 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 24 Oct 2012 12:00:21 -0700 Subject: [PATCH 231/263] Update ChangeLog --- guacamole-common-js/ChangeLog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/guacamole-common-js/ChangeLog b/guacamole-common-js/ChangeLog index f2c396ea1..5150c076c 100644 --- a/guacamole-common-js/ChangeLog +++ b/guacamole-common-js/ChangeLog @@ -1,3 +1,10 @@ +2012-10-24 Michael Jumper + + * Implement base audio support + * Implement audio instruction + * Add width/height getters to client + * Add onresize event to client + 2012-10-16 Michael Jumper * Fix stream inefficiency bug (ticket #201) From c6d12ebac00c8ade2a45766d51929c7fa9021605 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 25 Oct 2012 14:29:57 -0700 Subject: [PATCH 232/263] Implement video playback in layer. --- .../src/main/resources/layer.js | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index e6052e76f..a72030e3f 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -256,8 +256,10 @@ Guacamole.Layer = function(width, height) { * Unblocks this Task, allowing it to run. */ this.unblock = function() { - task.blocked = false; - handlePendingTasks(); + if (task.blocked) { + task.blocked = false; + handlePendingTasks(); + } } } @@ -470,6 +472,55 @@ Guacamole.Layer = function(width, height) { }; + /** + * Plays the video at the specified URL within this layer. The video + * will be loaded automatically, and this and any future operations will + * wait for the video to finish loading. Future operations will not be + * executed until the video finishes playing. + * + * @param {String} mimetype The mimetype of the video to play. + * @param {Number} duration The duration of the video in milliseconds. + * @param {String} url The URL of the video to play. + */ + this.play = function(mimetype, duration, url) { + + // Start loading the video + var video = document.createElement("video"); + video.type = mimetype; + video.src = url; + + // Main task - playing the video + var task = scheduleTask(function() { + video.play(); + }, true); + + // Lock which will be cleared after video ends + var lock = scheduleTask(null, true); + + // Start copying frames when playing + video.addEventListener("play", function() { + + function render_callback() { + displayContext.drawImage(video, 0, 0, width, height); + if (!video.ended) + window.setTimeout(render_callback, 20); + else + lock.unblock(); + } + + render_callback(); + + }); + + // Unblock future operations after an error + video.addEventListener("error", lock.unblock); + + // Play video as soon as current tasks are complete, now that the + // lock has been set up. + task.unblock(); + + }; + /** * Run an arbitrary function as soon as currently pending operations * are complete. From 5786dbcf0e4384ed0ae428764a6f5ad0a86cdba1 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 25 Oct 2012 14:30:09 -0700 Subject: [PATCH 233/263] Implement video instruction. --- .../src/main/resources/guacamole.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index e2384c52e..3003d2ce6 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -1075,8 +1075,20 @@ Guacamole.Client = function(tunnel) { layer.transform(a, b, c, d, e, f); + }, + + "video": function(parameters) { + + var layer = getLayer(parseInt(parameters[0])); + var mimetype = parameters[1]; + var duration = parseInt(parameters[2]); + var data = parameters[3]; + + layer.play(mimetype, duration, "data:" + mimetype + ";base64," + data); + } - + + }; From 43a823e5c8b5ffc9b656bcdba02e4c6d54fca70a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 26 Oct 2012 12:23:18 -0700 Subject: [PATCH 234/263] Add file instruction handler and event, modify parser to not drop length if only partially received. --- .../src/main/resources/guacamole.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 3003d2ce6..9f9fbf3ad 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -82,7 +82,7 @@ Guacamole.Parser = function() { this.receive = function(packet) { // Truncate buffer as necessary - if (start_index > 4096) { + if (start_index > 4096 && element_end >= start_index) { buffer = buffer.substring(start_index); @@ -473,6 +473,18 @@ Guacamole.Client = function(tunnel) { */ this.onresize = null; + /** + * Fired when a file is received. Note that this will contain the entire + * data of the file. + * + * @event + * @param {String} name A human-readable name describing the file. + * @param {String} mimetype The mimetype of the file received. + * @param {String} data The actual entire contents of the file, + * base64-encoded. + */ + this.onfile = null; + // Layers function getBufferLayer(index) { @@ -773,6 +785,15 @@ Guacamole.Client = function(tunnel) { guac_client.disconnect(); }, + "file": function(parameters) { + if (guac_client.onfile) + guac_client.onfile( + parameters[0], // Name + parameters[1], // Mimetype + parameters[2] // Data + ); + }, + "identity": function(parameters) { var layer = getLayer(parseInt(parameters[0])); From 4e2f4dff31d1d72898043bd3560cb3f3ff8ba46f Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 29 Oct 2012 09:20:21 -0700 Subject: [PATCH 235/263] Remove old mimetype events. --- .../src/main/resources/guacamole.js | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 9f9fbf3ad..c0a605cdc 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -323,36 +323,6 @@ Guacamole.Client = function(tunnel) { return bounds; }; - /** - * Sends a supported audio mimetype. - * - * @param {String} mimetype The supported mimetype to send. - */ - this.sendAudioMimetype = function(mimetype) { - - // Do not send requests if not connected - if (!isConnected()) - return; - - tunnel.sendMessage("audio", mimetype); - - }; - - /** - * Sends a supported video mimetype. - * - * @param {String} mimetype The supported mimetype to send. - */ - this.sendVideoMimetype = function(mimetype) { - - // Do not send requests if not connected - if (!isConnected()) - return; - - tunnel.sendMessage("video", mimetype); - - }; - /** * Sends the current size of the screen. * From 01b4c416509a5912a9f93dbb48af20758f1b52e1 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 29 Oct 2012 15:15:12 -0700 Subject: [PATCH 236/263] Implement Web Audio API packet. --- .../src/main/resources/audio.js | 84 ++++++++++++++++--- 1 file changed, 71 insertions(+), 13 deletions(-) diff --git a/guacamole-common-js/src/main/resources/audio.js b/guacamole-common-js/src/main/resources/audio.js index 3cb0841a3..0bf708f34 100644 --- a/guacamole-common-js/src/main/resources/audio.js +++ b/guacamole-common-js/src/main/resources/audio.js @@ -111,6 +111,11 @@ Guacamole.AudioChannel = function() { }; +// Define context if available +if (window.webkitAudioContext) { + Guacamole.AudioChannel.context = new webkitAudioContext(); +} + /** * Abstract representation of an audio packet. * @@ -122,23 +127,76 @@ Guacamole.AudioChannel = function() { */ Guacamole.AudioChannel.Packet = function(mimetype, duration, data) { - // Build data URI - var data_uri = "data:" + mimetype + ";base64," + data; - - // Create audio element to house and play the data - var audio = new Audio(); - audio.src = data_uri; - /** * The duration of this packet, in milliseconds. */ this.duration = duration; - /** - * Plays the sound data contained by this packet immediately. - */ - this.play = function() { - audio.play(); - }; + // If audio API available, use it. + if (Guacamole.AudioChannel.context) { + + var readyBuffer = null; + + // By default, when decoding finishes, store buffer for future + // playback + var handleReady = function(buffer) { + readyBuffer = buffer; + }; + + // Convert to ArrayBuffer + var binary = window.atob(data); + var arrayBuffer = new ArrayBuffer(binary.length); + var bufferView = new Uint8Array(arrayBuffer); + + for (var i=0; i Date: Tue, 30 Oct 2012 17:05:15 -0700 Subject: [PATCH 237/263] Timeline-based packet scheduling. --- .../src/main/resources/audio.js | 86 ++++++++----------- 1 file changed, 38 insertions(+), 48 deletions(-) diff --git a/guacamole-common-js/src/main/resources/audio.js b/guacamole-common-js/src/main/resources/audio.js index 0bf708f34..94df391ee 100644 --- a/guacamole-common-js/src/main/resources/audio.js +++ b/guacamole-common-js/src/main/resources/audio.js @@ -54,32 +54,9 @@ Guacamole.AudioChannel = function() { var channel = this; /** - * Packet queue. + * When the next packet should play. */ - var packets = []; - - /** - * Whether this channel is currently playing sound. - */ - var playing = false; - - /** - * Advances to the next audio packet, if any, and plays it. - */ - function advance() { - - // If packets remain, play next - if (packets.length != 0) { - var packet = packets.shift(); - packet.play(); - window.setTimeout(advance, packet.duration); - } - - // Otherwise, no longer playing - else - playing = false; - - } + var next_packet_time = 0; /** * Queues up the given data for playing by this channel once all previously @@ -94,18 +71,20 @@ Guacamole.AudioChannel = function() { this.play = function(mimetype, duration, data) { var packet = - new Guacamole.AudioChannel.Packet(mimetype, duration, data); + new Guacamole.AudioChannel.Packet(mimetype, data); - // If currently playing sound, add packet to queue - if (playing) - packets.push(packet); + var now = new Date().getTime(); - // Otherwise, play now, flag channel as playing - else { - playing = true; - packet.play(); - window.setTimeout(advance, packet.duration); - } + // If time not initialized, initialize now + if (next_packet_time == 0) + next_packet_time = now; + + var time_until_play = next_packet_time - now; + + // Schedule next packet + next_packet_time += duration; + + packet.play(time_until_play); }; @@ -125,12 +104,7 @@ if (window.webkitAudioContext) { * @param {Number} duration The duration of the data contained by this packet. * @param {String} data The base64-encoded sound data contained by this packet. */ -Guacamole.AudioChannel.Packet = function(mimetype, duration, data) { - - /** - * The duration of this packet, in milliseconds. - */ - this.duration = duration; +Guacamole.AudioChannel.Packet = function(mimetype, data) { // If audio API available, use it. if (Guacamole.AudioChannel.context) { @@ -162,20 +136,34 @@ Guacamole.AudioChannel.Packet = function(mimetype, duration, data) { var source = Guacamole.AudioChannel.context.createBufferSource(); source.connect(Guacamole.AudioChannel.context.destination); - function playImmediately(buffer) { + var play_call; + var play_delay; + + function playDelayed(buffer) { + + // Calculate time since call to play() + var offset = new Date().getTime() - play_call; + source.buffer = buffer; - source.noteOn(0); + source.noteOn(Math.max(play_delay - offset, 0) / 1000); + + if (offset > play_delay) + console.log("processing lag", offset - play_delay); + } - this.play = function() { + this.play = function(delay) { + play_call = new Date().getTime(); + play_delay = delay; + // If buffer available, play it NOW if (readyBuffer) - playImmediately(readyBuffer); + playDelayed(readyBuffer); // Otherwise, play when decoded else - handleReady = playImmediately; + handleReady = playDelayed; }; @@ -193,8 +181,10 @@ Guacamole.AudioChannel.Packet = function(mimetype, duration, data) { /** * Plays the sound data contained by this packet immediately. */ - this.play = function() { - audio.play(); + this.play = function(delay) { + window.setTimeout(function() { + audio.play(); + }, delay); }; } From 88ca65ac84b46a82429fa31a26c1ce453f5e85dd Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 31 Oct 2012 14:09:48 -0700 Subject: [PATCH 238/263] Use setTimeout() rather than potentially-inaccurate noteOn(). --- .../src/main/resources/audio.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/guacamole-common-js/src/main/resources/audio.js b/guacamole-common-js/src/main/resources/audio.js index 94df391ee..5ba7ff015 100644 --- a/guacamole-common-js/src/main/resources/audio.js +++ b/guacamole-common-js/src/main/resources/audio.js @@ -76,8 +76,10 @@ Guacamole.AudioChannel = function() { var now = new Date().getTime(); // If time not initialized, initialize now - if (next_packet_time == 0) - next_packet_time = now; + if (next_packet_time == 0 || next_packet_time < now) { + next_packet_time = now + 50; + console.log("underflow"); + } var time_until_play = next_packet_time - now; @@ -101,7 +103,6 @@ if (window.webkitAudioContext) { * @constructor * * @param {String} mimetype The mimetype of the data contained by this packet. - * @param {Number} duration The duration of the data contained by this packet. * @param {String} data The base64-encoded sound data contained by this packet. */ Guacamole.AudioChannel.Packet = function(mimetype, data) { @@ -143,9 +144,18 @@ Guacamole.AudioChannel.Packet = function(mimetype, data) { // Calculate time since call to play() var offset = new Date().getTime() - play_call; + var delay = play_delay - offset; source.buffer = buffer; - source.noteOn(Math.max(play_delay - offset, 0) / 1000); + + if (delay <= 0) + source.noteOn(0); + else + window.setTimeout(function() { + source.noteOn(0); + }, delay); + + //source.noteOn(Math.max(play_delay - offset, 0) / 1000); if (offset > play_delay) console.log("processing lag", offset - play_delay); From 0e920a58165086e3364aa420c8aef1aa893da395 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 1 Nov 2012 11:15:26 -0700 Subject: [PATCH 239/263] Add error handling to parser. --- guacamole-common-js/src/main/resources/guacamole.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index c0a605cdc..46b39d98f 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -122,6 +122,8 @@ Guacamole.Parser = function() { element_buffer.length = 0; } + else if (terminator != ',') + throw new Error("Illegal terminator."); // Start searching for length at character after // element terminator @@ -135,6 +137,8 @@ Guacamole.Parser = function() { // Parse length var length = parseInt(buffer.substring(element_end+1, length_end)); + if (length == NaN) + throw new Error("Non-numeric character in element length."); // Calculate start of element start_index = length_end + 1; From e0407c3ad21c5952241700504fe2c68fe5e2eff0 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 1 Nov 2012 19:39:26 -0700 Subject: [PATCH 240/263] Use proper timeline sheduling, leverage existing noteOn() semantics. --- .../src/main/resources/audio.js | 67 ++++++++----------- 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/guacamole-common-js/src/main/resources/audio.js b/guacamole-common-js/src/main/resources/audio.js index 5ba7ff015..463bb5a14 100644 --- a/guacamole-common-js/src/main/resources/audio.js +++ b/guacamole-common-js/src/main/resources/audio.js @@ -73,21 +73,20 @@ Guacamole.AudioChannel = function() { var packet = new Guacamole.AudioChannel.Packet(mimetype, data); - var now = new Date().getTime(); + var now; + if (Guacamole.AudioChannel.context) + now = Guacamole.AudioChannel.context.currentTime * 1000; + else + now = new Date().getTime(); - // If time not initialized, initialize now - if (next_packet_time == 0 || next_packet_time < now) { + // If underflow is detected, delay start + if (next_packet_time < now) next_packet_time = now + 50; - console.log("underflow"); - } - - var time_until_play = next_packet_time - now; // Schedule next packet + packet.play(next_packet_time); next_packet_time += duration; - packet.play(time_until_play); - }; }; @@ -129,44 +128,24 @@ Guacamole.AudioChannel.Packet = function(mimetype, data) { // Get context and start decoding Guacamole.AudioChannel.context.decodeAudioData( arrayBuffer, - function(buffer) { handleReady(buffer); }, - function(e) { console.log("play error", e); } + function(buffer) { handleReady(buffer); } ); // Set up buffer source var source = Guacamole.AudioChannel.context.createBufferSource(); source.connect(Guacamole.AudioChannel.context.destination); - var play_call; - var play_delay; + var play_when; function playDelayed(buffer) { - - // Calculate time since call to play() - var offset = new Date().getTime() - play_call; - var delay = play_delay - offset; - source.buffer = buffer; - - if (delay <= 0) - source.noteOn(0); - else - window.setTimeout(function() { - source.noteOn(0); - }, delay); - - //source.noteOn(Math.max(play_delay - offset, 0) / 1000); - - if (offset > play_delay) - console.log("processing lag", offset - play_delay); - + source.noteOn(play_when / 1000); } - this.play = function(delay) { + this.play = function(when) { + + play_when = when; - play_call = new Date().getTime(); - play_delay = delay; - // If buffer available, play it NOW if (readyBuffer) playDelayed(readyBuffer); @@ -191,10 +170,22 @@ Guacamole.AudioChannel.Packet = function(mimetype, data) { /** * Plays the sound data contained by this packet immediately. */ - this.play = function(delay) { - window.setTimeout(function() { + this.play = function(when) { + + // Calculate time until play + var now = new Date().getTime(); + var delay = when - now; + + // Play now if too late + if (delay < 0) audio.play(); - }, delay); + + // Otherwise, schedule later playback + else + window.setTimeout(function() { + audio.play(); + }, delay); + }; } From b592b74513c92911970608370fcbec0785f5f5ea Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 1 Nov 2012 21:05:37 -0700 Subject: [PATCH 241/263] Support float durations. --- guacamole-common-js/src/main/resources/guacamole.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 46b39d98f..2e6e01a10 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -576,7 +576,7 @@ Guacamole.Client = function(tunnel) { var channel = getAudioChannel(parseInt(parameters[0])); var mimetype = parameters[1]; - var duration = parseInt(parameters[2]); + var duration = parseFloat(parameters[2]); var data = parameters[3]; channel.play(mimetype, duration, data); @@ -1076,7 +1076,7 @@ Guacamole.Client = function(tunnel) { var layer = getLayer(parseInt(parameters[0])); var mimetype = parameters[1]; - var duration = parseInt(parameters[2]); + var duration = parseFloat(parameters[2]); var data = parameters[3]; layer.play(mimetype, duration, "data:" + mimetype + ";base64," + data); From 7858b631d6a847ca833560ec065b202875c82fe6 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 3 Nov 2012 18:38:35 -0700 Subject: [PATCH 242/263] Stub implementation of flatten(). --- guacamole-common-js/src/main/resources/guacamole.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 2e6e01a10..dd97769ef 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -1167,6 +1167,17 @@ Guacamole.Client = function(tunnel) { return displayScale; }; + /** + * Returns a canvas element containing the entire display, with all child + * layers composited within. + */ + this.flatten = function() { + + // STUB: For now, just return canvas from root layer + return getLayer(0).getCanvas(); + + }; + }; /** From 3862a84014fa3f815b9e1341816ba75e5a2605bb Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 7 Nov 2012 14:54:02 -0800 Subject: [PATCH 243/263] Fix call to addEventListener (ticket #210). --- guacamole-common-js/src/main/resources/layer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index a72030e3f..0553aa333 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -510,10 +510,10 @@ Guacamole.Layer = function(width, height) { render_callback(); - }); + }, false); // Unblock future operations after an error - video.addEventListener("error", lock.unblock); + video.addEventListener("error", lock.unblock, false); // Play video as soon as current tasks are complete, now that the // lock has been set up. From a261bd2305bb1f5e6ccbe4d9260da0a16a8ccfe4 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 8 Nov 2012 10:30:02 -0800 Subject: [PATCH 244/263] Key state object should be object, not Array. --- guacamole-common-js/src/main/resources/keyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 8c08f39c5..fce0c46c8 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -241,7 +241,7 @@ Guacamole.Keyboard = function(element) { * is not currently pressed, the value for that keysym may be false or * undefined. */ - this.pressed = []; + this.pressed = {}; var keydownChar = new Array(); From 944dce0dc04a73da814863c51fc1bcd4e67db46e Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 8 Nov 2012 10:45:36 -0800 Subject: [PATCH 245/263] Do not use false to mark unpressed - just delete entry. --- guacamole-common-js/src/main/resources/keyboard.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index fce0c46c8..47a5a0b58 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -238,8 +238,7 @@ Guacamole.Keyboard = function(element) { /** * 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. + * is not currently pressed, it will not be defined. */ this.pressed = {}; @@ -341,7 +340,7 @@ Guacamole.Keyboard = function(element) { function sendKeyReleased(keysym) { // Mark key as released - guac_keyboard.pressed[keysym] = false; + delete guac_keyboard.pressed[keysym]; // Send key event if (keysym != null && guac_keyboard.onkeyup) From 6332e5015f1beb3cc0474a80c0cc129aaa257c50 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 8 Nov 2012 12:41:46 -0800 Subject: [PATCH 246/263] Ignore touch-generated mouse events. --- .../src/main/resources/oskeyboard.js | 64 +++++++++++++++---- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/guacamole-common-js/src/main/resources/oskeyboard.js b/guacamole-common-js/src/main/resources/oskeyboard.js index f5e72d2b2..7da6b4b81 100644 --- a/guacamole-common-js/src/main/resources/oskeyboard.js +++ b/guacamole-common-js/src/main/resources/oskeyboard.js @@ -86,6 +86,22 @@ Guacamole.OnScreenKeyboard = function(url) { */ var removeClass; + /** + * The number of mousemove events to require before re-enabling mouse + * event handling after receiving a touch event. + */ + this.touchMouseThreshold = 3; + + /** + * 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; + + // Ignore all pending mouse events when touch events are the apparent source + function ignorePendingMouseEvents() { ignore_mouse = on_screen_keyboard.touchMouseThreshold; } + // If Node.classList is supported, implement addClass/removeClass using that if (Node.classList) { @@ -336,7 +352,7 @@ Guacamole.OnScreenKeyboard = function(url) { row.appendChild(key_container_element); // Set up click handler for key - function press(e) { + function press() { // Press key if not yet pressed if (!key.pressed) { @@ -389,11 +405,9 @@ Guacamole.OnScreenKeyboard = function(url) { } - e.preventDefault(); - } - function release(e) { + function release() { // Release key if currently pressed if (key.pressed) { @@ -412,16 +426,38 @@ Guacamole.OnScreenKeyboard = function(url) { } - e.preventDefault(); - } - key_element.addEventListener("mousedown", press, true); - key_element.addEventListener("touchstart", press, true); + function touchPress(e) { + e.preventDefault(); + ignore_mouse = on_screen_keyboard.touchMouseThreshold; + press(); + } - key_element.addEventListener("mouseup", release, true); - key_element.addEventListener("mouseout", release, true); - key_element.addEventListener("touchend", release, true); + function touchRelease(e) { + e.preventDefault(); + ignore_mouse = on_screen_keyboard.touchMouseThreshold; + release(); + } + + function mousePress(e) { + e.preventDefault(); + if (ignore_mouse == 0) + press(); + } + + function mouseRelease(e) { + e.preventDefault(); + if (ignore_mouse == 0) + release(); + } + + key_element.addEventListener("touchstart", touchPress, true); + key_element.addEventListener("touchend", touchRelease, true); + + key_element.addEventListener("mousedown", mousePress, true); + key_element.addEventListener("mouseup", mouseRelease, true); + key_element.addEventListener("mouseout", mouseRelease, true); } @@ -482,8 +518,14 @@ Guacamole.OnScreenKeyboard = function(url) { keyboard.onmouseup = keyboard.onmousedown = function(e) { + + // If ignoring events, decrement counter + if (ignore_mouse) + ignore_mouse--; + e.stopPropagation(); return false; + }; /** From 5b017e0b7729ae4b06f758e5c4ed580183043882 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 13 Nov 2012 12:17:14 -0800 Subject: [PATCH 247/263] Use high-resolution timestamps if available. --- .../src/main/resources/audio.js | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/guacamole-common-js/src/main/resources/audio.js b/guacamole-common-js/src/main/resources/audio.js index 463bb5a14..2ac3287ed 100644 --- a/guacamole-common-js/src/main/resources/audio.js +++ b/guacamole-common-js/src/main/resources/audio.js @@ -73,15 +73,11 @@ Guacamole.AudioChannel = function() { var packet = new Guacamole.AudioChannel.Packet(mimetype, data); - var now; - if (Guacamole.AudioChannel.context) - now = Guacamole.AudioChannel.context.currentTime * 1000; - else - now = new Date().getTime(); + var now = Guacamole.AudioChannel.getTimestamp(); - // If underflow is detected, delay start + // If underflow is detected, reschedule new packets relative to now. if (next_packet_time < now) - next_packet_time = now + 50; + next_packet_time = now; // Schedule next packet packet.play(next_packet_time); @@ -96,6 +92,28 @@ if (window.webkitAudioContext) { Guacamole.AudioChannel.context = new webkitAudioContext(); } +Guacamole.AudioChannel.getTimestamp = function() { + + // If we have an audio context, use its timestamp + if (Guacamole.AudioChannel.context) + return Guacamole.AudioChannel.context.currentTime * 1000; + + // If we have high-resolution timers, use those + if (window.performance) { + + if (window.performance.now) + return window.peformance.now(); + + if (window.performance.webkitNow) + return window.performance.webkitNow(); + + } + + // Fallback to millisecond-resolution system time + return new Date().getTime(); + +}; + /** * Abstract representation of an audio packet. * @@ -173,7 +191,7 @@ Guacamole.AudioChannel.Packet = function(mimetype, data) { this.play = function(when) { // Calculate time until play - var now = new Date().getTime(); + var now = Guacamole.AudioChannel.getTimestamp(); var delay = when - now; // Play now if too late From 3ed048640ed0aeff4abed649316599407f43441c Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 13 Nov 2012 12:22:36 -0800 Subject: [PATCH 248/263] Fix typo in "performance". --- guacamole-common-js/src/main/resources/audio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/audio.js b/guacamole-common-js/src/main/resources/audio.js index 2ac3287ed..1f40870f4 100644 --- a/guacamole-common-js/src/main/resources/audio.js +++ b/guacamole-common-js/src/main/resources/audio.js @@ -102,7 +102,7 @@ Guacamole.AudioChannel.getTimestamp = function() { if (window.performance) { if (window.performance.now) - return window.peformance.now(); + return window.performance.now(); if (window.performance.webkitNow) return window.performance.webkitNow(); From 0971180cd6a425a3e837ea2582048b419a9a5bda Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 13 Nov 2012 12:28:15 -0800 Subject: [PATCH 249/263] Make copy of canvas, rather than simply returning root layer. --- .../src/main/resources/guacamole.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index dd97769ef..03d81340e 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -1172,9 +1172,21 @@ Guacamole.Client = function(tunnel) { * layers composited within. */ this.flatten = function() { + + // Get source and destination canvases + var source = getLayer(0).getCanvas(); + var canvas = document.createElement("canvas"); + + // Set dimensions + canvas.width = source.width; + canvas.height = source.height; + + // Copy image from source + var context = canvas.getContext("2d"); + context.drawImage(source, 0, 0); - // STUB: For now, just return canvas from root layer - return getLayer(0).getCanvas(); + // Return new canvas copy + return canvas; }; From d56756390d610e750df67b5fa7f595ec3f767c33 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 28 Nov 2012 20:50:27 -0800 Subject: [PATCH 250/263] Do not attempt to monitor up/down if key handled via keypress (fixes #208). Partial style fix. --- .../src/main/resources/keyboard.js | 227 ++++++++---------- 1 file changed, 102 insertions(+), 125 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 47a5a0b58..f4387a42b 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -80,7 +80,7 @@ Guacamole.Keyboard = function(element) { * to their unshifted X11 keysym equivalents. * @private */ - var unshiftedKeySym = { + var unshiftedKeysym = { 8: 0xFF08, // backspace 9: 0xFF09, // tab 13: 0xFF0D, // enter @@ -209,10 +209,19 @@ Guacamole.Keyboard = function(element) { * equivalents. * @private */ - var shiftedKeySym = { + var shiftedKeysym = { 18: 0xFFE7 // alt }; + /** + * All keysyms which should not repeat when held down. + */ + var no_repeat = { + 0xFFE1: true, + 0xFFE3: true, + 0xFFE9: true + }; + /** * All modifiers and their states. */ @@ -242,28 +251,23 @@ Guacamole.Keyboard = function(element) { */ this.pressed = {}; - var keydownChar = new Array(); + /** + * The keysym associated with a given keycode when keydown fired. + */ + var keydownChar = []; - // ID of routine repeating keystrokes. -1 = not repeating. - var repeatKeyTimeoutId = -1; - var repeatKeyIntervalId = -1; + /** + * Timeout before key repeat starts. + */ + var key_repeat_timeout = null; - // Starts repeating keystrokes - function startRepeat(keySym) { - repeatKeyIntervalId = setInterval(function() { - sendKeyReleased(keySym); - sendKeyPressed(keySym); - }, 50); - } + /** + * Interval which presses and releases the last key pressed while that + * key is still being held down. + */ + var key_repeat_interval = null; - // Stops repeating keystrokes - function stopRepeat() { - if (repeatKeyTimeoutId != -1) clearTimeout(repeatKeyTimeoutId); - if (repeatKeyIntervalId != -1) clearInterval(repeatKeyIntervalId); - } - - - function getKeySymFromKeyIdentifier(shifted, keyIdentifier) { + function keysym_from_key_identifier(shifted, keyIdentifier) { var unicodePrefixLocation = keyIdentifier.indexOf("U+"); if (unicodePrefixLocation >= 0) { @@ -281,7 +285,7 @@ Guacamole.Keyboard = function(element) { // Get codepoint codepoint = typedCharacter.charCodeAt(0); - return getKeySymFromCharCode(codepoint); + return keysym_from_charcode(codepoint); } @@ -293,7 +297,7 @@ Guacamole.Keyboard = function(element) { return codepoint <= 0x1F || (codepoint >= 0x7F && codepoint <= 0x9F); } - function getKeySymFromCharCode(codepoint) { + function keysym_from_charcode(codepoint) { // Keysyms for control characters if (isControlCharacter(codepoint)) return 0xFF00 | codepoint; @@ -310,13 +314,13 @@ Guacamole.Keyboard = function(element) { } - function getKeySymFromKeyCode(keyCode) { + function keysyom_from_keycode(keyCode) { var keysym = null; - if (!guac_keyboard.modifiers.shift) keysym = unshiftedKeySym[keyCode]; + if (!guac_keyboard.modifiers.shift) keysym = unshiftedKeysym[keyCode]; else { - keysym = shiftedKeySym[keyCode]; - if (keysym == null) keysym = unshiftedKeySym[keyCode]; + keysym = shiftedKeysym[keyCode]; + if (keysym == null) keysym = unshiftedKeysym[keyCode]; } return keysym; @@ -324,69 +328,62 @@ Guacamole.Keyboard = function(element) { } - // Sends a single keystroke over the network - function sendKeyPressed(keysym) { + /** + * Marks a key as pressed, firing the keydown event if registered. Key + * repeat for the pressed key will start after a delay if that key is + * not a modifier. + */ + function press_key(keysym) { - // Mark key as pressed - guac_keyboard.pressed[keysym] = true; + // Only press if released + if (!guac_keyboard.pressed[keysym]) { - // Send key event - if (keysym != null && guac_keyboard.onkeydown) - guac_keyboard.onkeydown(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) { + // Stop any current repeat + window.clearTimeout(key_repeat_timeout); + window.clearInterval(key_repeat_interval); - // Mark key as released - delete guac_keyboard.pressed[keysym]; - - // Send key event - if (keysym != null && guac_keyboard.onkeyup) - guac_keyboard.onkeyup(keysym); - - } + // Repeat after a delay as long as pressed + if (!no_repeat[keysym]) + key_repeat_timeout = setTimeout(function() { + key_repeat_interval = window.setInterval(function() { + guac_keyboard.onkeyup(keysym); + guac_keyboard.onkeydown(keysym); + }, 50); + }, 500); - 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; + } + + /** + * Marks a key as released, firing the keyup event if registered. + */ + function release_key(keysym) { + + // Only release if pressed + if (guac_keyboard.pressed[keysym]) { + + // Mark key as released + delete guac_keyboard.pressed[keysym]; + + // Stop repeat + window.clearTimeout(key_repeat_timeout); + window.clearInterval(key_repeat_interval); + + // Send key event + if (keysym != null && guac_keyboard.onkeyup) + guac_keyboard.onkeyup(keysym); + + } } @@ -425,25 +422,26 @@ Guacamole.Keyboard = function(element) { return; } - expect_keypress = true; - // Ctrl/Alt/Shift - if (keynum == 16) guac_keyboard.modifiers.shift = true; + 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); + var keysym = keysyom_from_keycode(keynum); + + // By default, we expect a corresponding keypress event + var expect_keypress = true; // If key is known from keycode, prevent default - if (keydown_keysym) + if (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); + keysym = keysym || + keysym_from_key_identifier(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 @@ -457,20 +455,11 @@ Guacamole.Keyboard = function(element) { } - // 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 { + // If we do not expect to handle via keypress, handle now + if (!expect_keypress) { e.preventDefault(); - handleKeyEvents(); + keydownChar[keynum] = keysym; + press_key(keysym); } }, true); @@ -479,33 +468,26 @@ Guacamole.Keyboard = function(element) { element.addEventListener("keypress", function(e) { // Only intercept if handler set - if (!guac_keyboard.onkeydown) return; + if (!guac_keyboard.onkeydown && !guac_keyboard.onkeyup) 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); + var keysym = keysym_from_charcode(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); + release_key(0xFFE3); + release_key(0xFFE9); } - // Clear timeout, if any - if (deferred_keypress) - window.clearTimeout(deferred_keypress); - - // Handle event with all aggregated data - handleKeyEvents(); + // Send press + release + press_key(keysym); + release_key(keysym); }, true); @@ -522,27 +504,22 @@ Guacamole.Keyboard = function(element) { else if (e.which) keynum = e.which; // Ctrl/Alt/Shift - if (keynum == 16) guac_keyboard.modifiers.shift = false; + 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]; + // Send release event + release_key(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.alt = false; + guac_keyboard.modifiers.ctrl = false; guac_keyboard.modifiers.shift = false; }, true); From d75ee894304c0a9b2ee3f06586b32ec9ba1c55e2 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 28 Nov 2012 22:13:32 -0800 Subject: [PATCH 251/263] Properly check for null. --- .../src/main/resources/keyboard.js | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index f4387a42b..5a472cdcd 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -335,6 +335,9 @@ Guacamole.Keyboard = function(element) { */ function press_key(keysym) { + // Don't bother with pressing the key if the key is unknown + if (keysym == null) return; + // Only press if released if (!guac_keyboard.pressed[keysym]) { @@ -342,7 +345,7 @@ Guacamole.Keyboard = function(element) { guac_keyboard.pressed[keysym] = true; // Send key event - if (keysym != null && guac_keyboard.onkeydown) { + if (guac_keyboard.onkeydown) { guac_keyboard.onkeydown(keysym); // Stop any current repeat @@ -458,8 +461,13 @@ Guacamole.Keyboard = function(element) { // If we do not expect to handle via keypress, handle now if (!expect_keypress) { e.preventDefault(); - keydownChar[keynum] = keysym; - press_key(keysym); + + // Press key if known + if (keysym != null) { + keydownChar[keynum] = keysym; + press_key(keysym); + } + } }, true); @@ -485,9 +493,11 @@ Guacamole.Keyboard = function(element) { release_key(0xFFE9); } - // Send press + release - press_key(keysym); - release_key(keysym); + // Send press + release if keysym known + if (keysym != null) { + press_key(keysym); + release_key(keysym); + } }, true); @@ -508,8 +518,10 @@ Guacamole.Keyboard = function(element) { else if (keynum == 17) guac_keyboard.modifiers.ctrl = false; else if (keynum == 18) guac_keyboard.modifiers.alt = false; - // Send release event - release_key(keydownChar[keynum]); + // Send release event if original key known + var keydown_keysym = keydownChar[keynum]; + if (keydown_keysym != null) + release_key(keydown_keysym); // Clear character record keydownChar[keynum] = null; From 4efc08e8efd1c52d21d9a236302fbe852aff1c1d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 28 Nov 2012 22:13:51 -0800 Subject: [PATCH 252/263] Modify for consistency. --- guacamole-common-js/src/main/resources/keyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 5a472cdcd..e42317e99 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -354,7 +354,7 @@ Guacamole.Keyboard = function(element) { // Repeat after a delay as long as pressed if (!no_repeat[keysym]) - key_repeat_timeout = setTimeout(function() { + key_repeat_timeout = window.setTimeout(function() { key_repeat_interval = window.setInterval(function() { guac_keyboard.onkeyup(keysym); guac_keyboard.onkeydown(keysym); From 0b88c48038751137801f3676feb23866ec43357d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 1 Dec 2012 20:57:59 -0800 Subject: [PATCH 253/263] Fix JSDoc. --- .../src/main/resources/audio.js | 23 ++++++-- .../src/main/resources/guacamole.js | 53 +++++++++++++++++-- .../src/main/resources/keyboard.js | 6 +++ .../src/main/resources/tunnel.js | 1 + 4 files changed, 76 insertions(+), 7 deletions(-) diff --git a/guacamole-common-js/src/main/resources/audio.js b/guacamole-common-js/src/main/resources/audio.js index 1f40870f4..8a3243cdb 100644 --- a/guacamole-common-js/src/main/resources/audio.js +++ b/guacamole-common-js/src/main/resources/audio.js @@ -55,6 +55,7 @@ Guacamole.AudioChannel = function() { /** * When the next packet should play. + * @private */ var next_packet_time = 0; @@ -92,6 +93,14 @@ if (window.webkitAudioContext) { Guacamole.AudioChannel.context = new webkitAudioContext(); } +/** + * Returns a base timestamp which can be used for scheduling future audio + * playback. Scheduling playback for the value returned by this function plus + * N will cause the associated audio to be played back N milliseconds after + * the function is called. + * + * @return {Number} An arbitrary channel-relative timestamp, in milliseconds. + */ Guacamole.AudioChannel.getTimestamp = function() { // If we have an audio context, use its timestamp @@ -124,6 +133,15 @@ Guacamole.AudioChannel.getTimestamp = function() { */ Guacamole.AudioChannel.Packet = function(mimetype, data) { + /** + * Schedules this packet for playback at the given time. + * + * @function + * @param {Number} when The time this packet should be played, in + * milliseconds. + */ + this.play = undefined; // Defined conditionally depending on support + // If audio API available, use it. if (Guacamole.AudioChannel.context) { @@ -160,6 +178,7 @@ Guacamole.AudioChannel.Packet = function(mimetype, data) { source.noteOn(play_when / 1000); } + /** @ignore */ this.play = function(when) { play_when = when; @@ -185,9 +204,7 @@ Guacamole.AudioChannel.Packet = function(mimetype, data) { var audio = new Audio(); audio.src = data_uri; - /** - * Plays the sound data contained by this packet immediately. - */ + /** @ignore */ this.play = function(when) { // Calculate time until play diff --git a/guacamole-common-js/src/main/resources/guacamole.js b/guacamole-common-js/src/main/resources/guacamole.js index 03d81340e..523f61b01 100644 --- a/guacamole-common-js/src/main/resources/guacamole.js +++ b/guacamole-common-js/src/main/resources/guacamole.js @@ -61,7 +61,7 @@ Guacamole.Parser = function() { * element is available. After a full element is available, that element * is flushed into the element buffer. * - * @priate + * @private */ var buffer = ""; @@ -69,7 +69,7 @@ Guacamole.Parser = function() { * Buffer of all received, complete elements. After an entire instruction * is read, this buffer is flushed, and a new instruction begins. * - * @priate + * @private */ var element_buffer = []; @@ -79,6 +79,13 @@ Guacamole.Parser = function() { // Where to start the next length search or the next element var start_index = 0; + /** + * Appends the given instruction data packet to the internal buffer of + * this Guacamole.Parser, executing all completed instructions at + * the beginning of this buffer, if any. + * + * @param {String} packet The instruction data to append. + */ this.receive = function(packet) { // Truncate buffer as necessary @@ -1096,6 +1103,9 @@ Guacamole.Client = function(tunnel) { }; + /** + * Sends a disconnect instruction to the server and closes the tunnel. + */ this.disconnect = function() { // Only attempt disconnection not disconnected. @@ -1117,6 +1127,13 @@ Guacamole.Client = function(tunnel) { }; + /** + * Connects the underlying tunnel of this Guacamole.Client, passing the + * given arbitrary data to the tunnel during the connection process. + * + * @param data Arbitrary connection data to be sent to the underlying + * tunnel during the connection process. + */ this.connect = function(data) { setState(STATE_CONNECTING); @@ -1137,6 +1154,14 @@ Guacamole.Client = function(tunnel) { setState(STATE_WAITING); }; + /** + * Sets the scale of the client display element such that it renders at + * a relatively smaller or larger size, without affecting the true + * resolution of the display. + * + * @param {Number} scale The scale to resize to, where 1.0 is normal + * size (1:1 scale). + */ this.scale = function(scale) { display.style.transform = @@ -1155,14 +1180,29 @@ Guacamole.Client = function(tunnel) { }; + /** + * Returns the width of the display. + * + * @return {Number} The width of the display. + */ this.getWidth = function() { return displayWidth; }; + /** + * Returns the height of the display. + * + * @return {Number} The height of the display. + */ this.getHeight = function() { return displayHeight; }; + /** + * Returns the scale of the display. + * + * @return {Number} The scale of the display. + */ this.getScale = function() { return displayScale; }; @@ -1170,6 +1210,9 @@ Guacamole.Client = function(tunnel) { /** * Returns a canvas element containing the entire display, with all child * layers composited within. + * + * @return {HTMLCanvasElement} A new canvas element containing a copy of + * the display. */ this.flatten = function() { @@ -1248,7 +1291,8 @@ Guacamole.Client.LayerContainer = function(width, height) { /** * Returns the Layer contained within this LayerContainer. - * @returns {Guacamole.Layer} The Layer contained within this LayerContainer. + * @returns {Guacamole.Layer} The Layer contained within this + * LayerContainer. */ this.getLayer = function() { return layer; @@ -1256,7 +1300,8 @@ Guacamole.Client.LayerContainer = function(width, height) { /** * Returns the element containing the Layer within this LayerContainer. - * @returns {Element} The element containing the Layer within this LayerContainer. + * @returns {Element} The element containing the Layer within this + * LayerContainer. */ this.getElement = function() { return div; diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index e42317e99..b00d1df0c 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -215,6 +215,7 @@ Guacamole.Keyboard = function(element) { /** * All keysyms which should not repeat when held down. + * @private */ var no_repeat = { 0xFFE1: true, @@ -253,17 +254,20 @@ Guacamole.Keyboard = function(element) { /** * The keysym associated with a given keycode when keydown fired. + * @private */ var keydownChar = []; /** * Timeout before key repeat starts. + * @private */ var key_repeat_timeout = null; /** * Interval which presses and releases the last key pressed while that * key is still being held down. + * @private */ var key_repeat_interval = null; @@ -332,6 +336,7 @@ Guacamole.Keyboard = function(element) { * Marks a key as pressed, firing the keydown event if registered. Key * repeat for the pressed key will start after a delay if that key is * not a modifier. + * @private */ function press_key(keysym) { @@ -369,6 +374,7 @@ Guacamole.Keyboard = function(element) { /** * Marks a key as released, firing the keyup event if registered. + * @private */ function release_key(keysym) { diff --git a/guacamole-common-js/src/main/resources/tunnel.js b/guacamole-common-js/src/main/resources/tunnel.js index 812ee897d..5cec1be01 100644 --- a/guacamole-common-js/src/main/resources/tunnel.js +++ b/guacamole-common-js/src/main/resources/tunnel.js @@ -436,6 +436,7 @@ Guacamole.HTTPTunnel = function(tunnelURL) { /** * Arbitrary integer, unique for each tunnel read request. + * @private */ var request_id = 0; From b7071563279dc12f3643f9d3e986f022dffdd1c9 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 9 Jan 2013 15:18:35 -0800 Subject: [PATCH 254/263] Fix typo in variable name. --- guacamole-common-js/src/main/resources/keyboard.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index b00d1df0c..13efc071e 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -318,7 +318,7 @@ Guacamole.Keyboard = function(element) { } - function keysyom_from_keycode(keyCode) { + function keysym_from_keycode(keyCode) { var keysym = null; if (!guac_keyboard.modifiers.shift) keysym = unshiftedKeysym[keyCode]; @@ -437,7 +437,7 @@ Guacamole.Keyboard = function(element) { else if (keynum == 18) guac_keyboard.modifiers.alt = true; // Try to get keysym from keycode - var keysym = keysyom_from_keycode(keynum); + var keysym = keysym_from_keycode(keynum); // By default, we expect a corresponding keypress event var expect_keypress = true; From 339dc3dcc805a29c7c00b090dfb5a05e648b0ef8 Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Wed, 16 Jan 2013 09:50:50 -0800 Subject: [PATCH 255/263] Fix for ticket 257 - add meta (apple) key to list of modifiers to ignore keypress --- .../src/main/resources/keyboard.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index b00d1df0c..563b6942d 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -241,7 +241,12 @@ Guacamole.Keyboard = function(element) { /** * Whether alt is currently pressed. */ - "alt" : false + "alt" : false, + + /** + * Whether meta (apple key) is currently pressed. + */ + "meta" : false }; @@ -431,10 +436,11 @@ Guacamole.Keyboard = function(element) { return; } - // Ctrl/Alt/Shift + // Ctrl/Alt/Shift/Meta 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; + else if (keynum == 91) guac_keyboard.modifiers.meta = true; // Try to get keysym from keycode var keysym = keysyom_from_keycode(keynum); @@ -450,7 +456,7 @@ Guacamole.Keyboard = function(element) { if (e.keyIdentifier) { keysym = keysym || - keysym_from_key_identifier(guac_keyboard.modifiers.shift, e.keyIdentifier); + keysym_from_key_identifier(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 @@ -458,8 +464,9 @@ Guacamole.Keyboard = function(element) { // 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)) + || ( guac_keyboard.modifiers.ctrl && !guac_keyboard.modifiers.alt) + || (!guac_keyboard.modifiers.ctrl && guac_keyboard.modifiers.alt) + || (guac_keyboard.modifiers.meta)) expect_keypress = false; } @@ -519,10 +526,11 @@ Guacamole.Keyboard = function(element) { if (window.event) keynum = window.event.keyCode; else if (e.which) keynum = e.which; - // Ctrl/Alt/Shift + // Ctrl/Alt/Shift/Meta 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 if (keynum == 91) guac_keyboard.modifiers.meta = false; // Send release event if original key known var keydown_keysym = keydownChar[keynum]; @@ -539,6 +547,7 @@ Guacamole.Keyboard = function(element) { guac_keyboard.modifiers.alt = false; guac_keyboard.modifiers.ctrl = false; guac_keyboard.modifiers.shift = false; + guac_keyboard.modifiers.meta = false; }, true); }; From 7ffff054a80def4576c2aa2632e3e653e2211acd Mon Sep 17 00:00:00 2001 From: James Muehlner Date: Thu, 24 Jan 2013 19:08:17 -0800 Subject: [PATCH 256/263] Ticket 254: Put in fix for chrome bug 108404. Automatically release key if a keydown is recieved while meta is held down. --- guacamole-common-js/src/main/resources/keyboard.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 563b6942d..4fe2a57b7 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -479,6 +479,11 @@ Guacamole.Keyboard = function(element) { if (keysym != null) { keydownChar[keynum] = keysym; press_key(keysym); + + // If a key is pressed while meta is held down, the keyup will never be sent in Chrome, so send it now. (bug #108404) + if(guac_keyboard.modifiers.meta) { + release_key(keysym); + } } } From f4554da7b1b3a0d8481816ca49583771aec9a938 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 17 Mar 2013 21:50:35 -0700 Subject: [PATCH 257/263] Bump version to 0.7.1. --- guacamole-common-js/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/pom.xml b/guacamole-common-js/pom.xml index aee81f5a6..27626a977 100644 --- a/guacamole-common-js/pom.xml +++ b/guacamole-common-js/pom.xml @@ -5,7 +5,7 @@ net.sourceforge.guacamole guacamole-common-js pom - 0.7.0 + 0.7.1 guacamole-common-js http://guac-dev.org/ From e4008c973dcf9d461f014172653e802d20d615bb Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 7 May 2013 10:23:19 -0700 Subject: [PATCH 258/263] Bump version, add support for keyboard sidedness. --- guacamole-common-js/pom.xml | 2 +- .../src/main/resources/keyboard.js | 273 ++++++++++-------- 2 files changed, 150 insertions(+), 125 deletions(-) diff --git a/guacamole-common-js/pom.xml b/guacamole-common-js/pom.xml index 27626a977..d79ba6436 100644 --- a/guacamole-common-js/pom.xml +++ b/guacamole-common-js/pom.xml @@ -5,7 +5,7 @@ net.sourceforge.guacamole guacamole-common-js pom - 0.7.1 + 0.7.2 guacamole-common-js http://guac-dev.org/ diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index fa3a7ee01..ad9b63a13 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -81,43 +81,43 @@ Guacamole.Keyboard = function(element) { * @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 + 8: [0xFF08], // backspace + 9: [0xFF09], // tab + 13: [0xFF0D], // enter + 16: [0xFFE1, 0xFFE1, 0xFFE2], // shift + 17: [0xFFE3, 0xFFE3, 0xFFE4], // ctrl + 18: [0xFFE9, 0xFFE9, 0xFFEA], // 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 }; /** @@ -126,80 +126,80 @@ Guacamole.Keyboard = function(element) { * @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, + "AllCandidates": [0xFF3D], + "Alphanumeric": [0xFF30], + "Alt": [0xFFE9, 0xFFE9, 0xFFEA], + "Attn": [0xFD0E], + "AltGraph": [0xFFEA], + "CapsLock": [0xFFE5], + "Clear": [0xFF0B], + "Convert": [0xFF21], + "Copy": [0xFD15], + "Crsel": [0xFD1C], + "CodeInput": [0xFF37], + "Control": [0xFFE3, 0xFFE3, 0xFFE4], + "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, + "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 + "Scroll": [0xFF14], + "Select": [0xFF60], + "Shift": [0xFFE1, 0xFFE1, 0xFFE2], + "Up": [0xFF52], + "Undo": [0xFF65], + "Win": [0xFFEB] }; /** @@ -210,7 +210,7 @@ Guacamole.Keyboard = function(element) { * @private */ var shiftedKeysym = { - 18: 0xFFE7 // alt + 18: [0xFFE7, 0xFFE7, 0xFFEA] // alt }; /** @@ -218,9 +218,12 @@ Guacamole.Keyboard = function(element) { * @private */ var no_repeat = { - 0xFFE1: true, - 0xFFE3: true, - 0xFFE9: true + 0xFFE1: true, // Left shift + 0xFFE2: true, // Right shift + 0xFFE3: true, // Left ctrl + 0xFFE4: true, // Right ctrl + 0xFFE9: true, // Left alt + 0xFFEA: true // Right alt (or AltGr) }; /** @@ -276,7 +279,22 @@ Guacamole.Keyboard = function(element) { */ var key_repeat_interval = null; - function keysym_from_key_identifier(shifted, keyIdentifier) { + /** + * Given an array of keysyms indexed by location, returns the keysym + * for the given location, or the keysym for the standard location if + * undefined. + * + * @param {Array} keysyms An array of keysyms, where the index of the + * keysym in the array is the location value. + * @param {Number} location The location on the keyboard corresponding to + * the key pressed, as defined at: + * http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent + */ + function get_keysym(keysyms, location) { + return keysyms[location] || keysyms[0]; + } + + function keysym_from_key_identifier(shifted, keyIdentifier, location) { var unicodePrefixLocation = keyIdentifier.indexOf("U+"); if (unicodePrefixLocation >= 0) { @@ -298,7 +316,7 @@ Guacamole.Keyboard = function(element) { } - return keyidentifier_keysym[keyIdentifier]; + return get_keysym(keyidentifier_keysym[keyIdentifier], location); } @@ -323,16 +341,19 @@ Guacamole.Keyboard = function(element) { } - function keysym_from_keycode(keyCode) { + function keysym_from_keycode(keyCode, location) { - var keysym = null; - if (!guac_keyboard.modifiers.shift) keysym = unshiftedKeysym[keyCode]; - else { - keysym = shiftedKeysym[keyCode]; - if (keysym == null) keysym = unshiftedKeysym[keyCode]; - } + var keysyms; - return keysym; + // If not shifted, just return unshifted keysym + if (!guac_keyboard.modifiers.shift) + keysyms = unshiftedKeysym[keyCode]; + + // Otherwise, return shifted keysym, if defined + else + keysyms = shiftedKeysym[keyCode] || unshiftedKeysym[keyCode]; + + return get_keysym(keysyms, location); } @@ -430,6 +451,9 @@ Guacamole.Keyboard = function(element) { if (window.event) keynum = window.event.keyCode; else if (e.which) keynum = e.which; + // Get key location + var location = e.location || e.keyLocation || 0; + // Ignore any unknown key events if (keynum == 0 && !e.keyIdentifier) { e.preventDefault(); @@ -443,7 +467,7 @@ Guacamole.Keyboard = function(element) { else if (keynum == 91) guac_keyboard.modifiers.meta = true; // Try to get keysym from keycode - var keysym = keysym_from_keycode(keynum); + var keysym = keysym_from_keycode(keynum, location); // By default, we expect a corresponding keypress event var expect_keypress = true; @@ -456,7 +480,8 @@ Guacamole.Keyboard = function(element) { if (e.keyIdentifier) { keysym = keysym || - keysym_from_key_identifier(guac_keyboard.modifiers.shift, e.keyIdentifier); + keysym_from_key_identifier(guac_keyboard.modifiers.shift, + e.keyIdentifier, location); // Prevent default if non-typable character or if modifier combination // likely to be eaten by browser otherwise (NOTE: We must not prevent From 52579d6f5c68a2551c2420ea2fb7fa1a773c9501 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 7 May 2013 16:09:01 -0700 Subject: [PATCH 259/263] Unify modifier behavior across browsers, maintain state between events. --- .../src/main/resources/keyboard.js | 55 +++++++++++++++---- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index ad9b63a13..5dbcd1122 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -441,6 +441,38 @@ Guacamole.Keyboard = function(element) { } + /** + * Given a keyboard event, updates the local modifier state and remote + * key state based on the modifier flags within the event. This function + * pays no attention to keycodes. + * + * @param {} e The keyboard event containing the flags to update. + */ + function update_modifier_state(e) { + + // Release alt if implicitly released + if (guac_keyboard.modifiers.alt && e.altKey === false) { + release_key(0xFFE9); // Left alt + release_key(0xFFEA); // Right alt (or AltGr) + guac_keyboard.modifiers.alt = false; + } + + // Release shift if implicitly released + if (guac_keyboard.modifiers.shift && e.shiftKey === false) { + release_key(0xFFE1); // Left shift + release_key(0xFFE2); // Right shift + guac_keyboard.modifiers.shift = false; + } + + // Release ctrl if implicitly released + if (guac_keyboard.modifiers.ctrl && e.ctrlKey === false) { + release_key(0xFFE3); // Left ctrl + release_key(0xFFE4); // Right ctrl + guac_keyboard.modifiers.ctrl = false; + } + + } + // When key pressed element.addEventListener("keydown", function(e) { @@ -460,6 +492,9 @@ Guacamole.Keyboard = function(element) { return; } + // Fix modifier states + update_modifier_state(e); + // Ctrl/Alt/Shift/Meta if (keynum == 16) guac_keyboard.modifiers.shift = true; else if (keynum == 17) guac_keyboard.modifiers.ctrl = true; @@ -529,11 +564,16 @@ Guacamole.Keyboard = function(element) { var keysym = keysym_from_charcode(keynum); + // Fix modifier states + update_modifier_state(e); + // 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) { - release_key(0xFFE3); - release_key(0xFFE9); + release_key(0xFFE3); // Left ctrl + release_key(0xFFE4); // Right ctrl + release_key(0xFFE9); // Left alt + release_key(0xFFEA); // Right alt } // Send press + release if keysym known @@ -556,6 +596,9 @@ Guacamole.Keyboard = function(element) { if (window.event) keynum = window.event.keyCode; else if (e.which) keynum = e.which; + // Fix modifier states + update_modifier_state(e); + // Ctrl/Alt/Shift/Meta if (keynum == 16) guac_keyboard.modifiers.shift = false; else if (keynum == 17) guac_keyboard.modifiers.ctrl = false; @@ -572,12 +615,4 @@ Guacamole.Keyboard = function(element) { }, 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; - guac_keyboard.modifiers.meta = false; - }, true); - }; From 32bea8c30e6b0420d6a8fdc79a533ee10bba9e7a Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 7 May 2013 16:09:51 -0700 Subject: [PATCH 260/263] Add missing type to doc. --- guacamole-common-js/src/main/resources/keyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index 5dbcd1122..d570e1b08 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -446,7 +446,7 @@ Guacamole.Keyboard = function(element) { * key state based on the modifier flags within the event. This function * pays no attention to keycodes. * - * @param {} e The keyboard event containing the flags to update. + * @param {KeyboardEvent} e The keyboard event containing the flags to update. */ function update_modifier_state(e) { From a75b651422c8e8409805d73e430ea639e69270bc Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 7 May 2013 16:27:29 -0700 Subject: [PATCH 261/263] Properly handle null. --- guacamole-common-js/src/main/resources/keyboard.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/guacamole-common-js/src/main/resources/keyboard.js b/guacamole-common-js/src/main/resources/keyboard.js index d570e1b08..46b2bfa3c 100644 --- a/guacamole-common-js/src/main/resources/keyboard.js +++ b/guacamole-common-js/src/main/resources/keyboard.js @@ -291,6 +291,10 @@ Guacamole.Keyboard = function(element) { * http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent */ function get_keysym(keysyms, location) { + + if (!keysyms) + return null; + return keysyms[location] || keysyms[0]; } From c874fb7817332b0c2374ba8bc54d835a8e1b79ba Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 12 May 2013 22:31:00 -0700 Subject: [PATCH 262/263] #320: Ensure source rectangle of transfer and copy is clipped to source canvas bounds. --- .../src/main/resources/layer.js | 99 ++++++++++++------- 1 file changed, 61 insertions(+), 38 deletions(-) diff --git a/guacamole-common-js/src/main/resources/layer.js b/guacamole-common-js/src/main/resources/layer.js index 0553aa333..3b4343890 100644 --- a/guacamole-common-js/src/main/resources/layer.js +++ b/guacamole-common-js/src/main/resources/layer.js @@ -555,50 +555,60 @@ Guacamole.Layer = function(width, height) { this.transfer = function(srcLayer, srcx, srcy, srcw, srch, x, y, transferFunction) { scheduleTaskSynced(srcLayer, function() { + var srcCanvas = srcLayer.getCanvas(); + + // If entire rectangle outside source canvas, stop + if (srcx >= srcCanvas.width || srcy >= srcCanvas.height) return; + + // Otherwise, clip rectangle to area + if (srcx + srcw > srcCanvas.width) + srcw = srcCanvas.width - srcx; + + if (srcy + srch > srcCanvas.height) + srch = srcCanvas.height - srcy; + + // Stop if nothing to draw. + if (srcw == 0 || srch == 0) return; + 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); - // 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= srcCanvas.width || srcy >= srcCanvas.height) return; + + // Otherwise, clip rectangle to area + if (srcx + srcw > srcCanvas.width) + srcw = srcCanvas.width - srcx; + + if (srcy + srch > srcCanvas.height) + srch = srcCanvas.height - srcy; + + // Stop if nothing to draw. + if (srcw == 0 || srch == 0) return; + + if (layer.autosize != 0) fitRect(x, y, srcw, srch); + displayContext.drawImage(srcCanvas, srcx, srcy, srcw, srch, x, y, srcw, srch); }); }; From 674af9b1fda92fda8074fc9f2cb59e26626b1387 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Wed, 29 May 2013 14:21:28 -0700 Subject: [PATCH 263/263] Update ChangeLog. --- guacamole-common-js/ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/guacamole-common-js/ChangeLog b/guacamole-common-js/ChangeLog index 5150c076c..c95084408 100644 --- a/guacamole-common-js/ChangeLog +++ b/guacamole-common-js/ChangeLog @@ -1,3 +1,8 @@ +2013-05-29 Michael Jumper + + * Fix support for AltGr and modifiers + * Handle bad source rect sizes in copy + 2012-10-24 Michael Jumper * Implement base audio support