[gtk+] [broadway] Implement wm close in browser



commit 02e9b97981a2b4eebb10989d29c141c5da327e6e
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Apr 18 11:50:29 2011 +0200

    [broadway] Implement wm close in browser

 gdk/broadway/broadway.js |   60 ++++++++++++++++++++++++++++++++++++---------
 gdk/broadway/client.html |    8 +----
 2 files changed, 50 insertions(+), 18 deletions(-)
---
diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js
index 806ed76..7870eef 100644
--- a/gdk/broadway/broadway.js
+++ b/gdk/broadway/broadway.js
@@ -461,6 +461,7 @@ function cmdCreateSurface(id, x, y, width, height, isTemp)
 	surface.frame = frame;
 
 	var button = document.createElement("center");
+	button.closeFor = surface;
 	var X = document.createTextNode("X");
 	button.appendChild(X);
 	button.className = "frame-close";
@@ -975,17 +976,19 @@ function updateForEvent(ev) {
 function onMouseMove (ev) {
     updateForEvent(ev);
     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";
-	sendConfigureNotify(surface);
-	localGrab.lastX = ev.pageX;
-	localGrab.lastY = ev.pageY;
+	if (localGrab.type == "move") {
+	    var dx = ev.pageX - localGrab.lastX;
+	    var dy = ev.pageY - localGrab.lastY;
+	    var surface = localGrab.surface;
+	    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";
+	    sendConfigureNotify(surface);
+	    localGrab.lastX = ev.pageX;
+	    localGrab.lastY = ev.pageY;
+	}
 	return;
     }
     var id = getSurfaceId(ev);
@@ -996,6 +999,13 @@ function onMouseMove (ev) {
 
 function onMouseOver (ev) {
     updateForEvent(ev);
+
+    if (!grab.window && ev.target.closeFor) {
+	ev.target.className = ev.target.className + " frame-hover";
+	if (ev.target.isDown)
+	    ev.target.className = ev.target.className + " frame-active";
+    }
+
     if (localGrab)
 	return;
     var id = getSurfaceId(ev);
@@ -1010,6 +1020,11 @@ function onMouseOver (ev) {
 
 function onMouseOut (ev) {
     updateForEvent(ev);
+    if (ev.target.closeFor) {
+	ev.target.className = ev.target.className.replace(" frame-hover", "");
+	if (ev.target.isDown)
+	    ev.target.className = ev.target.className.replace(" frame-active", "");
+    }
     if (localGrab)
 	return;
     var id = getSurfaceId(ev);
@@ -1067,6 +1082,8 @@ function onMouseDown (ev) {
 
     if (id == 0 && ev.target.frameFor) { /* mouse click on frame */
 	localGrab = new Object();
+	localGrab.surface = ev.target.frameFor;
+	localGrab.type = "move";
 	localGrab.frame = ev.target;
 	localGrab.lastX = ev.pageX;
 	localGrab.lastY = ev.pageY;
@@ -1074,6 +1091,18 @@ function onMouseDown (ev) {
 	return;
     }
 
+    if (id == 0 && ev.target.closeFor) { /* mouse click on frame */
+	ev.target.isDown = true;
+	ev.target.className = ev.target.className + " frame-active";
+	localGrab = new Object();
+	localGrab.surface = ev.target.closeFor;
+	localGrab.type = "close";
+	localGrab.button = ev.target;
+	localGrab.lastX = ev.pageX;
+	localGrab.lastY = ev.pageY;
+	return;
+    }
+
     var pos = getPositionsFromEvent(ev, id);
     if (grab.window == null)
 	doGrab (id, false, true);
@@ -1089,7 +1118,6 @@ function onMouseUp (ev) {
     var pos = getPositionsFromEvent(ev, id);
 
     if (localGrab) {
-	localGrab = null;
 	realWindowWithMouse = evId;
 	if (windowWithMouse != id) {
 	    if (windowWithMouse != 0) {
@@ -1100,6 +1128,14 @@ function onMouseUp (ev) {
 		sendInput ("e", [realWindowWithMouse, id, pos.rootX, pos.rootY, pos.winX, pos.winY, lastState, GDK_CROSSING_NORMAL]);
 	    }
 	}
+
+	if (localGrab.type == "close") {
+	    localGrab.button.isDown = false;
+	    localGrab.button.className = localGrab.button.className.replace( " frame-active", "");
+	    if (ev.target == localGrab.button)
+		sendInput ("W", [localGrab.surface.id]);
+	}
+	localGrab = null;
 	return;
     }
 
diff --git a/gdk/broadway/client.html b/gdk/broadway/client.html
index 43a74ad..e98aac4 100644
--- a/gdk/broadway/client.html
+++ b/gdk/broadway/client.html
@@ -50,15 +50,11 @@
     user-select: none;
 }
 
-.frame-close:focus {
-    left: 0;
-}
-
-.frame-close:hover {
+.frame-close.frame-hover {
     background-color: #EE4A4A;
 }
 
-.frame-close:active {
+.frame-close.frame-active {
     background-color: #AA2020;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]