Skip to content

Representation of computed style

Patrick Walton edited this page Aug 28, 2013 · 1 revision

Computed style in WebKit

In WebKit, the computed style is represented by a RenderStyle object. Most of RenderStyle consists of two large bitfields: InheritedFlags and NonInheritedFlags.

InheritedFlags consists of:

  • empty cells
  • caption-side
  • list-style-type, list-style-position
  • visibility
  • text-align, text-transform, text-decoration
  • cursor-style
  • text-direction
  • border-collapse
  • white-space
  • box-direction
  • writing-mode
  • … as well as some random non-inherited flags, presumably thrown in here to pack bitfields.

NonInheritedFlags consists of:

  • display
  • overflow-x, overflow-y
  • vertical-align
  • clear, float
  • position

There are also pointers to five reference-counted non-inherited sub-structs (presumably reference counted so that they can be shared): StyleBoxData, StyleVisualData, StyleBackgroundData, StyleSurroundData, and StyleRareNonInheritedData (and also optionally SVGRenderStyle). Additionally, there are two pointers to inherited sub-structs, also reference counted: StyleRareInheritedData and StyleInheritedData.

In general the strategy seems to be: pack into a bitfield where possible, otherwise throw into a reference-counted side struct. Bitfields and structs are generally separated into inherited and non-inherited fields.

Possible representation of computed style in Servo

In Servo we would like to perform CSS selector matching in parallel, which means that style structs are going to need to be thread-safe. We may be forced to do atomic reference counting for the sub-structs, which is unfortunate. Assuming we find a solution to that, it seems that WebKit's bitfield approach would probably work for Servo.

Clone this wiki locally