This reverts commit 103b329d32
. It causes problems
with screenshot tests (GridColumnAutoWidthServerTest).
Change-Id: I1de4a44573b22e0bea8ffa2626724e2a182cb876
tags/7.4.4^0
@@ -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<TableCellElement> 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<TableRowElement> 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<Column> columns = new ArrayList<Column>(); | |||
@@ -4133,7 +4151,6 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker | |||
return; | |||
} | |||
List<Integer> autosizeColumns = new ArrayList<Integer>(); | |||
for (Entry<Integer, Double> 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<Integer> columns) { | |||
if (columns.isEmpty()) { | |||
return; | |||
} | |||
// Must process columns in index order | |||
Collections.sort(columns); | |||
Map<Integer, List<TableCellElement>> autoSizeElements = new HashMap<Integer, List<TableCellElement>>(); | |||
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<TableCellElement> elements = new ArrayList<TableCellElement>(); | |||
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<TableCellElement> 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<TableCellElement> 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. | |||
* |
@@ -1,45 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.tests.components.grid; | |||
import com.vaadin.annotations.Widgetset; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.util.ResizeTerrorizer; | |||
import com.vaadin.tests.widgetset.TestingWidgetSet; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.UI; | |||
@Widgetset(TestingWidgetSet.NAME) | |||
public class GridResizeTerror extends UI { | |||
@Override | |||
protected void init(VaadinRequest request) { | |||
Grid grid = new Grid(); | |||
int cols = 10; | |||
Object[] data = new Object[cols]; | |||
for (int i = 0; i < cols; i++) { | |||
grid.addColumn("Col " + i); | |||
data[i] = "Data " + i; | |||
} | |||
for (int i = 0; i < 500; i++) { | |||
grid.addRow(data); | |||
} | |||
setContent(new ResizeTerrorizer(grid)); | |||
} | |||
} |
@@ -1,51 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.tests.util; | |||
import com.vaadin.tests.widgetset.client.ResizeTerrorizerControlConnector.ResizeTerorrizerState; | |||
import com.vaadin.ui.AbstractComponent; | |||
import com.vaadin.ui.Component; | |||
import com.vaadin.ui.VerticalLayout; | |||
public class ResizeTerrorizer extends VerticalLayout { | |||
private final ResizeTerrorizerControl control; | |||
public class ResizeTerrorizerControl extends AbstractComponent implements | |||
Component { | |||
public ResizeTerrorizerControl(Component target) { | |||
getState().target = target; | |||
} | |||
@Override | |||
protected ResizeTerorrizerState getState() { | |||
return (ResizeTerorrizerState) super.getState(); | |||
} | |||
} | |||
public ResizeTerrorizer(Component target) { | |||
target.setWidth("700px"); | |||
setSizeFull(); | |||
addComponent(target); | |||
setExpandRatio(target, 1); | |||
control = new ResizeTerrorizerControl(target); | |||
addComponent(control); | |||
} | |||
public void setDefaultWidthOffset(int px) { | |||
control.getState().defaultWidthOffset = px; | |||
} | |||
} |
@@ -1,157 +0,0 @@ | |||
/* | |||
* Copyright 2000-2014 Vaadin Ltd. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.tests.widgetset.client; | |||
import com.google.gwt.animation.client.AnimationScheduler; | |||
import com.google.gwt.animation.client.AnimationScheduler.AnimationCallback; | |||
import com.google.gwt.event.dom.client.ClickEvent; | |||
import com.google.gwt.event.dom.client.ClickHandler; | |||
import com.google.gwt.user.client.ui.Button; | |||
import com.google.gwt.user.client.ui.FlowPanel; | |||
import com.google.gwt.user.client.ui.IntegerBox; | |||
import com.google.gwt.user.client.ui.Label; | |||
import com.google.gwt.user.client.ui.RequiresResize; | |||
import com.vaadin.client.ui.AbstractComponentConnector; | |||
import com.vaadin.client.ui.PostLayoutListener; | |||
import com.vaadin.shared.AbstractComponentState; | |||
import com.vaadin.shared.Connector; | |||
import com.vaadin.shared.ui.Connect; | |||
import com.vaadin.tests.util.ResizeTerrorizer; | |||
@Connect(ResizeTerrorizer.ResizeTerrorizerControl.class) | |||
public class ResizeTerrorizerControlConnector extends | |||
AbstractComponentConnector implements PostLayoutListener { | |||
public static class ResizeTerorrizerState extends AbstractComponentState { | |||
public Connector target; | |||
public int defaultWidthOffset = 200; | |||
} | |||
public class ResizeTerrorizerControlPanel extends FlowPanel { | |||
private Label results = new Label("Results"); | |||
private IntegerBox startWidth = new IntegerBox(); | |||
private IntegerBox endWidth = new IntegerBox(); | |||
private final Button terrorizeButton = new Button("Terrorize", | |||
new ClickHandler() { | |||
@Override | |||
public void onClick(ClickEvent event) { | |||
terrorize(startWidth.getValue(), endWidth.getValue(), | |||
1000); | |||
} | |||
}); | |||
public ResizeTerrorizerControlPanel() { | |||
add(new Label("Start width")); | |||
add(startWidth); | |||
add(new Label("End width")); | |||
add(endWidth); | |||
add(terrorizeButton); | |||
add(results); | |||
startWidth.getElement().setId("terror-start-width"); | |||
endWidth.getElement().setId("terror-end-width"); | |||
terrorizeButton.getElement().setId("terror-button"); | |||
results.getElement().setId("terror-results"); | |||
} | |||
private void showResults(String results) { | |||
Integer temp = startWidth.getValue(); | |||
startWidth.setValue(endWidth.getValue()); | |||
endWidth.setValue(temp); | |||
this.results.setText(results); | |||
} | |||
} | |||
private void terrorize(final double startWidth, final double endWidth, | |||
final double duration) { | |||
final AbstractComponentConnector target = getTarget(); | |||
final AnimationScheduler scheduler = AnimationScheduler.get(); | |||
AnimationCallback callback = new AnimationCallback() { | |||
double startTime = -1; | |||
int frameCount = 0; | |||
@Override | |||
public void execute(double timestamp) { | |||
frameCount++; | |||
boolean done = false; | |||
if (startTime == -1) { | |||
startTime = timestamp; | |||
} | |||
double time = timestamp - startTime; | |||
if (time > duration) { | |||
time = duration; | |||
done = true; | |||
} | |||
double progress = time / duration; | |||
double widthToSet = startWidth + (endWidth - startWidth) | |||
* progress; | |||
// TODO Optionally inform LayoutManager as well | |||
target.getWidget().setWidth(widthToSet + "px"); | |||
if (target.getWidget() instanceof RequiresResize) { | |||
((RequiresResize) target.getWidget()).onResize(); | |||
} | |||
if (!done) { | |||
scheduler.requestAnimationFrame(this); | |||
} else { | |||
double fps = Math.round(frameCount / (duration / 1000)); | |||
String results = frameCount + " frames, " + fps + " fps"; | |||
getWidget().showResults(results); | |||
} | |||
} | |||
}; | |||
scheduler.requestAnimationFrame(callback); | |||
} | |||
private AbstractComponentConnector getTarget() { | |||
return (AbstractComponentConnector) getState().target; | |||
} | |||
@Override | |||
public ResizeTerorrizerState getState() { | |||
return (ResizeTerorrizerState) super.getState(); | |||
} | |||
@Override | |||
public ResizeTerrorizerControlPanel getWidget() { | |||
return (ResizeTerrorizerControlPanel) super.getWidget(); | |||
} | |||
@Override | |||
protected ResizeTerrorizerControlPanel createWidget() { | |||
return new ResizeTerrorizerControlPanel(); | |||
} | |||
@Override | |||
public void postLayout() { | |||
if (getWidget().startWidth.getValue() == null) { | |||
int width = getTarget().getWidget().getElement().getOffsetWidth(); | |||
getWidget().startWidth.setValue(width); | |||
getWidget().endWidth | |||
.setValue(width + getState().defaultWidthOffset); | |||
} | |||
} | |||
} |
@@ -136,9 +136,6 @@ public class TestWidgetRegistryGenerator extends Generator { | |||
} else if (!widgetType.getPackage().getName() | |||
.startsWith(TestWidgetConnector.class.getPackage().getName())) { | |||
return false; | |||
} else if (widgetType.getEnclosingType() != null | |||
&& !widgetType.isStatic()) { | |||
return false; | |||
} | |||
return true; |