]> source.dussan.org Git - vaadin-framework.git/commitdiff
#7115 Fixes VOverlay offset in IE6/IE7 when body is set to position: relative
authorArtur Signell <artur.signell@itmill.com>
Tue, 7 Jun 2011 14:54:41 +0000 (14:54 +0000)
committerArtur Signell <artur.signell@itmill.com>
Tue, 7 Jun 2011 14:54:41 +0000 (14:54 +0000)
svn changeset:19270/svn branch:6.6

src/com/vaadin/terminal/gwt/client/ui/VOverlay.java

index ae8b2dd9c35e4ff40f62ee8d891d0c0e3d067f05..b301fd3861954697f6cc4e1ad297b8943ecac802 100644 (file)
@@ -155,18 +155,32 @@ public class VOverlay extends PopupPanel implements CloseHandler<PopupPanel> {
 
     private static int adjustByRelativeTopBodyMargin() {
         if (topFix == -1) {
-            topFix = detectRelativeBodyFixes("top");
+            boolean ie6OrIe7 = BrowserInfo.get().isIE()
+                    && BrowserInfo.get().getIEVersion() <= 7;
+            topFix = detectRelativeBodyFixes("top", ie6OrIe7);
         }
         return topFix;
     }
 
-    private native static int detectRelativeBodyFixes(String axis)
+    private native static int detectRelativeBodyFixes(String axis,
+            boolean removeClientLeftOrTop)
     /*-{
         try {
             var b = $wnd.document.body;
             var cstyle = b.currentStyle ? b.currentStyle : getComputedStyle(b);
             if(cstyle && cstyle.position == 'relative') {
-                return b.getBoundingClientRect()[axis];
+                var offset = b.getBoundingClientRect()[axis];
+                if (removeClientLeftOrTop) {
+                    // IE6 and IE7 include the top left border of the client area into the boundingClientRect
+                    var clientTopOrLeft = 0;
+                    if (axis == "top")
+                        clientTopOrLeft = $wnd.document.documentElement.clientTop;
+                    else
+                        clientTopOrLeft = $wnd.document.documentElement.clientLeft;
+
+                    offset -= clientTopOrLeft;
+                }
+                return offset;
             }
         } catch(e){}
         return 0;
@@ -174,7 +188,10 @@ public class VOverlay extends PopupPanel implements CloseHandler<PopupPanel> {
 
     private static int adjustByRelativeLeftBodyMargin() {
         if (leftFix == -1) {
-            leftFix = detectRelativeBodyFixes("left");
+            boolean ie6OrIe7 = BrowserInfo.get().isIE()
+                    && BrowserInfo.get().getIEVersion() <= 7;
+            leftFix = detectRelativeBodyFixes("left", ie6OrIe7);
+
         }
         return leftFix;
     }