Mozilla's Layout Engine

L. David Baron

Mozilla Corporation

dbaron@dbaron.org

Mozilla Corporation, Mountain View, California, USA

Wednesday, July 12, 2006, 16:00 PDT

Some bits taken from 2002 tech talks on gecko (waterson) and style system (dbaron)

Layout

Layout (and neighbors)

Layout (and neighbors)

Layout (and neighbors)

Layout (and neighbors)

Input (concepts)

Input: Content tree

<doc>
  <title>A few quotes</title>
  <para class="emph">
    Franklin said that <quote>"A penny
    saved is a penny earned."</quote>
  </para>
  <para>
    FDR said <quote>"We have nothing to
    fear but <span class="emph">fear
    itself.</span>"</quote>
  </para>
</doc>

Input: Content tree

doc
titlepara
class="emph"
para
quotequote
span
class="emph"

Input: Content Tree APIs

Output (concepts)

Parts of Layout

Sources of style data

Style context

Rule tree

Rules:
/* rule 1 */ doc { display: block; text-indent: 1em; }
/* rule 2 */ title { display: block; font-size: 3em; }
/* rule 3 */ para { display: block; }
/* rule 4 */ [class="emph"] { font-style: italic; }
Rule tree:
A: null
B: 1C: 2D: 3E: 4
F: 4
Style context tree:
doc: B
title: Cpara: F
class="emph"
para: D
quote: Aquote: A
span: E
class="emph"

Frames

Examples of frame classes

Frame construction

Continuations

Continuations

<p>text <span>with
line</span> breaks</p>
text with
line
breaks
<Block>text <Inline(1)>with</Inline(1)>
<Inline(2)>line</Inline(2)> breaks</Block>

Continuations

(diagram from continuation model)

    Root                      Root
     |                       / |  \ 
     A                     A1  A2  A3
    / \                   / |  |    |
   B   C                 B  C1 C2   C3
   |  /|\                |  |  | \   |
   D E F G               D  E  F G1  G2

Generated content

(Differences between frame and content trees, #1.)

<p>World</p>
p:before { display: inline; content: url(icon.png) "Hello"; }
p
"World"
Block(p)
Inline(p:before)Text
"World"
ImageText
"Hello"

XBL

(Differences between frame and content trees, #2.)

Floats and absolute positioning

(Differences between frame and content trees, #3.)

Floats and absolute positioning

(Differences between frame and content trees, #3.)

<p>This is a document with <span>some
markup and a floating <img align="left"
src="icon.png"> image</span> in it.</p>

This is a document with some
markup and a floating image
in
it. Blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah blah blah.

Extra frames

(Differences between frame and content trees, #4.)

Extra frames

(Differences between frame and content trees, #4.)

table
tbody
tr
td
"Cell"
TableOuter(table)
Table(table)
TableRowGroup(tbody)
TableRow(tr)
TableCell(td)
Block(td)
"Cell"

Reflow

Intrinsic sizes

Reflow

Breaking

Intrinsic widths (future)

Incremental layout (future)

Box Layout

Painting

Painting: BuildDisplayList

Invalidation

Painting

Event handling

Reasons to optimize dynamic changes

Dynamic changes: content changes

Dynamic changes: attribute and event state changes

Dynamic changes: style changes