Table of Contents
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-sidelist-style-type,list-style-positionvisibilitytext-align,text-transform,text-decorationcursor-styletext-directionborder-collapsewhite-spacebox-directionwriting-mode- … as well as some random non-inherited flags, presumably thrown in here to pack bitfields.
NonInheritedFlags consists of:
displayoverflow-x,overflow-yvertical-alignclear,floatposition
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.