Minor tweaks to Layout code in response to post-TBR review.
Review: http://gwt-code-reviews.appspot.com/55804
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5882 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/javadoc/com/google/gwt/examples/LayoutPanelExample.java b/user/javadoc/com/google/gwt/examples/LayoutPanelExample.java
index 13372d7..f1300f9 100644
--- a/user/javadoc/com/google/gwt/examples/LayoutPanelExample.java
+++ b/user/javadoc/com/google/gwt/examples/LayoutPanelExample.java
@@ -29,7 +29,7 @@
public void onModuleLoad() {
// Attach two child widgets to a LayoutPanel, laying them out horizontally,
// splitting at 50%.
- Widget childOne = new HTML(), childTwo = new HTML();
+ Widget childOne = new HTML("left"), childTwo = new HTML("right");
LayoutPanel p = new LayoutPanel();
p.add(childOne);
p.add(childTwo);
diff --git a/user/src/com/google/gwt/layout/client/Layout.java b/user/src/com/google/gwt/layout/client/Layout.java
index 6df50e1..032f571 100644
--- a/user/src/com/google/gwt/layout/client/Layout.java
+++ b/user/src/com/google/gwt/layout/client/Layout.java
@@ -50,7 +50,7 @@
* element. There is a set of methods available on this class to manipulate the
* child element's position and size. In order for changes to a layer to take
* effect, you must finally call one of {@link #layout()} or
- * {@link #animate(int)}. This allows many changes to different layers to be
+ * {@link #layout(int)}. This allows many changes to different layers to be
* applied efficiently, and to be animated.
* </p>
*
@@ -78,7 +78,7 @@
public class Layout {
/**
- * Callback interface used by {@link Layout#animate(int, AnimationCallback)}
+ * Callback interface used by {@link Layout#layout(int, AnimationCallback)}
* to provide updates on animation progress.
*/
public interface AnimationCallback {
@@ -294,13 +294,122 @@
}
/**
+ * Asserts that the given child element is managed by this layout.
+ *
+ * @param elem the element to be tested
+ */
+ public void assertIsChild(Element elem) {
+ assert elem.getParentElement().getParentElement() == this.parentElem : "Element is not a child of this layout";
+ }
+
+ /**
+ * Attaches a child element to this layout.
+ *
+ * <p>
+ * This method will attach the child to the layout, removing it from its
+ * current parent element. Use the {@link Layer} it returns to manipulate the
+ * child.
+ * </p>
+ *
+ * @param child the child to be attached
+ * @return the {@link Layer} associated with the element
+ */
+ public Layer attachChild(Element child) {
+ return attachChild(child, null);
+ }
+
+ /**
+ * Attaches a child element to this layout.
+ *
+ * <p>
+ * This method will attach the child to the layout, removing it from its
+ * current parent element. Use the {@link Layer} it returns to manipulate the
+ * child.
+ * </p>
+ *
+ * @param child the child to be attached
+ * @param userObject an arbitrary object to be associated with this layer
+ * @return the {@link Layer} associated with the element
+ */
+ public Layer attachChild(Element child, Object userObject) {
+ Element container = impl.attachChild(parentElem, child);
+ Layer layer = new Layer(container, child, userObject);
+ layers.add(layer);
+ return layer;
+ }
+
+ /**
+ * Causes the parent element to fill its own parent.
+ *
+ * <p>
+ * This is most useful for top-level layouts that need to follow the size of
+ * another element, such as the <body>.
+ * </p>
+ */
+ public void fillParent() {
+ impl.fillParent(parentElem);
+ }
+
+ /**
+ * Returns the size of one unit, in pixels, in the context of this layout.
+ *
+ * <p>
+ * This will work for any unit type, but be aware that certain unit types,
+ * such as {@link Unit#EM}, and {@link Unit#EX}, will return different values
+ * based upon the parent's associated font size. {@link Unit#PCT} is dependent
+ * upon the parent's actual size, and the axis to be measured.
+ * </p>
+ *
+ * @param unit the unit type to be measured
+ * @param vertical whether the unit to be measured is on the vertical or
+ * horizontal axis (this matters only for {@link Unit#PCT})
+ * @return the unit size, in pixels
+ */
+ public double getUnitSize(Unit unit, boolean vertical) {
+ return impl.getUnitSizeInPixels(parentElem, unit, vertical);
+ }
+
+ /**
+ * Updates this layout's children immediately. This method <em>must</em> be
+ * called after updating any of its children's {@link Layer layers}.
+ */
+ public void layout() {
+ for (Layer l : layers) {
+ l.left = l.sourceLeft = l.targetLeft;
+ l.top = l.sourceTop = l.targetTop;
+ l.right = l.sourceRight = l.targetRight;
+ l.bottom = l.sourceBottom = l.targetBottom;
+ l.width = l.sourceWidth = l.targetWidth;
+ l.height = l.sourceHeight = l.targetHeight;
+
+ l.setLeft = l.setTargetLeft;
+ l.setTop = l.setTargetTop;
+ l.setRight = l.setTargetRight;
+ l.setBottom = l.setTargetBottom;
+ l.setWidth = l.setTargetWidth;
+ l.setHeight = l.setTargetHeight;
+
+ l.leftUnit = l.targetLeftUnit;
+ l.topUnit = l.targetTopUnit;
+ l.rightUnit = l.targetRightUnit;
+ l.bottomUnit = l.targetBottomUnit;
+ l.widthUnit = l.targetWidthUnit;
+ l.heightUnit = l.targetHeightUnit;
+
+ impl.layout(l);
+ }
+
+ impl.finalizeLayout(parentElem);
+ }
+
+ /**
* Updates the layout by animating it over time.
*
* @param duration the duration of the animation
- * @see #animate(int, AnimationCallback)
+ * @see #layout(int, AnimationCallback)
*/
- public void animate(int duration) {
- animate(duration, null);
+ public void layout(int duration) {
+ layout(duration, null);
}
/**
@@ -310,7 +419,7 @@
* @param duration the duration of the animation
* @param callback the animation callback
*/
- public void animate(int duration, final AnimationCallback callback) {
+ public void layout(int duration, final AnimationCallback callback) {
// Deal with constraint changes (e.g. left-width => right-width, etc)
int parentWidth = parentElem.getClientWidth();
int parentHeight = parentElem.getClientHeight();
@@ -378,132 +487,23 @@
}
/**
- * Asserts that the given child element is managed by this layout
- *
- * @param elem the element to be tested
- */
- public void assertIsChild(Element elem) {
- assert elem.getParentElement().getParentElement() == this.parentElem : "Element is not a child of this layout";
- }
-
- /**
* This method must be called when the parent element becomes attached to the
* document.
*
- * @see #detach()
+ * @see #onDetach()
*/
- public void attach() {
- impl.attach(parentElem);
- }
-
- /**
- * Attaches a child element to this layout.
- *
- * <p>
- * This method will attach the child to the layout, removing it from its
- * current parent element. Use the {@link Layer} it returns to manipulate the
- * child.
- * </p>
- *
- * @param child the child to be attached
- * @return the {@link Layer} associated with the element
- */
- public Layer attachChild(Element child) {
- return attachChild(child, null);
- }
-
- /**
- * Attaches a child element to this layout.
- *
- * <p>
- * This method will attach the child to the layout, removing it from its
- * current parent element. Use the {@link Layer} it returns to manipulate the
- * child.
- * </p>
- *
- * @param child the child to be attached
- * @param userObject an arbitrary object to be associated with this layer
- * @return the {@link Layer} associated with the element
- */
- public Layer attachChild(Element child, Object userObject) {
- Element container = impl.attachChild(parentElem, child);
- Layer layer = new Layer(container, child, userObject);
- layers.add(layer);
- return layer;
+ public void onAttach() {
+ impl.onAttach(parentElem);
}
/**
* This method must be called when the parent element becomes detached from
* the document.
*
- * @see #attach()
+ * @see #onAttach()
*/
- public void detach() {
- impl.detach(parentElem);
- }
-
- /**
- * Causes the parent element to fill its own parent.
- *
- * <p>
- * This is most useful for top-level layouts that need to follow the size of
- * another element, such as the <body>.
- * </p>
- */
- public void fillParent() {
- impl.fillParent(parentElem);
- }
-
- /**
- * Returns the size of one unit, in pixels, in the context of this layout.
- *
- * <p>
- * This will work for any unit type, but be aware that certain unit types,
- * such as {@link Unit#EM}, and {@link Unit#EX}, will return different values
- * based upon the parent's associated font size. {@link Unit#PCT} is dependent
- * upon the parent's actual size, and the axis to be measured.
- * </p>
- *
- * @param unit the unit type to be measured
- * @param vertical whether the unit to be measured is on the vertical or
- * horizontal axis (this matters only for {@link Unit#PCT})
- * @return the unit size, in pixels
- */
- public double getUnitSize(Unit unit, boolean vertical) {
- return impl.getUnitSizeInPixels(parentElem, unit, vertical);
- }
-
- /**
- * Updates this layout's children immediately. This method <em>must</em> be
- * called after updating any of its children's {@link Layer layers}.
- */
- public void layout() {
- for (Layer l : layers) {
- l.left = l.sourceLeft = l.targetLeft;
- l.top = l.sourceTop = l.targetTop;
- l.right = l.sourceRight = l.targetRight;
- l.bottom = l.sourceBottom = l.targetBottom;
- l.width = l.sourceWidth = l.targetWidth;
- l.height = l.sourceHeight = l.targetHeight;
-
- l.setLeft = l.setTargetLeft;
- l.setTop = l.setTargetTop;
- l.setRight = l.setTargetRight;
- l.setBottom = l.setTargetBottom;
- l.setWidth = l.setTargetWidth;
- l.setHeight = l.setTargetHeight;
-
- l.leftUnit = l.targetLeftUnit;
- l.topUnit = l.targetTopUnit;
- l.rightUnit = l.targetRightUnit;
- l.bottomUnit = l.targetBottomUnit;
- l.widthUnit = l.targetWidthUnit;
- l.heightUnit = l.targetHeightUnit;
-
- impl.layout(l);
- }
-
- impl.finalizeLayout(parentElem);
+ public void onDetach() {
+ impl.onDetach(parentElem);
}
/**
diff --git a/user/src/com/google/gwt/layout/client/LayoutImpl.java b/user/src/com/google/gwt/layout/client/LayoutImpl.java
index 4085413..9eccd0d 100644
--- a/user/src/com/google/gwt/layout/client/LayoutImpl.java
+++ b/user/src/com/google/gwt/layout/client/LayoutImpl.java
@@ -60,10 +60,6 @@
protected DivElement relativeRuler;
- public void attach(Element parent) {
- // Do nothing. This exists only to help LayoutImplIE6 avoid memory leaks.
- }
-
public Element attachChild(Element parent, Element child) {
DivElement container = Document.get().createDivElement();
container.appendChild(child);
@@ -81,10 +77,6 @@
return container;
}
- public void detach(Element parent) {
- // Do nothing. This exists only to help LayoutImplIE6 avoid memory leaks.
- }
-
public void fillParent(Element elem) {
Style style = elem.getStyle();
style.setPosition(Position.ABSOLUTE);
@@ -147,6 +139,14 @@
? (layer.height + layer.heightUnit.getType()) : "");
}
+ public void onAttach(Element parent) {
+ // Do nothing. This exists only to help LayoutImplIE6 avoid memory leaks.
+ }
+
+ public void onDetach(Element parent) {
+ // Do nothing. This exists only to help LayoutImplIE6 avoid memory leaks.
+ }
+
public void removeChild(Element container, Element child) {
container.removeFromParent();
diff --git a/user/src/com/google/gwt/layout/client/LayoutImplIE6.java b/user/src/com/google/gwt/layout/client/LayoutImplIE6.java
index 38231a5..d5e3c5d 100644
--- a/user/src/com/google/gwt/layout/client/LayoutImplIE6.java
+++ b/user/src/com/google/gwt/layout/client/LayoutImplIE6.java
@@ -111,16 +111,6 @@
elem[name] = value;
}-*/;
- @Override
- public void attach(Element parent) {
- if (UserAgent.isIE6()) {
- // No need to re-connect layer refs. This will be taken care of
- // automatically in layout().
- initResizeHandler(parent);
- initUnitChangeHandler(parent, relativeRuler);
- }
- }
-
public Element attachChild(Element parent, Element child) {
if (!UserAgent.isIE6()) {
return super.attachChild(parent, child);
@@ -142,15 +132,6 @@
}
@Override
- public void detach(Element parent) {
- if (UserAgent.isIE6()) {
- removeLayerRefs(parent);
- removeResizeHandler(parent);
- removeUnitChangeHandler(relativeRuler);
- }
- }
-
- @Override
public void fillParent(Element elem) {
if (!UserAgent.isIE6()) {
super.fillParent(elem);
@@ -190,6 +171,25 @@
setLayer(elem, layer);
}
+ @Override
+ public void onAttach(Element parent) {
+ if (UserAgent.isIE6()) {
+ // No need to re-connect layer refs. This will be taken care of
+ // automatically in layout().
+ initResizeHandler(parent);
+ initUnitChangeHandler(parent, relativeRuler);
+ }
+ }
+
+ @Override
+ public void onDetach(Element parent) {
+ if (UserAgent.isIE6()) {
+ removeLayerRefs(parent);
+ removeResizeHandler(parent);
+ removeUnitChangeHandler(relativeRuler);
+ }
+ }
+
private native void fillParentImpl(Element elem) /*-{
// Hook the parent element's onresize event. If the parent is the <body>,
// then we have to go through the Window class to get the resize event,
diff --git a/user/src/com/google/gwt/user/client/ui/LayoutPanel.java b/user/src/com/google/gwt/user/client/ui/LayoutPanel.java
index 99d067b..ddfe76b 100644
--- a/user/src/com/google/gwt/user/client/ui/LayoutPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/LayoutPanel.java
@@ -122,7 +122,7 @@
* @see #layout(int, com.google.gwt.layout.client.Layout.AnimationCallback)
*/
public void layout(int duration) {
- layout.animate(duration);
+ layout.layout(duration);
}
/**
@@ -143,7 +143,7 @@
* @see #layout(int, com.google.gwt.layout.client.Layout.AnimationCallback)
*/
public void layout(int duration, final Layout.AnimationCallback callback) {
- layout.animate(duration, new Layout.AnimationCallback() {
+ layout.layout(duration, new Layout.AnimationCallback() {
public void onAnimationComplete() {
// Chain to the passed callback.
if (callback != null) {
@@ -195,11 +195,11 @@
@Override
protected void onLoad() {
- layout.attach();
+ layout.onAttach();
}
@Override
protected void onUnload() {
- layout.detach();
+ layout.onDetach();
}
}
diff --git a/user/src/com/google/gwt/user/client/ui/RootLayoutPanel.java b/user/src/com/google/gwt/user/client/ui/RootLayoutPanel.java
index 9c30378..88969e0 100644
--- a/user/src/com/google/gwt/user/client/ui/RootLayoutPanel.java
+++ b/user/src/com/google/gwt/user/client/ui/RootLayoutPanel.java
@@ -81,7 +81,7 @@
@Override
protected void onLoad() {
- getLayout().attach();
+ getLayout().onAttach();
getLayout().fillParent();
}
}
diff --git a/user/test/com/google/gwt/layout/client/LayoutTest.java b/user/test/com/google/gwt/layout/client/LayoutTest.java
index 7611556..2a8248c 100644
--- a/user/test/com/google/gwt/layout/client/LayoutTest.java
+++ b/user/test/com/google/gwt/layout/client/LayoutTest.java
@@ -54,7 +54,7 @@
@Override
public String getModuleName() {
- return "com.google.gwt.layout.Layout";
+ return "com.google.gwt.layout.LayoutTest";
}
/**
@@ -164,7 +164,7 @@
container.getStyle().setHeight(256, PX);
Layout layout = new Layout(parent);
- layout.attach();
+ layout.onAttach();
Layer layer = layout.attachChild(child);
layer.setTopBottom(0, PX, 0, PX);
layer.setLeftRight(0, PX, 0, PX);
@@ -187,7 +187,7 @@
assertEquals(256, parent.getOffsetWidth());
assertEquals(256, child.getOffsetWidth());
- layout.detach();
+ layout.onDetach();
}
/**
@@ -379,7 +379,7 @@
doc.getBody().appendChild(parent);
layout = new Layout(parent);
- layout.attach();
+ layout.onAttach();
layout.fillParent();
layer0 = layout.attachChild(child0);
@@ -393,7 +393,7 @@
protected void gwtTearDown() throws Exception {
Window.enableScrolling(true);
Document.get().getBody().removeChild(parent);
- layout.detach();
+ layout.onDetach();
}
private void assertLeftRightTopBottomUnitsMakeSense(Element elem) {
@@ -500,7 +500,7 @@
after.setupLayers(layer0, layer1);
delayTestFinish(200);
- layout.animate(100, new Layout.AnimationCallback() {
+ layout.layout(100, new Layout.AnimationCallback() {
public void onAnimationComplete() {
// Assert that the two layers have swapped positions.
assertEquals(l0, wrapper1.getOffsetLeft());