summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ahlroos <john@vaadin.com>2012-09-13 11:02:13 +0300
committerJohn Ahlroos <john@vaadin.com>2012-09-13 11:02:13 +0300
commiteef6af3029923b6ad9076e264394bfa8b9b4b789 (patch)
treea622577e9f2360faa8254d7874b5ee355a9f8fef
parent0bd47dcbb4813d08ecba6941ac63465f21cfde0b (diff)
downloadvaadin-framework-eef6af3029923b6ad9076e264394bfa8b9b4b789.tar.gz
vaadin-framework-eef6af3029923b6ad9076e264394bfa8b9b4b789.zip
Ensures negative height is not returned in HorizontalLayout height calculations #9596
-rw-r--r--client/src/com/vaadin/client/ui/AbstractComponentConnector.java4
-rw-r--r--client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java42
-rw-r--r--shared/src/com/vaadin/shared/ui/ComponentStateUtil.java8
3 files changed, 45 insertions, 9 deletions
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.
*