Commit e2e7c224 authored by Joel Martin's avatar Joel Martin

Move DOM event handling from vnc.js to canvas.js.

parent 96a6eaad
...@@ -23,6 +23,10 @@ ctx : null, ...@@ -23,6 +23,10 @@ ctx : null,
prevStyle: "", prevStyle: "",
keyPress : null,
mouseButton : null,
mouseMove : null,
getX: function() { getX: function() {
var c = $(Canvas.id); var c = $(Canvas.id);
...@@ -34,46 +38,79 @@ getY: function() { ...@@ -34,46 +38,79 @@ getY: function() {
return c.getPosition().y - document.getScroll().y; return c.getPosition().y - document.getScroll().y;
}, },
mouseDown: function (e) { onMouseButton: function(e, down) {
var evt = e.event || window.event; var evt, x, y, bmask;
evt = e.event || window.event;
x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.getY());
bmask = 1 << evt.button;
//console.log('mouse ' + evt.which + '/' + evt.button + ' down:' + x + "," + y);
if (Canvas.mouseButton) {
Canvas.mouseButton(x, y, down, bmask);
}
e.stop(); e.stop();
console.log('mouse ' + evt.which + '/' + evt.button + ' down:' + return false;
(evt.clientX - Canvas.getX()) + "," + (evt.clientY - Canvas.getY()));
}, },
mouseUp: function (e) { onMouseDown: function (e) {
var evt = e.event || window.event; Canvas.onMouseButton(e, 1);
e.stop();
console.log('mouse ' + evt.which + '/' + evt.button + ' up:' +
(evt.clientX - Canvas.getX()) + "," + (evt.clientY - Canvas.getY()));
}, },
mouseMove: function (e) { onMouseUp: function (e) {
var evt = e.event || window.event; Canvas.onMouseButton(e, 0);
console.log('mouse ' + evt.which + '/' + evt.button + ' up:' +
(evt.clientX - Canvas.getX()) + "," + (evt.clientY - Canvas.getY()));
}, },
mouseWheel: function (e) { onMouseWheel: function (e) {
var evt = e.event || window.event; var evt, x, y, bmask;
evt = e.event || window.event;
//e = e ? e : window.event; //e = e ? e : window.event;
x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.getY());
var wheelData = evt.detail ? evt.detail * -1 : evt.wheelDelta / 40; var wheelData = evt.detail ? evt.detail * -1 : evt.wheelDelta / 40;
console.log('mouse scroll by ' + wheelData + ':' + if (wheelData > 0) {
(evt.clientX - Canvas.getX()) + "," + (evt.clientY - Canvas.getY())); bmask = 1 << 3;
} else {
bmask = 1 << 4;
}
//console.log('mouse scroll by ' + wheelData + ':' + x + "," + y);
if (Canvas.mouseButton) {
Canvas.mouseButton(x, y, 1, bmask);
Canvas.mouseButton(x, y, 0, bmask);
}
e.stop();
return false;
}, },
keyDown: function (e) { onMouseMove: function (e) {
var evt = e.event || window.event;
x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.getY());
//console.log('mouse ' + evt.which + '/' + evt.button + ' up:' + x + "," + y);
if (Canvas.keyPress) {
Canvas.mouseMove(x, y);
}
},
onKeyDown: function (e) {
//console.log("keydown: " + e.key + "(" + e.code + ")");
if (Canvas.keyPress) {
Canvas.keyPress(Canvas.getKeysym(e), 1);
}
e.stop(); e.stop();
console.log("keydown: " + e.key + "(" + e.code + ")"); return false;
}, },
keyUp : function (e) { onKeyUp : function (e) {
//console.log("keyup: " + e.key + "(" + e.code + ")");
if (Canvas.keyPress) {
Canvas.keyPress(Canvas.getKeysym(e), 0);
}
e.stop(); e.stop();
console.log("keyup: " + e.key + "(" + e.code + ")"); return false;
}, },
ctxDisable: function (e) { onMouseDisable: function (e) {
var evt = e.event || window.event; var evt = e.event || window.event;
/* Stop propagation if inside canvas area */ /* Stop propagation if inside canvas area */
if ((evt.clientX >= Canvas.getX()) && if ((evt.clientX >= Canvas.getX()) &&
...@@ -86,30 +123,27 @@ ctxDisable: function (e) { ...@@ -86,30 +123,27 @@ ctxDisable: function (e) {
}, },
init: function (id, width, height, true_color, keyDown, keyUp, init: function (id, width, height, true_color, keyPress,
mouseDown, mouseUp, mouseMove, mouseWheel) { mouseButton, mouseMove) {
//console.log(">> Canvas.init"); //console.log(">> Canvas.init");
Canvas.id = id; Canvas.id = id;
if (! keyDown) { keyDown = Canvas.keyDown; } Canvas.keyPress = keyPress || null;
if (! keyUp) { keyUp = Canvas.keyUp; } Canvas.mouseButton = mouseButton || null;
if (! mouseDown) { mouseDown = Canvas.mouseDown; } Canvas.mouseMove = mouseMove || null;
if (! mouseUp) { mouseUp = Canvas.mouseUp; }
if (! mouseMove) { mouseMove = Canvas.mouseMove; }
if (! mouseWheel) { mouseWheel = Canvas.mouseWheel; }
var c = $(Canvas.id); var c = $(Canvas.id);
document.addEvent('keydown', keyDown); document.addEvent('keydown', Canvas.onKeyDown);
document.addEvent('keyup', keyUp); document.addEvent('keyup', Canvas.onKeyUp);
c.addEvent('mousedown', mouseDown); c.addEvent('mousedown', Canvas.onMouseDown);
c.addEvent('mouseup', mouseUp); c.addEvent('mouseup', Canvas.onMouseUp);
c.addEvent('mousemove', mouseMove); c.addEvent('mousewheel', Canvas.onMouseWheel);
c.addEvent('mousewheel', mouseWheel); c.addEvent('mousemove', Canvas.onMouseMove);
/* Work around right and middle click browser behaviors */ /* Work around right and middle click browser behaviors */
document.addEvent('click', Canvas.ctxDisable); document.addEvent('click', Canvas.onMouseDisable);
document.body.addEvent('contextmenu', Canvas.ctxDisable); document.body.addEvent('contextmenu', Canvas.onMouseDisable);
Canvas.resize(width, height); Canvas.resize(width, height);
Canvas.c_wx = c.getSize().x; Canvas.c_wx = c.getSize().x;
......
...@@ -453,8 +453,7 @@ init_msg: function () { ...@@ -453,8 +453,7 @@ init_msg: function () {
RFB.fb_name = RQ.shiftStr(name_length); RFB.fb_name = RQ.shiftStr(name_length);
Canvas.init(RFB.canvasID, RFB.fb_width, RFB.fb_height, RFB.true_color, Canvas.init(RFB.canvasID, RFB.fb_width, RFB.fb_height, RFB.true_color,
RFB.keyDown, RFB.keyUp, RFB.mouseDown, RFB.mouseUp, RFB.keyPress, RFB.mouseButton, RFB.mouseMove);
RFB.mouseMove, RFB.mouseWheel);
if (RFB.true_color) { if (RFB.true_color) {
RFB.fb_Bpp = 4; RFB.fb_Bpp = 4;
...@@ -955,12 +954,6 @@ display_tight_png: function() { ...@@ -955,12 +954,6 @@ display_tight_png: function() {
FBU.imgs.push([img, FBU.x, FBU.y]); FBU.imgs.push([img, FBU.x, FBU.y]);
img.src = "data:image/" + cmode + img.src = "data:image/" + cmode +
RFB.extract_data_uri(RQ.shiftBytes(clength[1])); RFB.extract_data_uri(RQ.shiftBytes(clength[1]));
/*
img.onload = (function () {
var x = FBU.x, y = FBU.y, me = img;
return function () { Canvas.ctx.drawImage(me, x, y); };
})();
*/
img = null; img = null;
break; break;
} }
...@@ -1303,88 +1296,31 @@ checkEvents: function () { ...@@ -1303,88 +1296,31 @@ checkEvents: function () {
RFB.checkEvents.delay(RFB.check_rate); RFB.checkEvents.delay(RFB.check_rate);
}, },
keyX: function (e, down) { keyPress: function (keysym, down) {
var arr; var arr;
if (RFB.clipboardFocus) { if (RFB.clipboardFocus) {
return true; return true;
} }
e.stop(); arr = RFB.keyEvent(keysym, down);
arr = RFB.keyEvent(Canvas.getKeysym(e), down);
arr = arr.concat(RFB.fbUpdateRequest(1)); arr = arr.concat(RFB.fbUpdateRequest(1));
RFB.send_array(arr); RFB.send_array(arr);
}, },
keyDown: function (e) { mouseButton: function(x, y, down, bmask) {
//console.log(">> keyDown: " + Canvas.getKeysym(e)); if (down) {
RFB.keyX(e, 1); RFB.mouse_buttonMask |= bmask;
}, } else {
RFB.mouse_buttonMask ^= bmask;
keyUp: function (e) { }
//console.log(">> keyUp: " + Canvas.getKeysym(e));
RFB.keyX(e, 0);
},
mouseDown: function(e) {
var evt, x, y;
evt = e.event || window.event;
x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.getY());
//console.log(">> mouseDown " + evt.which + "/" + evt.button +
// " " + x + "," + y);
RFB.mouse_buttonMask |= 1 << evt.button;
RFB.mouse_arr = RFB.mouse_arr.concat( RFB.pointerEvent(x, y) );
RFB.flushClient();
return false;
},
mouseUp: function(e) {
var evt, x, y;
evt = e.event || window.event;
x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.getY());
//console.log(">> mouseUp " + evt.which + "/" + evt.button +
// " " + x + "," + y);
RFB.mouse_buttonMask ^= 1 << evt.button;
RFB.mouse_arr = RFB.mouse_arr.concat( RFB.pointerEvent(x, y) ); RFB.mouse_arr = RFB.mouse_arr.concat( RFB.pointerEvent(x, y) );
RFB.flushClient(); RFB.flushClient();
return false;
}, },
mouseMove: function(e) { mouseMove: function(x, y) {
var evt, x, y;
evt = e.event || window.event;
x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.getY());
//console.log('>> mouseMove ' + x + "," + y); //console.log('>> mouseMove ' + x + "," + y);
RFB.mouse_arr = RFB.mouse_arr.concat( RFB.pointerEvent(x, y) ); RFB.mouse_arr = RFB.mouse_arr.concat( RFB.pointerEvent(x, y) );
}, },
mouseWheel: function (e) {
var evt, wheelData, bmask;
evt = e.event || window.event;
//e = e ? e : window.event;
x = (evt.clientX - Canvas.getX());
y = (evt.clientY - Canvas.getY());
wheelData = evt.detail ? evt.detail * -1 : evt.wheelDelta / 40;
//console.log('>> mouseWheel ' + wheelData +
// " " + x + "," + y);
if (wheelData > 0) {
bmask = 1 << 3;
} else {
bmask = 1 << 4;
}
RFB.mouse_buttonMask |= bmask;
RFB.mouse_arr = RFB.mouse_arr.concat( RFB.pointerEvent(x, y) );
RFB.mouse_buttonMask ^= bmask;
RFB.mouse_arr = RFB.mouse_arr.concat( RFB.pointerEvent(x, y) );
RFB.flushClient();
return false;
},
clipboardCopyTo: function (text) { clipboardCopyTo: function (text) {
console.log(">> clipboardCopyTo stub"); console.log(">> clipboardCopyTo stub");
// Stub // Stub
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment