{
infiniteMarginTop = (visiblePrev == null);
}
else
{
final ComputedLayoutProperties sBlp = boxParent.getComputedLayoutProperties();
final BoxLayoutProperties pBlp = boxParent.getBoxLayoutProperties();
infiniteMarginTop =
(pBlp.isInfiniteMarginTop() && visiblePrev == null &&
sBlp.getBorderTop() == 0 && sBlp.getPaddingTop() != 0);
}
marginCollection.clear();
// Collect all elements that will contribute to the margins.
RenderBox marginBox = box;
while (true)
{
marginCollection.add(marginBox);
final ComputedLayoutProperties cblp = marginBox.getComputedLayoutProperties();
if (cblp.getBorderBottom() != 0)
{
break;
}
if (cblp.getPaddingBottom() != 0)
{
break;
}
final RenderNode node = marginBox.getVisibleFirst();
if (node instanceof RenderBox == false)
{
break;
}
marginBox = (RenderBox) node;
}
// If we are the first child on an infinite margin area, copy the
// infinite area to yourself ..
if (infiniteMarginTop)
{
for (int i = 0; i < marginCollection.size(); i++)
{
final RenderBox renderBox = (RenderBox) marginCollection.get(i);
final BoxLayoutProperties cblp = renderBox.getBoxLayoutProperties();
cblp.setEffectiveMarginTop(0);
cblp.setInfiniteMarginTop(true);
cblp.setMarginOpenState(marginChangeKey);
}
return true;
}
// Compute the top margin.
long topMarginPositive = 0;
long topMarginNegative = 0;
final ComputedLayoutProperties sblp = box.getComputedLayoutProperties();
final long marginTop = sblp.getMarginTop();
if (marginTop < 0)
{
topMarginNegative = marginTop;
}
else
{
topMarginPositive = marginTop;
}
if (visiblePrev != null)
{
final long effectiveMarginBottom =
visiblePrev.getEffectiveMarginBottom();
if (effectiveMarginBottom < 0)
{
topMarginNegative = Math.min(topMarginNegative, effectiveMarginBottom);
}
else
{
topMarginPositive = Math.max(topMarginPositive, effectiveMarginBottom);
}
}
// Dive into all other childs, and set their effective margin to zero.
// Perform the collapsing, but the result only affects the first child.
// The margin is already handled by the first element.
for (int i = 1; i < marginCollection.size(); i++)
{
final RenderBox renderBox = (RenderBox) marginCollection.get(i);
final BoxLayoutProperties cblp = renderBox.getBoxLayoutProperties();
final ComputedLayoutProperties scblp = renderBox.getComputedLayoutProperties();
final long childMarginTop = scblp.getMarginTop();
if (childMarginTop < 0)
{
topMarginNegative = Math.min(topMarginNegative, childMarginTop);
}