From: Artur Signell Date: Mon, 26 Nov 2012 18:27:02 +0000 (+0200) Subject: Fixed Window to support empty content (#10325) X-Git-Tag: 7.0.0.beta11~125 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F88%2F388%2F3;p=vaadin-framework.git Fixed Window to support empty content (#10325) Change-Id: I90a5f4e4011452f07e4bea2cef2207ad8635cd31 --- diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java index 1b35b020f2..dc64eb7529 100644 --- a/client/src/com/vaadin/client/ui/VWindow.java +++ b/client/src/com/vaadin/client/ui/VWindow.java @@ -39,7 +39,6 @@ import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.BrowserInfo; -import com.vaadin.client.ComponentConnector; import com.vaadin.client.ConnectorMap; import com.vaadin.client.Console; import com.vaadin.client.Focusable; @@ -78,9 +77,6 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, public static final int Z_INDEX = 10000; - /** For internal use only. May be removed or replaced in the future. */ - public ComponentConnector layout; - /** For internal use only. May be removed or replaced in the future. */ public Element contents; @@ -742,16 +738,17 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, } private void updateContentsSize() { + Widget childWidget = getWidget(); + // Update child widget dimensions - if (client != null) { - Widget childWidget = layout.getWidget(); + if (client != null && childWidget != null) { client.handleComponentRelativeSize(childWidget); if (childWidget instanceof HasWidgets) { client.runDescendentsLayout((HasWidgets) childWidget); } } - LayoutManager layoutManager = LayoutManager.get(client); + LayoutManager layoutManager = getLayoutManager(); layoutManager.setNeedsMeasure(ConnectorMap.get(client).getConnector( this)); layoutManager.layoutNow(); @@ -939,18 +936,22 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, } private int getDecorationHeight() { - LayoutManager lm = layout.getLayoutManager(); + LayoutManager lm = getLayoutManager(); int headerHeight = lm.getOuterHeight(header); int footerHeight = lm.getOuterHeight(footer); return headerHeight + footerHeight; } + private LayoutManager getLayoutManager() { + return LayoutManager.get(client); + } + public int getMinWidth() { return MIN_CONTENT_AREA_WIDTH + getDecorationWidth(); } private int getDecorationWidth() { - LayoutManager layoutManager = layout.getLayoutManager(); + LayoutManager layoutManager = getLayoutManager(); return layoutManager.getOuterWidth(getElement()) - contentPanel.getElement().getOffsetWidth(); } diff --git a/client/src/com/vaadin/client/ui/window/WindowConnector.java b/client/src/com/vaadin/client/ui/window/WindowConnector.java index 4f1825e749..a2bac218f4 100644 --- a/client/src/com/vaadin/client/ui/window/WindowConnector.java +++ b/client/src/com/vaadin/client/ui/window/WindowConnector.java @@ -212,7 +212,6 @@ public class WindowConnector extends AbstractSingleComponentContainerConnector @Override public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) { // We always have 1 child, unless the child is hidden - getWidget().layout = getContent(); getWidget().contentPanel.setWidget(getContentWidget()); } @@ -220,12 +219,13 @@ public class WindowConnector extends AbstractSingleComponentContainerConnector public void layout() { LayoutManager lm = getLayoutManager(); VWindow window = getWidget(); - ComponentConnector layout = window.layout; + ComponentConnector content = getContent(); + boolean hasContent = (content != null); Element contentElement = window.contentPanel.getElement(); if (!minWidthChecked) { - boolean needsMinWidth = !isUndefinedWidth() - || layout.isRelativeWidth(); + boolean needsMinWidth = !isUndefinedWidth() || !hasContent + || content.isRelativeWidth(); int minWidth = window.getMinWidth(); if (needsMinWidth && lm.getInnerWidth(contentElement) < minWidth) { minWidthChecked = true; @@ -235,8 +235,8 @@ public class WindowConnector extends AbstractSingleComponentContainerConnector minWidthChecked = true; } - boolean needsMinHeight = !isUndefinedHeight() - || layout.isRelativeHeight(); + boolean needsMinHeight = !isUndefinedHeight() || !hasContent + || content.isRelativeHeight(); int minHeight = window.getMinHeight(); if (needsMinHeight && lm.getInnerHeight(contentElement) < minHeight) { // Use minimum height if less than a certain size @@ -259,26 +259,29 @@ public class WindowConnector extends AbstractSingleComponentContainerConnector * otherwise not take the scrollbar into account when calculating the * height. */ - Element layoutElement = layout.getWidget().getElement(); - Style childStyle = layoutElement.getStyle(); - if (layout.isRelativeHeight() && !BrowserInfo.get().isIE9()) { - childStyle.setPosition(Position.ABSOLUTE); - - Style wrapperStyle = contentElement.getStyle(); - if (window.getElement().getStyle().getWidth().length() == 0 - && !layout.isRelativeWidth()) { - /* - * Need to lock width to make undefined width work even with - * absolute positioning - */ - int contentWidth = lm.getOuterWidth(layoutElement); - wrapperStyle.setWidth(contentWidth, Unit.PX); + if (hasContent) { + Element layoutElement = content.getWidget().getElement(); + Style childStyle = layoutElement.getStyle(); + if (content.isRelativeHeight() && !BrowserInfo.get().isIE9()) { + childStyle.setPosition(Position.ABSOLUTE); + + Style wrapperStyle = contentElement.getStyle(); + if (window.getElement().getStyle().getWidth().length() == 0 + && !content.isRelativeWidth()) { + /* + * Need to lock width to make undefined width work even with + * absolute positioning + */ + int contentWidth = lm.getOuterWidth(layoutElement); + wrapperStyle.setWidth(contentWidth, Unit.PX); + } else { + wrapperStyle.clearWidth(); + } } else { - wrapperStyle.clearWidth(); + childStyle.clearPosition(); } - } else { - childStyle.clearPosition(); } + } @Override diff --git a/uitest/src/com/vaadin/tests/components/ui/EmptyWindow.html b/uitest/src/com/vaadin/tests/components/ui/EmptyWindow.html new file mode 100644 index 0000000000..cc7b0751fc --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/EmptyWindow.html @@ -0,0 +1,27 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.ui.EmptyWindow?restartApplication
screenCaptureemptyWindow
+ + diff --git a/uitest/src/com/vaadin/tests/components/ui/EmptyWindow.java b/uitest/src/com/vaadin/tests/components/ui/EmptyWindow.java new file mode 100644 index 0000000000..c3975921df --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/EmptyWindow.java @@ -0,0 +1,26 @@ +package com.vaadin.tests.components.ui; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Label; +import com.vaadin.ui.Window; + +public class EmptyWindow extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + addWindow(new Window("My empty window")); + setContent(new Label("UI")); + } + + @Override + protected String getTestDescription() { + return "There should be an empty window on the screen. Currently it should have the min width defined in VWindow"; + } + + @Override + protected Integer getTicketNumber() { + return 10325; + } + +}