Revision: 8467
Author: [email protected]
Date: Mon Aug  2 22:47:54 2010
Log: Fix for issue 1813: RootPanel.get(id) fails to set 'position:relative' and 'overflow:hidden'

Adds a development mode only GWT.log() warning message when an instance of AbsolutePanel inserts a non-statically positioned child and the parent has 'position:static', which
tells developers what's wrong with their CSS and how to fix it.

In production mode the warning message is compiled out and the extra check becomes a no-op.

Review at http://gwt-code-reviews.appspot.com/636803

Fixes issues: 1813

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8467

Modified:
 /trunk/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java

=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java Thu Jul 29 11:09:15 2010 +++ /trunk/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java Mon Aug 2 22:47:54 2010
@@ -15,6 +15,7 @@
  */
 package com.google.gwt.user.client.ui;

+import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Element;

@@ -113,6 +114,7 @@
     int beforeIndex = getWidgetCount();
     setWidgetPositionImpl(w, left, top);
     insert(w, beforeIndex);
+    verifyPositionNotStatic(w);
   }

   /**
@@ -166,6 +168,7 @@
     w.removeFromParent();
     setWidgetPositionImpl(w, left, top);
     insert(w, beforeIndex);
+    verifyPositionNotStatic(w);
   }

   /**
@@ -195,6 +198,7 @@
   public void setWidgetPosition(Widget w, int left, int top) {
     checkWidgetParent(w);
     setWidgetPositionImpl(w, left, top);
+    verifyPositionNotStatic(w);
   }

   protected void setWidgetPositionImpl(Widget w, int left, int top) {
@@ -214,4 +218,20 @@
           "Widget must be a child of this panel.");
     }
   }
-}
+
+  private void verifyPositionNotStatic(Widget w) {
+    if (!GWT.isProdMode()) {
+      if (w.getElement().getOffsetParent() != getElement()) {
+        String className = getClass().getName();
+ GWT.log("Warning: " + className + " descendants will be incorrectly " + + "positioned, i.e. not relative to their parent element, when " + + "'position:static', which is the CSS default, is in effect. One "
+            + "possible fix is to call "
+ + "'panel.getElement().getStyle().setPosition(Position.RELATIVE)'.",
+            // Stack trace provides context for the developer
+            new IllegalStateException(className
+                + " is missing CSS 'position:{relative,absolute,fixed}'"));
+      }
+    }
+  }
+}

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to