2011-03-14 09:05:24 +00:00
|
|
|
/* Helper functions for debugging */
|
|
|
|
var logDiv = null;
|
|
|
|
function log(str) {
|
|
|
|
if (!logDiv) {
|
|
|
|
logDiv = document.createElement('div');
|
|
|
|
document.body.appendChild(logDiv);
|
|
|
|
logDiv.style["position"] = "absolute";
|
|
|
|
logDiv.style["right"] = "0px";
|
|
|
|
}
|
|
|
|
logDiv.appendChild(document.createTextNode(str));
|
|
|
|
logDiv.appendChild(document.createElement('br'));
|
|
|
|
}
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
var base64Values = [
|
2011-03-15 09:33:08 +00:00
|
|
|
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
|
|
|
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
|
|
|
|
255,255,255,255,255,255,255,255,255,255,255, 62,255,255,255, 63,
|
|
|
|
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,255,255,255, 0,255,255,
|
|
|
|
255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
|
|
|
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,255,255,255,255,255,
|
|
|
|
255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
|
|
|
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,255,255,255,255,255
|
2010-11-16 21:56:59 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
function base64_8(str, index) {
|
2011-03-15 09:33:08 +00:00
|
|
|
var v =
|
|
|
|
(base64Values[str.charCodeAt(index)]) +
|
|
|
|
(base64Values[str.charCodeAt(index+1)] << 6);
|
|
|
|
return v;
|
2010-11-16 21:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function base64_16(str, index) {
|
2011-03-15 09:33:08 +00:00
|
|
|
var v =
|
|
|
|
(base64Values[str.charCodeAt(index)]) +
|
|
|
|
(base64Values[str.charCodeAt(index+1)] << 6) +
|
|
|
|
(base64Values[str.charCodeAt(index+2)] << 12);
|
|
|
|
return v;
|
2010-11-16 21:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function base64_16s(str, index) {
|
2011-03-15 09:33:08 +00:00
|
|
|
var v = base64_16(str, index);
|
|
|
|
if (v > 32767)
|
|
|
|
return v - 65536;
|
|
|
|
else
|
|
|
|
return v;
|
2010-11-16 21:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function base64_24(str, index) {
|
2011-03-15 09:33:08 +00:00
|
|
|
var v =
|
|
|
|
(base64Values[str.charCodeAt(index)]) +
|
|
|
|
(base64Values[str.charCodeAt(index+1)] << 6) +
|
|
|
|
(base64Values[str.charCodeAt(index+2)] << 12) +
|
|
|
|
(base64Values[str.charCodeAt(index+3)] << 18);
|
|
|
|
return v;
|
2010-11-16 21:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function base64_32(str, index) {
|
2011-03-15 09:33:08 +00:00
|
|
|
var v =
|
|
|
|
(base64Values[str.charCodeAt(index)]) +
|
|
|
|
(base64Values[str.charCodeAt(index+1)] << 6) +
|
|
|
|
(base64Values[str.charCodeAt(index+2)] << 12) +
|
|
|
|
(base64Values[str.charCodeAt(index+3)] << 18) +
|
|
|
|
(base64Values[str.charCodeAt(index+4)] << 24) +
|
|
|
|
(base64Values[str.charCodeAt(index+5)] << 30);
|
|
|
|
return v;
|
2010-11-16 21:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function createXHR()
|
|
|
|
{
|
2011-03-15 09:33:08 +00:00
|
|
|
try { return new XMLHttpRequest(); } catch(e) {}
|
|
|
|
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) {}
|
|
|
|
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) {}
|
|
|
|
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
|
|
|
|
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
|
2010-11-16 21:56:59 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
return null;
|
2010-11-16 21:56:59 +00:00
|
|
|
}
|
|
|
|
|
2011-04-06 09:40:40 +00:00
|
|
|
/* This resizes the window so the *inner* size is the specified size */
|
|
|
|
function resizeBrowserWindow(window, w, h) {
|
|
|
|
var innerW = window.innerWidth;
|
|
|
|
var innerH = window.innerHeight;
|
|
|
|
|
|
|
|
var outerW = window.outerWidth;
|
|
|
|
var outerH = window.outerHeight;
|
|
|
|
|
|
|
|
window.resizeTo(w + outerW - innerW,
|
|
|
|
h + outerH - innerH);
|
|
|
|
}
|
|
|
|
|
2011-04-06 14:39:07 +00:00
|
|
|
function resizeCanvas(canvas, w, h)
|
|
|
|
{
|
|
|
|
/* Canvas resize clears the data, so we need to save it first */
|
|
|
|
var tmpCanvas = canvas.ownerDocument.createElement("canvas");
|
|
|
|
tmpCanvas.width = canvas.width;
|
|
|
|
tmpCanvas.height = canvas.height;
|
|
|
|
var tmpContext = tmpCanvas.getContext("2d");
|
|
|
|
tmpContext.globalCompositeOperation = "copy";
|
|
|
|
tmpContext.drawImage(canvas, 0, 0, tmpCanvas.width, tmpCanvas.height);
|
|
|
|
|
|
|
|
canvas.width = w;
|
|
|
|
canvas.height = h;
|
|
|
|
|
|
|
|
var context = canvas.getContext("2d");
|
|
|
|
|
|
|
|
context.globalCompositeOperation = "copy";
|
|
|
|
context.drawImage(tmpCanvas, 0, 0, tmpCanvas.width, tmpCanvas.height);
|
|
|
|
}
|
|
|
|
|
2011-04-08 09:45:51 +00:00
|
|
|
var useToplevelWindows = false;
|
2011-04-06 14:39:07 +00:00
|
|
|
var toplevelWindows = [];
|
2011-03-14 10:46:43 +00:00
|
|
|
var grab = new Object();
|
|
|
|
grab.window = null;
|
2011-03-15 09:26:53 +00:00
|
|
|
grab.ownerEvents = false;
|
2011-03-14 10:46:43 +00:00
|
|
|
grab.implicit = false;
|
2011-04-08 09:45:51 +00:00
|
|
|
var localGrab = null;
|
2011-03-15 09:26:53 +00:00
|
|
|
var lastSerial = 0;
|
|
|
|
var lastX = 0;
|
|
|
|
var lastY = 0;
|
|
|
|
var lastState;
|
2011-04-01 13:08:28 +00:00
|
|
|
var lastTimeStamp = 0;
|
2011-03-15 09:26:53 +00:00
|
|
|
var realWindowWithMouse = 0;
|
|
|
|
var windowWithMouse = 0;
|
2010-11-16 21:56:59 +00:00
|
|
|
var surfaces = {};
|
2011-03-15 09:26:53 +00:00
|
|
|
var outstandingCommands = new Array();
|
|
|
|
var inputSocket = null;
|
2011-04-06 14:39:07 +00:00
|
|
|
var frameSizeX = -1;
|
|
|
|
var frameSizeY = -1;
|
|
|
|
|
2011-03-14 10:46:43 +00:00
|
|
|
var GDK_CROSSING_NORMAL = 0;
|
|
|
|
var GDK_CROSSING_GRAB = 1;
|
|
|
|
var GDK_CROSSING_UNGRAB = 2;
|
|
|
|
|
2011-03-14 11:09:19 +00:00
|
|
|
// GdkModifierType
|
|
|
|
var GDK_SHIFT_MASK = 1 << 0;
|
|
|
|
var GDK_LOCK_MASK = 1 << 1;
|
|
|
|
var GDK_CONTROL_MASK = 1 << 2;
|
|
|
|
var GDK_MOD1_MASK = 1 << 3;
|
|
|
|
var GDK_MOD2_MASK = 1 << 4;
|
|
|
|
var GDK_MOD3_MASK = 1 << 5;
|
|
|
|
var GDK_MOD4_MASK = 1 << 6;
|
|
|
|
var GDK_MOD5_MASK = 1 << 7;
|
|
|
|
var GDK_BUTTON1_MASK = 1 << 8;
|
|
|
|
var GDK_BUTTON2_MASK = 1 << 9;
|
|
|
|
var GDK_BUTTON3_MASK = 1 << 10;
|
|
|
|
var GDK_BUTTON4_MASK = 1 << 11;
|
|
|
|
var GDK_BUTTON5_MASK = 1 << 12;
|
|
|
|
var GDK_SUPER_MASK = 1 << 26;
|
|
|
|
var GDK_HYPER_MASK = 1 << 27;
|
|
|
|
var GDK_META_MASK = 1 << 28;
|
|
|
|
var GDK_RELEASE_MASK = 1 << 30;
|
|
|
|
|
|
|
|
function getButtonMask (button) {
|
|
|
|
if (button == 1)
|
|
|
|
return GDK_BUTTON1_MASK;
|
|
|
|
if (button == 2)
|
|
|
|
return GDK_BUTTON2_MASK;
|
|
|
|
if (button == 3)
|
|
|
|
return GDK_BUTTON3_MASK;
|
|
|
|
if (button == 4)
|
|
|
|
return GDK_BUTTON4_MASK;
|
|
|
|
if (button == 5)
|
|
|
|
return GDK_BUTTON5_MASK;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-15 08:50:07 +00:00
|
|
|
function flushSurface(surface)
|
|
|
|
{
|
|
|
|
var commands = surface.drawQueue;
|
|
|
|
surface.queue = [];
|
2011-04-06 07:46:49 +00:00
|
|
|
var context = surface.context;
|
2011-03-15 08:50:07 +00:00
|
|
|
var i = 0;
|
|
|
|
for (i = 0; i < commands.length; i++) {
|
|
|
|
var cmd = commands[i];
|
|
|
|
switch (cmd.op) {
|
2011-04-06 07:46:49 +00:00
|
|
|
case 'i': // put image data surface
|
2011-03-15 08:50:07 +00:00
|
|
|
context.globalCompositeOperation = "source-over";
|
|
|
|
context.drawImage(cmd.img, cmd.x, cmd.y);
|
|
|
|
break;
|
|
|
|
|
2011-04-06 07:46:49 +00:00
|
|
|
case 'b': // copy rects
|
2011-03-15 08:50:07 +00:00
|
|
|
context.save();
|
|
|
|
context.beginPath();
|
|
|
|
|
|
|
|
var minx;
|
|
|
|
var miny;
|
|
|
|
var maxx;
|
|
|
|
var maxy;
|
|
|
|
for (var j = 0; j < cmd.rects.length; j++) {
|
|
|
|
var rect = cmd.rects[j];
|
|
|
|
context.rect(rect.x, rect.y, rect.w, rect.h);
|
|
|
|
if (j == 0) {
|
|
|
|
minx = rect.x;
|
|
|
|
miny = rect.y;
|
|
|
|
maxx = rect.x + rect.w;
|
|
|
|
maxy = rect.y + rect.h;
|
|
|
|
} else {
|
|
|
|
if (rect.x < minx)
|
|
|
|
minx = rect.x;
|
|
|
|
if (rect.y < miny)
|
|
|
|
miny = rect.y;
|
|
|
|
if (rect.x + rect.w > maxx)
|
|
|
|
maxx = rect.x + rect.w;
|
|
|
|
if (rect.y + rect.h > maxy)
|
|
|
|
maxy = rect.y + rect.h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
context.clip();
|
|
|
|
context.globalCompositeOperation = "copy";
|
|
|
|
context.drawImage(context.canvas,
|
|
|
|
minx - cmd.dx, miny - cmd.dy, maxx - minx, maxy - miny,
|
|
|
|
minx, miny, maxx - minx, maxy - miny);
|
|
|
|
context.restore();
|
|
|
|
break;
|
|
|
|
|
2011-04-06 07:46:49 +00:00
|
|
|
default:
|
2011-03-15 08:50:07 +00:00
|
|
|
alert("Unknown drawing op " + cmd.op);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-06 09:40:40 +00:00
|
|
|
function ensureSurfaceInDocument(surface, doc)
|
|
|
|
{
|
|
|
|
if (surface.document != doc) {
|
|
|
|
var oldCanvas = surface.canvas;
|
|
|
|
var canvas = doc.importNode(oldCanvas, false);
|
|
|
|
doc.body.appendChild(canvas);
|
|
|
|
canvas.surface = surface;
|
|
|
|
oldCanvas.parentNode.removeChild(oldCanvas);
|
|
|
|
|
|
|
|
surface.canvas = canvas;
|
|
|
|
surface.document = doc;
|
|
|
|
|
|
|
|
var context = canvas.getContext("2d");
|
|
|
|
context.globalCompositeOperation = "source-over";
|
|
|
|
surface.context = context;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-06 14:39:07 +00:00
|
|
|
var windowGeometryTimeout = null;
|
|
|
|
|
|
|
|
function updateBrowserWindowGeometry(win) {
|
|
|
|
if (win.closed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var surface = win.surface;
|
|
|
|
|
|
|
|
var innerW = win.innerWidth;
|
|
|
|
var innerH = win.innerHeight;
|
|
|
|
|
|
|
|
var x = surface.x;
|
|
|
|
var y = surface.y;
|
|
|
|
if (frameSizeX > 0) {
|
|
|
|
x = win.screenX + frameSizeX;
|
|
|
|
y = win.screenY + frameSizeY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x != surface.x || y != surface.y ||
|
|
|
|
innerW != surface.width || innerH != surface.height) {
|
|
|
|
var oldX = surface.x;
|
|
|
|
var oldY = surface.y;
|
|
|
|
surface.x = x;
|
|
|
|
surface.y = y;
|
|
|
|
if (surface.width != innerW || surface.height != innerH)
|
|
|
|
resizeCanvas(surface.canvas, innerW, innerH);
|
|
|
|
surface.width = innerW;
|
|
|
|
surface.height = innerH;
|
|
|
|
sendInput ("w", [surface.id, surface.x, surface.y, surface.width, surface.height]);
|
|
|
|
for (id in surfaces) {
|
|
|
|
if (surfaces[id].transientToplevel != null && surfaces[id].transientToplevel == surface) {
|
|
|
|
var childSurface = surfaces[id];
|
|
|
|
childSurface.x += surface.x - oldX;
|
|
|
|
childSurface.y += surface.y - oldY;
|
|
|
|
sendInput ("w", [childSurface.id, childSurface.x, childSurface.y, childSurface.width, childSurface.height]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-06 20:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function browserWindowClosed(win) {
|
|
|
|
var surface = win.surface;
|
2011-04-06 14:39:07 +00:00
|
|
|
|
2011-04-06 20:13:18 +00:00
|
|
|
sendInput ("W", [surface.id]);
|
|
|
|
for (id in surfaces) {
|
2011-04-07 13:10:39 +00:00
|
|
|
if (surfaces[id].transientToplevel != null &&
|
|
|
|
surfaces[id].transientToplevel == surface) {
|
2011-04-06 20:13:18 +00:00
|
|
|
var childSurface = surfaces[id];
|
|
|
|
sendInput ("W", [childSurface.id]);
|
|
|
|
}
|
|
|
|
}
|
2011-04-06 14:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function registerWindow(win)
|
|
|
|
{
|
|
|
|
toplevelWindows.push(win);
|
|
|
|
win.onresize = function(ev) { updateBrowserWindowGeometry(ev.target); };
|
|
|
|
if (!windowGeometryTimeout)
|
|
|
|
windowGeometryTimeout = setInterval(function () { toplevelWindows.forEach(updateBrowserWindowGeometry); }, 2000);
|
2011-04-06 20:13:18 +00:00
|
|
|
win.onunload = function(ev) { browserWindowClosed(ev.target.defaultView); };
|
2011-04-06 14:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function unregisterWindow(win)
|
|
|
|
{
|
|
|
|
var i = toplevelWindows.indexOf(win);
|
|
|
|
if (i >= 0)
|
|
|
|
toplevelWindows.splice(i, 1);
|
|
|
|
|
|
|
|
if (windowGeometryTimeout && toplevelWindows.length == 0) {
|
|
|
|
clearInterval(windowGeometryTimeout);
|
|
|
|
windowGeometryTimeout = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-06 09:40:40 +00:00
|
|
|
function getTransientToplevel(surface)
|
|
|
|
{
|
|
|
|
while (surface.transientParent != 0) {
|
|
|
|
surface = surfaces[surface.transientParent];
|
|
|
|
if (surface.window)
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-04-08 09:45:51 +00:00
|
|
|
function getFrameOffset(surface) {
|
|
|
|
var x = 1;
|
|
|
|
var y = 1;
|
|
|
|
var el = surface.canvas;
|
|
|
|
while (el != null && el != surface.frame) {
|
|
|
|
x += el.offsetLeft;
|
|
|
|
y += el.offsetTop;
|
|
|
|
el = el.offsetParent;
|
|
|
|
}
|
|
|
|
return {x: x, y: y};
|
|
|
|
}
|
|
|
|
|
2011-04-06 07:57:31 +00:00
|
|
|
function cmdCreateSurface(id, x, y, width, height, isTemp)
|
|
|
|
{
|
|
|
|
var surface = { id: id, x: x, y:y, width: width, height: height, isTemp: isTemp };
|
|
|
|
surface.drawQueue = [];
|
|
|
|
surface.transientParent = 0;
|
2011-04-06 09:40:40 +00:00
|
|
|
surface.visible = false;
|
|
|
|
surface.window = null;
|
|
|
|
surface.document = document;
|
2011-04-06 14:39:07 +00:00
|
|
|
surface.transientToplevel = null;
|
2011-04-08 09:45:51 +00:00
|
|
|
surface.frame = null;
|
2011-04-06 07:57:31 +00:00
|
|
|
|
|
|
|
var canvas = document.createElement("canvas");
|
|
|
|
canvas.width = width;
|
|
|
|
canvas.height = height;
|
|
|
|
canvas.surface = surface;
|
|
|
|
surface.canvas = canvas;
|
|
|
|
|
2011-04-08 09:45:51 +00:00
|
|
|
if (useToplevelWindows || isTemp) {
|
|
|
|
canvas.style["position"] = "absolute";
|
|
|
|
canvas.style["left"] = "0px";
|
|
|
|
canvas.style["top"] = "0px";
|
|
|
|
canvas.style["display"] = "none";
|
|
|
|
document.body.appendChild(canvas);
|
|
|
|
} else {
|
|
|
|
var frame = document.createElement("div");
|
|
|
|
frame.frameFor = surface;
|
|
|
|
frame.style["position"] = "absolute";
|
|
|
|
frame.style["left"] = "0px";
|
|
|
|
frame.style["top"] = "0px";
|
|
|
|
frame.style["display"] = "inline";
|
|
|
|
// We hide the frame with visibility rather than display none
|
|
|
|
// so getFrameOffset still works with hidden windows
|
|
|
|
frame.style["visibility"] = "hidden";
|
|
|
|
frame.className = "frame-window";
|
|
|
|
|
|
|
|
var button = document.createElement("center");
|
|
|
|
var X = document.createTextNode("X");
|
|
|
|
button.appendChild(X);
|
|
|
|
button.className = "frame-close";
|
|
|
|
frame.appendChild(button);
|
|
|
|
|
|
|
|
var contents = document.createElement("div");
|
|
|
|
contents.className = "frame-contents";
|
|
|
|
frame.appendChild(contents);
|
|
|
|
|
|
|
|
document.body.appendChild(frame);
|
|
|
|
contents.appendChild(canvas);
|
|
|
|
canvas.style["display"] = "block";
|
|
|
|
|
|
|
|
surface.frame = frame;
|
|
|
|
}
|
|
|
|
|
2011-04-06 07:57:31 +00:00
|
|
|
var context = canvas.getContext("2d");
|
|
|
|
context.globalCompositeOperation = "source-over";
|
|
|
|
surface.context = context;
|
|
|
|
|
|
|
|
surfaces[id] = surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
function cmdShowSurface(id)
|
|
|
|
{
|
2011-04-06 09:40:40 +00:00
|
|
|
var surface = surfaces[id];
|
|
|
|
|
|
|
|
if (surface.visible)
|
|
|
|
return;
|
|
|
|
surface.visible = true;
|
|
|
|
|
2011-04-08 09:45:51 +00:00
|
|
|
var element = surface.canvas;
|
2011-04-06 09:40:40 +00:00
|
|
|
var xOffset = surface.x;
|
|
|
|
var yOffset = surface.y;
|
|
|
|
|
|
|
|
if (useToplevelWindows) {
|
|
|
|
var doc = document;
|
|
|
|
if (!surface.isTemp) {
|
|
|
|
var win = window.open('','_blank',
|
|
|
|
'width='+surface.width+',height='+surface.height+
|
|
|
|
',left='+surface.x+',top='+surface.y+',screenX='+surface.x+',screenY='+surface.y+
|
|
|
|
',location=no,menubar=no,scrollbars=no,toolbar=no');
|
2011-04-06 14:39:07 +00:00
|
|
|
win.surface = surface;
|
|
|
|
registerWindow(win);
|
2011-04-06 09:40:40 +00:00
|
|
|
doc = win.document;
|
|
|
|
doc.open();
|
|
|
|
doc.write("<body></body>");
|
|
|
|
setupDocument(doc);
|
|
|
|
|
|
|
|
surface.window = win;
|
|
|
|
xOffset = 0;
|
|
|
|
yOffset = 0;
|
|
|
|
} else {
|
2011-04-06 14:39:07 +00:00
|
|
|
surface.transientToplevel = getTransientToplevel(surface);
|
|
|
|
if (surface.transientToplevel) {
|
|
|
|
doc = surface.transientToplevel.window.document;
|
|
|
|
xOffset = surface.x - surface.transientToplevel.x;
|
|
|
|
yOffset = surface.y - surface.transientToplevel.y;
|
2011-04-06 09:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ensureSurfaceInDocument(surface, doc);
|
2011-04-08 09:45:51 +00:00
|
|
|
} else {
|
|
|
|
if (surface.frame) {
|
|
|
|
element = surface.frame;
|
|
|
|
var offset = getFrameOffset(surface);
|
|
|
|
xOffset -= offset.x;
|
|
|
|
yOffset -= offset.y;
|
|
|
|
}
|
2011-04-06 09:40:40 +00:00
|
|
|
}
|
|
|
|
|
2011-04-08 09:45:51 +00:00
|
|
|
element.style["position"] = "absolute";
|
|
|
|
element.style["left"] = xOffset + "px";
|
|
|
|
element.style["top"] = yOffset + "px";
|
|
|
|
element.style["display"] = "inline";
|
|
|
|
if (surface.frame)
|
|
|
|
surface.frame.style["visibility"] = "visible";
|
2011-04-06 07:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function cmdHideSurface(id)
|
|
|
|
{
|
2011-04-06 09:40:40 +00:00
|
|
|
var surface = surfaces[id];
|
|
|
|
|
|
|
|
if (!surface.visible)
|
|
|
|
return;
|
|
|
|
surface.visible = false;
|
|
|
|
|
2011-04-08 09:45:51 +00:00
|
|
|
var element = surface.canvas;
|
|
|
|
if (surface.frame)
|
|
|
|
element = surface.frame;
|
|
|
|
|
|
|
|
if (surface.frame)
|
|
|
|
surface.frame.style["visibility"] = "hidden";
|
|
|
|
else
|
|
|
|
element.style["display"] = "none";
|
2011-04-06 09:40:40 +00:00
|
|
|
|
|
|
|
// Import the canvas into the main document
|
|
|
|
ensureSurfaceInDocument(surface, document);
|
|
|
|
|
|
|
|
if (surface.window) {
|
2011-04-06 14:39:07 +00:00
|
|
|
unregisterWindow(surface.window);
|
2011-04-06 09:40:40 +00:00
|
|
|
surface.window.close();
|
|
|
|
surface.window = null;
|
|
|
|
}
|
2011-04-06 07:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function cmdSetTransientFor(id, parentId)
|
|
|
|
{
|
2011-04-06 09:40:40 +00:00
|
|
|
var surface = surfaces[id];
|
|
|
|
|
|
|
|
if (surface.transientParent == parentId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
surface.transientParent = parentId;
|
|
|
|
if (surface.visible && surface.isTemp) {
|
|
|
|
alert("TODO: move temps between transient parents when visible");
|
|
|
|
}
|
2011-04-06 07:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function cmdDeleteSurface(id)
|
|
|
|
{
|
|
|
|
var canvas = surfaces[id].canvas;
|
|
|
|
delete surfaces[id];
|
|
|
|
canvas.parentNode.removeChild(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
function cmdMoveSurface(id, x, y)
|
|
|
|
{
|
2011-04-06 09:40:40 +00:00
|
|
|
var surface = surfaces[id];
|
|
|
|
surface.x = x;
|
|
|
|
surface.y = y;
|
|
|
|
|
|
|
|
if (surface.visible) {
|
|
|
|
if (surface.window) {
|
|
|
|
/* TODO: This moves the outer frame position, we really want the inner position.
|
|
|
|
* However this isn't *strictly* invalid, as any WM could have done whatever it
|
|
|
|
* wanted with the positioning of the window.
|
|
|
|
*/
|
2011-04-08 09:45:16 +00:00
|
|
|
surface.window.moveTo(surface.x, surface.y);
|
2011-04-06 09:40:40 +00:00
|
|
|
} else {
|
|
|
|
var xOffset = surface.x;
|
|
|
|
var yOffset = surface.y;
|
|
|
|
|
|
|
|
var transientToplevel = getTransientToplevel(surface);
|
|
|
|
if (transientToplevel) {
|
|
|
|
xOffset = surface.x - transientToplevel.x;
|
|
|
|
yOffset = surface.y - transientToplevel.y;
|
|
|
|
}
|
|
|
|
|
2011-04-08 09:45:51 +00:00
|
|
|
var element = surface.canvas;
|
|
|
|
if (surface.frame) {
|
|
|
|
element = surface.frame;
|
|
|
|
var offset = getFrameOffset(surface);
|
|
|
|
xOffset -= offset.x;
|
|
|
|
yOffset -= offset.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
element.style["left"] = xOffset + "px";
|
|
|
|
element.style["top"] = yOffset + "px";
|
2011-04-06 09:40:40 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-06 07:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function cmdResizeSurface(id, w, h)
|
|
|
|
{
|
|
|
|
var surface = surfaces[id];
|
|
|
|
|
2011-04-06 09:40:40 +00:00
|
|
|
surface.width = w;
|
|
|
|
surface.height = h;
|
|
|
|
|
2011-04-06 07:57:31 +00:00
|
|
|
/* Flush any outstanding draw ops before changing size */
|
|
|
|
flushSurface(surface);
|
|
|
|
|
2011-04-06 14:39:07 +00:00
|
|
|
resizeCanvas(surface.canvas, w, h);
|
2011-04-06 09:40:40 +00:00
|
|
|
|
|
|
|
if (surface.window) {
|
|
|
|
resizeBrowserWindow(surface.window, w, h);
|
|
|
|
}
|
2011-04-06 07:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function cmdFlushSurface(id)
|
|
|
|
{
|
|
|
|
flushSurface(surfaces[id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function cmdGrabPointer(id, ownerEvents)
|
|
|
|
{
|
2011-04-06 08:01:53 +00:00
|
|
|
doGrab(id, ownerEvents, false);
|
2011-04-06 07:57:31 +00:00
|
|
|
sendInput ("g", []);
|
|
|
|
}
|
|
|
|
|
|
|
|
function cmdUngrabPointer()
|
|
|
|
{
|
|
|
|
sendInput ("u", []);
|
|
|
|
|
2011-04-06 09:00:32 +00:00
|
|
|
grab.window = null;
|
2011-04-06 07:57:31 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
function handleCommands(cmdObj)
|
2010-11-16 21:56:59 +00:00
|
|
|
{
|
2011-03-15 09:33:08 +00:00
|
|
|
var cmd = cmdObj.data;
|
|
|
|
var i = cmdObj.pos;
|
2010-11-23 11:52:10 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
while (i < cmd.length) {
|
|
|
|
var command = cmd[i++];
|
|
|
|
lastSerial = base64_32(cmd, i);
|
|
|
|
i = i + 6;
|
|
|
|
switch (command) {
|
|
|
|
case 's': // create new surface
|
|
|
|
var id = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
var x = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
var y = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
var w = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
var h = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
2011-04-05 10:27:43 +00:00
|
|
|
var isTemp = cmd[i] == '1';
|
|
|
|
i = i + 1;
|
2011-04-06 07:57:31 +00:00
|
|
|
cmdCreateSurface(id, x, y, w, h, isTemp);
|
2011-03-15 09:33:08 +00:00
|
|
|
break;
|
2010-11-16 21:56:59 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
case 'S': // Show a surface
|
|
|
|
var id = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
2011-04-06 07:57:31 +00:00
|
|
|
cmdShowSurface(id);
|
2011-03-15 09:33:08 +00:00
|
|
|
break;
|
2010-11-16 21:56:59 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
case 'H': // Hide a surface
|
|
|
|
var id = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
2011-04-06 07:57:31 +00:00
|
|
|
cmdHideSurface(id);
|
2011-03-15 09:33:08 +00:00
|
|
|
break;
|
|
|
|
|
2011-04-05 10:02:46 +00:00
|
|
|
case 'p': // Set transient parent
|
|
|
|
var id = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
var parentId = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
2011-04-06 07:57:31 +00:00
|
|
|
cmdSetTransientFor(id, parentId);
|
|
|
|
break;
|
2011-04-05 10:02:46 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
case 'd': // Delete surface
|
|
|
|
var id = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
2011-04-06 07:57:31 +00:00
|
|
|
cmdDeleteSurface(id);
|
2011-03-15 09:33:08 +00:00
|
|
|
break;
|
2010-11-16 21:56:59 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
case 'm': // Move a surface
|
|
|
|
var id = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
var x = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
var y = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
2011-04-06 07:57:31 +00:00
|
|
|
cmdMoveSurface(id, x, y);
|
2011-03-15 09:33:08 +00:00
|
|
|
break;
|
2010-11-16 21:56:59 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
case 'r': // Resize a surface
|
|
|
|
var id = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
var w = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
var h = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
2011-04-06 07:57:31 +00:00
|
|
|
cmdResizeSurface(id, w, h);
|
2011-03-15 09:33:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'i': // Put image data surface
|
|
|
|
var q = new Object();
|
|
|
|
q.op = 'i';
|
|
|
|
q.id = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
q.x = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
q.y = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
var size = base64_32(cmd, i);
|
|
|
|
i = i + 6;
|
|
|
|
var url = cmd.slice(i, i + size);
|
|
|
|
i = i + size;
|
|
|
|
q.img = new Image();
|
|
|
|
q.img.src = url;
|
|
|
|
surfaces[q.id].drawQueue.push(q);
|
|
|
|
if (!q.img.complete) {
|
|
|
|
cmdObj.pos = i;
|
|
|
|
q.img.onload = function() { handleOutstanding(); };
|
|
|
|
return false;
|
2011-03-14 10:46:43 +00:00
|
|
|
}
|
2011-03-15 09:33:08 +00:00
|
|
|
break;
|
2011-03-14 10:46:43 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
case 'b': // Copy rects
|
|
|
|
var q = new Object();
|
|
|
|
q.op = 'b';
|
|
|
|
q.id = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
|
|
|
|
var nrects = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
|
|
|
|
q.rects = [];
|
|
|
|
for (var r = 0; r < nrects; r++) {
|
|
|
|
var rect = new Object();
|
|
|
|
rect.x = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
rect.y = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
rect.w = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
rect.h = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
q.rects.push (rect);
|
|
|
|
}
|
2011-03-14 10:46:43 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
q.dx = base64_16s(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
q.dy = base64_16s(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
surfaces[q.id].drawQueue.push(q);
|
|
|
|
break;
|
2011-03-14 10:46:43 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
case 'f': // Flush surface
|
|
|
|
var id = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
2011-03-14 10:46:43 +00:00
|
|
|
|
2011-04-06 07:57:31 +00:00
|
|
|
cmdFlushSurface(id);
|
2011-03-15 09:33:08 +00:00
|
|
|
break;
|
2011-03-14 10:46:43 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
case 'g': // Grab
|
|
|
|
var id = base64_16(cmd, i);
|
|
|
|
i = i + 3;
|
|
|
|
var ownerEvents = cmd[i++] == '1';
|
|
|
|
|
2011-04-06 07:57:31 +00:00
|
|
|
cmdGrabPointer(id, ownerEvents);
|
2011-03-15 09:33:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u': // Ungrab
|
2011-04-06 07:57:31 +00:00
|
|
|
cmdUngrabPointer();
|
2011-03-15 09:33:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
alert("Unknown op " + command);
|
|
|
|
}
|
2010-11-16 21:56:59 +00:00
|
|
|
}
|
2011-03-15 09:33:08 +00:00
|
|
|
return true;
|
2010-11-16 21:56:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function handleOutstanding()
|
|
|
|
{
|
2011-03-15 09:33:08 +00:00
|
|
|
while (outstandingCommands.length > 0) {
|
|
|
|
var cmd = outstandingCommands.shift();
|
|
|
|
if (!handleCommands(cmd)) {
|
|
|
|
outstandingCommands.unshift(cmd);
|
|
|
|
return;
|
|
|
|
}
|
2010-11-16 21:56:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleLoad(event)
|
|
|
|
{
|
2011-03-15 09:33:08 +00:00
|
|
|
var cmdObj = {};
|
|
|
|
cmdObj.data = event.target.responseText;
|
|
|
|
cmdObj.pos = 0;
|
|
|
|
|
|
|
|
outstandingCommands.push(cmdObj);
|
|
|
|
if (outstandingCommands.length == 1) {
|
|
|
|
handleOutstanding();
|
|
|
|
}
|
2010-11-16 21:56:59 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
function getSurfaceId(ev) {
|
2011-04-06 07:46:49 +00:00
|
|
|
var surface = ev.target.surface;
|
|
|
|
if (surface != undefined)
|
|
|
|
return surface.id;
|
2011-03-15 09:33:08 +00:00
|
|
|
return 0;
|
2010-11-20 21:39:40 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
function sendInput(cmd, args)
|
2010-11-20 21:25:54 +00:00
|
|
|
{
|
2011-03-15 09:33:08 +00:00
|
|
|
if (inputSocket != null) {
|
2011-04-01 13:08:28 +00:00
|
|
|
inputSocket.send(cmd + ([lastSerial, lastTimeStamp].concat(args)).join(","));
|
2011-03-15 09:33:08 +00:00
|
|
|
}
|
2010-11-19 19:21:20 +00:00
|
|
|
}
|
|
|
|
|
2011-03-11 20:28:39 +00:00
|
|
|
function getPositionsFromAbsCoord(absX, absY, relativeId) {
|
2011-03-11 20:10:23 +00:00
|
|
|
var res = Object();
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
res.rootX = absX;
|
|
|
|
res.rootY = absY;
|
|
|
|
res.winX = absX;
|
|
|
|
res.winY = absY;
|
2011-03-11 20:10:23 +00:00
|
|
|
if (relativeId != 0) {
|
2011-04-06 14:51:31 +00:00
|
|
|
var surface = surfaces[relativeId];
|
|
|
|
res.winX = res.winX - surface.x;
|
|
|
|
res.winY = res.winY - surface.y;
|
2011-03-11 20:10:23 +00:00
|
|
|
}
|
|
|
|
|
2011-03-11 20:28:39 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPositionsFromEvent(ev, relativeId) {
|
2011-04-06 14:51:31 +00:00
|
|
|
var absX, absY;
|
|
|
|
if (useToplevelWindows) {
|
|
|
|
absX = ev.screenX;
|
|
|
|
absY = ev.screenY;
|
|
|
|
} else {
|
|
|
|
absX = ev.pageX;
|
|
|
|
absY = ev.pageY;
|
|
|
|
}
|
|
|
|
var res = getPositionsFromAbsCoord(absX, absY, relativeId);
|
2011-03-11 20:28:39 +00:00
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
lastX = res.rootX;
|
|
|
|
lastY = res.rootY;
|
2011-03-11 20:10:23 +00:00
|
|
|
|
|
|
|
return res;
|
2011-03-11 13:56:31 +00:00
|
|
|
}
|
|
|
|
|
2011-03-14 10:46:43 +00:00
|
|
|
function getEffectiveEventTarget (id) {
|
|
|
|
if (grab.window != null) {
|
2011-03-15 09:26:53 +00:00
|
|
|
if (!grab.ownerEvents)
|
2011-03-14 10:46:43 +00:00
|
|
|
return grab.window;
|
|
|
|
if (id == 0)
|
|
|
|
return grab.window;
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2011-04-01 13:08:28 +00:00
|
|
|
function updateForEvent(ev) {
|
|
|
|
lastTimeStamp = ev.timeStamp;
|
2011-04-06 14:39:07 +00:00
|
|
|
if (ev.target.surface && ev.target.surface.window) {
|
|
|
|
var win = ev.target.surface.window;
|
|
|
|
if (ev.screenX != undefined && ev.clientX != undefined) {
|
|
|
|
var newFrameSizeX = ev.screenX - ev.clientX - win.screenX;
|
|
|
|
var newFrameSizeY = ev.screenY - ev.clientY - win.screenY;
|
|
|
|
if (newFrameSizeX != frameSizeX || newFrameSizeY != frameSizeY) {
|
|
|
|
frameSizeX = newFrameSizeX;
|
|
|
|
frameSizeY = newFrameSizeY;
|
|
|
|
toplevelWindows.forEach(updateBrowserWindowGeometry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateBrowserWindowGeometry(win);
|
|
|
|
}
|
2011-04-01 13:08:28 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
function onMouseMove (ev) {
|
2011-04-01 13:08:28 +00:00
|
|
|
updateForEvent(ev);
|
2011-04-08 09:45:51 +00:00
|
|
|
if (localGrab) {
|
|
|
|
var dx = ev.pageX - localGrab.lastX;
|
|
|
|
var dy = ev.pageY - localGrab.lastY;
|
|
|
|
var surface = localGrab.frame.frameFor;
|
|
|
|
surface.x += dx;
|
|
|
|
surface.y += dy;
|
|
|
|
var offset = getFrameOffset(surface);
|
|
|
|
localGrab.frame.style["left"] = (surface.x - offset.x) + "px";
|
|
|
|
localGrab.frame.style["top"] = (surface.y - offset.y) + "px";
|
|
|
|
sendInput ("w", [surface.id, surface.x, surface.y, surface.width, surface.height]);
|
|
|
|
localGrab.lastX = ev.pageX;
|
|
|
|
localGrab.lastY = ev.pageY;
|
|
|
|
return;
|
|
|
|
}
|
2011-03-15 09:26:53 +00:00
|
|
|
var id = getSurfaceId(ev);
|
2011-03-14 10:46:43 +00:00
|
|
|
id = getEffectiveEventTarget (id);
|
2011-03-11 20:10:23 +00:00
|
|
|
var pos = getPositionsFromEvent(ev, id);
|
2011-04-05 08:03:14 +00:00
|
|
|
sendInput ("m", [realWindowWithMouse, id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState]);
|
2011-03-11 20:10:23 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
function onMouseOver (ev) {
|
2011-04-01 13:08:28 +00:00
|
|
|
updateForEvent(ev);
|
2011-04-08 09:45:51 +00:00
|
|
|
if (localGrab)
|
|
|
|
return;
|
2011-03-15 09:26:53 +00:00
|
|
|
var id = getSurfaceId(ev);
|
|
|
|
realWindowWithMouse = id;
|
2011-03-14 10:46:43 +00:00
|
|
|
id = getEffectiveEventTarget (id);
|
2011-03-11 20:10:23 +00:00
|
|
|
var pos = getPositionsFromEvent(ev, id);
|
2011-03-15 09:26:53 +00:00
|
|
|
windowWithMouse = id;
|
|
|
|
if (windowWithMouse != 0) {
|
2011-04-05 08:03:14 +00:00
|
|
|
sendInput ("e", [realWindowWithMouse, id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_NORMAL]);
|
2011-03-11 20:10:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
function onMouseOut (ev) {
|
2011-04-01 13:08:28 +00:00
|
|
|
updateForEvent(ev);
|
2011-04-08 09:45:51 +00:00
|
|
|
if (localGrab)
|
|
|
|
return;
|
2011-03-15 09:26:53 +00:00
|
|
|
var id = getSurfaceId(ev);
|
2011-03-14 10:46:43 +00:00
|
|
|
var origId = id;
|
|
|
|
id = getEffectiveEventTarget (id);
|
2011-03-11 20:10:23 +00:00
|
|
|
var pos = getPositionsFromEvent(ev, id);
|
|
|
|
|
|
|
|
if (id != 0) {
|
2011-04-05 08:03:14 +00:00
|
|
|
sendInput ("l", [realWindowWithMouse, id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_NORMAL]);
|
2011-03-11 20:10:23 +00:00
|
|
|
}
|
2011-03-15 09:26:53 +00:00
|
|
|
realWindowWithMouse = 0;
|
|
|
|
windowWithMouse = 0;
|
2010-11-20 21:25:54 +00:00
|
|
|
}
|
|
|
|
|
2011-04-06 08:01:53 +00:00
|
|
|
function doGrab(id, ownerEvents, implicit) {
|
2011-03-14 10:46:43 +00:00
|
|
|
var pos;
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
if (windowWithMouse != id) {
|
|
|
|
if (windowWithMouse != 0) {
|
|
|
|
pos = getPositionsFromAbsCoord(lastX, lastY, windowWithMouse);
|
2011-04-05 08:03:14 +00:00
|
|
|
sendInput ("l", [realWindowWithMouse, windowWithMouse, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_GRAB]);
|
2011-03-14 10:46:43 +00:00
|
|
|
}
|
2011-03-15 09:26:53 +00:00
|
|
|
pos = getPositionsFromAbsCoord(lastX, lastY, id);
|
2011-04-05 08:03:14 +00:00
|
|
|
sendInput ("e", [realWindowWithMouse, id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_GRAB]);
|
2011-03-15 09:26:53 +00:00
|
|
|
windowWithMouse = id;
|
2011-03-14 10:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
grab.window = id;
|
2011-03-15 09:26:53 +00:00
|
|
|
grab.ownerEvents = ownerEvents;
|
2011-03-14 10:46:43 +00:00
|
|
|
grab.implicit = implicit;
|
|
|
|
}
|
|
|
|
|
2011-04-06 08:01:53 +00:00
|
|
|
function doUngrab() {
|
2011-03-14 10:46:43 +00:00
|
|
|
var pos;
|
2011-03-15 09:26:53 +00:00
|
|
|
if (realWindowWithMouse != windowWithMouse) {
|
|
|
|
if (windowWithMouse != 0) {
|
|
|
|
pos = getPositionsFromAbsCoord(lastX, lastY, windowWithMouse);
|
2011-04-05 08:03:14 +00:00
|
|
|
sendInput ("l", [realWindowWithMouse, windowWithMouse, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_UNGRAB]);
|
2011-03-14 10:46:43 +00:00
|
|
|
}
|
2011-03-15 09:26:53 +00:00
|
|
|
if (realWindowWithMouse != 0) {
|
|
|
|
pos = getPositionsFromAbsCoord(lastX, lastY, realWindowWithMouse);
|
2011-04-05 08:03:14 +00:00
|
|
|
sendInput ("e", [realWindowWithMouse, realWindowWithMouse, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_UNGRAB]);
|
2011-03-14 10:46:43 +00:00
|
|
|
}
|
2011-03-15 09:26:53 +00:00
|
|
|
windowWithMouse = realWindowWithMouse;
|
2011-03-14 10:46:43 +00:00
|
|
|
}
|
|
|
|
grab.window = null;
|
|
|
|
}
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
function onMouseDown (ev) {
|
2011-04-01 13:08:28 +00:00
|
|
|
updateForEvent(ev);
|
2011-04-08 09:45:51 +00:00
|
|
|
var button = ev.button + 1;
|
|
|
|
lastState = lastState | getButtonMask (button);
|
2011-03-15 09:26:53 +00:00
|
|
|
var id = getSurfaceId(ev);
|
2011-03-14 10:46:43 +00:00
|
|
|
id = getEffectiveEventTarget (id);
|
2011-04-08 09:45:51 +00:00
|
|
|
|
|
|
|
if (id == 0 && ev.target.frameFor) { /* mouse click on frame */
|
|
|
|
localGrab = new Object();
|
|
|
|
localGrab.frame = ev.target;
|
|
|
|
localGrab.lastX = ev.pageX;
|
|
|
|
localGrab.lastY = ev.pageY;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-11 20:10:23 +00:00
|
|
|
var pos = getPositionsFromEvent(ev, id);
|
2011-04-07 13:26:37 +00:00
|
|
|
if (grab.window == null)
|
2011-04-06 08:01:53 +00:00
|
|
|
doGrab (id, false, true);
|
2011-04-05 08:03:14 +00:00
|
|
|
sendInput ("b", [realWindowWithMouse, id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, button]);
|
2010-11-19 19:21:20 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
function onMouseUp (ev) {
|
2011-04-01 13:08:28 +00:00
|
|
|
updateForEvent(ev);
|
2011-03-14 11:09:19 +00:00
|
|
|
var button = ev.button + 1;
|
2011-03-15 09:26:53 +00:00
|
|
|
lastState = lastState & ~getButtonMask (button);
|
2011-04-08 09:45:51 +00:00
|
|
|
var evId = getSurfaceId(ev);
|
|
|
|
id = getEffectiveEventTarget (evId);
|
|
|
|
var pos = getPositionsFromEvent(ev, id);
|
|
|
|
|
|
|
|
if (localGrab) {
|
|
|
|
localGrab = null;
|
|
|
|
realWindowWithMouse = evId;
|
|
|
|
if (windowWithMouse != id) {
|
|
|
|
if (windowWithMouse != 0) {
|
|
|
|
sendInput ("l", [realWindowWithMouse, windowWithMouse, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_NORMAL]);
|
|
|
|
}
|
|
|
|
windowWithMouse = id;
|
|
|
|
if (windowWithMouse != 0) {
|
|
|
|
sendInput ("e", [realWindowWithMouse, id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_NORMAL]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-05 08:03:14 +00:00
|
|
|
sendInput ("B", [realWindowWithMouse, id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, button]);
|
2011-03-14 10:46:43 +00:00
|
|
|
|
|
|
|
if (grab.window != null && grab.implicit)
|
2011-03-14 15:38:24 +00:00
|
|
|
doUngrab(ev.timeStamp);
|
2010-11-19 19:21:20 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
var lastKeyDown = 0;
|
|
|
|
function onKeyDown (ev) {
|
2011-04-01 13:08:28 +00:00
|
|
|
updateForEvent(ev);
|
2011-04-08 09:45:51 +00:00
|
|
|
if (localGrab)
|
|
|
|
return;
|
2011-03-15 09:33:08 +00:00
|
|
|
var keyCode = ev.keyCode;
|
|
|
|
if (keyCode != lastKeyDown) {
|
2011-04-01 13:08:28 +00:00
|
|
|
sendInput ("k", [keyCode]);
|
2011-03-15 09:33:08 +00:00
|
|
|
lastKeyDown = keyCode;
|
|
|
|
}
|
2010-11-25 20:57:31 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
function onKeyUp (ev) {
|
2011-04-01 13:08:28 +00:00
|
|
|
updateForEvent(ev);
|
2011-04-08 09:45:51 +00:00
|
|
|
if (localGrab)
|
|
|
|
return;
|
2011-03-15 09:33:08 +00:00
|
|
|
var keyCode = ev.keyCode;
|
2011-04-01 13:08:28 +00:00
|
|
|
sendInput ("K", [keyCode]);
|
2011-03-15 09:33:08 +00:00
|
|
|
lastKeyDown = 0;
|
2010-11-25 20:57:31 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
function cancelEvent(ev)
|
2010-11-25 20:02:21 +00:00
|
|
|
{
|
2011-03-15 09:33:08 +00:00
|
|
|
ev = ev ? ev : window.event;
|
|
|
|
if (ev.stopPropagation)
|
|
|
|
ev.stopPropagation();
|
|
|
|
if (ev.preventDefault)
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.cancelBubble = true;
|
|
|
|
ev.cancel = true;
|
|
|
|
ev.returnValue = false;
|
|
|
|
return false;
|
2010-11-25 20:02:21 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 09:26:53 +00:00
|
|
|
function onMouseWheel(ev)
|
2010-11-25 20:02:21 +00:00
|
|
|
{
|
2011-04-01 13:08:28 +00:00
|
|
|
updateForEvent(ev);
|
2011-04-08 09:45:51 +00:00
|
|
|
if (localGrab)
|
|
|
|
return;
|
2011-03-15 09:33:08 +00:00
|
|
|
ev = ev ? ev : window.event;
|
2011-03-11 20:10:23 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
var id = getSurfaceId(ev);
|
|
|
|
var pos = getPositionsFromEvent(ev, id);
|
2011-03-11 20:10:23 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
var offset = ev.detail ? ev.detail : ev.wheelDelta;
|
|
|
|
var dir = 0;
|
|
|
|
if (offset > 0)
|
|
|
|
dir = 1;
|
2011-04-05 08:03:14 +00:00
|
|
|
sendInput ("s", [realWindowWithMouse, id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, dir]);
|
2010-11-25 20:02:21 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
return cancelEvent(ev);
|
2010-11-25 20:02:21 +00:00
|
|
|
}
|
|
|
|
|
2011-04-06 08:03:42 +00:00
|
|
|
function setupDocument(document)
|
|
|
|
{
|
|
|
|
document.oncontextmenu = function () { return false; };
|
|
|
|
document.onmousemove = onMouseMove;
|
|
|
|
document.onmouseover = onMouseOver;
|
|
|
|
document.onmouseout = onMouseOut;
|
|
|
|
document.onmousedown = onMouseDown;
|
|
|
|
document.onmouseup = onMouseUp;
|
|
|
|
document.onkeydown = onKeyDown;
|
|
|
|
document.onkeyup = onKeyUp;
|
|
|
|
|
|
|
|
if (document.addEventListener) {
|
|
|
|
document.addEventListener('DOMMouseScroll', onMouseWheel, false);
|
|
|
|
document.addEventListener('mousewheel', onMouseWheel, false);
|
|
|
|
} else if (document.attachEvent) {
|
|
|
|
element.attachEvent("onmousewheel", onMouseWheel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-18 21:21:16 +00:00
|
|
|
function connect()
|
2010-11-16 21:56:59 +00:00
|
|
|
{
|
2011-03-15 09:33:08 +00:00
|
|
|
var xhr = createXHR();
|
|
|
|
if (xhr) {
|
|
|
|
if (typeof xhr.multipart == 'undefined') {
|
|
|
|
alert("Sorry, this example only works in browsers that support multipart.");
|
|
|
|
return;
|
|
|
|
}
|
2010-11-16 21:56:59 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
xhr.multipart = true;
|
|
|
|
xhr.open("GET", "/output", true);
|
|
|
|
xhr.onload = handleLoad;
|
|
|
|
xhr.send(null);
|
|
|
|
}
|
2010-11-25 20:02:21 +00:00
|
|
|
|
2011-03-15 09:33:08 +00:00
|
|
|
if ("WebSocket" in window) {
|
|
|
|
var loc = window.location.toString().replace("http:", "ws:");
|
|
|
|
loc = loc.substr(0, loc.lastIndexOf('/')) + "/input";
|
|
|
|
var ws = new WebSocket(loc, "broadway");
|
|
|
|
ws.onopen = function() {
|
|
|
|
inputSocket = ws;
|
2011-04-07 13:10:39 +00:00
|
|
|
|
|
|
|
var w, h;
|
|
|
|
if (useToplevelWindows) {
|
|
|
|
w = window.screen.width;
|
|
|
|
h = window.screen.height;
|
|
|
|
} else {
|
|
|
|
w = window.innerWidth;
|
|
|
|
h = window.innerHeight;
|
2011-04-08 09:45:16 +00:00
|
|
|
window.onresize = function(ev) {
|
2011-04-07 13:10:39 +00:00
|
|
|
var w, h;
|
|
|
|
w = window.innerWidth;
|
|
|
|
h = window.innerHeight;
|
|
|
|
sendInput ("d", [w, h]);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
sendInput ("d", [w, h]);
|
2011-03-15 09:33:08 +00:00
|
|
|
};
|
|
|
|
ws.onclose = function() {
|
|
|
|
inputSocket = null;
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
alert("WebSocket not supported, input will not work!");
|
|
|
|
}
|
2011-04-06 08:03:42 +00:00
|
|
|
setupDocument(document);
|
2011-04-06 14:39:07 +00:00
|
|
|
window.onunload = function (ev) {
|
|
|
|
for (var i = 0; i < toplevelWindows.length; i++)
|
|
|
|
toplevelWindows[i].close();
|
|
|
|
};
|
2010-11-16 21:56:59 +00:00
|
|
|
}
|