Line Layout |
Line layout is the process of placing inline frames horizontally (left to right or right to left depending on the CSS direction property value). An attempt is made to describe how it works.
nsLineLayout is the class that provides support for line layout. The container frames nsBlockFrame and nsInlineFrame use nsLineLayout to perform line layout and span layout. Span layout is a subset of line layout used for inline container classes - for example, the HTML "B" element). Because of spans, nsLineLayout handles the nested nature of line layout.
Line layout as a process contains the following steps:
When frames are reflowed they return a reflow status. During line layout, there are several additions to the basic reflow status used by most frames:
Line Breaking |
Another aspect of nsLineLayout is that it supports line breaking. At the highest level, line breaking consists of identifying where it is appropriate to break a line that doesn't fit in the available horizontal space. At a lower level, some frames are breakable (e.g. text) and some frames are not (e.g. images).
In order to break text properly, some out-of-band information is needed by the text frame code (nsTextFrame). In particular, because a "word" (a non-breakable unit of text) may span several frames (for example: "<B>H</B>ello there" is breakable after the "o" in ello but not after the "H"), text-run information is used to allow the text frame to find adjacent text and look at them to determine where the next breakable point is. nsLineLayout supports this by keeping track of the text-runs as well as both storing and interrogating "word" state.
In addition, nsLineLayout assists in the compression/expansion of whitespace
for the CSS white-space property. Compression occurs when neighboring
whitespace either inside a single piece of text is compressed or when spaces
between abutting elements is collapsed. Expansion occurs in preformatted
text when tabs are found. nsLineLayout keeps track of a "column" which
is used to determine where the next tab "moves" to.