]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix caption listener leak and caption measurement (#13741)
authorJuuso Valli <juuso@vaadin.com>
Fri, 23 May 2014 08:00:48 +0000 (11:00 +0300)
committerJuuso Valli <juuso@vaadin.com>
Fri, 23 May 2014 11:03:17 +0000 (14:03 +0300)
Reverting the previous fix to caption measurement, it caused a leak with
the listeners.
Change-Id: If1c06db692c0e829d91528eceb49a9a07f58ed4a

client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java
client/src/com/vaadin/client/ui/orderedlayout/Slot.java

index 918b7fbdaae5a5d9fa759dfe655f5e254081611a..0c09ae49c6f36e7e385fb63b19e2a88b31515a1b 100644 (file)
@@ -204,6 +204,13 @@ public abstract class AbstractOrderedLayoutConnector extends
      */
     private boolean hasChildrenWithRelativeHeight = false;
 
+    /**
+     * Keep track of whether any child has relative width. Used to determine
+     * whether measurements are needed to make relative child widths work
+     * together with undefined container width.
+     */
+    private boolean hasChildrenWithRelativeWidth = false;
+
     /**
      * Keep track of whether any child is middle aligned. Used to determine if
      * measurements are needed to make middle aligned children work.
@@ -423,6 +430,8 @@ public abstract class AbstractOrderedLayoutConnector extends
         processedResponseId = lastResponseId;
 
         hasChildrenWithRelativeHeight = false;
+        hasChildrenWithRelativeWidth = false;
+
         hasChildrenWithMiddleAlignment = false;
 
         needsExpand = getWidget().vertical ? !isUndefinedHeight()
@@ -476,6 +485,9 @@ public abstract class AbstractOrderedLayoutConnector extends
             if (child.isRelativeHeight()) {
                 hasChildrenWithRelativeHeight = true;
             }
+            if (child.isRelativeWidth()) {
+                hasChildrenWithRelativeWidth = true;
+            }
         }
 
         if (needsFixedHeight()) {
@@ -575,7 +587,7 @@ public abstract class AbstractOrderedLayoutConnector extends
             if (slot.hasCaption()) {
                 slot.setCaptionResizeListener(slotCaptionResizeListener);
             }
-        } else if ((child.isRelativeHeight() || child.isRelativeWidth())
+        } else if ((hasChildrenWithRelativeHeight || hasChildrenWithRelativeWidth)
                 && slot.hasCaption()) {
             /*
              * If the slot has caption, we need to listen for its size changes
index f16351ab54b39705191168aa9097c3746d95b117..b1d7dd280420a19e6e0a305be092777b35de1657 100644 (file)
@@ -79,25 +79,6 @@ public final class Slot extends SimplePanel {
         }
     };
 
-    /*
-     * This listener is only used to force the LayoutManager to measure the
-     * caption size. #13741
-     */
-    private static final ElementResizeListener CAPTION_DUMMY_LISTENER = new ElementResizeListener() {
-        @Override
-        public void onElementResize(ElementResizeEvent e) {
-            // Do nothing
-            // We must include a listener for the element so
-            // that it gets measured during layout.
-
-            // TODO Alter the way in which LayoutManager
-            // determines which elements should be measured.
-            // There should be an easier way to do add items
-            // to LayoutManager.measuredNonConnectorElements
-            // (#13792)
-        }
-    };
-
     // Caption is placed after component unless there is some part which
     // moves it above.
     private CaptionPosition captionPosition = CaptionPosition.RIGHT;
@@ -490,8 +471,6 @@ public final class Slot extends SimplePanel {
         if (captionText != null || icon != null || error != null || required) {
             if (caption == null) {
                 caption = DOM.createDiv();
-                layout.getLayoutManager().addElementResizeListener(caption,
-                        CAPTION_DUMMY_LISTENER);
                 captionWrap = DOM.createDiv();
                 captionWrap.addClassName(StyleConstants.UI_WIDGET);
                 captionWrap.addClassName("v-has-caption");
@@ -510,8 +489,6 @@ public final class Slot extends SimplePanel {
             getElement().appendChild(widget.getElement());
             adopt(widget);
             captionWrap.removeFromParent();
-            layout.getLayoutManager().removeElementResizeListener(caption,
-                    CAPTION_DUMMY_LISTENER);
             caption = null;
             captionWrap = null;