]> source.dussan.org Git - vaadin-framework.git/commitdiff
Hide components if width 100% + expand ratio 0 #10783 7.0.0.rc2
authorJohn Ahlroos <john@vaadin.com>
Mon, 21 Jan 2013 13:02:56 +0000 (15:02 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 23 Jan 2013 12:31:36 +0000 (14:31 +0200)
Change-Id: I5ca5eac5fbfeec744078ebcb83f08192c1bf2af8

client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java
client/src/com/vaadin/client/ui/orderedlayout/VAbstractOrderedLayout.java
uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalRelativeSizeWithoutExpand.html [new file with mode: 0755]
uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalRelativeSizeWithoutExpand.java [new file with mode: 0755]
uitest/src/com/vaadin/tests/components/orderedlayout/OrderedLayoutCases.java
uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildWithoutExpand.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/orderedlayout/VerticalRelativeSizeWithoutExpand.html [new file with mode: 0755]
uitest/src/com/vaadin/tests/components/orderedlayout/VerticalRelativeSizeWithoutExpand.java [new file with mode: 0755]

index 5653e1d1cfa6e15a8853a04464908bcd3f3effc7..afe81c79a0907c8c4bb6e220ca79dc4531de2011 100644 (file)
@@ -251,9 +251,6 @@ public abstract class AbstractOrderedLayoutConnector extends
         slot.setCaption(caption, iconUrlString, styles, error, showError,
                 required, enabled);
 
-        slot.setRelativeWidth(child.isRelativeWidth());
-        slot.setRelativeHeight(child.isRelativeHeight());
-
         if (slot.hasCaption()) {
             CaptionPosition pos = slot.getCaptionPosition();
             getLayoutManager().addElementResizeListener(
@@ -360,12 +357,15 @@ public abstract class AbstractOrderedLayoutConnector extends
 
         // First update bookkeeping for all children
         for (ComponentConnector child : getChildComponents()) {
+            Slot slot = getWidget().getSlot(child.getWidget());
+
+            slot.setRelativeWidth(child.isRelativeWidth());
+            slot.setRelativeHeight(child.isRelativeHeight());
+
             if (child.delegateCaptionHandling()) {
                 updateCaptionInternal(child);
             }
 
-            Slot slot = getWidget().getSlot(child.getWidget());
-
             // Update slot style names
             List<String> childStyles = child.getState().styles;
             if (childStyles == null) {
index c9f5b92c902dee2cefe74464d6c7a4d0c98ce2c3..93176f67bbad5660cc64777820bb018c66e13045 100644 (file)
@@ -21,6 +21,7 @@ import java.util.Map;
 import com.google.gwt.dom.client.Node;
 import com.google.gwt.dom.client.Style;
 import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.dom.client.Style.Visibility;
 import com.google.gwt.regexp.shared.MatchResult;
 import com.google.gwt.regexp.shared.RegExp;
 import com.google.gwt.user.client.DOM;
@@ -367,34 +368,54 @@ public class VAbstractOrderedLayout extends FlowPanel {
         // Sum up expand ratios to get the denominator
         double total = 0;
         for (Slot slot : widgetToSlot.values()) {
-            if (slot.getExpandRatio() != 0) {
-                total += slot.getExpandRatio();
-            } else {
-                if (vertical) {
-                    slot.getElement().getStyle().clearHeight();
-                } else {
-                    slot.getElement().getStyle().clearWidth();
-                }
-            }
-            slot.getElement().getStyle().clearMarginLeft();
-            slot.getElement().getStyle().clearMarginTop();
+            // FIXME expandRatio might be <0
+            total += slot.getExpandRatio();
         }
 
-        // Give each child its own share
+        // Give each expanded child its own share
         for (Slot slot : widgetToSlot.values()) {
+
+            Element slotElement = slot.getElement();
+            slotElement.removeAttribute("aria-hidden");
+
+            Style slotStyle = slotElement.getStyle();
+            slotStyle.clearVisibility();
+            slotStyle.clearMarginLeft();
+            slotStyle.clearMarginTop();
+
             if (slot.getExpandRatio() != 0) {
+                // FIXME expandRatio might be <0
+                double size = 100 * (slot.getExpandRatio() / total);
+
                 if (vertical) {
-                    slot.setHeight((100 * (slot.getExpandRatio() / total))
-                            + "%");
+                    slot.setHeight(size + "%");
                     if (slot.hasRelativeHeight()) {
                         Util.notifyParentOfSizeChange(this, true);
                     }
                 } else {
-                    slot.setWidth((100 * (slot.getExpandRatio() / total)) + "%");
+                    slot.setWidth(size + "%");
                     if (slot.hasRelativeWidth()) {
                         Util.notifyParentOfSizeChange(this, true);
                     }
                 }
+
+            } else if (slot.isRelativeInDirection(vertical)) {
+                // Relative child without expansion gets no space at all
+                if (vertical) {
+                    slot.setHeight("0");
+                } else {
+                    slot.setWidth("0");
+                }
+                slotStyle.setVisibility(Visibility.HIDDEN);
+                slotElement.setAttribute("aria-hidden", "true");
+
+            } else {
+                // Non-relative child without expansion should be unconstrained
+                if (vertical) {
+                    slotStyle.clearHeight();
+                } else {
+                    slotStyle.clearWidth();
+                }
             }
         }
     }
@@ -440,6 +461,7 @@ public class VAbstractOrderedLayout extends FlowPanel {
     public void updateExpandCompensation() {
         boolean isExpanding = false;
         for (Widget slot : getChildren()) {
+            // FIXME expandRatio might be <0
             if (((Slot) slot).getExpandRatio() != 0) {
                 isExpanding = true;
                 break;
@@ -501,6 +523,7 @@ public class VAbstractOrderedLayout extends FlowPanel {
                             }
                         }
                     } else {
+                        // FIXME expandRatio might be <0
                         totalSize += vertical ? slot.getOffsetHeight() : slot
                                 .getOffsetWidth();
                     }
@@ -532,6 +555,7 @@ public class VAbstractOrderedLayout extends FlowPanel {
                 lastExpandSize = totalSize;
                 for (Widget w : getChildren()) {
                     Slot slot = (Slot) w;
+                    // FIXME expandRatio might be <0
                     if (slot.getExpandRatio() != 0) {
                         if (layoutManager != null) {
                             layoutManager.setNeedsMeasure(Util
diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalRelativeSizeWithoutExpand.html b/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalRelativeSizeWithoutExpand.html
new file mode 100755 (executable)
index 0000000..06de880
--- /dev/null
@@ -0,0 +1,27 @@
+<?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="http://localhost:8888/" />
+<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.HorizontalRelativeSizeWithoutExpand?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>spacing-and-panel</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalRelativeSizeWithoutExpand.java b/uitest/src/com/vaadin/tests/components/orderedlayout/HorizontalRelativeSizeWithoutExpand.java
new file mode 100755 (executable)
index 0000000..8c59531
--- /dev/null
@@ -0,0 +1,51 @@
+package com.vaadin.tests.components.orderedlayout;
+
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.Tree;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+
+public class HorizontalRelativeSizeWithoutExpand extends UI {
+
+    @Override
+    protected void init(VaadinRequest request) {
+
+        final HorizontalLayout layout = new HorizontalLayout();
+        layout.setSizeFull();
+        layout.setMargin(true);
+        layout.setSpacing(true);
+        setContent(layout);
+
+        Panel panel1 = new Panel("This should not be seen");
+        panel1.setSizeFull();
+        VerticalLayout verticalLayout1 = new VerticalLayout();
+        verticalLayout1.setSizeFull();
+        Tree tree = new Tree();
+        tree.setSizeFull();
+        tree.setContainerDataSource(new BeanItemContainer<String>(String.class));
+        String a = "aaaaaaaaaaaaaaaaaaaaaaaa";
+        String b = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
+        String c = "ccccccccccccccccccccccccccccccccccccccccccccccccc";
+        tree.addItem(a);
+        tree.addItem(b);
+        tree.addItem(c);
+        tree.setChildrenAllowed(a, true);
+        tree.setChildrenAllowed(b, true);
+        tree.setParent(b, a);
+        tree.setParent(c, b);
+        verticalLayout1.addComponent(tree);
+        panel1.setContent(verticalLayout1);
+        layout.addComponent(panel1);
+
+        final Panel panel2 = new Panel("This should use all space");
+        panel2.setSizeFull();
+
+        layout.addComponent(panel2);
+        layout.setExpandRatio(panel2, 1);
+
+    }
+
+}
index fe1dfe3e6dc51d318b8ae45b0989288d0a025101..d7dbe11769d225ea72d2f9960f073637fbcada4b 100644 (file)
@@ -179,8 +179,15 @@ public class OrderedLayoutCases extends AbstractTestUI {
                         }
 
                         while (currentLayout.getComponentCount() > 0) {
-                            newLayout.addComponent(currentLayout
-                                    .getComponent(0));
+                            Component child = currentLayout.getComponent(0);
+                            Alignment alignment = currentLayout
+                                    .getComponentAlignment(child);
+                            float expRatio = currentLayout
+                                    .getExpandRatio(child);
+                            newLayout.addComponent(child);
+                            newLayout.setExpandRatio(child, expRatio);
+                            newLayout.setComponentAlignment(child, alignment);
+
                         }
                         newLayout.setStyleName("theLayout");
 
@@ -337,6 +344,24 @@ public class OrderedLayoutCases extends AbstractTestUI {
                         setChildState(2, 4, 7);
                     }
                 }));
+        caseBar.addComponent(new Button("Relative child without expand",
+                new ClickListener() {
+                    @Override
+                    public void buttonClick(ClickEvent event) {
+                        resetState();
+                        // Width 800px
+                        setState(sizeBar, 0, 3);
+                        // First child 100% wide
+                        setChildState(0, 0, 4);
+                        // Second child expand 1
+                        setChildState(1, 3, 1);
+                    }
+                }));
+        /*
+         * Hidden for not to avoid changing screenshots, functionality is still
+         * available by adding case=9 to the query string...
+         */
+        caseBar.getComponent(9).setVisible(false);
 
         caseBar.setSpacing(true);
 
@@ -348,6 +373,13 @@ public class OrderedLayoutCases extends AbstractTestUI {
         getContent().setSizeFull();
         getLayout().setSizeFull();
         getLayout().setExpandRatio(currentLayout, 1);
+
+        String caseParameter = request.getParameter("case");
+        if (caseParameter != null) {
+            int caseIndex = Integer.parseInt(caseParameter);
+            Button button = (Button) caseBar.getComponent(caseIndex);
+            button.click();
+        }
     }
 
     private void resetState() {
diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildWithoutExpand.html b/uitest/src/com/vaadin/tests/components/orderedlayout/RelativeChildWithoutExpand.html
new file mode 100644 (file)
index 0000000..c7f75ff
--- /dev/null
@@ -0,0 +1,46 @@
+<?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.OrderedLayoutCases?case=9</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>first-child-hidden-two-visible</td>
+</tr>
+<tr>
+       <td>select</td>
+       <td>vaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutCases::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VHorizontalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VNativeSelect[0]/domChild[0]</td>
+       <td>label=0</td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>three-children-visible</td>
+</tr>
+<tr>
+       <td>select</td>
+       <td>vaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutCases::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VHorizontalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VNativeSelect[0]/domChild[0]</td>
+       <td>label=1</td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>first-child-hidden-two-visible-again</td>
+</tr>
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/VerticalRelativeSizeWithoutExpand.html b/uitest/src/com/vaadin/tests/components/orderedlayout/VerticalRelativeSizeWithoutExpand.html
new file mode 100755 (executable)
index 0000000..caf4347
--- /dev/null
@@ -0,0 +1,27 @@
+<?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="http://localhost:8888/" />
+<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.VerticalRelativeSizeWithoutExpand?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>spacing-and-panel</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/VerticalRelativeSizeWithoutExpand.java b/uitest/src/com/vaadin/tests/components/orderedlayout/VerticalRelativeSizeWithoutExpand.java
new file mode 100755 (executable)
index 0000000..86525da
--- /dev/null
@@ -0,0 +1,53 @@
+package com.vaadin.tests.components.orderedlayout;
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.Tree;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+
+/**
+ * The Application's "main" class
+ */
+@SuppressWarnings("serial")
+public class VerticalRelativeSizeWithoutExpand extends UI {
+
+    @Override
+    protected void init(VaadinRequest request) {
+
+        final VerticalLayout layout = new VerticalLayout();
+        layout.setSizeFull();
+        layout.setMargin(true);
+        layout.setSpacing(true);
+        setContent(layout);
+
+        Panel panel1 = new Panel("This should not be seen");
+        panel1.setSizeFull();
+        VerticalLayout verticalLayout1 = new VerticalLayout();
+        verticalLayout1.setSizeFull();
+        Tree tree = new Tree();
+        tree.setSizeFull();
+        tree.setContainerDataSource(new BeanItemContainer<String>(String.class));
+        String a = "aaaaaaaaaaaaaaaaaaaaaaaa";
+        String b = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
+        String c = "ccccccccccccccccccccccccccccccccccccccccccccccccc";
+        tree.addItem(a);
+        tree.addItem(b);
+        tree.addItem(c);
+        tree.setChildrenAllowed(a, true);
+        tree.setChildrenAllowed(b, true);
+        tree.setParent(b, a);
+        tree.setParent(c, b);
+        verticalLayout1.addComponent(tree);
+        panel1.setContent(verticalLayout1);
+        layout.addComponent(panel1);
+
+        final Panel panel2 = new Panel("This should use all space");
+        panel2.setSizeFull();
+
+        layout.addComponent(panel2);
+        layout.setExpandRatio(panel2, 1);
+
+    }
+
+}