[webkit-dev] How does Zooming Work?

Dan Bernstein mitz at apple.com
Tue Oct 6 21:09:59 PDT 2009

On Oct 6, 2009, at 8:49 PM, Alex Milowski wrote:

> What exactly happens during a zoom (command +/-) ?

Depends on the flavor of zoom (“full-page” zoom vs. text-only zoom),  
but in both cases, a full style recalculation for the document is  

> I have code that works well but layout doesn't seem to happen after
> a zoom in/out operation.  If I then resize the window, that forces a
> layout for the zoomed size and things adjust themselves
> appropriately (because layout() eventually gets called).
> So, what sequence of events happens after a zoom?

Frame::setZoomFactor() calls Document::recalcStyle(Force). If after  
that the document has a renderer (which would be a RenderView) and  
that renderer is marked for layout, then FrameView::layout() is  
called, which will call RenderView::layout() and recursively lay out  
every render tree object marked as needing layout.

One explanation for what you’re seeing would be that as your objects’  
style changes, they fail to call setNeedsLayout() (or  
setNeedsLayoutAndPerfWidthsRecalc()), and therefore layout doesn’t  
occur at that time. An alternative, less likely, explanation is that  
your objects have anonymous children, but they don’t propagate the  
style changes correctly to those children.

> Also, if I need layout() to be called for things to be handled  
> properly, is
> something out of place?

No, layout() is the correct way to update the layout after a style  
change. To ensure that it happens, objects should mark themselves for  
layout in response to the style change when necessary.  
RenderObject::styleDidChange() is an example, and most render objects  
that override styleDidChange() invoke their base class’s  
implementation, so they get marked for layout as needed.

> This all relates to the stretchy operator code in the MathML  
> rendering.  The
> operator's box stretches correctly after layout but after a zoom, it  
> doesn't
> stretch until layout happens again.

I hope the above helps you debug the problem. You may want to  
experiment with more localized style changes (such that should affect  
only your object of interest) and see whether they work and if not,  
why not.

More information about the webkit-dev mailing list