From: Matti Tahvonen Date: Wed, 3 Sep 2008 13:12:52 +0000 (+0000) Subject: fixes #2040 (accordion with defined height) X-Git-Tag: 6.7.0.beta1~4218 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=772990262d2fcb4a6957e7bb6e126a782b6ecb34;p=vaadin-framework.git fixes #2040 (accordion with defined height) svn changeset:5344/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java index ef50c7b950..7923d3d977 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java @@ -120,53 +120,56 @@ public class IAccordion extends ITabsheetBase implements return; } - if (height != null && height != "") { - // Detach visible widget from document flow for a while to calculate - // used height correctly - Widget w = item.getPaintable(); - String originalPositioning = ""; - if (w != null) { - originalPositioning = DOM.getStyleAttribute(w.getElement(), - "position"); - DOM.setStyleAttribute(w.getElement(), "visibility", "hidden"); - DOM.setStyleAttribute(w.getElement(), "position", "absolute"); + if (height != null && !height.equals("")) { + + int usedPixels = 0; + for (Iterator iterator = stack.iterator(); iterator.hasNext();) { + StackItem si = (StackItem) iterator.next(); + if (si != item) { + usedPixels += si.getOffsetHeight(); + } } - DOM.setStyleAttribute(item.getContainerElement(), "height", "0"); // Calculate target height super.setHeight(height); - int targetHeight = DOM.getElementPropertyInt(DOM - .getParent(getElement()), "offsetHeight"); - super.setHeight(""); - // Calculate used height - int usedHeight = getOffsetHeight(); + int offsetHeight = getOffsetHeight(); - int h = targetHeight - usedHeight; - if (h < 0) { - h = 0; - } - DOM.setStyleAttribute(item.getContainerElement(), "height", h - + "px"); - - // Put widget back into normal flow - if (w != null) { - DOM.setStyleAttribute(w.getElement(), "position", - originalPositioning); - DOM.setStyleAttribute(w.getElement(), "visibility", ""); + int spaceForOpenItem = offsetHeight - usedPixels; + + if (spaceForOpenItem > 0) { + item.setHeight(spaceForOpenItem + "px"); } + } else { - DOM.setStyleAttribute(item.getContainerElement(), "height", ""); + super.setHeight(""); + item.setHeight(""); } - Util.runDescendentsLayout(this); + Util.runDescendentsLayout(item); } /** - * TODO Caption widget not properly attached + * */ protected class StackItem extends ComplexPanel implements ClickListener { + public void setHeight(String height) { + super.setHeight(height); + if (!"".equals(height)) { + int offsetHeight = getOffsetHeight(); + int captionHeight = DOM.getElementPropertyInt(captionNode, + "offsetHeight"); + int contentSpace = offsetHeight - captionHeight; + if (contentSpace > 0) { + DOM.setStyleAttribute(content, "height", contentSpace + + "px"); + } + } else { + DOM.setStyleAttribute(content, "height", ""); + } + } + private ICaption caption; private boolean open = false; private Element content = DOM.createDiv(); @@ -190,6 +193,7 @@ public class IAccordion extends ITabsheetBase implements // Force 'hasLayout' in IE6 (prevents layout problems) if (BrowserInfo.get().isIE6()) { DOM.setStyleAttribute(content, "zoom", "1"); + DOM.setStyleAttribute(getElement(), "overflow", "hidden"); } close(); @@ -215,6 +219,7 @@ public class IAccordion extends ITabsheetBase implements } DOM.setStyleAttribute(content, "visibility", ""); DOM.setStyleAttribute(content, "position", ""); + DOM.setStyleAttribute(content, "top", ""); addStyleDependentName("open"); if (getPaintable() != null) { add(getPaintable(), content); @@ -225,7 +230,9 @@ public class IAccordion extends ITabsheetBase implements open = false; DOM.setStyleAttribute(content, "visibility", "hidden"); DOM.setStyleAttribute(content, "position", "absolute"); + DOM.setStyleAttribute(content, "top", "0"); removeStyleDependentName("open"); + setHeight(""); // only open StackItem may contain height } public boolean isOpen() {