michael@0: michael@0: michael@0: michael@0: michael@0:
michael@0: michael@0: michael@0: michael@0: michael@0: michael@0:nsBlockFrame implements layout behavior that conforms to the michael@0: CSS "display:block" and "display: list-item" layout. It has several responsibilities: michael@0:
"inline" lines which contain only inline elements michael@0:michael@0: Each line has a "dirty" bit which indicates that it needs reflow. Reflow michael@0: consists of identifying which lines need to be marked dirty and then reflowing michael@0: all lines. For lines which are "clean" the reflow logic will endeavor to michael@0: recover the state of reflow as if the line had been reflowed. This michael@0: saves time and allows for a faster incremental reflow. For lines which michael@0: are dirty, the line is reflowed appropriately. michael@0:
"block" lines which contain exactly one block element
The only special thing about incremental reflow command handling is michael@0: that it marks lines dirty before proceeding, and keeps track of the child michael@0: frame that is the next frame on the reflow command path. michael@0:
Here is a list of the various classes involved in block layout: michael@0:
nsBlockFrame michael@0:
The primary culprit.michael@0: nsBlockReflowState michael@0:
This helper class is used to augment the nsHTMLReflowState michael@0: with other information needed by the block reflow logic during reflow. michael@0: It is a temporary object that is designed to live on the processor stack michael@0: and contains "running" state used by the blocks reflow logic.michael@0: nsBlockBandData michael@0:
Another helper class that wraps up management of a space manager michael@0: (nsISpaceManager, nsSpaceManager) and nsBandData. It also assists in management michael@0: of floating elements. While nsSpaceManager is policy free, nsBlockBandData michael@0: provides specific HTML and CSS policy.michael@0: nsBlockReflowContext michael@0:
A helper class that encapsulates the logic needed to reflow michael@0: a child block frame. This is used by the block code reflow a child block michael@0: and to reflow floating elements (which are to be treated as blocks according michael@0: to the CSS2 spec).michael@0: nsLineBox michael@0:
A data class used to store line information for the block frame michael@0: code. Each line has a list of children (though the frames are linked together michael@0: across lines to maintain the sibling list for nsIFrame::FirstChild) and michael@0: some other state used to assist in incremental reflow.michael@0: nsLineLayout michael@0:
This class is the line layout engine. Its a passive entity michael@0: in the sense that its the responsibility of the block/inline code to use michael@0: the class (this is done so that the line layout engine doesn't have to michael@0: manage child frame lists so that both nsBlockFrame and nsInlineFrame can michael@0: use the class).michael@0: nsTextRun michael@0:
This is a data class used to store text run information. Text michael@0: runs are logically contiguous runs of text (they may or may not michael@0: be structurally contiguous). The block frame stores a pointer to a list michael@0: of nsTextRun's and during line layout provides the list to the nsLineLayout michael@0: engine so that when text is reflowed the text layout code (nsTextFrame) michael@0: can find related text to properly handle word breaking.michael@0: michael@0:
When structural changes are made to the blocks children (append/insert/remove) michael@0: the block code updates the line's and then marks the affected lines "dirty" michael@0: (each nsLineBox has a dirty bit). After the structural changes are finished michael@0: then the block will generate an incremental reflow command of type "ReflowDirty". michael@0:
The helper class nsLineLayout provides the majority of the line layout michael@0: behavior needed by the block. michael@0:
The block does keep "text-run" information around for the nsLineLayout michael@0: logic to use during reflow. Text runs keep track of logically adjacent michael@0: pieces of text within a block. This information is essential for properly michael@0: computing line and word breaking. Why? Well, because in html you can write michael@0: something like this: michael@0:
<p>I <b>W</b>as thinking one day</p> michael@0:
Notice that the word "Was" is composed of two pieces of text, and that michael@0: they do not have the same parent (content or frame). To properly michael@0: reflow this and not break the word prematurely after the "W", the text-run michael@0: information is used by the text frame code to "look ahead" and prevent michael@0: premature breaking. michael@0:
Lines also keep track of the type of "break" that occurred on the line. michael@0: This is used, for example, to support html's "<br clear=left>" behavior. michael@0:
The nsLineLayout class and the block frame cooperate in the management michael@0: of floats. Since the frame construction code leaves a "placeholder" frame michael@0: in-flow where the float was found, when nsLineLayout reflows a placeholder michael@0: frame it knows to inform the block about it. That triggers the blocks "AddFloat" michael@0: logic which then determines where the float should be placed (on the michael@0: current line or below the current line). michael@0:
The block frame uses the space manager to manage the effects of floats, michael@0: namely the consumption of available space. For example, for a left aligned michael@0: floating element, the inline elements must be placed to the right of the michael@0: float. To simplify this process, the spacemanager is used to keep track michael@0: of available and busy space. Floats when placed mark space as busy and michael@0: the spacemanager will them compute the available space. Most of this logic michael@0: is handled by the nsBlockReflowState which uses a helper class, nsBlockBandData, michael@0: in concert with the space manager, to do the available space computations. michael@0:
<div>
michael@0:
<p>abc</p>
michael@0:
<p>def</p>
michael@0:
</div>
michael@0:
In the content model for the above html, there is white space between michael@0: the various block elements (some after the <div>, some after the first michael@0: </p>, again after the second </p>). michael@0:
For css margin collapsing to work properly, each of those instances michael@0: of white space has to behave as if they didn't exist. Consequently, there michael@0: is special logic in the inline line reflow code, and in the nsBlockReflowContext michael@0: code and in the GetTopBlockChild method, to basically ignore such lines. michael@0:
There are two things different that the block does: michael@0:
It is responsible for calling nsLineLayout::SetFirstLetterStyleOK
michael@0:
It is responsible for continuing to place frames on a line, even after
michael@0: a frame has said "it can't fit". Normally during inline reflow, if a frame
michael@0: comes back and says it can't fit, the block will end the line, push all
michael@0: remaining frames to the next line and pick up the reflow from there after
michael@0: making sure the frame that didn't fit is continued. For letter-frames,
michael@0: this would result in the first-letter being on one line with the remaining
michael@0: text on subsequent lines. Hence, the block code handles this special case.
michael@0:
michael@0: