]> source.dussan.org Git - vaadin-framework.git/commitdiff
Don't include relative sizes in expand compensation (#10222) 74/574/2
authorLeif Åstrand <leif@vaadin.com>
Fri, 4 Jan 2013 15:18:28 +0000 (17:18 +0200)
committerLeif Åstrand <leif@vaadin.com>
Fri, 4 Jan 2013 15:18:28 +0000 (17:18 +0200)
Change-Id: I1b94a8ffbbe66e64a585e1d7729dae3af6d815b6

client/src/com/vaadin/client/ui/orderedlayout/Slot.java
client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java
uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildrenWithoutExpand.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildrenWithoutExpand.java [new file with mode: 0644]

index 8b6ad146694d3270686706e99dc80ea0a91ac8c4..b59c3664c74b70f042e7b725dc641f40e3ac48c4 100644 (file)
@@ -661,4 +661,12 @@ public final class Slot extends SimplePanel {
             getElement().getParentElement().insertBefore(spacer, getElement());
         }
     }
+
+    public boolean isRelativeInDirection(boolean vertical) {
+        if (vertical) {
+            return hasRelativeHeight();
+        } else {
+            return hasRelativeWidth();
+        }
+    }
 }
\ No newline at end of file
index a11251f0b09305f5f9c23910fcc97071db44f702..84f946dec4d1b74432ba9829746dc67b81e2e4db 100644 (file)
@@ -426,10 +426,25 @@ public class VAbstractOrderedLayout extends FlowPanel {
         }
 
         if (isExpanding) {
+            /*
+             * Expanded slots have relative sizes that together add up to 100%.
+             * To make room for slots without expand, we will add padding that
+             * is not considered for relative sizes and a corresponding negative
+             * margin for the unexpanded slots. We calculate the size by summing
+             * the size of all non-expanded non-relative slots.
+             * 
+             * Relatively sized slots without expansion are considered to get
+             * 0px, but we still keep them visible (causing overflows) to help
+             * the developer see what's happening. Forcing them to only get 0px
+             * would make them disappear which would avoid overflows but would
+             * instead cause confusion as they would then just disappear without
+             * any obvious reason.
+             */
             int totalSize = 0;
             for (Widget w : getChildren()) {
                 Slot slot = (Slot) w;
-                if (slot.getExpandRatio() == 0) {
+                if (slot.getExpandRatio() == 0
+                        && !slot.isRelativeInDirection(vertical)) {
 
                     if (layoutManager != null) {
                         // TODO check caption position
diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildrenWithoutExpand.html b/uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildrenWithoutExpand.html
new file mode 100644 (file)
index 0000000..46252bc
--- /dev/null
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.orderedlayout.RelativeChildrenWithoutExpand?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertElementNotPresent</td>
+       <td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertElementNotPresent</td>
+       <td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertElementNotPresent</td>
+       <td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertElementNotPresent</td>
+       <td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::/VVerticalLayout[0]/Slot[1]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertElementNotPresent</td>
+       <td>vaadin=runcomvaadintestscomponentsorderedlayoutRelativeChildrenWithoutExpand::Root/VNotification[0]</td>
+       <td></td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildrenWithoutExpand.java b/uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildrenWithoutExpand.java
new file mode 100644 (file)
index 0000000..a1ac1df
--- /dev/null
@@ -0,0 +1,55 @@
+package com.vaadin.tests.components.orderedlayout;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+
+public class RelativeChildrenWithoutExpand extends AbstractTestUI {
+
+    private final String loremIpsum = "This is a label without expand but with relative width that shouldn't get any space at all. ";
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        final HorizontalLayout horizontalExpand = new HorizontalLayout();
+
+        VerticalLayout vl = new VerticalLayout();
+        vl.addComponent(new Label(getTestDescription()));
+        vl.setSizeFull();
+
+        // Replacing default AbstractTestUI content to get the right expansions
+        setContent(vl);
+
+        HorizontalLayout verticalExpand = new HorizontalLayout();
+        verticalExpand.addComponent(new Button("Add relative child",
+                new Button.ClickListener() {
+                    @Override
+                    public void buttonClick(ClickEvent event) {
+                        horizontalExpand.addComponent(new Label(loremIpsum), 0);
+                    }
+                }));
+        vl.addComponent(verticalExpand);
+        vl.setExpandRatio(verticalExpand, 1);
+
+        horizontalExpand.setWidth("100%");
+        vl.addComponent(horizontalExpand);
+
+        Label lblExpandRatio1 = new Label(
+                "This is an expanding label that will get all of the normal space in the component.");
+        horizontalExpand.addComponent(lblExpandRatio1);
+        horizontalExpand.setExpandRatio(lblExpandRatio1, 1);
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "HorizontalLayout containing relatively sized components that are not expanded should not cause infinite layout loops when scrollbars appear. Add children until the entire space is filled up.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return Integer.valueOf(10222);
+    }
+}
\ No newline at end of file