From: John Ahlroos Date: Thu, 13 Sep 2012 08:02:13 +0000 (+0300) Subject: Ensures negative height is not returned in HorizontalLayout height calculations ... X-Git-Tag: 7.0.0.beta1~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=eef6af3029923b6ad9076e264394bfa8b9b4b789;p=vaadin-framework.git Ensures negative height is not returned in HorizontalLayout height calculations #9596 --- diff --git a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java index c40dc27581..b1d31370b3 100644 --- a/client/src/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/com/vaadin/client/ui/AbstractComponentConnector.java @@ -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 diff --git a/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java b/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java index 7092109d11..8fb7b6d936 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java @@ -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); diff --git a/shared/src/com/vaadin/shared/ui/ComponentStateUtil.java b/shared/src/com/vaadin/shared/ui/ComponentStateUtil.java index a7b3d5a281..5e6700b425 100644 --- a/shared/src/com/vaadin/shared/ui/ComponentStateUtil.java +++ b/shared/src/com/vaadin/shared/ui/ComponentStateUtil.java @@ -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. *