From c3a7f53253552309a0719d4f80c89aafbd7d2755 Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Wed, 29 Sep 2010 20:09:09 +0200 Subject: [PATCH] Split util into two file: - util.js that contains essential functions - webutils.js that contains the GUI utility function.js this helps to include noVNC in other project, especially Cappuccino Application --- include/canvas.js | 59 ++++++++------- include/default_controls.js | 24 +++--- include/rfb.js | 73 +++++------------- include/util.js | 146 ++++++------------------------------ include/vnc.js | 1 + include/webutil.js | 144 +++++++++++++++++++++++++++++++++++ tests/vnc_playback.html | 6 +- vnc_auto.html | 12 +-- 8 files changed, 236 insertions(+), 229 deletions(-) create mode 100644 include/webutil.js diff --git a/include/canvas.js b/include/canvas.js index 0f38e065..ff73ba1f 100644 --- a/include/canvas.js +++ b/include/canvas.js @@ -10,7 +10,7 @@ /*jslint browser: true, white: false, bitwise: false */ /*global window, Util, Base64 */ -function Canvas(conf) { +var Canvas = function(conf) { conf = conf || {}; // Configuration var that = {}, // Public API interface @@ -38,7 +38,6 @@ function cdef(v, type, defval, desc) { // Capability settings, default can be overridden cdef('prefer_js', 'raw', null, 'Prefer Javascript over canvas methods'); cdef('cursor_uri', 'raw', null, 'Can we render cursor using data URI'); - cdef('target', 'dom', null, 'Canvas element for VNC viewport'); cdef('focusContainer', 'dom', document, 'DOM element that traps keyboard input'); cdef('true_color', 'bool', true, 'Request true color pixel data'); @@ -46,8 +45,6 @@ cdef('focused', 'bool', true, 'Capture and send key strokes'); cdef('colourMap', 'raw', [], 'Colour map array (not true color)'); cdef('scale', 'float', 1, 'VNC viewport scale factor'); -cdef('render_mode', 'str', '', 'Canvas rendering mode (read-only)'); - // Override some specific getters/setters that.set_prefer_js = function(val) { if (val && c_forceCanvas) { @@ -74,8 +71,6 @@ that.set_colourMap = function(val, idx) { } }; -that.set_render_mode = function () { throw("render_mode is read-only"); }; - // Add some other getters/setters that.get_width = function() { return c_width; @@ -84,8 +79,6 @@ that.get_height = function() { return c_height; }; - - // // Private functions // @@ -139,12 +132,9 @@ function constructor() { if (ctx.createImageData) { // If it's there, it's faster Util.Info("Using Canvas createImageData"); - conf.render_mode = "createImageData rendering"; that.imageData = that.imageDataCreate; } else if (ctx.getImageData) { - // I think this is mostly just Opera Util.Info("Using Canvas getImageData"); - conf.render_mode = "getImageData rendering"; that.imageData = that.imageDataGet; } Util.Info("Prefering javascript operations"); @@ -155,7 +145,6 @@ function constructor() { that.cmapImage = that.cmapImageData; } else { Util.Warn("Canvas lacks imageData, using fillRect (slow)"); - conf.render_mode = "fillRect rendering (slow)"; c_forceCanvas = true; conf.prefer_js = false; that.rgbxImage = that.rgbxImageFill; @@ -418,30 +407,44 @@ that.start = function(keyPressFunc, mouseButtonFunc, mouseMoveFunc) { that.rescale = function(factor) { var c, tp, x, y, - properties = ['transform', 'WebkitTransform', 'MozTransform', null]; + properties = ['transform', 'WebkitTransform', 'MozTransform', 'oTransform', null], + origin = ['transformOrigin', 'WebkitTransformOrigin', 'MozTransformOrigin', 'oTransformOrigin', null]; + + if (conf.scale === factor) { + return; + } + c = conf.target; - tp = properties.shift(); - while (tp) { - if (typeof c.style[tp] !== 'undefined') { + conf.scale = factor; + x = c.width - c.width * factor; + y = c.height - c.height * factor; + + //tp = properties.shift(); + + if (typeof(c.style.zoom) != "undefined") { + c.style.zoom = conf.scale; + return + } + + while (tp = properties.shift()) { + if (typeof c.style[tp] != 'undefined') { break; } - tp = properties.shift(); } - + + while (tpo = origin.shift()) { + if (typeof c.style[tpo] != 'undefined') { + break; + } + } + if (tp === null) { Util.Debug("No scaling support"); return; } - - if (conf.scale === factor) { - //Util.Debug("Canvas already scaled to '" + factor + "'"); - return; - } - - conf.scale = factor; - x = c.width - c.width * factor; - y = c.height - c.height * factor; - c.style[tp] = "scale(" + conf.scale + ") translate(-" + x + "px, -" + y + "px)"; + + c.style[tpo] = "top left"; + c.style[tp] = "scale(" + conf.scale + ")"; }; that.resize = function(width, height, true_color) { diff --git a/include/default_controls.js b/include/default_controls.js index 2864ee71..ceb374bd 100644 --- a/include/default_controls.js +++ b/include/default_controls.js @@ -56,8 +56,8 @@ load: function(target) { // Stylesheet selection dropdown html += '