summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-02-27 13:42:15 +0200
committerLeif Åstrand <leif@vaadin.com>2012-02-27 13:42:15 +0200
commita9541c3abdb4805ee905864d8942a62fc7bbcae2 (patch)
treeef5581c541650b3c641e898d11d6f98432cafdad /src
parent43bff90363a786ff7087719736c49daa4ee21d50 (diff)
downloadvaadin-framework-a9541c3abdb4805ee905864d8942a62fc7bbcae2.tar.gz
vaadin-framework-a9541c3abdb4805ee905864d8942a62fc7bbcae2.zip
Refactor #8313 based on API review
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ApplicationConnection.java19
-rw-r--r--src/com/vaadin/terminal/gwt/client/CalculatingLayout.java10
-rw-r--r--src/com/vaadin/terminal/gwt/client/DirectionalManagedLayout.java12
-rw-r--r--src/com/vaadin/terminal/gwt/client/FastStringSet.java14
-rw-r--r--src/com/vaadin/terminal/gwt/client/LayoutManager.java334
-rw-r--r--src/com/vaadin/terminal/gwt/client/MeasureManager.java154
-rw-r--r--src/com/vaadin/terminal/gwt/client/MeasuredSize.java102
-rw-r--r--src/com/vaadin/terminal/gwt/client/VPaintableMap.java2
-rw-r--r--src/com/vaadin/terminal/gwt/client/VPaintableWidget.java2
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/LayoutPhaseListener.java10
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/ManagedLayout.java7
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/PostLayoutListener.java8
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/ResizeRequired.java10
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/SimpleManagedLayout.java9
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayoutPaintable.java8
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java16
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java7
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VAccordionPaintable.java4
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VCustomLayoutPaintable.java4
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VFilterSelectPaintable.java4
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java17
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java17
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java16
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayoutPaintable.java46
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VMenuBarPaintable.java4
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java30
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VScrollTablePaintable.java8
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VTabsheetPaintable.java4
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java12
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/layout/VPaintableLayoutSlot.java31
30 files changed, 532 insertions, 389 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
index 2cb1b1fcd0..24683b0c9c 100644
--- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
+++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
@@ -162,7 +162,7 @@ public class ApplicationConnection {
private Set<VPaintableWidget> zeroHeightComponents = null;
- private final MeasureManager measureManager = new MeasureManager();
+ private final LayoutManager layoutManager = new LayoutManager(this);
public ApplicationConnection() {
view = GWT.create(VViewPaintable.class);
@@ -1594,16 +1594,7 @@ public class ApplicationConnection {
public void forceLayout() {
Duration duration = new Duration();
- VPaintableMap paintableMap = getPaintableMap();
- VPaintableWidget[] paintableWidgets = paintableMap
- .getRegisteredPaintableWidgets();
- for (VPaintableWidget vPaintableWidget : paintableWidgets) {
- MeasuredSize measuredSize = vPaintableWidget.getMeasuredSize();
- measuredSize.setHeightNeedsUpdate();
- measuredSize.setWidthNeedsUpdate();
- }
-
- doLayout(false);
+ layoutManager.foceLayout();
VConsole.log("forceLayout in " + duration.elapsedMillis() + " ms");
}
@@ -2015,7 +2006,7 @@ public class ApplicationConnection {
public void execute() {
layoutScheduled = false;
- measureManager.doLayout(ApplicationConnection.this);
+ layoutManager.doLayout();
}
};
@@ -2027,4 +2018,8 @@ public class ApplicationConnection {
Scheduler.get().scheduleDeferred(layoutCommand);
}
}
+
+ LayoutManager getLayoutManager() {
+ return layoutManager;
+ }
}
diff --git a/src/com/vaadin/terminal/gwt/client/CalculatingLayout.java b/src/com/vaadin/terminal/gwt/client/CalculatingLayout.java
deleted file mode 100644
index 2409505704..0000000000
--- a/src/com/vaadin/terminal/gwt/client/CalculatingLayout.java
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
-@VaadinApache2LicenseForJavaFiles@
- */
-package com.vaadin.terminal.gwt.client;
-
-public interface CalculatingLayout extends VPaintableWidgetContainer {
- public void updateVerticalSizes();
-
- public void updateHorizontalSizes();
-} \ No newline at end of file
diff --git a/src/com/vaadin/terminal/gwt/client/DirectionalManagedLayout.java b/src/com/vaadin/terminal/gwt/client/DirectionalManagedLayout.java
new file mode 100644
index 0000000000..296fbb22ff
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/DirectionalManagedLayout.java
@@ -0,0 +1,12 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+package com.vaadin.terminal.gwt.client;
+
+import com.vaadin.terminal.gwt.client.ui.ManagedLayout;
+
+public interface DirectionalManagedLayout extends ManagedLayout {
+ public void layoutVertically();
+
+ public void layoutHorizontally();
+} \ No newline at end of file
diff --git a/src/com/vaadin/terminal/gwt/client/FastStringSet.java b/src/com/vaadin/terminal/gwt/client/FastStringSet.java
index b5b4b8dc1d..05ed8addc8 100644
--- a/src/com/vaadin/terminal/gwt/client/FastStringSet.java
+++ b/src/com/vaadin/terminal/gwt/client/FastStringSet.java
@@ -32,7 +32,9 @@ public final class FastStringSet extends JavaScriptObject {
/*-{
var array = [];
for(var string in this) {
- array.push(string);
+ if (this.hasOwnProperty(string)) {
+ array.push(string);
+ }
}
return array;
}-*/;
@@ -42,6 +44,16 @@ public final class FastStringSet extends JavaScriptObject {
delete this[string];
}-*/;
+ public native boolean isEmpty()
+ /*-{
+ for(var string in this) {
+ if (this.hasOwnProperty(string)) {
+ return false;
+ }
+ }
+ return true;
+ }-*/;
+
public static FastStringSet create() {
return JavaScriptObject.createObject().cast();
}
diff --git a/src/com/vaadin/terminal/gwt/client/LayoutManager.java b/src/com/vaadin/terminal/gwt/client/LayoutManager.java
new file mode 100644
index 0000000000..d125543c2d
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/LayoutManager.java
@@ -0,0 +1,334 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+package com.vaadin.terminal.gwt.client;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import com.google.gwt.core.client.Duration;
+import com.google.gwt.core.client.JsArrayString;
+import com.google.gwt.dom.client.Element;
+import com.vaadin.terminal.gwt.client.ui.ManagedLayout;
+import com.vaadin.terminal.gwt.client.ui.PostLayoutListener;
+import com.vaadin.terminal.gwt.client.ui.SimpleManagedLayout;
+
+public class LayoutManager {
+ private final ApplicationConnection connection;
+ private final Set<Element> nonPaintableElements = new HashSet<Element>();
+ private final MeasuredSize nullSize = new MeasuredSize();
+
+ public LayoutManager(ApplicationConnection connection) {
+ this.connection = connection;
+ }
+
+ public static LayoutManager get(ApplicationConnection connection) {
+ return connection.getLayoutManager();
+ }
+
+ public void registerDependency(ManagedLayout owner, Element element) {
+ MeasuredSize measuredSize = ensureMeasured(element);
+
+ MeasuredSize ownerSize = getMeasuredSize(owner);
+ if (measuredSize.isHeightNeedsUpdate()) {
+ ownerSize.setHeightNeedsUpdate();
+ }
+ if (measuredSize.isWidthNeedsUpdate()) {
+ ownerSize.setWidthNeedsUpdate();
+ }
+ measuredSize.addDependent(owner.getId());
+ }
+
+ private MeasuredSize ensureMeasured(Element element) {
+ MeasuredSize measuredSize = getMeasuredSize(element, null);
+ if (measuredSize == null) {
+ measuredSize = new MeasuredSize();
+
+ if (VPaintableMap.get(connection).getPaintable(element) == null) {
+ nonPaintableElements.add(element);
+ }
+ setMeasuredSize(element, measuredSize);
+ }
+ return measuredSize;
+ }
+
+ private boolean needsMeasure(Element e) {
+ if (connection.getPaintableMap().getPid(e) != null) {
+ return true;
+ } else if (getMeasuredSize(e, nullSize).hasDependents()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private static native void setMeasuredSize(Element element,
+ MeasuredSize measuredSize)
+ /*-{
+ if (measuredSize) {
+ element.vMeasuredSize = measuredSize;
+ } else {
+ delete element.vMeasuredSize;
+ }
+ }-*/;
+
+ private static native final MeasuredSize getMeasuredSize(Element element,
+ MeasuredSize defaultSize)
+ /*-{
+ return element.vMeasuredSize || defaultSize;
+ }-*/;
+
+ private static final MeasuredSize getMeasuredSize(VPaintableWidget paintable) {
+ Element element = paintable.getWidgetForPaintable().getElement();
+ MeasuredSize measuredSize = getMeasuredSize(element, null);
+ if (measuredSize == null) {
+ measuredSize = new MeasuredSize();
+ setMeasuredSize(element, measuredSize);
+ }
+ return measuredSize;
+ }
+
+ public void unregisterDependency(ManagedLayout owner, Element element) {
+ MeasuredSize measuredSize = getMeasuredSize(element, null);
+ if (measuredSize == null) {
+ return;
+ }
+ measuredSize.removeDependent(owner.getId());
+ if (!needsMeasure(element)) {
+ nonPaintableElements.remove(element);
+ setMeasuredSize(element, null);
+ }
+ }
+
+ public void doLayout() {
+ VPaintableMap paintableMap = connection.getPaintableMap();
+ VPaintableWidget[] paintableWidgets = paintableMap
+ .getRegisteredPaintableWidgets();
+
+ int passes = 0;
+ Duration totalDuration = new Duration();
+
+ while (true) {
+ Duration passDuration = new Duration();
+ passes++;
+ measureElements(paintableWidgets);
+
+ FastStringSet needsHeightUpdate = FastStringSet.create();
+ FastStringSet needsWidthUpdate = FastStringSet.create();
+
+ for (VPaintableWidget paintable : paintableWidgets) {
+ MeasuredSize measuredSize = getMeasuredSize(paintable);
+ boolean notifiableType = isNotifiableType(paintable);
+
+ VPaintableWidgetContainer parent = paintable.getParent();
+ boolean parentNotifiable = parent != null
+ && isNotifiableType(parent);
+
+ if (measuredSize.isHeightNeedsUpdate()) {
+ if (notifiableType) {
+ needsHeightUpdate.add(paintable.getId());
+ }
+ if (!paintable.isRelativeHeight() && parentNotifiable) {
+ needsHeightUpdate.add(parent.getId());
+ }
+ }
+ if (measuredSize.isWidthNeedsUpdate()) {
+ if (notifiableType) {
+ needsWidthUpdate.add(paintable.getId());
+ }
+ if (!paintable.isRelativeWidth() && parentNotifiable) {
+ needsWidthUpdate.add(parent.getId());
+ }
+ }
+ measuredSize.clearDirtyState();
+ }
+
+ int measureTime = passDuration.elapsedMillis();
+ VConsole.log("Measure in " + measureTime + " ms");
+
+ FastStringSet updatedSet = FastStringSet.create();
+
+ JsArrayString needsWidthUpdateArray = needsWidthUpdate.dump();
+
+ for (int i = 0; i < needsWidthUpdateArray.length(); i++) {
+ String pid = needsWidthUpdateArray.get(i);
+
+ VPaintable paintable = paintableMap.getPaintable(pid);
+ if (paintable instanceof DirectionalManagedLayout) {
+ DirectionalManagedLayout cl = (DirectionalManagedLayout) paintable;
+ cl.layoutHorizontally();
+ } else if (paintable instanceof SimpleManagedLayout) {
+ SimpleManagedLayout rr = (SimpleManagedLayout) paintable;
+ rr.layout();
+ needsHeightUpdate.remove(pid);
+ }
+ updatedSet.add(pid);
+ }
+
+ JsArrayString needsHeightUpdateArray = needsHeightUpdate.dump();
+ for (int i = 0; i < needsHeightUpdateArray.length(); i++) {
+ String pid = needsHeightUpdateArray.get(i);
+
+ VPaintableWidget paintable = (VPaintableWidget) paintableMap
+ .getPaintable(pid);
+ if (paintable instanceof DirectionalManagedLayout) {
+ DirectionalManagedLayout cl = (DirectionalManagedLayout) paintable;
+ cl.layoutVertically();
+ } else if (paintable instanceof SimpleManagedLayout) {
+ SimpleManagedLayout rr = (SimpleManagedLayout) paintable;
+ rr.layout();
+ }
+ updatedSet.add(pid);
+ }
+
+ JsArrayString changed = updatedSet.dump();
+ VConsole.log(changed.length() + " requestLayout invocations in "
+ + (passDuration.elapsedMillis() - measureTime) + "ms");
+
+ StringBuilder b = new StringBuilder();
+ b.append(changed.length());
+ b.append(" changed widgets in pass ");
+ b.append(passes);
+ b.append(" in ");
+ b.append(passDuration.elapsedMillis());
+ b.append(" ms: ");
+ if (changed.length() < 10) {
+ for (int i = 0; i < changed.length(); i++) {
+ if (i != 0) {
+ b.append(", ");
+ }
+ b.append(changed.get(i));
+ }
+ }
+ VConsole.log(b.toString());
+
+ if (changed.length() == 0) {
+ VConsole.log("No more changes in pass " + passes);
+ break;
+ }
+
+ if (passes > 100) {
+ VConsole.log("Aborting layout");
+ break;
+ }
+ }
+
+ for (VPaintableWidget vPaintableWidget : paintableWidgets) {
+ if (vPaintableWidget instanceof PostLayoutListener) {
+ ((PostLayoutListener) vPaintableWidget).postLayout();
+ }
+ }
+
+ VConsole.log("Total layout time: " + totalDuration.elapsedMillis()
+ + "ms");
+ }
+
+ private void measureElements(VPaintableWidget[] paintableWidgets) {
+
+ for (VPaintableWidget paintableWidget : paintableWidgets) {
+ Element element = paintableWidget.getWidgetForPaintable()
+ .getElement();
+ MeasuredSize measuredSize = getMeasuredSize(paintableWidget);
+ measuredAndUpdate(element, measuredSize);
+ }
+
+ for (Element element : nonPaintableElements) {
+ MeasuredSize measuredSize = getMeasuredSize(element, null);
+ measuredAndUpdate(element, measuredSize);
+ }
+ }
+
+ private void measuredAndUpdate(Element element, MeasuredSize measuredSize) {
+ if (measuredSize.measure(element)) {
+ JsArrayString dependents = measuredSize.getDependents();
+ for (int i = 0; i < dependents.length(); i++) {
+ String pid = dependents.get(i);
+ VPaintableWidget dependent = (VPaintableWidget) connection
+ .getPaintableMap().getPaintable(pid);
+ if (dependent != null) {
+ MeasuredSize dependentSize = getMeasuredSize(dependent);
+ if (measuredSize.isHeightNeedsUpdate()) {
+ dependentSize.setHeightNeedsUpdate();
+ }
+ if (measuredSize.isWidthNeedsUpdate()) {
+ dependentSize.setWidthNeedsUpdate();
+ }
+ }
+ }
+ }
+ }
+
+ private static boolean isNotifiableType(VPaintableWidget paintable) {
+ return paintable instanceof SimpleManagedLayout
+ || paintable instanceof DirectionalManagedLayout;
+ }
+
+ public void foceLayout() {
+ VPaintableMap paintableMap = connection.getPaintableMap();
+ VPaintableWidget[] paintableWidgets = paintableMap
+ .getRegisteredPaintableWidgets();
+ for (VPaintableWidget vPaintableWidget : paintableWidgets) {
+ MeasuredSize measuredSize = getMeasuredSize(vPaintableWidget);
+ measuredSize.setHeightNeedsUpdate();
+ measuredSize.setWidthNeedsUpdate();
+ }
+ doLayout();
+ }
+
+ public final void setNeedsUpdate(ManagedLayout layout) {
+ setWidthNeedsUpdate(layout);
+ setHeightNeedsUpdate(layout);
+ }
+
+ public final void setWidthNeedsUpdate(ManagedLayout layout) {
+ getMeasuredSize(layout).setWidthNeedsUpdate();
+ }
+
+ public final void setHeightNeedsUpdate(ManagedLayout layout) {
+ getMeasuredSize(layout).setHeightNeedsUpdate();
+ }
+
+ public boolean isMeasured(Element element) {
+ return getMeasuredSize(element, nullSize) != nullSize;
+ }
+
+ public final int getOuterHeight(Element element) {
+ return getMeasuredSize(element, nullSize).getOuterHeight();
+ }
+
+ public final int getOuterWidth(Element element) {
+ return getMeasuredSize(element, nullSize).getOuterWidth();
+ }
+
+ public final int getInnerHeight(Element element) {
+ return getMeasuredSize(element, nullSize).getInnerHeight();
+ }
+
+ public final int getInnerWidth(Element element) {
+ return getMeasuredSize(element, nullSize).getInnerWidth();
+ }
+
+ public final int getBorderHeight(Element element) {
+ return getMeasuredSize(element, nullSize).getBorderHeight();
+ }
+
+ public int getPaddingHeight(Element element) {
+ return getMeasuredSize(element, nullSize).getPaddingHeight();
+ }
+
+ public int getBorderWidth(Element element) {
+ return getMeasuredSize(element, nullSize).getBorderWidth();
+ }
+
+ public int getPaddingWidth(Element element) {
+ return getMeasuredSize(element, nullSize).getPaddingWidth();
+ }
+
+ public int getPaddingTop(Element element) {
+ return getMeasuredSize(element, nullSize).getPaddingTop();
+ }
+
+ public int getPaddingLeft(Element element) {
+ return getMeasuredSize(element, nullSize).getPaddingLeft();
+ }
+}
diff --git a/src/com/vaadin/terminal/gwt/client/MeasureManager.java b/src/com/vaadin/terminal/gwt/client/MeasureManager.java
deleted file mode 100644
index f661ce66be..0000000000
--- a/src/com/vaadin/terminal/gwt/client/MeasureManager.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
-@VaadinApache2LicenseForJavaFiles@
- */
-package com.vaadin.terminal.gwt.client;
-
-import com.google.gwt.core.client.Duration;
-import com.google.gwt.core.client.JsArrayString;
-import com.vaadin.terminal.gwt.client.ui.LayoutPhaseListener;
-import com.vaadin.terminal.gwt.client.ui.ResizeRequired;
-
-public class MeasureManager {
-
- public void doLayout(ApplicationConnection client) {
- VPaintableMap paintableMap = client.getPaintableMap();
- VPaintableWidget[] paintableWidgets = paintableMap
- .getRegisteredPaintableWidgets();
-
- for (VPaintableWidget vPaintableWidget : paintableWidgets) {
- if (vPaintableWidget instanceof LayoutPhaseListener) {
- ((LayoutPhaseListener) vPaintableWidget).beforeLayout();
- }
- }
-
- int passes = 0;
- Duration totalDuration = new Duration();
-
- while (true) {
- Duration passDuration = new Duration();
- passes++;
- measureWidgets(paintableWidgets);
-
- FastStringSet needsHeightUpdate = FastStringSet.create();
- FastStringSet needsWidthUpdate = FastStringSet.create();
-
- for (VPaintableWidget paintable : paintableWidgets) {
- MeasuredSize measuredSize = paintable.getMeasuredSize();
- boolean notifiableType = isNotifiableType(paintable);
-
- VPaintableWidgetContainer parent = paintable.getParent();
- boolean parentNotifiable = parent != null
- && isNotifiableType(parent);
-
- if (measuredSize.isHeightNeedsUpdate()) {
- if (notifiableType) {
- needsHeightUpdate.add(paintable.getId());
- }
- if (!paintable.isRelativeHeight() && parentNotifiable) {
- needsHeightUpdate.add(parent.getId());
- }
- }
- if (measuredSize.isWidthNeedsUpdate()) {
- if (notifiableType) {
- needsWidthUpdate.add(paintable.getId());
- }
- if (!paintable.isRelativeWidth() && parentNotifiable) {
- needsWidthUpdate.add(parent.getId());
- }
- }
- measuredSize.clearDirtyState();
- }
-
- int measureTime = passDuration.elapsedMillis();
- VConsole.log("Measure in " + measureTime + " ms");
-
- FastStringSet updatedSet = FastStringSet.create();
-
- JsArrayString needsWidthUpdateArray = needsWidthUpdate.dump();
-
- for (int i = 0; i < needsWidthUpdateArray.length(); i++) {
- String pid = needsWidthUpdateArray.get(i);
-
- VPaintable paintable = paintableMap.getPaintable(pid);
- if (paintable instanceof CalculatingLayout) {
- CalculatingLayout cl = (CalculatingLayout) paintable;
- cl.updateHorizontalSizes();
- } else if (paintable instanceof ResizeRequired) {
- ResizeRequired rr = (ResizeRequired) paintable;
- rr.onResize();
- needsHeightUpdate.remove(pid);
- }
- updatedSet.add(pid);
- }
-
- JsArrayString needsHeightUpdateArray = needsHeightUpdate.dump();
- for (int i = 0; i < needsHeightUpdateArray.length(); i++) {
- String pid = needsHeightUpdateArray.get(i);
-
- VPaintableWidget paintable = (VPaintableWidget) paintableMap
- .getPaintable(pid);
- if (paintable instanceof CalculatingLayout) {
- CalculatingLayout cl = (CalculatingLayout) paintable;
- cl.updateVerticalSizes();
- } else if (paintable instanceof ResizeRequired) {
- ResizeRequired rr = (ResizeRequired) paintable;
- rr.onResize();
- }
- updatedSet.add(pid);
- }
-
- JsArrayString changed = updatedSet.dump();
- VConsole.log(changed.length() + " requestLayout invocations in "
- + (passDuration.elapsedMillis() - measureTime) + "ms");
-
- StringBuilder b = new StringBuilder();
- b.append(changed.length());
- b.append(" changed widgets in pass ");
- b.append(passes);
- b.append(" in ");
- b.append(passDuration.elapsedMillis());
- b.append(" ms: ");
- if (changed.length() < 10) {
- for (int i = 0; i < changed.length(); i++) {
- if (i != 0) {
- b.append(", ");
- }
- b.append(changed.get(i));
- }
- }
- VConsole.log(b.toString());
-
- if (changed.length() == 0) {
- VConsole.log("No more changes in pass " + passes);
- break;
- }
-
- if (passes > 100) {
- VConsole.log("Aborting layout");
- break;
- }
- }
-
- for (VPaintableWidget vPaintableWidget : paintableWidgets) {
- if (vPaintableWidget instanceof LayoutPhaseListener) {
- ((LayoutPhaseListener) vPaintableWidget).afterLayout();
- }
- }
-
- VConsole.log("Total layout time: " + totalDuration.elapsedMillis()
- + "ms");
- }
-
- private void measureWidgets(VPaintableWidget[] paintableWidgets) {
-
- for (VPaintableWidget paintableWidget : paintableWidgets) {
- MeasuredSize measuredSize = paintableWidget.getMeasuredSize();
- measuredSize.measure();
- }
- }
-
- private static boolean isNotifiableType(VPaintableWidget paintable) {
- return paintable instanceof ResizeRequired
- || paintable instanceof CalculatingLayout;
- }
-}
diff --git a/src/com/vaadin/terminal/gwt/client/MeasuredSize.java b/src/com/vaadin/terminal/gwt/client/MeasuredSize.java
index d45c5381c9..9a70ff06d3 100644
--- a/src/com/vaadin/terminal/gwt/client/MeasuredSize.java
+++ b/src/com/vaadin/terminal/gwt/client/MeasuredSize.java
@@ -3,14 +3,10 @@
*/
package com.vaadin.terminal.gwt.client;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
+import com.google.gwt.core.client.JsArrayString;
import com.google.gwt.dom.client.Element;
-import com.google.gwt.user.client.ui.Widget;
-public final class MeasuredSize {
+public class MeasuredSize {
private int width = -1;
private int height = -1;
@@ -18,16 +14,10 @@ public final class MeasuredSize {
private int[] borders = new int[4];
private int[] margins = new int[4];
- private final VPaintableWidget paintable;
-
private boolean heightChanged = true;
private boolean widthChanged = true;
- private final Map<Element, int[]> dependencySizes = new HashMap<Element, int[]>();
-
- public MeasuredSize(VPaintableWidget paintable) {
- this.paintable = paintable;
- }
+ private FastStringSet dependents = FastStringSet.create();
public int getOuterHeight() {
return height;
@@ -37,6 +27,22 @@ public final class MeasuredSize {
return width;
}
+ public void addDependent(String pid) {
+ dependents.add(pid);
+ }
+
+ public void removeDependent(String pid) {
+ dependents.remove(pid);
+ }
+
+ public boolean hasDependents() {
+ return !dependents.isEmpty();
+ }
+
+ public JsArrayString getDependents() {
+ return dependents.dump();
+ }
+
private static int sumWidths(int[] sizes) {
return sizes[1] + sizes[3];
}
@@ -69,33 +75,6 @@ public final class MeasuredSize {
}
}
- public void registerDependency(Element element) {
- if (!dependencySizes.containsKey(element)) {
- dependencySizes.put(element, new int[] { -1, -1 });
- }
- }
-
- public void unregisterDependency(Element element) {
- dependencySizes.remove(element);
- }
-
- public int getDependencyOuterWidth(Element e) {
- return getDependencySize(e, 0);
- }
-
- public int getDependencyOuterHeight(Element e) {
- return getDependencySize(e, 1);
- }
-
- private int getDependencySize(Element e, int index) {
- int[] sizes = dependencySizes.get(e);
- if (sizes == null) {
- return -1;
- } else {
- return sizes[index];
- }
- }
-
public int getBorderHeight() {
return sumHeights(borders);
}
@@ -168,9 +147,11 @@ public final class MeasuredSize {
return paddings[3];
}
- void measure() {
- Widget widget = paintable.getWidgetForPaintable();
- ComputedStyle computedStyle = new ComputedStyle(widget.getElement());
+ boolean measure(Element element) {
+ boolean wasHeightChanged = heightChanged;
+ boolean wasWidthChanged = widthChanged;
+
+ ComputedStyle computedStyle = new ComputedStyle(element);
int[] paddings = computedStyle.getPadding();
if (!heightChanged && hasHeightChanged(this.paddings, paddings)) {
@@ -199,43 +180,16 @@ public final class MeasuredSize {
}
this.borders = borders;
- int requiredHeight = Util.getRequiredHeight(widget);
+ int requiredHeight = Util.getRequiredHeight(element);
int marginHeight = sumHeights(margins);
setOuterHeight(requiredHeight + marginHeight);
- int requiredWidth = Util.getRequiredWidth(widget);
+ int requiredWidth = Util.getRequiredWidth(element);
int marginWidth = sumWidths(margins);
setOuterWidth(requiredWidth + marginWidth);
- // int i = 0;
- for (Entry<Element, int[]> entry : dependencySizes.entrySet()) {
- Element element = entry.getKey();
- // int[] elementMargin = new ComputedStyle(element).getMargin();
- int[] sizes = entry.getValue();
-
- int elementWidth = element.getOffsetWidth();
- // elementWidth += elementMargin[1] + elementMargin[3];
- if (elementWidth != sizes[0]) {
- // System.out.println(paintable.getId() + " dependency " + i
- // + " width changed from " + sizes[0] + " to "
- // + elementWidth);
- sizes[0] = elementWidth;
- widthChanged = true;
- }
-
- int elementHeight = element.getOffsetHeight();
- // Causes infinite loops as a negative margin based on the
- // measured height is currently used for captions
- // elementHeight += elementMargin[0] + elementMargin[1];
- if (elementHeight != sizes[1]) {
- // System.out.println(paintable.getId() + " dependency " + i
- // + " height changed from " + sizes[1] + " to "
- // + elementHeight);
- sizes[1] = elementHeight;
- heightChanged = true;
- }
- // i++;
- }
+ return wasHeightChanged != heightChanged
+ || wasWidthChanged != widthChanged;
}
void clearDirtyState() {
diff --git a/src/com/vaadin/terminal/gwt/client/VPaintableMap.java b/src/com/vaadin/terminal/gwt/client/VPaintableMap.java
index 03fb599fe9..c196fa0953 100644
--- a/src/com/vaadin/terminal/gwt/client/VPaintableMap.java
+++ b/src/com/vaadin/terminal/gwt/client/VPaintableMap.java
@@ -13,7 +13,7 @@ import java.util.Map;
import java.util.Set;
import com.google.gwt.core.client.GWT;
-import com.google.gwt.user.client.Element;
+import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.Paintable;
diff --git a/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java b/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java
index 39bd2d21b8..c42248e835 100644
--- a/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java
+++ b/src/com/vaadin/terminal/gwt/client/VPaintableWidget.java
@@ -29,7 +29,7 @@ public interface VPaintableWidget extends VPaintable {
// FIXME: Rename to getParent()
public VPaintableWidgetContainer getParent();
- public MeasuredSize getMeasuredSize();
+ public LayoutManager getLayoutManager();
/**
* Returns <code>true</code> if the width of this paintable is currently
diff --git a/src/com/vaadin/terminal/gwt/client/ui/LayoutPhaseListener.java b/src/com/vaadin/terminal/gwt/client/ui/LayoutPhaseListener.java
deleted file mode 100644
index 495b923d8a..0000000000
--- a/src/com/vaadin/terminal/gwt/client/ui/LayoutPhaseListener.java
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
-@VaadinApache2LicenseForJavaFiles@
- */
-package com.vaadin.terminal.gwt.client.ui;
-
-public interface LayoutPhaseListener {
- public void beforeLayout();
-
- public void afterLayout();
-}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/ManagedLayout.java b/src/com/vaadin/terminal/gwt/client/ui/ManagedLayout.java
new file mode 100644
index 0000000000..3c6c246a1e
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/ui/ManagedLayout.java
@@ -0,0 +1,7 @@
+package com.vaadin.terminal.gwt.client.ui;
+
+import com.vaadin.terminal.gwt.client.VPaintableWidget;
+
+public interface ManagedLayout extends VPaintableWidget {
+
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/PostLayoutListener.java b/src/com/vaadin/terminal/gwt/client/ui/PostLayoutListener.java
new file mode 100644
index 0000000000..feb7494f87
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/ui/PostLayoutListener.java
@@ -0,0 +1,8 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+package com.vaadin.terminal.gwt.client.ui;
+
+public interface PostLayoutListener {
+ public void postLayout();
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/ResizeRequired.java b/src/com/vaadin/terminal/gwt/client/ui/ResizeRequired.java
deleted file mode 100644
index ac149822b5..0000000000
--- a/src/com/vaadin/terminal/gwt/client/ui/ResizeRequired.java
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
-@VaadinApache2LicenseForJavaFiles@
- */
-package com.vaadin.terminal.gwt.client.ui;
-
-import com.vaadin.terminal.gwt.client.VPaintableWidget;
-
-public interface ResizeRequired extends VPaintableWidget {
- public void onResize();
-}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/SimpleManagedLayout.java b/src/com/vaadin/terminal/gwt/client/ui/SimpleManagedLayout.java
new file mode 100644
index 0000000000..e8ab688db0
--- /dev/null
+++ b/src/com/vaadin/terminal/gwt/client/ui/SimpleManagedLayout.java
@@ -0,0 +1,9 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+package com.vaadin.terminal.gwt.client.ui;
+
+
+public interface SimpleManagedLayout extends ManagedLayout {
+ public void layout();
+}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayoutPaintable.java
index 6ae01c5c23..2677ea0f75 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayoutPaintable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayoutPaintable.java
@@ -15,14 +15,14 @@ import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.CalculatingLayout;
+import com.vaadin.terminal.gwt.client.DirectionalManagedLayout;
import com.vaadin.terminal.gwt.client.EventId;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
import com.vaadin.terminal.gwt.client.ui.VAbsoluteLayout.AbsoluteWrapper;
public class VAbsoluteLayoutPaintable extends VAbstractPaintableWidgetContainer
- implements CalculatingLayout {
+ implements DirectionalManagedLayout {
private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(
this, EventId.LAYOUT_CLICK) {
@@ -88,7 +88,7 @@ public class VAbsoluteLayoutPaintable extends VAbstractPaintableWidgetContainer
return (VAbsoluteLayout) super.getWidgetForPaintable();
}
- public void updateVerticalSizes() {
+ public void layoutVertically() {
VAbsoluteLayout layout = getWidgetForPaintable();
for (VPaintableWidget paintable : getChildren()) {
Widget widget = paintable.getWidgetForPaintable();
@@ -119,7 +119,7 @@ public class VAbsoluteLayoutPaintable extends VAbstractPaintableWidgetContainer
}
}
- public void updateHorizontalSizes() {
+ public void layoutHorizontally() {
VAbsoluteLayout layout = getWidgetForPaintable();
for (VPaintableWidget paintable : getChildren()) {
Widget widget = paintable.getWidgetForPaintable();
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
index ab09b5d60b..1fc995f584 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
@@ -8,7 +8,7 @@ import com.google.gwt.user.client.ui.FocusWidget;
import com.google.gwt.user.client.ui.Focusable;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.MeasuredSize;
+import com.vaadin.terminal.gwt.client.LayoutManager;
import com.vaadin.terminal.gwt.client.TooltipInfo;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VPaintableMap;
@@ -24,8 +24,6 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
private ApplicationConnection connection;
private String id;
- private final MeasuredSize measuredSize = new MeasuredSize(this);
-
/* State variables */
private boolean enabled = true;
private boolean visible = true;
@@ -200,15 +198,15 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
// and non-relative
if (w.endsWith("%") != declaredWidth.endsWith("%")) {
VPaintableWidgetContainer parent = getParent();
- if (parent != null) {
- parent.getMeasuredSize().setWidthNeedsUpdate();
+ if (parent instanceof ManagedLayout) {
+ getLayoutManager().setWidthNeedsUpdate((ManagedLayout) parent);
}
}
if (h.endsWith("%") != declaredHeight.endsWith("%")) {
VPaintableWidgetContainer parent = getParent();
- if (parent != null) {
- parent.getMeasuredSize().setHeightNeedsUpdate();
+ if (parent instanceof ManagedLayout) {
+ getLayoutManager().setHeightNeedsUpdate((ManagedLayout) parent);
}
}
@@ -377,7 +375,7 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
return styleBuf.toString();
}
- public MeasuredSize getMeasuredSize() {
- return measuredSize;
+ public LayoutManager getLayoutManager() {
+ return LayoutManager.get(connection);
}
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java
index 229dfae5c2..6242090f58 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java
@@ -16,7 +16,7 @@ import com.vaadin.terminal.gwt.client.VPaintableMap;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
public abstract class VAbstractSplitPanelPaintable extends
- VAbstractPaintableWidgetContainer implements ResizeRequired {
+ VAbstractPaintableWidgetContainer implements SimpleManagedLayout {
public static final String SPLITTER_CLICK_EVENT_IDENTIFIER = "sp_click";
@@ -123,11 +123,10 @@ public abstract class VAbstractSplitPanelPaintable extends
// appearing/disappearing scrollbars into account.
client.runDescendentsLayout(getWidgetForPaintable());
- getMeasuredSize().setHeightNeedsUpdate();
- getMeasuredSize().setWidthNeedsUpdate();
+ getLayoutManager().setNeedsUpdate(this);
}
- public void onResize() {
+ public void layout() {
VAbstractSplitPanel splitPanel = getWidgetForPaintable();
splitPanel.setSplitPosition(splitPanel.position);
splitPanel.updateSizes();
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAccordionPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VAccordionPaintable.java
index 86ef5d1c96..809eb1167b 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VAccordionPaintable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VAccordionPaintable.java
@@ -13,7 +13,7 @@ import com.vaadin.terminal.gwt.client.VPaintableWidget;
import com.vaadin.terminal.gwt.client.ui.VAccordion.StackItem;
public class VAccordionPaintable extends VTabsheetBasePaintable implements
- ResizeRequired {
+ SimpleManagedLayout {
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
@@ -66,7 +66,7 @@ public class VAccordionPaintable extends VTabsheetBasePaintable implements
/* Accordion does not render its children's captions */
}
- public void onResize() {
+ public void layout() {
VAccordion accordion = getWidgetForPaintable();
accordion.updateOpenTabSize();
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCustomLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VCustomLayoutPaintable.java
index f914d157d3..e5cc917aea 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VCustomLayoutPaintable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VCustomLayoutPaintable.java
@@ -15,7 +15,7 @@ import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
public class VCustomLayoutPaintable extends VAbstractPaintableWidgetContainer
- implements ResizeRequired {
+ implements SimpleManagedLayout {
/** Update the layout from UIDL */
@Override
@@ -90,7 +90,7 @@ public class VCustomLayoutPaintable extends VAbstractPaintableWidgetContainer
}
- public void onResize() {
+ public void layout() {
getWidgetForPaintable().iLayoutJS(
DOM.getFirstChild(getWidgetForPaintable().getElement()));
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelectPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelectPaintable.java
index 374b43914e..ae93b7c583 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VFilterSelectPaintable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VFilterSelectPaintable.java
@@ -13,7 +13,7 @@ import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.ui.VFilterSelect.FilterSelectSuggestion;
public class VFilterSelectPaintable extends VAbstractPaintableWidget implements
- ResizeRequired {
+ SimpleManagedLayout {
/*
* (non-Javadoc)
@@ -246,7 +246,7 @@ public class VFilterSelectPaintable extends VAbstractPaintableWidget implements
return (VFilterSelect) super.getWidgetForPaintable();
}
- public void onResize() {
+ public void layout() {
VFilterSelect widget = getWidgetForPaintable();
if (widget.initDone) {
widget.updateRootWidth();
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java
index a350983e6c..2cd7eaa539 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java
@@ -8,18 +8,17 @@ import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.MeasuredSize;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VPaintableMap;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
public class VFormPaintable extends VAbstractPaintableWidgetContainer implements
- ResizeRequired {
+ SimpleManagedLayout {
- public VFormPaintable() {
+ @Override
+ public void init() {
VForm form = getWidgetForPaintable();
- MeasuredSize measuredSize = getMeasuredSize();
- measuredSize.registerDependency(form.footerContainer);
+ getLayoutManager().registerDependency(this, form.footerContainer);
}
@Override
@@ -178,12 +177,12 @@ public class VFormPaintable extends VAbstractPaintableWidgetContainer implements
return GWT.create(VForm.class);
}
- public void onResize() {
- MeasuredSize measuredSize = getMeasuredSize();
+ public void layout() {
VForm form = getWidgetForPaintable();
- int footerHeight = measuredSize
- .getDependencyOuterHeight(form.footerContainer);
+ int footerHeight = getLayoutManager().getOuterHeight(
+ form.footerContainer);
+
form.fieldContainer.getStyle().setPaddingBottom(footerHeight, Unit.PX);
form.footerContainer.getStyle().setMarginTop(-footerHeight, Unit.PX);
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java
index 8168141ece..8ad4cd0496 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java
@@ -17,7 +17,7 @@ import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.MeasuredSize;
+import com.vaadin.terminal.gwt.client.LayoutManager;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VCaption;
@@ -59,10 +59,6 @@ public class VGridLayout extends ComplexPanel {
setStyleName(CLASSNAME);
}
- private MeasuredSize getMeasuredSize() {
- return getPaintable().getMeasuredSize();
- }
-
private VPaintableWidget getPaintable() {
return VPaintableMap.get(client).getPaintable(this);
}
@@ -91,7 +87,7 @@ public class VGridLayout extends ComplexPanel {
* @return
*/
protected int getHorizontalSpacing() {
- return getMeasuredSize().getDependencyOuterWidth(spacingMeasureElement);
+ return LayoutManager.get(client).getOuterWidth(spacingMeasureElement);
}
/**
@@ -100,8 +96,7 @@ public class VGridLayout extends ComplexPanel {
* @return
*/
protected int getVerticalSpacing() {
- return getMeasuredSize()
- .getDependencyOuterHeight(spacingMeasureElement);
+ return LayoutManager.get(client).getOuterHeight(spacingMeasureElement);
}
static int[] cloneArray(int[] toBeCloned) {
@@ -119,7 +114,8 @@ public class VGridLayout extends ComplexPanel {
for (int i = 1; i < minRowHeights.length; i++) {
usedSpace += verticalSpacing + minRowHeights[i];
}
- int availableSpace = getMeasuredSize().getInnerHeight();
+ int availableSpace = LayoutManager.get(client).getInnerHeight(
+ getElement());
int excessSpace = availableSpace - usedSpace;
int distributed = 0;
if (excessSpace > 0) {
@@ -168,7 +164,8 @@ public class VGridLayout extends ComplexPanel {
usedSpace += horizontalSpacing + minColumnWidths[i];
}
- int availableSpace = getMeasuredSize().getInnerWidth();
+ int availableSpace = LayoutManager.get(client).getInnerWidth(
+ getElement());
int excessSpace = availableSpace - usedSpace;
int distributed = 0;
if (excessSpace > 0) {
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java
index beb72d45b4..2c896825ec 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VGridLayoutPaintable.java
@@ -13,7 +13,7 @@ import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.CalculatingLayout;
+import com.vaadin.terminal.gwt.client.DirectionalManagedLayout;
import com.vaadin.terminal.gwt.client.EventId;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VCaption;
@@ -23,7 +23,7 @@ import com.vaadin.terminal.gwt.client.ui.VGridLayout.Cell;
import com.vaadin.terminal.gwt.client.ui.layout.VLayoutSlot;
public class VGridLayoutPaintable extends VAbstractPaintableWidgetContainer
- implements CalculatingLayout {
+ implements DirectionalManagedLayout {
private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(
this, EventId.LAYOUT_CLICK) {
@@ -39,8 +39,9 @@ public class VGridLayoutPaintable extends VAbstractPaintableWidgetContainer
}
};
- public VGridLayoutPaintable() {
- getMeasuredSize().registerDependency(
+ @Override
+ public void init() {
+ getLayoutManager().registerDependency(this,
getWidgetForPaintable().spacingMeasureElement);
}
@@ -120,8 +121,7 @@ public class VGridLayoutPaintable extends VAbstractPaintableWidgetContainer
layout.updateSpacingStyleName(uidl.getBooleanAttribute("spacing"));
- getMeasuredSize().setHeightNeedsUpdate();
- getMeasuredSize().setWidthNeedsUpdate();
+ getLayoutManager().setNeedsUpdate(this);
}
public void updateCaption(VPaintableWidget component, UIDL uidl) {
@@ -154,11 +154,11 @@ public class VGridLayoutPaintable extends VAbstractPaintableWidgetContainer
return GWT.create(VGridLayout.class);
}
- public void updateVerticalSizes() {
+ public void layoutVertically() {
getWidgetForPaintable().updateHeight();
}
- public void updateHorizontalSizes() {
+ public void layoutHorizontally() {
getWidgetForPaintable().updateWidth();
}
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayoutPaintable.java
index 72cc550651..5f35815cd8 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayoutPaintable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VMeasuringOrderedLayoutPaintable.java
@@ -8,10 +8,11 @@ import java.util.Iterator;
import com.google.gwt.dom.client.Node;
import com.google.gwt.dom.client.Style;
+import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.CalculatingLayout;
-import com.vaadin.terminal.gwt.client.MeasuredSize;
+import com.vaadin.terminal.gwt.client.DirectionalManagedLayout;
+import com.vaadin.terminal.gwt.client.LayoutManager;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VCaption;
import com.vaadin.terminal.gwt.client.VPaintableMap;
@@ -21,10 +22,11 @@ import com.vaadin.terminal.gwt.client.ui.layout.VLayoutSlot;
import com.vaadin.terminal.gwt.client.ui.layout.VPaintableLayoutSlot;
public abstract class VMeasuringOrderedLayoutPaintable extends
- VAbstractPaintableWidgetContainer implements CalculatingLayout {
+ VAbstractPaintableWidgetContainer implements DirectionalManagedLayout {
- public VMeasuringOrderedLayoutPaintable() {
- getMeasuredSize().registerDependency(
+ @Override
+ public void init() {
+ getLayoutManager().registerDependency(this,
getWidgetForPaintable().spacingMeasureElement);
}
@@ -145,18 +147,18 @@ public abstract class VMeasuringOrderedLayoutPaintable extends
layout.updateSpacingStyleName(uidl.getBooleanAttribute("spacing"));
- getMeasuredSize().setHeightNeedsUpdate();
- getMeasuredSize().setWidthNeedsUpdate();
+ getLayoutManager().setNeedsUpdate(this);
}
private int getSizeForInnerSize(int size, boolean isVertical) {
- MeasuredSize measuredSize = getMeasuredSize();
+ LayoutManager layoutManager = getLayoutManager();
+ Element element = getWidgetForPaintable().getElement();
if (isVertical) {
- return size + measuredSize.getBorderHeight()
- + measuredSize.getPaddingHeight();
+ return size + layoutManager.getBorderHeight(element)
+ + layoutManager.getPaddingHeight(element);
} else {
- return size + measuredSize.getBorderWidth()
- + measuredSize.getPaddingWidth();
+ return size + layoutManager.getBorderWidth(element)
+ + layoutManager.getPaddingWidth(element);
}
}
@@ -174,9 +176,11 @@ public abstract class VMeasuringOrderedLayoutPaintable extends
private int getInnerSizeInDirection(boolean isVertical) {
if (isVertical) {
- return getMeasuredSize().getInnerHeight();
+ return getLayoutManager().getInnerHeight(
+ getWidgetForPaintable().getElement());
} else {
- return getMeasuredSize().getInnerWidth();
+ return getLayoutManager().getInnerWidth(
+ getWidgetForPaintable().getElement());
}
}
@@ -210,10 +214,10 @@ public abstract class VMeasuringOrderedLayoutPaintable extends
private int getSpacingInDirection(boolean isVertical) {
if (isVertical) {
- return getMeasuredSize().getDependencyOuterHeight(
+ return getLayoutManager().getOuterHeight(
getWidgetForPaintable().spacingMeasureElement);
} else {
- return getMeasuredSize().getDependencyOuterWidth(
+ return getLayoutManager().getOuterWidth(
getWidgetForPaintable().spacingMeasureElement);
}
}
@@ -259,13 +263,15 @@ public abstract class VMeasuringOrderedLayoutPaintable extends
private int getStartPadding(boolean isVertical) {
if (isVertical) {
- return getMeasuredSize().getPaddingTop();
+ return getLayoutManager().getPaddingTop(
+ getWidgetForPaintable().getElement());
} else {
- return getMeasuredSize().getPaddingLeft();
+ return getLayoutManager().getPaddingLeft(
+ getWidgetForPaintable().getElement());
}
}
- public void updateHorizontalSizes() {
+ public void layoutHorizontally() {
if (getWidgetForPaintable().isVertical) {
layoutSecondaryDirection();
} else {
@@ -273,7 +279,7 @@ public abstract class VMeasuringOrderedLayoutPaintable extends
}
}
- public void updateVerticalSizes() {
+ public void layoutVertically() {
if (getWidgetForPaintable().isVertical) {
layoutPrimaryDirection();
} else {
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMenuBarPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VMenuBarPaintable.java
index 87c7a6c145..36e210971c 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VMenuBarPaintable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VMenuBarPaintable.java
@@ -15,7 +15,7 @@ import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.ui.VMenuBar.CustomMenuItem;
public class VMenuBarPaintable extends VAbstractPaintableWidget implements
- ResizeRequired {
+ SimpleManagedLayout {
/**
* This method must be implemented to update the client-side component from
* UIDL data received from server.
@@ -161,7 +161,7 @@ public class VMenuBarPaintable extends VAbstractPaintableWidget implements
return (VMenuBar) super.getWidgetForPaintable();
}
- public void onResize() {
+ public void layout() {
getWidgetForPaintable().iLayout();
}
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java
index eade1d7d0e..e88bae53d2 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java
@@ -11,12 +11,12 @@ import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.MeasuredSize;
+import com.vaadin.terminal.gwt.client.LayoutManager;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
public class VPanelPaintable extends VAbstractPaintableWidgetContainer
- implements ResizeRequired, LayoutPhaseListener {
+ implements SimpleManagedLayout, PostLayoutListener {
public static final String CLICK_EVENT_IDENTIFIER = "click";
@@ -34,13 +34,14 @@ public class VPanelPaintable extends VAbstractPaintableWidgetContainer
private Integer uidlScrollLeft;
- public VPanelPaintable() {
+ @Override
+ public void init() {
VPanel panel = getWidgetForPaintable();
- MeasuredSize measuredSize = getMeasuredSize();
+ LayoutManager layoutManager = getLayoutManager();
- measuredSize.registerDependency(panel.captionNode);
- measuredSize.registerDependency(panel.bottomDecoration);
- measuredSize.registerDependency(panel.contentNode);
+ layoutManager.registerDependency(this, panel.captionNode);
+ layoutManager.registerDependency(this, panel.bottomDecoration);
+ layoutManager.registerDependency(this, panel.contentNode);
}
@Override
@@ -178,12 +179,11 @@ public class VPanelPaintable extends VAbstractPaintableWidgetContainer
return GWT.create(VPanel.class);
}
- public void onResize() {
+ public void layout() {
updateSizes();
}
void updateSizes() {
- MeasuredSize measuredSize = getMeasuredSize();
VPanel panel = getWidgetForPaintable();
Style contentStyle = panel.contentNode.getStyle();
@@ -199,9 +199,9 @@ public class VPanelPaintable extends VAbstractPaintableWidgetContainer
contentStyle.setWidth(100, Unit.PCT);
}
- int top = measuredSize.getDependencyOuterHeight(panel.captionNode);
- int bottom = measuredSize
- .getDependencyOuterHeight(panel.bottomDecoration);
+ LayoutManager layoutManager = getLayoutManager();
+ int top = layoutManager.getOuterHeight(panel.captionNode);
+ int bottom = layoutManager.getOuterHeight(panel.bottomDecoration);
Style style = panel.getElement().getStyle();
panel.captionNode.getStyle().setMarginTop(-top, Unit.PX);
@@ -217,11 +217,7 @@ public class VPanelPaintable extends VAbstractPaintableWidgetContainer
panel.scrollLeft = panel.contentNode.getScrollLeft();
}
- public void beforeLayout() {
- // Nothing to do
- }
-
- public void afterLayout() {
+ public void postLayout() {
VPanel panel = getWidgetForPaintable();
if (uidlScrollTop != null) {
panel.contentNode.setScrollTop(uidlScrollTop.intValue());
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTablePaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTablePaintable.java
index 38fb077637..46eb22e01d 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTablePaintable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTablePaintable.java
@@ -10,13 +10,13 @@ import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.BrowserInfo;
-import com.vaadin.terminal.gwt.client.CalculatingLayout;
+import com.vaadin.terminal.gwt.client.DirectionalManagedLayout;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
public class VScrollTablePaintable extends VAbstractPaintableWidgetContainer
- implements CalculatingLayout {
+ implements DirectionalManagedLayout {
/*
* (non-Javadoc)
@@ -261,11 +261,11 @@ public class VScrollTablePaintable extends VAbstractPaintableWidgetContainer
// NOP, not rendered
}
- public void updateVerticalSizes() {
+ public void layoutVertically() {
getWidgetForPaintable().updateHeight();
}
- public void updateHorizontalSizes() {
+ public void layoutHorizontally() {
getWidgetForPaintable().updateWidth();
}
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTabsheetPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VTabsheetPaintable.java
index 7379362b3f..fe10db6604 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VTabsheetPaintable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VTabsheetPaintable.java
@@ -11,7 +11,7 @@ import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
public class VTabsheetPaintable extends VTabsheetBasePaintable implements
- ResizeRequired {
+ SimpleManagedLayout {
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
@@ -77,7 +77,7 @@ public class VTabsheetPaintable extends VTabsheetBasePaintable implements
/* Tabsheet does not render its children's captions */
}
- public void onResize() {
+ public void layout() {
VTabsheet tabsheet = getWidgetForPaintable();
tabsheet.updateContentNodeHeight();
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java
index a79379746c..a6235d769d 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java
@@ -19,8 +19,8 @@ import com.vaadin.terminal.gwt.client.VPaintableWidget;
import com.vaadin.terminal.gwt.client.ui.ShortcutActionHandler.BeforeShortcutActionListener;
public class VWindowPaintable extends VAbstractPaintableWidgetContainer
- implements BeforeShortcutActionListener, ResizeRequired,
- LayoutPhaseListener {
+ implements BeforeShortcutActionListener, SimpleManagedLayout,
+ PostLayoutListener {
private static final String CLICK_EVENT_IDENTIFIER = VPanelPaintable.CLICK_EVENT_IDENTIFIER;
@@ -304,15 +304,11 @@ public class VWindowPaintable extends VAbstractPaintableWidgetContainer
return GWT.create(VWindow.class);
}
- public void onResize() {
+ public void layout() {
getWidgetForPaintable().requestLayout();
}
- public void beforeLayout() {
-
- }
-
- public void afterLayout() {
+ public void postLayout() {
VWindow window = getWidgetForPaintable();
if (window.centered) {
window.center();
diff --git a/src/com/vaadin/terminal/gwt/client/ui/layout/VPaintableLayoutSlot.java b/src/com/vaadin/terminal/gwt/client/ui/layout/VPaintableLayoutSlot.java
index b2786ad0a0..13bfcaf5e2 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/layout/VPaintableLayoutSlot.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/layout/VPaintableLayoutSlot.java
@@ -3,17 +3,20 @@
*/
package com.vaadin.terminal.gwt.client.ui.layout;
-import com.vaadin.terminal.gwt.client.MeasuredSize;
+import com.vaadin.terminal.gwt.client.LayoutManager;
import com.vaadin.terminal.gwt.client.VCaption;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
+import com.vaadin.terminal.gwt.client.ui.ManagedLayout;
public class VPaintableLayoutSlot extends VLayoutSlot {
final VPaintableWidget paintable;
+ private LayoutManager layoutManager;
public VPaintableLayoutSlot(String baseClassName, VPaintableWidget paintable) {
super(baseClassName, paintable.getWidgetForPaintable());
this.paintable = paintable;
+ layoutManager = paintable.getLayoutManager();
}
public VPaintableWidget getPaintable() {
@@ -23,41 +26,43 @@ public class VPaintableLayoutSlot extends VLayoutSlot {
@Override
protected int getCaptionHeight() {
VCaption caption = getCaption();
- return caption != null ? getParentSize().getDependencyOuterHeight(
- caption.getElement()) : 0;
- }
-
- private MeasuredSize getParentSize() {
- return paintable.getParent().getMeasuredSize();
+ return caption != null ? layoutManager.getOuterHeight(caption
+ .getElement()) : 0;
}
@Override
protected int getCaptionWidth() {
VCaption caption = getCaption();
- return caption != null ? getParentSize().getDependencyOuterWidth(
- caption.getElement()) : 0;
+ return caption != null ? layoutManager.getOuterWidth(caption
+ .getElement()) : 0;
}
@Override
public void setCaption(VCaption caption) {
VCaption oldCaption = getCaption();
if (oldCaption != null) {
- getParentSize().unregisterDependency(oldCaption.getElement());
+ layoutManager.unregisterDependency(
+ (ManagedLayout) paintable.getParent(),
+ oldCaption.getElement());
}
super.setCaption(caption);
if (caption != null) {
- getParentSize().registerDependency(caption.getElement());
+ layoutManager
+ .registerDependency((ManagedLayout) paintable.getParent(),
+ caption.getElement());
}
}
@Override
public int getWidgetHeight() {
- return paintable.getMeasuredSize().getOuterHeight();
+ return layoutManager.getOuterHeight(paintable.getWidgetForPaintable()
+ .getElement());
}
@Override
public int getWidgetWidth() {
- return paintable.getMeasuredSize().getOuterWidth();
+ return layoutManager.getOuterWidth(paintable.getWidgetForPaintable()
+ .getElement());
}
@Override