]> source.dussan.org Git - vaadin-framework.git/commitdiff
Ensures negative height is not returned in HorizontalLayout height calculations ...
authorJohn Ahlroos <john@vaadin.com>
Thu, 13 Sep 2012 08:02:13 +0000 (11:02 +0300)
committerJohn Ahlroos <john@vaadin.com>
Thu, 13 Sep 2012 08:02:13 +0000 (11:02 +0300)
client/src/com/vaadin/client/ui/AbstractComponentConnector.java
client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java
shared/src/com/vaadin/shared/ui/ComponentStateUtil.java

index c40dc27581ffeed8b976eb81cc941520e54049bb..b1d31370b30802883f1f7c866e10b4bf2891ec21 100644 (file)
@@ -230,12 +230,12 @@ public abstract class AbstractComponentConnector extends AbstractConnector
 
     @Override
     public boolean isRelativeHeight() {
-        return getState().height != null && getState().height.endsWith("%");
+        return ComponentStateUtil.isRelativeHeight(getState());
     }
 
     @Override
     public boolean isRelativeWidth() {
-        return getState().width != null && getState().width.endsWith("%");
+        return ComponentStateUtil.isRelativeWidth(getState());
     }
 
     @Override
index 7092109d115d5b95c617a809c7a289020a5140a9..8fb7b6d936b6cb0d5fc0efb14394143c97e2d114 100644 (file)
@@ -404,14 +404,29 @@ public abstract class AbstractOrderedLayoutConnector extends
      * Does the layout need a fixed height?
      */
     private boolean needsFixedHeight() {
-        if (!getWidget().vertical
-                && isUndefinedHeight()
-                && (hasRelativeHeight.size() > 0 || (hasVerticalAlignment
-                        .size() > 0 && hasVerticalAlignment.size() < getChildren()
-                        .size()))) {
-            return true;
+        boolean isVertical = getWidget().vertical;
+        boolean hasChildrenWithVerticalAlignmentCenterOrBottom = !hasVerticalAlignment
+                .isEmpty();
+        boolean allChildrenHasVerticalAlignmentCenterOrBottom = hasVerticalAlignment
+                .size() == getChildren().size();
+        
+        if(isVertical){
+            return false;
         }
-        return false;
+        
+        else if(!isUndefinedHeight()){
+            return false;
+        }
+        
+        else if (!hasChildrenWithVerticalAlignmentCenterOrBottom) {
+            return false;
+        }
+
+        else if (allChildrenHasVerticalAlignmentCenterOrBottom) {
+            return false;
+        }
+
+        return true;
     }
 
     /**
@@ -493,6 +508,7 @@ public abstract class AbstractOrderedLayoutConnector extends
     private void updateLayoutHeight() {
         if (needsFixedHeight()) {
             int h = getMaxHeight();
+            assert(h >= 0);
             h += getLayoutManager().getBorderHeight(getWidget().getElement())
                     + getLayoutManager().getPaddingHeight(
                             getWidget().getElement());
@@ -518,6 +534,12 @@ public abstract class AbstractOrderedLayoutConnector extends
                     (Element) el.getParentElement().cast());
             if (needsMeasure.contains(el)) {
                 int h = getLayoutManager().getOuterHeight(el);
+                if (h == -1) {
+                    // Height has not yet been measured so using a more
+                    // conventional method instead.
+                    h = Util.getRequiredHeight(el);
+                }
+
                 String sHeight = el.getStyle().getHeight();
                 // Only add the caption size to the height of the slot if
                 // coption position is top or bottom
@@ -531,6 +553,12 @@ public abstract class AbstractOrderedLayoutConnector extends
                 }
             } else {
                 int h = getLayoutManager().getOuterHeight(el);
+                if (h == -1) {
+                    // Height has not yet been measured so using a more
+                    // conventional method instead.
+                    h = Util.getRequiredHeight(el);
+                }
+
                 if (childCaptionElementHeight.containsKey(el)
                         && (pos == CaptionPosition.TOP || pos == CaptionPosition.BOTTOM)) {
                     h += childCaptionElementHeight.get(el);
index a7b3d5a281844b5818aa2fd4c43df44d4c61d2e9..5e6700b425e92d9b1d9fb32b55bd0aa187c44660 100644 (file)
@@ -26,6 +26,14 @@ public final class ComponentStateUtil {
         return state.styles != null && !state.styles.isEmpty();
     }
 
+    public static final boolean isRelativeWidth(ComponentState state) {
+        return state.width != null && state.width.endsWith("%");
+    }
+
+    public static final boolean isRelativeHeight(ComponentState state) {
+        return state.height != null && state.height.endsWith("%");
+    }
+
     /**
      * Removes an event listener id.
      *