}
if (doc == null) {
return;
}
LayoutContext c = newLayoutContext((Graphics2D) g);
synchronized (this) {
this.layout_context = c;
}
long start = System.currentTimeMillis();
BlockBox root = (BlockBox)getRootBox();
if (root != null && isPendingResize()) {
root.reset(c);
} else {
root = BoxBuilder.createRootBox(c, doc);
setRootBox(root);
}
root.setContainingBlock(new ViewportBox(getInitialExtents(c)));
root.layout(c);
long end = System.currentTimeMillis();
XRLog.layout(Level.INFO, "Layout took " + (end - start) + "ms");
/*
System.out.println(root.dump(c, "", BlockBox.DUMP_LAYOUT));
*/
// if there is a fixed child then we need to set opaque to false
// so that the entire viewport will be repainted. this is slower
// but that's the hit you get from using fixed layout
if (root.getLayer().containsFixedContent()) {
super.setOpaque(false);
} else {
super.setOpaque(true);
}
XRLog.layout(Level.FINEST, "after layout: " + root);
Dimension intrinsic_size = root.getLayer().getPaintingDimension(c);
if (c.isPrint()) {
root.getLayer().trimEmptyPages(c, intrinsic_size.height);
root.getLayer().layoutPages(c);
}
setPreferredSize(intrinsic_size);
revalidate();
// if doc is shorter than viewport
// then stretch canvas to fill viewport exactly
// then adjust the body element accordingly
if (enclosingScrollPane != null) {
if (intrinsic_size.height < enclosingScrollPane.getViewport().getHeight()) {
//Uu.p("int height is less than viewport height");
// XXX Not threadsafe
if (enclosingScrollPane.getViewport().getHeight() != this.getHeight()) {
this.setPreferredSize(new Dimension(
intrinsic_size.width, enclosingScrollPane.getViewport().getHeight()));
this.revalidate();
}
//Uu.p("need to do the body hack");
if (root != null && ! c.isPrint()) {
intrinsic_size.height = root.getHeight();
}
}
// turn on simple scrolling mode if there's any fixed elements