[gtk+] [broadway] Fix up frame size calculation



commit 7a197e5b65637d94f3c215a74950a63869fbb719
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Apr 11 10:42:03 2011 +0200

    [broadway] Fix up frame size calculation
    
    Turns out that offsetTop/Left doesn't contain the border, so we need
    to manually add that in.

 gdk/broadway/broadway.js |   33 +++++++++++++++++++++++++++++++--
 1 files changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js
index 8cefb06..3494c78 100644
--- a/gdk/broadway/broadway.js
+++ b/gdk/broadway/broadway.js
@@ -322,15 +322,44 @@ function getTransientToplevel(surface)
     return null;
 }
 
+function getStyle(el, styleProp)
+{
+    if (el.currentStyle) {
+	return el.currentStyle[styleProp];
+    }  else if (window.getComputedStyle) {
+	var win = el.ownerDocument.defaultView;
+	return win.getComputedStyle(el, null).getPropertyValue(styleProp);
+    }
+    return undefined;
+}
+
+function parseOffset(value)
+{
+    var px = value.indexOf("px");
+    if (px > 0)
+	return parseInt(value.slice(0,px));
+    return 0;
+}
+
 function getFrameOffset(surface) {
-    var x = 1;
-    var y = 1;
+    var x = 0;
+    var y = 0;
     var el = surface.canvas;
     while (el != null && el != surface.frame) {
 	x += el.offsetLeft;
 	y += el.offsetTop;
+
+	/* For some reason the border is not includes in the offsets.. */
+	x += parseOffset(getStyle(el, "border-left-width"));
+	y += parseOffset(getStyle(el, "border-top-width"));
+
 	el = el.offsetParent;
     }
+
+    /* Also include frame border as per above */
+    x += parseOffset(getStyle(el, "border-left-width"));
+    y += parseOffset(getStyle(el, "border-top-width"));
+
     return {x: x, y: y};
 }
 



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