use table cell as outmost box and adjust the frame height

Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java
index 4e33052..39700ea 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/BoxFactory.java
@@ -177,11 +177,9 @@
 		return tableRow;
 	}
 
-	public static TableCell tableCell(final IStructuralBox... children) {
+	public static TableCell tableCell(final IStructuralBox component) {
 		final TableCell tableCell = new TableCell();
-		for (final IStructuralBox child : children) {
-			tableCell.appendChild(child);
-		}
+		tableCell.setComponent(component);
 		return tableCell;
 	}
 
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/DepthFirstBoxTraversal.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/DepthFirstBoxTraversal.java
index ac6a63c..8f87fb5 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/DepthFirstBoxTraversal.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/DepthFirstBoxTraversal.java
@@ -71,7 +71,7 @@
 
 	@Override
 	public T visit(final TableCell box) {
-		return traverseChildren(box);
+		return box.getComponent().accept(this);
 	}
 
 	@Override
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralFrame.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralFrame.java
index 8c05e4e..2495bce 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralFrame.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralFrame.java
@@ -85,6 +85,10 @@
 		return height;
 	}
 
+	public void setHeight(final int height) {
+		this.height = height;
+	}
+
 	@Override
 	public Rectangle getBounds() {
 		return new Rectangle(left, top, width, height);
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java
index 1d77585..03a7b45 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java
@@ -10,23 +10,20 @@
  *******************************************************************************/
 package org.eclipse.vex.core.internal.boxes;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.ListIterator;
-
 import org.eclipse.vex.core.internal.core.Graphics;
 import org.eclipse.vex.core.internal.core.Rectangle;
 
 /**
  * @author Florian Thienel
  */
-public class TableCell extends BaseBox implements IStructuralBox, IParentBox<IStructuralBox> {
+public class TableCell extends BaseBox implements IStructuralBox, IDecoratorBox<IStructuralBox> {
 
 	private IBox parent;
 	private int top;
 	private int left;
 	private int width;
-	private final ArrayList<IStructuralBox> children = new ArrayList<IStructuralBox>();
+
+	private IStructuralBox component;
 
 	private int startColumnIndex;
 	private int endColumnIndex;
@@ -116,45 +113,14 @@
 		return visitor.visit(this);
 	}
 
-	public boolean hasChildren() {
-		return !children.isEmpty();
-	}
-
-	public void prependChild(final IStructuralBox child) {
-		if (child == null) {
-			return;
-		}
-		child.setParent(this);
-		children.add(0, child);
-	}
-
-	public void appendChild(final IStructuralBox child) {
-		if (child == null) {
-			return;
-		}
-		child.setParent(this);
-		children.add(child);
+	public void setComponent(final IStructuralBox component) {
+		this.component = component;
+		component.setParent(this);
 	}
 
 	@Override
-	public void replaceChildren(final Collection<? extends IBox> oldChildren, final IStructuralBox newChild) {
-		boolean newChildInserted = false;
-
-		for (final ListIterator<IStructuralBox> iter = children.listIterator(); iter.hasNext();) {
-			final IStructuralBox child = iter.next();
-			if (oldChildren.contains(child)) {
-				iter.remove();
-				if (!newChildInserted) {
-					iter.add(newChild);
-					newChild.setParent(this);
-					newChildInserted = true;
-				}
-			}
-		}
-	}
-
-	public Iterable<IStructuralBox> getChildren() {
-		return children;
+	public IStructuralBox getComponent() {
+		return component;
 	}
 
 	public int getStartColumnIndex() {
@@ -215,12 +181,13 @@
 
 	public int calculateNaturalHeight(final Graphics graphics, final int width) {
 		naturalHeight = 0;
-		for (int i = 0; i < children.size(); i += 1) {
-			final IStructuralBox child = children.get(i);
-			child.setWidth(width);
-			child.layout(graphics);
-			naturalHeight += child.getHeight();
+		if (component == null) {
+			return 0;
 		}
+
+		component.setWidth(width);
+		component.layout(graphics);
+		naturalHeight = component.getHeight();
 		usedHeight = 0;
 
 		return naturalHeight;
@@ -231,16 +198,22 @@
 			naturalHeight = calculateNaturalHeight(graphics, width);
 		}
 
-		positionChildren();
+		component.setPosition(0, 0);
+		adjustFrameHeight();
 	}
 
-	private void positionChildren() {
-		int childTop = 0;
-		for (int i = 0; i < children.size(); i += 1) {
-			final IStructuralBox child = children.get(i);
-			child.setPosition(childTop, 0);
-			childTop += child.getHeight();
+	private void adjustFrameHeight() {
+		final StructuralFrame frame = accept(new DepthFirstBoxTraversal<StructuralFrame>() {
+			@Override
+			public StructuralFrame visit(final StructuralFrame box) {
+				return box;
+			}
+		});
+		if (frame == null) {
+			return;
 		}
+
+		frame.setHeight(usedHeight);
 	}
 
 	@Override
@@ -252,12 +225,13 @@
 			return false;
 		}
 
-		positionChildren();
+		component.setPosition(0, 0);
+		adjustFrameHeight();
 		return true;
 	}
 
 	@Override
 	public void paint(final Graphics graphics) {
-		ChildBoxPainter.paint(children, graphics);
+		ChildBoxPainter.paint(component, graphics);
 	}
 }
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
index 4c338fb..b929ded 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
@@ -315,7 +315,7 @@
 	}
 
 	private IStructuralBox visualizeAsTableCell(final IElement element, final Styles styles, final Collection<VisualizeResult> childrenResults) {
-		final TableCell cell = tableCell(visualizeStructuralElementContent(element, styles, childrenResults));
+		final TableCell cell = tableCell(wrapUpStructuralElementContent(element, styles, childrenResults, visualizeStructuralElementContent(element, styles, childrenResults)));
 
 		if ("entry".equals(element.getLocalName())) {
 			final IAttribute colName = element.getAttribute("colname");
@@ -339,7 +339,7 @@
 			// TODO HTML table
 		}
 
-		return wrapUpStructuralElementContent(element, styles, childrenResults, cell);
+		return cell;
 	}
 
 	private static int toInt(final IAttribute attribute) {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/DOMVisualization.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/DOMVisualization.java
index 4c6bbcd..57a501d 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/DOMVisualization.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/DOMVisualization.java
@@ -163,7 +163,7 @@
 
 			@Override
 			public void visit(final TableCell box) {
-				box.replaceChildren(modifiedBoxes, boxModelBuilder.visualizeStructure(node));
+				box.setComponent(boxModelBuilder.visualizeStructure(node));
 			}
 
 			@Override