From 4f00756da1ec3cd0d4515e707945fccedf78a3f0 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Tue, 25 May 2010 11:05:55 -0500 Subject: [PATCH] Add mouse wheel support and input test page. --- include/canvas.js | 13 ++++++- tests/include | 1 + tests/input.html | 95 +++++++++++++++++++++++++++++++++++++++++++++++ vnc.js | 27 +++++++++++++- 4 files changed, 133 insertions(+), 3 deletions(-) create mode 120000 tests/include create mode 100644 tests/input.html diff --git a/include/canvas.js b/include/canvas.js index 28dcc1b..96d6c27 100644 --- a/include/canvas.js +++ b/include/canvas.js @@ -42,6 +42,14 @@ mouseMove: function (e) { (evt.clientX - Canvas.c_x) + "," + (evt.clientY - Canvas.c_y)); }, +mouseWheel: function (e) { + var evt = e.event || window.event; + //e = e ? e : window.event; + var wheelData = evt.detail ? evt.detail * -1 : evt.wheelDelta / 40; + console.log('mouse scroll by ' + wheelData + ':' + + (evt.clientX - Canvas.c_x) + "," + (evt.clientY - Canvas.c_y)); +}, + keyDown: function (e) { e.stop(); @@ -67,7 +75,7 @@ ctxDisable: function (e) { init: function (id, width, height, keyDown, keyUp, - mouseDown, mouseUp, mouseMove) { + mouseDown, mouseUp, mouseMove, mouseWheel) { console.log(">> Canvas.init"); Canvas.id = id; @@ -77,6 +85,7 @@ init: function (id, width, height, keyDown, keyUp, if (! mouseDown) { mouseDown = Canvas.mouseDown; } if (! mouseUp) { mouseUp = Canvas.mouseUp; } if (! mouseMove) { mouseMove = Canvas.mouseMove; } + if (! mouseWheel) { mouseWheel = Canvas.mouseWheel; } var c = $(Canvas.id); document.addEvent('keydown', keyDown); @@ -84,6 +93,7 @@ init: function (id, width, height, keyDown, keyUp, c.addEvent('mousedown', mouseDown); c.addEvent('mouseup', mouseUp); c.addEvent('mousemove', mouseMove); + c.addEvent('mousewheel', mouseWheel); /* Work around right and middle click browser behaviors */ document.addEvent('click', Canvas.ctxDisable); @@ -122,6 +132,7 @@ stop: function () { c.removeEvents('mousedown'); c.removeEvents('mouseup'); c.removeEvents('mousemove'); + c.removeEvents('DOMMouseScroll'); /* Work around right and middle click browser behaviors */ document.removeEvents('click'); diff --git a/tests/include b/tests/include new file mode 120000 index 0000000..f5030fe --- /dev/null +++ b/tests/include @@ -0,0 +1 @@ +../include \ No newline at end of file diff --git a/tests/input.html b/tests/input.html new file mode 100644 index 0000000..e4f5611 --- /dev/null +++ b/tests/input.html @@ -0,0 +1,95 @@ + + Input Test + +

+ + Canvas:
+ + Canvas not supported. + + +
+ Results:
+ + + + + + + + + + + diff --git a/vnc.js b/vnc.js index 0d5286f..feaee38 100644 --- a/vnc.js +++ b/vnc.js @@ -289,8 +289,8 @@ init_msg: function () { RFB.fb_name = RQ.shiftStr(name_length); Canvas.init('VNC_canvas', RFB.fb_width, RFB.fb_height, - RFB.keyDown, RFB.keyUp, - RFB.mouseDown, RFB.mouseUp, RFB.mouseMove); + RFB.keyDown, RFB.keyUp, RFB.mouseDown, RFB.mouseUp, + RFB.mouseMove, RFB.mouseWheel); response = RFB.pixelFormat(); response = response.concat(RFB.encodings()); @@ -984,6 +984,29 @@ mouseMove: function(e) { 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.c_x); + y = (evt.clientY - Canvas.c_y); + 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(); +}, + + clipboardCopyTo: function (text) { console.log(">> clipboardCopyTo: " + text.substr(0,40) + "..."); RFB.clipboard.value = text;