Changes between Initial Version and Version 1 of LayoutUnit

Feb 6, 2012 2:16:35 PM (10 years ago)

Added initial draft of wiki page explaining LayoutUnits.


  • LayoutUnit

    v1 v1  
     1LayoutUnit^1^ 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 pixel^2^. This allows us to use integer math and avoids floating point imprecision.
     3Even 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.
     4When 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.
     6Certain cases require us to snap LayoutUnits to whole-pixel values, including:
     7 * scroll offsets - scrolling by subpixel values would cause off-by-one errors when pixel snapping, and would expose the embedding application to LayoutUnits.
     8 * border widths - to ensure that all borders are the same width as specified.
     9 * tables - to ensure even distribution of available space across columns.
     10 * 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.
     11 * 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.
     12 * painting - to avoid unwanted anti-aliasing.
     161: 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.
     182: Based on Mozilla’s implementation. See the proposal [ here] which was landed in [ this bug].