Change-Id: I0511bcf6814fa33d558712da2bc112b545468153tags/7.2.0.beta1
@@ -100,6 +100,13 @@ $border-color: #aaa; | |||
-moz-box-sizing: border-box; | |||
box-sizing: border-box; | |||
overflow:hidden; | |||
/* | |||
* Because Vaadin changes the font size after the initial render, we | |||
* need to mention the font size here explicitly, otherwise automatic | |||
* row height detection gets broken. | |||
*/ | |||
font-size: $font-size; | |||
} | |||
.#{$primaryStyleName}-cell.frozen { | |||
@@ -107,4 +114,4 @@ $border-color: #aaa; | |||
z-index: 0; | |||
} | |||
} | |||
} |
@@ -32,3 +32,7 @@ | |||
.popup-style .v-datefield-calendarpanel-body { | |||
background: yellow; | |||
} | |||
#escalator .v-escalator-body .v-escalator-cell { | |||
height: 50px; | |||
} |
@@ -30,6 +30,7 @@ import com.google.gwt.animation.client.AnimationScheduler.AnimationCallback; | |||
import com.google.gwt.animation.client.AnimationScheduler.AnimationHandle; | |||
import com.google.gwt.core.client.Duration; | |||
import com.google.gwt.core.client.JavaScriptObject; | |||
import com.google.gwt.core.client.Scheduler; | |||
import com.google.gwt.dom.client.Document; | |||
import com.google.gwt.dom.client.Element; | |||
import com.google.gwt.dom.client.NativeEvent; | |||
@@ -1013,8 +1014,6 @@ public class Escalator extends Widget { | |||
private abstract class AbstractRowContainer implements RowContainer { | |||
private static final int INITIAL_DEFAULT_ROW_HEIGHT = 20; | |||
private EscalatorUpdater updater = EscalatorUpdater.NULL; | |||
private int rows; | |||
@@ -1047,6 +1046,8 @@ public class Escalator extends Widget { | |||
@Deprecated | |||
private final Map<Element, Integer> rowTopPositionMap = new HashMap<Element, Integer>(); | |||
private boolean defaultRowHeightShouldBeAutodetected = true; | |||
private int defaultRowHeight = INITIAL_DEFAULT_ROW_HEIGHT; | |||
public AbstractRowContainer(final Element rowContainerElement) { | |||
@@ -1633,6 +1634,7 @@ public class Escalator extends Widget { | |||
+ px + " was given."); | |||
} | |||
defaultRowHeightShouldBeAutodetected = false; | |||
defaultRowHeight = px; | |||
reapplyDefaultRowHeights(); | |||
} | |||
@@ -1681,6 +1683,37 @@ public class Escalator extends Widget { | |||
protected void removeRowPosition(Element tr) { | |||
rowTopPositionMap.remove(tr); | |||
} | |||
public void autodetectRowHeight() { | |||
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() { | |||
@Override | |||
public void execute() { | |||
if (defaultRowHeightShouldBeAutodetected && isAttached()) { | |||
final Element detectionTr = DOM.createTR(); | |||
detectionTr | |||
.setClassName(getStylePrimaryName() + "-row"); | |||
final Element cellElem = DOM | |||
.createElement(getCellElementTagName()); | |||
cellElem.setClassName(getStylePrimaryName() + "-cell"); | |||
cellElem.setInnerHTML("foo"); | |||
detectionTr.appendChild(cellElem); | |||
root.appendChild(detectionTr); | |||
defaultRowHeight = Math.max(1, | |||
cellElem.getOffsetHeight()); | |||
root.removeChild(detectionTr); | |||
if (root.hasChildNodes()) { | |||
reapplyDefaultRowHeights(); | |||
} | |||
defaultRowHeightShouldBeAutodetected = false; | |||
} | |||
} | |||
}); | |||
} | |||
} | |||
private abstract class AbstractStaticRowContainer extends | |||
@@ -3513,6 +3546,10 @@ public class Escalator extends Widget { | |||
protected void onLoad() { | |||
super.onLoad(); | |||
header.autodetectRowHeight(); | |||
body.autodetectRowHeight(); | |||
footer.autodetectRowHeight(); | |||
header.paintInsertRows(0, header.getRowCount()); | |||
footer.paintInsertRows(0, footer.getRowCount()); | |||
recalculateElementSizes(); |
@@ -27,6 +27,13 @@ package com.vaadin.client.ui.grid; | |||
* @see Escalator#getFooter() | |||
*/ | |||
public interface RowContainer { | |||
/** | |||
* An arbitrary pixel height of a row, before any autodetection for the row | |||
* height has been made. | |||
* */ | |||
public static final int INITIAL_DEFAULT_ROW_HEIGHT = 20; | |||
/** | |||
* Returns the current {@link EscalatorUpdater} used to render cells. | |||
* | |||
@@ -131,13 +138,19 @@ public interface RowContainer { | |||
* the default height in pixels of the rows in this RowContainer | |||
* @throws IllegalArgumentException | |||
* if <code>px < 1</code> | |||
* @see #getDefaultRowHeight() | |||
*/ | |||
public void setDefaultRowHeight(int px) throws IllegalArgumentException; | |||
/** | |||
* Returns the default height of the rows in this RowContainer. | |||
* <p> | |||
* This value will be equal to {@link #INITIAL_DEFAULT_ROW_HEIGHT} if the | |||
* {@link Escalator} has not yet had a chance to autodetect the row height, | |||
* or no explicit value has yet given via {@link #setDefaultRowHeight(int)} | |||
* | |||
* @return the default height of the rows in this RowContainer, in pixels | |||
* @see #setDefaultRowHeight(int) | |||
*/ | |||
public int getDefaultRowHeight(); | |||
} |
@@ -0,0 +1,49 @@ | |||
/* | |||
* Copyright 2000-2013 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 org.junit.Test; | |||
import org.openqa.selenium.By; | |||
import org.openqa.selenium.WebElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class BasicEscalatorTest extends MultiBrowserTest { | |||
@Test | |||
public void testNormalHeight() throws Exception { | |||
openTestURL(); | |||
compareScreen("normalHeight"); | |||
} | |||
@Test | |||
public void testModifiedHeight() throws Exception { | |||
openTestURLWithTheme("reindeer-tests"); | |||
compareScreen("modifiedHeight"); | |||
} | |||
private WebElement getFirstBodyRowCell() { | |||
return getDriver().findElement( | |||
By.xpath("//tbody/tr[@class='v-escalator-row'][1]/td[1]")); | |||
} | |||
private void openTestURLWithTheme(String themeName) { | |||
String testUrl = getTestUrl(); | |||
testUrl += (testUrl.contains("?")) ? "&" : "?"; | |||
testUrl += "theme=" + themeName; | |||
getDriver().get(testUrl); | |||
} | |||
} |