[webkit-dev] Switching away from integers for layout

Levi Weintraub leviw at chromium.org
Thu Jun 23 11:46:18 PDT 2011

We’ve been getting an increasing number of complaints lately about the
zooming support in webkit and how hard it is to correctly support zooming in
complex web applications.

To address this we plan to convert the rendering tree to float to allow for
better zooming and scaling support. Furthermore this could be expanded to
support sub-pixel layout and positioning which in turn would allow higher
precision layout when zoomed. We’re the only rendering engine that hasn’t
yet made this change.

Changing rendering (and hit testing) to use floats does not necessarily mean
that we need to expose floats through the dom api, however if we are to
support sub-pixel layout (i.e. style=”left: 12.3px”) this would be required.
Specifically we’d need to change the offsetLeft/Top/Width/Height properties
to return floating point values [2].

We tried two strategies for building a proof of concept, one of which
involved accumulating error when laying out with an applied zoom, and the
other was a wholesale swap of integers for floats in the layout engine.
Ultimately, we discovered that our hopes of the former being a less-invasive
solution were lost when the patch grew to the size of the more-invasive
latter, and we decided to focus our efforts there.

In the span of 10 days, we built a working prototype that passes over 90% of
our layout tests and renders most webpages correctly, including our original
zooming test cases. There are still numerous rounding errors, but tracking
these down and fixing them is beyond the scope of our proof of concept.
We’ve uploaded the resulting patch on the meta bug [1] tracking our work.
It’s been tested on the Mac and QT ports.

To make this transition as painless as possible (read: to avoid landing one
massive patch), we plan on first moving our current int values to an
abstraction that will begin as a typedef to int and its progeny IntRect,
IntPoint, and IntSize. We’ll also implement requisite rounding functionality
behind a USE(FLOAT_OFFSETS) [or other name, pending discussion] flag. These
steps are transitional only, and this abstraction and USE flag will both be
removed once we successfully make the jump from int->float.

Levi & Emil

1: https://bugs.webkit.org/show_bug.cgi?id=60318 - Meta bug, has proof of
concept patch and a couple of test cases.
2: https://bugs.webkit.org/show_bug.cgi?id=54018 - Convert offset* to float.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20110623/89eba0a1/attachment.html>

More information about the webkit-dev mailing list