childBox.detach(); childBox = secondTry;
c.restoreStateForRelayout(relayoutData.getLayoutState()); BlockBox secondTry = layoutBlockChild( c, block, styleSetListener, listIndex, resetMargins, true, currentContent);  if (secondTry.crossesPageBreak(c)) { secondTry.detach(); } else { childBox.detach(); childBox = secondTry; }
    public static void layoutContent(final LayoutContext c, final Box block,             List contentList) {        Boxing.StyleSetListener styleSetListener = new Boxing.StyleSetListener() {            public void onStyleSet(BlockBox child) {                boolean moved = false;                if (child.getStyle().isRelative()) {                    Dimension delta = child.positionRelative(c);                    c.translate(delta.width, delta.height);                    moved = true;                }                if (c.isPrint() &&                         (child.isNeedPageClear() ||                                 child.getStyle().isForcePageBreakBefore())) {                    int delta = child.moveToNextPage(c);                    c.translate(0, delta);                    moved = true;                    child.setNeedPageClear(false);                }                if (child.getStyle().isCleared()) {                    c.translate(0, -child.y);                    c.getBlockFormattingContext().clear(c, child);                    c.translate(0, child.y);                    moved = true;                }                if (moved) {                    child.calcCanvasLocation();                }            }        };                boolean resetMargins = false;        int listIndex = 0;        int offset = -1;                List localContentList = contentList;        if (c.isPrint() && ! (localContentList instanceof RandomAccess)) {            localContentList = new ArrayList(localContentList);        }                Iterator contentIterator = localContentList.iterator();        RelayoutDataList relayoutDataList = null;        if (c.isPrint()) {            relayoutDataList = new RelayoutDataList(localContentList.size());        }                BlockBox previousChildBox = null;        while (contentIterator.hasNext()) {            Object o = contentIterator.next();            offset++;                        if (o instanceof FirstLineStyle || o instanceof FirstLetterStyle) {                continue;            }                        listIndex++;                        Content currentContent = (Content) o;            RelayoutData relayoutData = null;                        if (c.isPrint()) {                relayoutData = relayoutDataList.get(offset);                relayoutData.setLayoutState(c.copyStateForRelayout());                relayoutData.setInitialParentHeight(block.height);                relayoutData.setContent(currentContent);                relayoutData.setListIndex(listIndex);                relayoutData.setResetMargins(resetMargins);            }            BlockBox childBox = null;            //TODO:handle run-ins. For now, treat them as blocks                        childBox = layoutBlockChild(                    c, block, styleSetListener, listIndex,                    resetMargins, false, currentContent);                        if (c.isPrint() && childBox.getStyle().isAvoidPageBreakInside() &&                    childBox.crossesPageBreak(c)) {                c.restoreStateForRelayout(relayoutData.getLayoutState());                BlockBox secondTry = layoutBlockChild(                        c, block, styleSetListener, listIndex, resetMargins,                         true, currentContent);                                if (secondTry.crossesPageBreak(c)) {                    secondTry.detach();                } else {                    childBox.detach();                    childBox = secondTry;                }            }                        if (c.isPrint()) {                c.getRootLayer().ensureHasPage(c, childBox);            }                        if (childBox instanceof AnonymousBlockBox) {                listIndex--;            }            // increase the final layout width if the child was greater            block.adjustWidthForChild(childBox.getWidth());            // increase the final layout height by the height of the child            block.height = childBox.y + childBox.height;            if (c.isPrint()) {                if (childBox.getStyle().isForcePageBreakAfter()) {                    block.expandToPageBottom(c);                }                                if (previousChildBox != null) {                    relayoutDataList.markRun(offset, previousChildBox, childBox);                }                                processPageBreakAvoidRun(c, block, contentList,                         styleSetListener, offset, relayoutDataList, relayoutData, childBox);                resetMargins = childBox.getStyle().isForcePageBreakBefore();            }                        if (c.shouldStop()) {                break;            }                        previousChildBox = childBox;            dispatchRepaintEvent(c, block);        }    }