1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/doc/obsolete/line-layout.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +<!-- This Source Code Form is subject to the terms of the Mozilla Public 1.5 + - License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 1.7 + 1.8 +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> 1.9 +<html> 1.10 +<head> 1.11 + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 1.12 + <meta name="GENERATOR" content="Mozilla/4.61 [en] (X11; I; Linux 2.2.5-22 i686) [Netscape]"> 1.13 +</head> 1.14 +<body> 1.15 + 1.16 +<h1> 1.17 +<u>Line Layout</u></h1> 1.18 +Line layout is the process of placing inline frames horizontally (left 1.19 +to right or right to left depending on the CSS direction property value). 1.20 +An attempt is made to describe how it works. 1.21 +<p>nsLineLayout is the class that provides support for line layout. The 1.22 +container frames nsBlockFrame and nsInlineFrame use nsLineLayout to perform 1.23 +line layout and span layout. Span layout is a subset of line layout used 1.24 +for inline container classes - for example, the HTML "B" element). Because 1.25 +of spans, nsLineLayout handles the nested nature of line layout. 1.26 +<p>Line layout as a process contains the following steps: 1.27 +<ol> 1.28 +<li> 1.29 +Initialize the nsLineLayout object (done in nsBlockFrame). This prepares 1.30 +the line layout engine for reflow by initializing its internal data structures.</li> 1.31 + 1.32 +<br> 1.33 +<li> 1.34 +Reflowing of inline frames. The block code uses nsLineLayout's <b>ReflowFrame</b> 1.35 +method to reflow each inline frame in a line. This continues until the 1.36 +line runs out of room or the block runs out of frames. The block may be 1.37 +reflowing a span (an instance of nsInlineFrame) which will recursively 1.38 +use nsLineLayout for reflow and placement of the frames in the span.</li> 1.39 + 1.40 +<p><br>Note that the container frames (nsBlockFrame/nsInlineFrame) call 1.41 +nsLineLayout's ReflowFrame method instead of having the line layout code 1.42 +process a list of children. This is done so that the container frames can 1.43 +handle the issues of "pushing" and "pulling" of frames across continuations. 1.44 +Because block and inline maintain different data structures for their child 1.45 +lists, and because we don't want to mandate a common base class, the line 1.46 +layout code doesn't control the "outer loop" of frame reflow. 1.47 +<br> 1.48 +<li> 1.49 +Finish line layout by vertically aligning the frames, horizontally aligning 1.50 +the frames and relatively positioning the frames on the line.</li> 1.51 +</ol> 1.52 +nsLineLayout is also used by nsBlockFrame to construct text-run information; 1.53 +this process is independent of normal line layout is pretty much a hack. 1.54 +<p>When frames are reflowed they return a reflow status. During line layout, 1.55 +there are several additions to the basic reflow status used by most frames: 1.56 +<ul> 1.57 +<li> 1.58 +NS_FRAME_COMPLETE - this is a normal reflow status and indicates that the 1.59 +frame is complete and doesn't need to be continued.</li> 1.60 + 1.61 +<li> 1.62 +NS_FRAME_NOT_COMPLETE - this is another normal reflow status and indicates 1.63 +that the frame is not complete and will need a continuation frame created 1.64 +for it (if it doesn't already have one).</li> 1.65 + 1.66 +<li> 1.67 +NS_INLINE_BREAK - some kind of break has been requested. Breaks types include 1.68 +simple line breaks (like the BR tag in html sometime does) and more complex 1.69 +breaks like page breaks, float breaks, etc. Currently, we only support 1.70 +line breaks, and float clearing breaks. Breaks can occur before the frame 1.71 +(NS_INLINE_IS_BREAK_BEFORE) or after the frame (NS_INLINE_IS_BREAK_AFTER)</li> 1.72 +</ul> 1.73 +The handling of the reflow status is done by the container frame using 1.74 +nsLineLayout. 1.75 +<h3> 1.76 +<u>Line Breaking</u></h3> 1.77 +Another aspect of nsLineLayout is that it supports line breaking. At the 1.78 +highest level, line breaking consists of identifying where it is appropriate 1.79 +to break a line that doesn't fit in the available horizontal space. At 1.80 +a lower level, some frames are breakable (e.g. text) and some frames are 1.81 +not (e.g. images). 1.82 +<p>In order to break text properly, some out-of-band information is needed 1.83 +by the text frame code (nsTextFrame). In particular, because a "word" (a 1.84 +non-breakable unit of text) may span several frames (for example: <b>"<B>H</B>ello 1.85 +there"</b> is breakable after the <b>"o"</b> in "<b>ello</b>" but not after 1.86 +the <b>"H"</b>), text-run information is used to allow the text frame to 1.87 +find adjacent text and look at them to determine where the next breakable 1.88 +point is. nsLineLayout supports this by keeping track of the text-runs 1.89 +as well as both storing and interrogating "word" state. 1.90 +<h3> 1.91 +<u>White-space</u></h3> 1.92 +To support the white-space property, the line layout logic keeps track 1.93 +of the presence of white-space in the line as it told to reflow each inline 1.94 +frame. This allows for the compression of leading whitespace and the compression 1.95 +of adjacent whitespace that is in separate inline elements. 1.96 +<p>As a post-processing step, the TrimTrailingWhiteSpace logic is used 1.97 +to remove those pesky pices of white-space that end up being placed at 1.98 +the end of a line, that shouldn't really be seen. 1.99 +<p>To support pre-formatted text that contains tab characters, the line 1.100 +layout class keeps track of the current column on behalf of the text frame 1.101 +code. 1.102 +<h3> 1.103 +<u>Vertical Alignment</u></h3> 1.104 +Vertical alignment is peformed as a two and a half pass process. The first 1.105 +pass is done during nsInlineFrame reflow: the child frames of the nsInlineFrame 1.106 +are vertically aligned as best as can be done at the time. There are certain 1.107 +values for the vertical-align property that require the alignment be done 1.108 +after the lines entire height is known; those frames are placed during 1.109 +the last half pass. 1.110 +<p>The second pass is done by the block frame when all of the frames for 1.111 +a line are known. This is where the final height of the line 1.112 +<br>(not the line-height property) is known and where the final half pass 1.113 +can be done to place all of the top and bottom aligned elements. 1.114 +<br> 1.115 +<h3> 1.116 +<u>Horizontal Alignment</u></h3> 1.117 +After all frames on a line have been placed vertically, the block code 1.118 +will use nsLineLayout to perform horizontal alignment within the extra 1.119 +space. 1.120 +</body> 1.121 +</html>