From 1ec9e1a6357819ebcba7af6cade98f5389f81ca5 Mon Sep 17 00:00:00 2001 From: Markus Koivisto Date: Thu, 16 Apr 2015 15:00:07 +0300 Subject: Revert "Reduce reflows when sizing columns (#17315)" This reverts commit 103b329d328ab0dde95da9426462491be510a8be. It causes problems with screenshot tests (GridColumnAutoWidthServerTest). Change-Id: I1de4a44573b22e0bea8ffa2626724e2a182cb876 --- .../src/com/vaadin/client/widgets/Escalator.java | 110 +++++++-------------- 1 file changed, 38 insertions(+), 72 deletions(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/widgets/Escalator.java b/client/src/com/vaadin/client/widgets/Escalator.java index 83c176d6fd..3d4459a0cc 100644 --- a/client/src/com/vaadin/client/widgets/Escalator.java +++ b/client/src/com/vaadin/client/widgets/Escalator.java @@ -16,7 +16,6 @@ package com.vaadin.client.widgets; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; @@ -2011,8 +2010,9 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker return new Cell(domRowIndex, domColumnIndex, cellElement); } - void createAutoSizeElements(int colIndex, - Collection elements) { + double getMaxCellWidth(int colIndex) throws IllegalArgumentException { + double maxCellWidth = -1; + assert isAttached() : "Can't measure max width of cell, since Escalator is not attached to the DOM."; NodeList rows = root.getRows(); @@ -2041,9 +2041,24 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker cellClone.getStyle().clearWidth(); rowElement.insertBefore(cellClone, cellOriginal); + double requiredWidth = WidgetUtil + .getRequiredWidthBoundingClientRectDouble(cellClone); + + if (BrowserInfo.get().isIE()) { + /* + * IE browsers have some issues with subpixels. Occasionally + * content is overflown even if not necessary. Increase the + * counted required size by 0.01 just to be on the safe + * side. + */ + requiredWidth += 0.01; + } - elements.add(cellClone); + maxCellWidth = Math.max(requiredWidth, maxCellWidth); + cellClone.removeFromParent(); } + + return maxCellWidth; } private boolean cellIsPartOfSpan(TableCellElement cell) { @@ -3774,8 +3789,7 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker if (px < 0) { if (isAttached()) { - autosizeColumns(Collections.singletonList(columns - .indexOf(this))); + calculateWidth(); } else { /* * the column's width is calculated at Escalator.onLoad @@ -3829,6 +3843,10 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker } return false; } + + private void calculateWidth() { + calculatedWidth = getMaxCellWidth(columns.indexOf(this)); + } } private final List columns = new ArrayList(); @@ -4133,7 +4151,6 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker return; } - List autosizeColumns = new ArrayList(); for (Entry entry : indexWidthMap.entrySet()) { int index = entry.getKey().intValue(); double width = entry.getValue().doubleValue(); @@ -4143,14 +4160,9 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker } checkValidColumnIndex(index); - if (width >= 0) { - columns.get(index).setWidth(width); - } else { - autosizeColumns.add(index); - } - } + columns.get(index).setWidth(width); - autosizeColumns(autosizeColumns); + } widthsArray = null; header.reapplyColumnWidths(); @@ -4162,64 +4174,6 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker recalculateElementSizes(); } - private void autosizeColumns(List columns) { - if (columns.isEmpty()) { - return; - } - - // Must process columns in index order - Collections.sort(columns); - - Map> autoSizeElements = new HashMap>(); - try { - // Set up the entire DOM at once - for (int i = columns.size() - 1; i >= 0; i--) { - // Iterate backwards to not mess with the indexing - Integer colIndex = columns.get(i); - - ArrayList elements = new ArrayList(); - autoSizeElements.put(colIndex, elements); - - header.createAutoSizeElements(colIndex, elements); - body.createAutoSizeElements(colIndex, elements); - footer.createAutoSizeElements(colIndex, elements); - } - - // Extract all measurements & update values - for (Integer colIndex : columns) { - double maxWidth = Double.NEGATIVE_INFINITY; - List elements = autoSizeElements - .get(colIndex); - for (TableCellElement element : elements) { - - double cellWidth = WidgetUtil - .getRequiredWidthBoundingClientRectDouble(element); - - maxWidth = Math.max(maxWidth, cellWidth); - } - assert maxWidth >= 0 : "Got a negative max width for a column, which should be impossible."; - - if (BrowserInfo.get().isIE()) { - /* - * IE browsers have some issues with subpixels. - * Occasionally content is overflown even if not - * necessary. Increase the counted required size by 0.01 - * just to be on the safe side. - */ - maxWidth += 0.01; - } - - this.columns.get(colIndex).calculatedWidth = maxWidth; - } - } finally { - for (List list : autoSizeElements.values()) { - for (TableCellElement element : list) { - element.removeFromParent(); - } - } - } - } - private void checkValidColumnIndex(int index) throws IllegalArgumentException { if (!Range.withLength(0, getColumnCount()).contains(index)) { @@ -4239,6 +4193,18 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker return columns.get(index).getCalculatedWidth(); } + private double getMaxCellWidth(int colIndex) + throws IllegalArgumentException { + double headerWidth = header.getMaxCellWidth(colIndex); + double bodyWidth = body.getMaxCellWidth(colIndex); + double footerWidth = footer.getMaxCellWidth(colIndex); + + double maxWidth = Math.max(headerWidth, + Math.max(bodyWidth, footerWidth)); + assert maxWidth >= 0 : "Got a negative max width for a column, which should be impossible."; + return maxWidth; + } + /** * Calculates the width of the columns in a given range. * -- cgit v1.2.3