Fixes Issue #693.
Fixes a problem with AbsolutePanel where large Widgets may flicker when being
added to an AbsolutePanel due to position being set after DOM attachment.
This change reverses the order of operations such that the position is
set prior to DOM attachment. This also includes a javadoc fix to document
the special case in add(Widget, int, int) to get static positioning.
Patch by: bobv
Review by: knorton
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1009 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java b/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java
index 1d8a919..f1eca83 100644
--- a/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java
+++ b/user/src/com/google/gwt/user/client/ui/AbsolutePanel.java
@@ -69,15 +69,22 @@
}
/**
- * Adds a widget to the panel at the specified position.
+ * Adds a widget to the panel at the specified position. Setting a position
+ * of <code>(-1, -1)</code> will cause the child widget to be positioned
+ * statically.
*
* @param w the widget to be added
* @param left the widget's left position
* @param top the widget's top position
*/
public void add(Widget w, int left, int top) {
+ // In order to avoid the potential for a flicker effect, it is necessary
+ // to set the position of the widget before adding it to the AbsolutePanel.
+ // The Widget should be removed from its parent before any positional
+ // changes are made to prevent flickering.
+ w.removeFromParent();
+ setWidgetPositionImpl(w, left, top);
add(w);
- setWidgetPosition(w, left, top);
}
/**
@@ -113,15 +120,7 @@
*/
public void setWidgetPosition(Widget w, int left, int top) {
checkWidgetParent(w);
-
- Element h = w.getElement();
- if ((left == -1) && (top == -1)) {
- changeToStaticPositioning(h);
- } else {
- DOM.setStyleAttribute(h, "position", "absolute");
- DOM.setStyleAttribute(h, "left", left + "px");
- DOM.setStyleAttribute(h, "top", top + "px");
- }
+ setWidgetPositionImpl(w, left, top);
}
/**
@@ -143,4 +142,15 @@
"Widget must be a child of this panel.");
}
}
+
+ private void setWidgetPositionImpl(Widget w, int left, int top) {
+ Element h = w.getElement();
+ if ((left == -1) && (top == -1)) {
+ changeToStaticPositioning(h);
+ } else {
+ DOM.setStyleAttribute(h, "position", "absolute");
+ DOM.setStyleAttribute(h, "left", left + "px");
+ DOM.setStyleAttribute(h, "top", top + "px");
+ }
+ }
}