]> source.dussan.org Git - vaadin-framework.git/commitdiff
Workaround for firefox miscalculating row widths (#16606)
authorHenrik Paul <henrik@vaadin.com>
Fri, 6 Feb 2015 08:20:39 +0000 (10:20 +0200)
committerLeif Åstrand <leif@vaadin.com>
Fri, 6 Feb 2015 13:07:31 +0000 (13:07 +0000)
Change-Id: I7c6aeed36fe81a51feffe05e687527f08ac2bd65

client/src/com/vaadin/client/widgets/Escalator.java
client/src/com/vaadin/client/widgets/Grid.java

index 07173c487b30fb8f65c84f32deaea15580333b8a..450655c9d335b9872ba00d80b748dec47bb1b18b 100644 (file)
@@ -2037,8 +2037,14 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker
                 cellClone.getStyle().clearWidth();
 
                 rowElement.insertBefore(cellClone, cellOriginal);
+
+                /*
+                 * [[subpixelworkaround]] (6.2.2015, Henrik Paul) FIXME: not
+                 * using the double-version is a workaround for a bug. It'll be
+                 * converted to use the double version at a later time
+                 */
                 double requiredWidth = WidgetUtil
-                        .getRequiredWidthBoundingClientRectDouble(cellClone);
+                        .getRequiredWidthBoundingClientRect(cellClone);
 
                 if (BrowserInfo.get().isIE9()) {
                     /*
index 9a6a6d60298ed3472cadf10ab7862de6f53ad80c..cac8a1d6d378bcd6d492a411453fe9d0ad6dc3ea 100644 (file)
@@ -2447,6 +2447,29 @@ public class Grid<T> extends ResizeComposite implements
                 applyColumnWidths();
             } else {
                 applyColumnWidthsWithExpansion();
+
+                /*
+                 * [[subpixelworkaround]] (6.2.2015, Henrik Paul) FIXME: just
+                 * dump all the remaining pixels into the last column and
+                 * whistle loudly
+                 */
+                boolean dumpIntoLastColumn = false;
+                double escalatorWidth = escalator.getInnerWidth();
+                double occupiedWidth = 0;
+                for (Column column : getColumns()) {
+                    occupiedWidth += column.getWidthActual();
+                    if (column.getWidth() < 0 && column.getExpandRatio() != 0) {
+                        dumpIntoLastColumn = true;
+                    }
+                }
+
+                if (dumpIntoLastColumn) {
+                    Column<?, T> lastColumn = getColumn(getColumnCount() - 1);
+                    double width = Math.floor(lastColumn.getWidthActual()
+                            + (escalatorWidth - occupiedWidth));
+                    escalator.getColumnConfiguration().setColumnWidth(
+                            getColumnCount() - 1, width);
+                }
             }
         }
 
@@ -2565,7 +2588,8 @@ public class Grid<T> extends ResizeComposite implements
              * can distribute the remaining pixels to all columns according to
              * their expand ratios.
              */
-            double pixelsToDistribute = escalator.getInnerWidth()
+            // [[subpixelworkaround]] (6.2.2015, Henrik Paul) FIXME: ceil
+            double pixelsToDistribute = Math.ceil(escalator.getInnerWidth())
                     - reservedPixels;
             if (pixelsToDistribute <= 0 || totalRatios <= 0) {
                 return;
@@ -2579,7 +2603,9 @@ public class Grid<T> extends ResizeComposite implements
             boolean aColumnHasMaxedOut;
             do {
                 aColumnHasMaxedOut = false;
-                final double widthPerRatio = pixelsToDistribute / totalRatios;
+                // [[subpixelworkaround]] (6.2.2015, Henrik Paul) FIXME floor
+                final double widthPerRatio = Math.floor(pixelsToDistribute
+                        / totalRatios);
                 final Iterator<Column<?, ?>> i = columnsToExpand.iterator();
                 while (i.hasNext()) {
                     final Column<?, ?> column = i.next();
@@ -2615,7 +2641,9 @@ public class Grid<T> extends ResizeComposite implements
              * If we still have anything left, distribute the remaining pixels
              * to the remaining columns.
              */
-            final double widthPerRatio = pixelsToDistribute / totalRatios;
+            // [[subpixelworkaround]] (6.2.2015, Henrik Paul) FIXME: floor
+            final double widthPerRatio = Math.floor(pixelsToDistribute
+                    / totalRatios);
             for (Column<?, ?> column : columnsToExpand) {
                 final int expandRatio = getExpandRatio(column,
                         someColumnExpands);
@@ -2651,7 +2679,8 @@ public class Grid<T> extends ResizeComposite implements
                      * wouldn't show up in that set.
                      */
 
-                    double minWidth = getMinWidth(column);
+                    // [[subpixelworkaround]] (6.2.2015, Henrik Paul) FIXME ceil
+                    double minWidth = Math.ceil(getMinWidth(column));
                     double currentWidth = column.getWidthActual();
                     boolean hasAutoWidth = column.getWidth() < 0;
                     if (hasAutoWidth && currentWidth < minWidth) {
@@ -2676,8 +2705,9 @@ public class Grid<T> extends ResizeComposite implements
                 for (Column<?, ?> column : columnsToExpand) {
                     totalRatios += getExpandRatio(column, someColumnExpands);
                 }
-                final double pixelsToRemovePerRatio = pixelsToRemoveFromOtherColumns
-                        / totalRatios;
+                // [[subpixelworkaround]] (6.2.2015, Henrik Paul) FIXME: ceil
+                final double pixelsToRemovePerRatio = Math
+                        .ceil(pixelsToRemoveFromOtherColumns / totalRatios);
                 for (Column<?, ?> column : columnsToExpand) {
                     final double pixelsToRemove = pixelsToRemovePerRatio
                             * getExpandRatio(column, someColumnExpands);
@@ -3100,7 +3130,7 @@ public class Grid<T> extends ResizeComposite implements
          *            the width in pixels or negative for auto sizing
          */
         public Column<C, T> setWidth(double pixels) {
-            if (widthUser != pixels) {
+            if (!WidgetUtil.pixelValuesEqual(widthUser, pixels)) {
                 widthUser = pixels;
                 scheduleColumnWidthRecalculator();
             }