]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #6848
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 6 May 2011 12:03:18 +0000 (12:03 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 6 May 2011 12:03:18 +0000 (12:03 +0000)
svn changeset:18666/svn branch:6.6

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

index 9e4e167060c47bd2a76603ff8f81fa3a631f4d31..6d4e4007f184e73be9cc11b8b0fb309eeadb944b 100644 (file)
@@ -28,6 +28,10 @@ public class VOverlay extends PopupPanel {
      */
     protected static int Z_INDEX = 20000;
 
+    private static int leftFix = -1;
+
+    private static int topFix = -1;
+
     /*
      * Shadow element style. If an extending class wishes to use a different
      * style of shadow, it can use setShadowStyle(String) to give the shadow
@@ -114,12 +118,40 @@ public class VOverlay extends PopupPanel {
 
     @Override
     public void setPopupPosition(int left, int top) {
+        left -= adjustByRelativeLeftBodyMargin();
+        top -= adjustByRelativeTopBodyMargin();
         super.setPopupPosition(left, top);
         if (shadow != null) {
             updateShadowSizeAndPosition(isAnimationEnabled() ? 0 : 1);
         }
     }
 
+    private static int adjustByRelativeTopBodyMargin() {
+        if (topFix == -1) {
+            topFix = detectRelativeBodyFixes("top");
+        }
+        return topFix;
+    }
+
+    private native static int detectRelativeBodyFixes(String axis)
+    /*-{
+        try {
+            var b = $wnd.document.body;
+            var cstyle = b.currentStyle ? b.currentStyle : getComputedStyle(b);
+            if(cstyle && cstyle.position == 'relative') {
+                return b.getBoundingClientRect()[axis];
+            }
+        } catch(e){}
+        return 0;
+    }-*/;
+
+    private static int adjustByRelativeLeftBodyMargin() {
+        if (leftFix == -1) {
+            leftFix = detectRelativeBodyFixes("left");
+        }
+        return leftFix;
+    }
+
     @Override
     public void show() {
         super.show();
@@ -233,6 +265,8 @@ public class VOverlay extends PopupPanel {
         // body's positioning context.
         x -= Document.get().getBodyOffsetLeft();
         y -= Document.get().getBodyOffsetTop();
+        x -= adjustByRelativeLeftBodyMargin();
+        y -= adjustByRelativeTopBodyMargin();
 
         int width = getOffsetWidth();
         int height = getOffsetHeight();