]> source.dussan.org Git - vaadin-framework.git/commitdiff
Force horizontal scrolling with wide columns but no rows (#9187)
authorLeif Åstrand <leif@vaadin.com>
Mon, 6 Aug 2012 05:46:29 +0000 (05:46 +0000)
committerLeif Åstrand <leif@vaadin.com>
Mon, 6 Aug 2012 05:46:29 +0000 (05:46 +0000)
svn changeset:24065/svn branch:6.8

src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
tests/testbench/com/vaadin/tests/components/table/HorizontalScrollWithNoRows.html [new file with mode: 0644]

index e54493ca61b0468833cbf3656024ea9efee6d4a6..43e07376f4496c4c39137161b9d8e7a041ddd182 100644 (file)
@@ -6091,16 +6091,39 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler,
             // Hey IE, are you really sure about this?
             availW = scrollBody.getAvailableWidth();
             int visibleCellCount = tHead.getVisibleCellCount();
-            availW -= scrollBody.getCellExtraWidth() * visibleCellCount;
+            int totalExtraWidth = scrollBody.getCellExtraWidth()
+                    * visibleCellCount;
             if (willHaveScrollbars()) {
-                availW -= Util.getNativeScrollbarSize();
+                totalExtraWidth += Util.getNativeScrollbarSize();
             }
-
+            availW -= totalExtraWidth;
+            int forceScrollBodyWidth = -1;
+            
             int extraSpace = availW - usedMinimumWidth;
             if (extraSpace < 0) {
+                if (getTotalRows() == 0) {
+                    /*
+                     * Too wide header combined with no rows in the table.
+                     * 
+                     * No horizontal scrollbars would be displayed because
+                     * there's no rows that grows too wide causing the
+                     * scrollBody container div to overflow. Must explicitely
+                     * force a width to a scrollbar. (see #9187)
+                     */
+                    forceScrollBodyWidth = usedMinimumWidth + totalExtraWidth;
+                }
                 extraSpace = 0;
             }
 
+            if (forceScrollBodyWidth > 0) {
+                scrollBody.container.getStyle().setWidth(forceScrollBodyWidth,
+                        Unit.PX);
+            } else {
+                // Clear width that might have been set to force horizontal
+                // scrolling if there are no rows
+                scrollBody.container.getStyle().clearWidth();
+            }
+
             int totalUndefinedNaturalWidths = usedMinimumWidth
                     - totalExplicitColumnsWidths;
 
diff --git a/tests/testbench/com/vaadin/tests/components/table/HorizontalScrollWithNoRows.html b/tests/testbench/com/vaadin/tests/components/table/HorizontalScrollWithNoRows.html
new file mode 100644 (file)
index 0000000..9862925
--- /dev/null
@@ -0,0 +1,86 @@
+<?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.table.Tables?restartApplication</td>
+       <td></td>
+</tr>
+<!--Remove all rows-->
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTables::PID_Smenu#item0</td>
+       <td>23,8</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[0]/VMenuBar[0]#item5</td>
+       <td>33,5</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[1]/VMenuBar[0]#item1</td>
+       <td>50,8</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[2]/VMenuBar[0]#item0</td>
+       <td>54,10</td>
+</tr>
+<!--Remove log-->
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTables::PID_Smenu#item1</td>
+       <td>28,9</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[0]/VMenuBar[0]#item0</td>
+       <td>29,5</td>
+</tr>
+<!--Resize column, should get scrollbar-->
+<tr>
+       <td>drag</td>
+       <td>vaadin=runcomvaadintestscomponentstableTables::PID_StestComponent/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>0,7</td>
+</tr>
+<tr>
+       <td>drop</td>
+       <td>vaadin=runcomvaadintestscomponentstableTables::PID_StestComponent/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>150,7</td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>1-wide-header</td>
+</tr>
+<!--Resize back, scrollbar should disappear-->
+<tr>
+       <td>drag</td>
+       <td>vaadin=runcomvaadintestscomponentstableTables::PID_StestComponent/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>0,7</td>
+</tr>
+<!-- Overcompensate by 2px because of off-by-one bug in testbench -->
+<tr>
+       <td>drop</td>
+       <td>vaadin=runcomvaadintestscomponentstableTables::PID_StestComponent/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>-152,7</td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>2-narrow-header</td>
+</tr>
+</tbody></table>
+</body>
+</html>