Mozilla's Layout Engine

L. David Baron

Mozilla Corporation

dbaron@dbaron.org

Mozilla Corporation, Mountain View, California, USA

Thursday, December 14, 2006, 13:30 PST

Based on my presentation in July, which in turn had pieces taken from 2002 tech talks on gecko (waterson) and style system (dbaron)

Layout

Layout (and neighbors)

Layout (and neighbors): Basic Data Flow

Master slide Slide Drawing HTML Drawing Parser Drawing Content Sink Drawing Drawing Drawing Content Model Drawing Drawing CSS Parser Drawing Style Rules Drawing Style Sheets Drawing Drawing Drawing Drawing Frame Constructor Drawing Frame Tree Drawing Drawing Drawing Drawing Reflow Drawing Drawing Painting Drawing Display Drawing Drawing Drawing DOM Drawing

Layout (and neighbors): Key Data Structures

Master slide Slide Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Content Drawing Frames Drawing Views Drawing Widgets Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Drawing Style Contexts

Layout (and neighbors): Key Data Structures

Content
parse tree of markup
Frames
Rectangular formatting primitive
Style contexts
Computed style data
Views
Going away (z-order, compositing)
Widgets
Native windows (we want only one)

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

preferred width

Intrinsic sizes

minimum width

Intrinsic sizes

Reflow

Breaking

Incremental layout

Box Layout

Painting

Painting (in Layout)

Painting: BuildDisplayList

Invalidation

Painting

Mouse event handling

Reasons to optimize dynamic changes

Dynamic changes: content changes

Dynamic changes: attribute and event state changes

Dynamic changes: style changes