diff options
author | Jouni Koivuviita <jouni@jounikoivuviita.com> | 2012-04-25 11:18:20 +0300 |
---|---|---|
committer | Jouni Koivuviita <jouni@jounikoivuviita.com> | 2012-04-25 11:18:20 +0300 |
commit | f013a77f6ea1384a55d830ed6dcd53b956bbbe21 (patch) | |
tree | 1abef68d88366ddf07c3cd806b52f1e44e9932bd | |
parent | 13fa0ce71c59cb891bbf789c03f6974cc9d920b7 (diff) | |
download | vaadin-framework-f013a77f6ea1384a55d830ed6dcd53b956bbbe21.tar.gz vaadin-framework-f013a77f6ea1384a55d830ed6dcd53b956bbbe21.zip |
Removed PreLayoutListener again
4 files changed, 128 insertions, 48 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ComputedStyle.java b/src/com/vaadin/terminal/gwt/client/ComputedStyle.java index bedb217c63..7dc937cee7 100644 --- a/src/com/vaadin/terminal/gwt/client/ComputedStyle.java +++ b/src/com/vaadin/terminal/gwt/client/ComputedStyle.java @@ -83,19 +83,19 @@ public class ComputedStyle { // If we're not dealing with a regular pixel number // but a number that has a weird ending, we need to convert it to pixels - if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) { - // Remember the original values - var left = style.left, rsLeft = elem.runtimeStyle.left; - - // Put in the new values to get a computed value out - elem.runtimeStyle.left = cs.left; - style.left = ret || 0; - ret = style.pixelLeft + "px"; - - // Revert the changed values - style.left = left; - elem.runtimeStyle.left = rsLeft; - } + if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) { + // Remember the original values + var left = style.left, rsLeft = elem.runtimeStyle.left; + + // Put in the new values to get a computed value out + elem.runtimeStyle.left = cs.left; + style.left = ret || 0; + ret = style.pixelLeft + "px"; + + // Revert the changed values + style.left = left; + elem.runtimeStyle.left = rsLeft; + } } diff --git a/src/com/vaadin/terminal/gwt/client/LayoutManager.java b/src/com/vaadin/terminal/gwt/client/LayoutManager.java index 628a247d39..55d3fbe272 100644 --- a/src/com/vaadin/terminal/gwt/client/LayoutManager.java +++ b/src/com/vaadin/terminal/gwt/client/LayoutManager.java @@ -18,7 +18,6 @@ import com.google.gwt.user.client.Timer; import com.vaadin.terminal.gwt.client.MeasuredSize.MeasureResult; import com.vaadin.terminal.gwt.client.ui.ManagedLayout; import com.vaadin.terminal.gwt.client.ui.PostLayoutListener; -import com.vaadin.terminal.gwt.client.ui.PreLayoutListener; import com.vaadin.terminal.gwt.client.ui.SimpleManagedLayout; import com.vaadin.terminal.gwt.client.ui.layout.ElementResizeEvent; import com.vaadin.terminal.gwt.client.ui.layout.ElementResizeListener; @@ -30,8 +29,6 @@ public class LayoutManager { private static final boolean debugLogging = false; - private static int totalLayoutTime = 0; - private ApplicationConnection connection; private final Set<Element> measuredNonConnectorElements = new HashSet<Element>(); private final MeasuredSize nullSize = new MeasuredSize(); @@ -181,16 +178,6 @@ public class LayoutManager { Duration totalDuration = new Duration(); - int preLayoutStart = totalDuration.elapsedMillis(); - for (ComponentConnector connector : connection.getConnectorMap() - .getComponentConnectors()) { - if (connector instanceof PreLayoutListener) { - ((PreLayoutListener) connector).preLayout(); - } - } - VConsole.log("Invoke pre layout listeners in " - + (totalDuration.elapsedMillis() - preLayoutStart) + " ms"); - Map<ManagedLayout, Integer> layoutCounts = new HashMap<ManagedLayout, Integer>(); int passes = 0; @@ -205,6 +192,9 @@ public class LayoutManager { needsVerticalLayout.clear(); for (ComponentConnector connector : needsMeasure) { + // Ensure the MeasuredSize is attached to the DOM element before + // doing measurements to avoid reflows in "some" browsers + getMeasuredSize(connector); currentDependencyTree.setNeedsMeasure(connector, true); } needsMeasure.clear(); @@ -229,6 +219,9 @@ public class LayoutManager { VConsole.log(" Measured " + measuredConnectorCount + " elements in " + measureTime + " ms"); + VConsole.log(" Total of " + measureCount + + " measurement operations"); + if (!listenersToFire.isEmpty()) { for (Element element : listenersToFire) { Collection<ElementResizeListener> listeners = elementResizeListeners @@ -365,14 +358,9 @@ public class LayoutManager { VConsole.log("Invoke post layout listeners in " + (totalDuration.elapsedMillis() - postLayoutStart) + " ms"); - VConsole.log("Total layout phase time: " - + totalDuration.elapsedMillis() + "ms"); + VConsole.log("<b>Total layout phase time: " + + totalDuration.elapsedMillis() + "ms</b>"); - totalLayoutTime += totalDuration.elapsedMillis(); - VConsole.log(""); - VConsole.log("### Total combined layout phase: " + totalLayoutTime - + "ms"); - VConsole.log(""); } private void logConnectorStatus(int connectorId) { @@ -457,7 +445,7 @@ public class LayoutManager { ComponentConnector[] connectors = ConnectorMap.get(connection) .getComponentConnectors(); for (ComponentConnector connector : connectors) { - measueConnector(connector); + measureConnector(connector); } for (ComponentConnector connector : connectors) { layoutDependencyTree.setNeedsMeasure(connector, false); @@ -469,7 +457,7 @@ public class LayoutManager { Collection<ComponentConnector> measureTargets = layoutDependencyTree .getMeasureTargets(); for (ComponentConnector connector : measureTargets) { - measueConnector(connector); + measureConnector(connector); measureCount++; } for (ComponentConnector connector : measureTargets) { @@ -479,9 +467,16 @@ public class LayoutManager { return measureCount; } - private void measueConnector(ComponentConnector connector) { - Element element = connector.getWidget().getElement(); + private void measureConnector(ComponentConnector connector) { MeasuredSize measuredSize = getMeasuredSize(connector); + if (!isManagedLayout(connector) + && !isManagedLayout(connector.getParent()) + && elementResizeListeners.get(connector.getWidget() + .getElement()) == null && !measuredSize.hasDependents()) { + return; + } + + Element element = connector.getWidget().getElement(); MeasureResult measureResult = measuredAndUpdate(element, measuredSize); if (measureResult.isChanged()) { @@ -521,8 +516,11 @@ public class LayoutManager { + " non connector elements"); } + int measureCount = 0; + private MeasureResult measuredAndUpdate(Element element, MeasuredSize measuredSize) { + measureCount++; MeasureResult measureResult = measuredSize.measure(element); if (measureResult.isChanged()) { notifyListenersAndDepdendents(element, diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractBoxLayoutConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractBoxLayoutConnector.java index b3857cdae9..ab0168b39b 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/AbstractBoxLayoutConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractBoxLayoutConnector.java @@ -143,7 +143,7 @@ PostLayoutListener { // extra space equally if no expand ratios are specified inside a // layout with specified size if (expandRatios.getKeySet().size() == 0 - && ((getWidget().vertical && !isUndefinedHeight()) || !isUndefinedWidth())) { + && ((getWidget().vertical && !isUndefinedHeight()) || (!getWidget().vertical && !isUndefinedWidth()))) { expandRatio = 1; hasExpandRatio.add(child); } else if (expandRatios.containsKey(pid) @@ -153,6 +153,35 @@ PostLayoutListener { } else { expandRatio = -1; hasExpandRatio.remove(child); + if (expandRatios.getKeySet().size() > 0 + || hasExpandRatio.size() > 0) { + // Only add resize listeners if there are expand ratios in + // use + getLayoutManager().addElementResizeListener( + child.getWidget().getElement(), + childComponentResizeListener); + if (slot.hasCaption()) { + getLayoutManager().addElementResizeListener( + slot.getCaptionElement(), + slotCaptionResizeListener); + } + } + } + slot.setExpandRatio(expandRatio); + + if (slot.getSpacingElement() != null && needsExpand()) { + getLayoutManager().addElementResizeListener( + slot.getSpacingElement(), spacingResizeListener); + } else if (slot.getSpacingElement() != null) { + getLayoutManager().removeElementResizeListener( + slot.getSpacingElement(), spacingResizeListener); + } + + } + + if (needsFixedHeight()) { + for (ComponentConnector child : getChildren()) { + Slot slot = layout.getSlot(child); getLayoutManager().addElementResizeListener( child.getWidget().getElement(), childComponentResizeListener); @@ -162,13 +191,6 @@ PostLayoutListener { slotCaptionResizeListener); } } - slot.setExpandRatio(expandRatio); - - if (slot.getSpacingElement() != null) { - getLayoutManager().addElementResizeListener( - slot.getSpacingElement(), spacingResizeListener); - } - } if (needsExpand()) { @@ -353,7 +375,7 @@ PostLayoutListener { getLayoutManager().addElementResizeListener( slot.getSpacingElement(), spacingResizeListener); } else if (slot.getSpacingElement() != null) { - getLayoutManager().addElementResizeListener( + getLayoutManager().removeElementResizeListener( slot.getSpacingElement(), spacingResizeListener); } @@ -420,8 +442,10 @@ PostLayoutListener { .getOuterHeight(captionElement)); } } - // System.out.println(" ### SlotCaption sizes: " - // + childCaptionElementHeight.values().toString()); + System.out.println(" ### Child sizes: " + + childElementHeight.values().toString()); + System.out.println(" ### Caption sizes: " + + childCaptionElementHeight.values().toString()); // If no height has been set, use the natural height for the // component (this is mostly just a precaution so that something diff --git a/tests/testbench/com/vaadin/tests/components/orderedlayout/LayoutRenderTimeTest.java b/tests/testbench/com/vaadin/tests/components/orderedlayout/LayoutRenderTimeTest.java new file mode 100644 index 0000000000..871a467877 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/orderedlayout/LayoutRenderTimeTest.java @@ -0,0 +1,58 @@ +package com.vaadin.tests.components.orderedlayout; + +import com.vaadin.Application.LegacyApplication; +import com.vaadin.terminal.ThemeResource; +import com.vaadin.ui.Button; +import com.vaadin.ui.Embedded; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Root; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.themes.Reindeer; + +public class LayoutRenderTimeTest extends LegacyApplication { + + @Override + public void init() { + Root.LegacyWindow main = new Root.LegacyWindow(); + setMainWindow(main); + + VerticalLayout root = new VerticalLayout(); + root.setWidth("100%"); + main.setContent(root); + + for (int i = 1; i <= 100; i++) { + root.addComponent(getRow(i)); + } + } + + private HorizontalLayout getRow(int i) { + HorizontalLayout row = new HorizontalLayout(); + // row.setWidth("100%"); + // row.setSpacing(true); + + Embedded icon = new Embedded(null, new ThemeResource( + "../runo/icons/32/document.png")); + // row.addComponent(icon); + // row.setComponentAlignment(icon, Alignment.MIDDLE_LEFT); + + Label text = new Label( + "Row content #" + + i + + ". In pellentesque faucibus vestibulum. Nulla at nulla justo, eget luctus tortor. Nulla facilisi. Duis aliquet."); + // row.addComponent(text); + // row.setExpandRatio(text, 1); + + Button button = new Button("Edit"); + button.addStyleName(Reindeer.BUTTON_SMALL); + row.addComponent(button); + // row.setComponentAlignment(button, Alignment.MIDDLE_LEFT); + + button = new Button("Delete"); + button.addStyleName(Reindeer.BUTTON_SMALL); + row.addComponent(button); + // row.setComponentAlignment(button, Alignment.MIDDLE_LEFT); + + return row; + } +} |