summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Paul <henrik@vaadin.com>2014-03-06 15:45:48 +0200
committerHenrik Paul <henrik@vaadin.com>2014-03-11 11:14:38 +0200
commita7604cfaa21e0c5d8a075d2d563a61038d96f295 (patch)
tree6a34a72ae21f0f117910fa834c08fa5a2cbb3292
parent91559310f9b9ad5758944e2d36ab750b87b009a1 (diff)
downloadvaadin-framework-a7604cfaa21e0c5d8a075d2d563a61038d96f295.tar.gz
vaadin-framework-a7604cfaa21e0c5d8a075d2d563a61038d96f295.zip
Makes Escalator autodetect the initial row height (#13239)
Change-Id: I0511bcf6814fa33d558712da2bc112b545468153
-rw-r--r--WebContent/VAADIN/themes/base/escalator/escalator.scss9
-rw-r--r--WebContent/VAADIN/themes/reindeer-tests/styles.css4
-rw-r--r--client/src/com/vaadin/client/ui/grid/Escalator.java41
-rw-r--r--client/src/com/vaadin/client/ui/grid/RowContainer.java13
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/BasicEscalatorTest.java49
5 files changed, 113 insertions, 3 deletions
diff --git a/WebContent/VAADIN/themes/base/escalator/escalator.scss b/WebContent/VAADIN/themes/base/escalator/escalator.scss
index 21424bd456..6f85a541ee 100644
--- a/WebContent/VAADIN/themes/base/escalator/escalator.scss
+++ b/WebContent/VAADIN/themes/base/escalator/escalator.scss
@@ -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;
}
-} \ No newline at end of file
+}
diff --git a/WebContent/VAADIN/themes/reindeer-tests/styles.css b/WebContent/VAADIN/themes/reindeer-tests/styles.css
index 679de01b9c..9dd88707d1 100644
--- a/WebContent/VAADIN/themes/reindeer-tests/styles.css
+++ b/WebContent/VAADIN/themes/reindeer-tests/styles.css
@@ -32,3 +32,7 @@
.popup-style .v-datefield-calendarpanel-body {
background: yellow;
}
+
+#escalator .v-escalator-body .v-escalator-cell {
+ height: 50px;
+} \ No newline at end of file
diff --git a/client/src/com/vaadin/client/ui/grid/Escalator.java b/client/src/com/vaadin/client/ui/grid/Escalator.java
index 042286a742..e02ca52e6b 100644
--- a/client/src/com/vaadin/client/ui/grid/Escalator.java
+++ b/client/src/com/vaadin/client/ui/grid/Escalator.java
@@ -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();
diff --git a/client/src/com/vaadin/client/ui/grid/RowContainer.java b/client/src/com/vaadin/client/ui/grid/RowContainer.java
index ed82f74224..0312164569 100644
--- a/client/src/com/vaadin/client/ui/grid/RowContainer.java
+++ b/client/src/com/vaadin/client/ui/grid/RowContainer.java
@@ -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 &lt; 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();
}
diff --git a/uitest/src/com/vaadin/tests/components/grid/BasicEscalatorTest.java b/uitest/src/com/vaadin/tests/components/grid/BasicEscalatorTest.java
new file mode 100644
index 0000000000..5afe826196
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/BasicEscalatorTest.java
@@ -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);
+ }
+}