Reviewers: jgw,
Description:
Fix for issue 1813:
RootPanel.get(id) fails to set 'position:relative' and 'overflow:hidden'
http://code.google.com/p/google-web-toolkit/issues/detail?id=1813
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.
Please review this at http://gwt-code-reviews.appspot.com/636803/show
Affected files:
M user/src/com/google/gwt/user/client/ui/AbsolutePanel.java
Index: user/src/com/google/gwt/user/client/ui/AbsolutePanel.java
===================================================================
--- user/src/com/google/gwt/user/client/ui/AbsolutePanel.java (revision
8450)
+++ user/src/com/google/gwt/user/client/ui/AbsolutePanel.java (working copy)
@@ -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) {
@@ -208,6 +212,22 @@
}
}
+ 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}'"));
+ }
+ }
+ }
+
private void checkWidgetParent(Widget w) {
if (w.getParent() != this) {
throw new IllegalArgumentException(
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors