final StaticBoxLayoutProperties blp = box.getStaticBoxLayoutProperties();
final long insetBottom = blp.getBorderBottom() + boxDefinition.getPaddingBottom();
final long insetTop = blp.getBorderTop() + boxDefinition.getPaddingTop();
final long usedHeight;
RenderNode child = box.getFirstChild();
// initialize with the values computed in the InfMajorStep
long maxChildY2 = box.getCachedY() + box.getCachedHeight();
if (child != null)
{
while (child != null)
{
maxChildY2 = Math.max(child.getCachedY() + child.getCachedHeight() + child.getEffectiveMarginBottom(),
maxChildY2);
child = child.getNext();
}
usedHeight = (maxChildY2 - (box.getCachedY() + insetTop));
}
else
{
usedHeight = 0;
}
final long rminH = minimumHeight.resolve(resolveSize, 0);
final long rmaxH = maximumHeight.resolve(resolveSize, CanvasMajorAxisLayoutStep.MAX_AUTO);
final long computedContentHeight;
if (boxDefinition.isSizeSpecifiesBorderBox())
{
final long rprefH = preferredHeight.resolve(resolveSize, usedHeight + insetTop + insetBottom);
final long specifiedHeight = ProcessUtility.computeLength(rminH, rmaxH, rprefH);
computedContentHeight = specifiedHeight - insetTop - insetBottom;
}
else
{
final long rprefH = preferredHeight.resolve(resolveSize, usedHeight);
computedContentHeight = ProcessUtility.computeLength(rminH, rmaxH, rprefH);
}
child = box.getFirstChild();
final ElementAlignment valign = box.getNodeLayoutProperties().getVerticalAlignment();
final long boxY1 = box.getCachedY() + insetTop;
final long boxY2 = boxY1 + computedContentHeight;
while (child != null)
{
final long childY1 = child.getCachedY();
final long childY2 = childY1 + child.getCachedHeight();
// we have extra space to distribute. So lets shift some boxes.
if (ElementAlignment.BOTTOM.equals(valign))
{
final long boxBottom = (boxY2 - insetBottom);
final long delta = boxBottom - childY2;
CacheBoxShifter.shiftBox(child, delta);
}
else if (ElementAlignment.MIDDLE.equals(valign))
{
final long extraHeight = computedContentHeight - (childY2 - childY1);
final long boxTop = boxY1 + (extraHeight / 2);
final long delta = boxTop - childY1;
CacheBoxShifter.shiftBox(child, delta);
}
child = child.getNext();
}
final long retval = Math.max(0, computedContentHeight + insetTop + insetBottom);
if (retval < 0)
{