From: Matti Tahvonen Date: Wed, 28 Oct 2009 10:11:27 +0000 (+0000) Subject: merged [9424] (partly by hand because of source folder refactoring) from 6.1 X-Git-Tag: 6.7.0.beta1~2369 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=08cc349e8b4e81f5f5f3c037417d32d661bd09d7;p=vaadin-framework.git merged [9424] (partly by hand because of source folder refactoring) from 6.1 svn changeset:9425/svn branch:6.2 --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VForm.java b/src/com/vaadin/terminal/gwt/client/ui/VForm.java index 97fbf9b72a..7117d2cebf 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VForm.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VForm.java @@ -48,9 +48,7 @@ public class VForm extends ComplexPanel implements Container { private RenderInformation renderInformation = new RenderInformation(); - private int borderPaddingHorizontal; - - private int borderPaddingVertical; + private int borderPaddingHorizontal = -1; private boolean rendering = false; @@ -75,25 +73,13 @@ public class VForm extends ComplexPanel implements Container { public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { rendering = true; - boolean measure = false; - if (this.client == null) { - this.client = client; - measure = true; - } + this.client = client; if (client.updateComponent(this, uidl, false)) { rendering = false; return; } - if (measure) { - // Measure the border when the style names have been set - borderPaddingVertical = getOffsetHeight(); - int ow = getOffsetWidth(); - int dow = desc.getOffsetWidth(); - borderPaddingHorizontal = ow - dow; - } - boolean legendEmpty = true; if (uidl.hasAttribute("caption")) { DOM.setInnerText(caption, uidl.getStringAttribute("caption")); @@ -138,19 +124,8 @@ public class VForm extends ComplexPanel implements Container { // TODO Check if this is needed client.runDescendentsLayout(this); - final UIDL layoutUidl = uidl.getChildUIDL(0); - Container newLo = (Container) client.getPaintable(layoutUidl); - if (lo == null) { - lo = newLo; - add((Widget) lo, fieldContainer); - } else if (lo != newLo) { - client.unregisterPaintable(lo); - remove((Widget) lo); - lo = newLo; - add((Widget) lo, fieldContainer); - } - lo.updateFromUIDL(layoutUidl, client); - + // first render footer so it will be easier to handle relative height of + // main layout if (uidl.getChildCount() > 1) { // render footer Container newFooter = (Container) client.getPaintable(uidl @@ -165,13 +140,28 @@ public class VForm extends ComplexPanel implements Container { } footer = newFooter; footer.updateFromUIDL(uidl.getChildUIDL(1), client); + updateSize(); } else { if (footer != null) { remove((Widget) footer); client.unregisterPaintable(footer); + updateSize(); } } + final UIDL layoutUidl = uidl.getChildUIDL(0); + Container newLo = (Container) client.getPaintable(layoutUidl); + if (lo == null) { + lo = newLo; + add((Widget) lo, fieldContainer); + } else if (lo != newLo) { + client.unregisterPaintable(lo); + remove((Widget) lo); + lo = newLo; + add((Widget) lo, fieldContainer); + } + lo.updateFromUIDL(layoutUidl, client); + rendering = false; } @@ -181,7 +171,7 @@ public class VForm extends ComplexPanel implements Container { renderInformation.setContentAreaHeight(renderInformation .getRenderedSize().getHeight() - - borderPaddingVertical); + - getSpaceConsumedVertically()); if (BrowserInfo.get().isIE6()) { getElement().getStyle().setProperty("overflow", "hidden"); } @@ -192,18 +182,7 @@ public class VForm extends ComplexPanel implements Container { public RenderSpace getAllocatedSpace(Widget child) { if (child == lo) { - int hPixels = 0; - if (!"".equals(height)) { - hPixels = getOffsetHeight(); - hPixels -= borderPaddingVertical; - hPixels -= footerContainer.getOffsetHeight(); - hPixels -= errorMessage.getOffsetHeight(); - hPixels -= desc.getOffsetHeight(); - - } - - return new RenderSpace(renderInformation.getContentAreaSize() - .getWidth(), hPixels); + return renderInformation.getContentAreaSize(); } else if (child == footer) { return new RenderSpace(renderInformation.getContentAreaSize() .getWidth(), 0); @@ -271,8 +250,26 @@ public class VForm extends ComplexPanel implements Container { updateSize(); } + /** + * @return pixels consumed by decoration, captions, descrioptiosn etc.. In + * other words space, not used by the actual layout in form. + */ + private int getSpaceConsumedVertically() { + int offsetHeight2 = fieldSet.getOffsetHeight(); + int offsetHeight3 = fieldContainer.getOffsetHeight(); + int borderPadding = offsetHeight2 - offsetHeight3; + return borderPadding; + } + @Override public void setWidth(String width) { + if (borderPaddingHorizontal < 0) { + // measure excess size lazyly after stylename setting, but before + // setting width + int ow = getOffsetWidth(); + int dow = desc.getOffsetWidth(); + borderPaddingHorizontal = ow - dow; + } if (Util.equals(this.width, width)) { return; } diff --git a/tests/src/com/vaadin/tests/components/form/FormWithRelativelySizedLayout.java b/tests/src/com/vaadin/tests/components/form/FormWithRelativelySizedLayout.java new file mode 100644 index 0000000000..17fe4477c3 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/form/FormWithRelativelySizedLayout.java @@ -0,0 +1,52 @@ +package com.vaadin.tests.components.form; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Component; +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.Form; +import com.vaadin.ui.Label; + +public class FormWithRelativelySizedLayout extends TestBase { + + @Override + protected String getDescription() { + return "Forms mainlayouts relative height should be everyting left out from footer and possible borders/paddings. "; + } + + @Override + protected Integer getTicketNumber() { + return 3488; + } + + @Override + protected void setup() { + + Form f = new Form(); + f.setCaption("Form, full size"); + + f.setWidth("100%"); + f.setHeight("100%"); + + Label l = new Label( + "This green label should consume all available space, pushing ok button to bottom of the view"); + l.setSizeFull(); + + CssLayout lo = new CssLayout() { + @Override + protected String getCss(Component c) { + return "background: green;color:red;"; + } + }; + lo.setSizeFull(); + + f.setLayout(lo); + lo.addComponent(l); + + f.getFooter().addComponent(new Button("OK button")); + + getLayout().setSizeFull(); + getLayout().addComponent(f); + } + +}