From 162ceb97ba75c62c581d4cd20455030687bcfe91 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 16 Oct 2014 15:03:22 -0700 Subject: [PATCH] GUAC-823: Add setCursor() function to Guacamole.Mouse. Stub out feature detection. --- .../src/main/webapp/modules/Mouse.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/guacamole-common-js/src/main/webapp/modules/Mouse.js b/guacamole-common-js/src/main/webapp/modules/Mouse.js index 3559eef32..3cd0b8a48 100644 --- a/guacamole-common-js/src/main/webapp/modules/Mouse.js +++ b/guacamole-common-js/src/main/webapp/modules/Mouse.js @@ -303,6 +303,45 @@ Guacamole.Mouse = function(element) { element.addEventListener('mousewheel', mousewheel_handler, false); element.addEventListener('wheel', mousewheel_handler, false); + /** + * Whether the browser supports CSS3 cursor styling, including hotspot + * coordinates. + * + * @private + * @type Boolean + */ + var CSS3_CURSOR_SUPPORTED = true; + + /** + * Changes the local mouse cursor to the given canvas, having the given + * hotspot coordinates. This affects styling of the element backing this + * Guacamole.Mouse only, and may fail depending on browser support for + * setting the mouse cursor. + * + * If setting the local cursor is desired, it is up to the implementation + * to do something else, such as use the software cursor built into + * Guacamole.Display, if the local cursor cannot be set. + * + * @param {HTMLCanvasElement} canvas The cursor image. + * @param {Number} x The X-coordinate of the cursor hotspot. + * @param {Number} y The Y-coordinate of the cursor hotspot. + * @return {Boolean} true if the cursor was successfully set, false if the + * cursor could not be set for any reason. + */ + this.setCursor = function(canvas, x, y) { + + // Attempt to set via CSS3 cursor styling + if (CSS3_CURSOR_SUPPORTED) { + var dataURL = canvas.toDataURL('image/png'); + element.style.cursor = "url(" + dataURL + ") " + x + " " + y; + return true; + } + + // Otherwise, setting cursor failed + return false; + + }; + }; /**