Version 1 (modified by, 11 years ago) (diff)

Added initial draft of wiki page explaining LayoutUnits.

LayoutUnit1 is an abstraction used to represent the location or size of a render object in fractions of a logical pixel, it is used primarily for layout and hit testing. The current implementation represents values as multiples of 1/60th pixel2. This allows us to use integer math and avoids floating point imprecision.

Even though layout calculations are done using LayoutUnits the values are aligned to integer pixel values at paint time to line up with device pixels. While most modern graphics libraries support painting with subpixel precision, this results in unwanted anti-aliasing. When aligning to device pixels the edges are aligned to the nearest pixel and then the size is adjusted accordingly. This ensures that the bottom/right edge and the total width/height is at most off-by-one.

Certain cases require us to snap LayoutUnits to whole-pixel values, including:

  • scroll offsets - scrolling by subpixel values would cause off-by-one errors when pixel snapping, and would expose the embedding application to LayoutUnits.
  • border widths - to ensure that all borders are the same width as specified.
  • tables - to ensure even distribution of available space across columns.
  • size/position of widgets, plugins, video, and foreign objects - these are either rendered outside of WebCore, or pass through an intermediary embedding layer. We need to use integers so the contents are painted at whole-pixel values.
  • positioning of InlineBoxes in a RenderBlock - we lose the ability to pixel snap in sync with containing block because the line box tree paints with floats.
  • painting - to avoid unwanted anti-aliasing.

1: LayoutUnit is currently a typedef that maps to int. Once the subpixel branch has been merged this will map to AppUnit which is the underlying fixed point implementation. The eventual plan is to rename AppUnit to LayoutUnit and remove the typedef.

2: Based on Mozilla’s implementation. See the proposal here which was landed in this bug.

Attachments (1)

Download all attachments as: .zip