if (c.isPrint()) {
relayoutDataList = new RelayoutDataList(localChildren.size());
}
int pageCount = NO_PAGE_TRIM;
BlockBox previousChildBox = null;
for (Iterator i = localChildren.iterator(); i.hasNext();) {
BlockBox child = (BlockBox) i.next();
offset++;
RelayoutData relayoutData = null;
boolean mayCheckKeepTogether = false;
if (c.isPrint()) {
relayoutData = relayoutDataList.get(offset);
relayoutData.setLayoutState(c.copyStateForRelayout());
relayoutData.setChildOffset(childOffset);
pageCount = c.getRootLayer().getPages().size();
child.setNeedPageClear(false);
if ((child.getStyle().isAvoidPageBreakInside() || child.getStyle().isKeepWithInline())
&& c.isMayCheckKeepTogether()) {
mayCheckKeepTogether = true;
c.setMayCheckKeepTogether(false);
}
}
layoutBlockChild(
c, block, child, false, childOffset, NO_PAGE_TRIM, relayoutData.getLayoutState());
if (c.isPrint()) {
if (mayCheckKeepTogether) {
c.setMayCheckKeepTogether(true);
boolean tryToAvoidPageBreak =
child.getStyle().isAvoidPageBreakInside() && child.crossesPageBreak(c);
boolean needPageClear = child.isNeedPageClear();
boolean keepWithInline = child.isNeedsKeepWithInline(c);
if (tryToAvoidPageBreak || needPageClear || keepWithInline) {
c.restoreStateForRelayout(relayoutData.getLayoutState());
child.reset(c);
layoutBlockChild(
c, block, child, true, childOffset, pageCount, relayoutData.getLayoutState());
if (tryToAvoidPageBreak && child.crossesPageBreak(c) && ! keepWithInline) {
c.restoreStateForRelayout(relayoutData.getLayoutState());
child.reset(c);
layoutBlockChild(
c, block, child, false, childOffset, pageCount, relayoutData.getLayoutState());
}
}
}
c.getRootLayer().ensureHasPage(c, child);
}
Dimension relativeOffset = child.getRelativeOffset();
if (relativeOffset == null) {
childOffset = child.getY() + child.getHeight();
} else {
// Box will have been positioned by this point so calculate
// relative to where it would have been if it hadn't been
// moved
childOffset = child.getY() - relativeOffset.height + child.getHeight();
}
if (childOffset > block.getHeight()) {
block.setHeight(childOffset);
}
if (c.isPrint()) {
if (child.getStyle().isForcePageBreakAfter()) {
block.forcePageBreakAfter(c, child.getStyle().getIdent(CSSName.PAGE_BREAK_AFTER));
childOffset = block.getHeight();
}
if (previousChildBox != null) {
relayoutDataList.markRun(offset, previousChildBox, child);