[webkit-qt] Pinch zoom for QWebView?

Kenneth Rohde Christiansen kenneth.christiansen at gmail.com
Sat Jan 8 08:35:47 PST 2011

Let me repost as I was subscribed with another address:

Hi there,

To get the right result you will need to scale the contents and not
zoom it, as zooming is not the same as just applying a scale. Scaling
the QPainter would do. On the other hand, you cannot ensure a really
smooth pinch animation as you repaint the whole time without being
able to ensure how long that repaint will take. What you really should
do is to use the QGraphicsWebView as it supports a tiled backing
store. Then you can pinch the following way:

1) freeze the backing store
2) apply a scale to the QGraphicsWebView (this will scale the frozen
tiles (pixmaps))
3) unfreeze the backing store (it will now repaint and become crisp)

It would be nice if you could add such support to our demo/test
browser QtTestBrowser found in our webkit repository.

Just to make it clear, with the QGraphicsWebView you do not need to
change the QPainter directly. A QGraphicsWebView is a QGraphicsWidget
and it has a ::setScale() method, which you can use.

I forgot to mention one more thing:

1) You need to enable resizesToContents if you are going to scale the
QGraphicsWebView, which means that you need to implement your own
panning as well. ie have a QGraphicsItem serve as a view to your
QGraphicsWebView. Every time, the viewport is (re)sized, or a
pinch/panning animation has ended, you will need to call
setActualVisibleContentsRect(). Do not do this during animations for
performance reasons.

QtTestBrowser shows how to use resizesToContents with tiling etc, but
it still lacks the setActualVisibleContentsRect() code, which is

1) for not ending up in infinit tiling creation (it needs an initial
size; the (re)sizing)
2) for programmatic scrolling to work, anchor links (it needs the new
visible rect after each pinch, panning ended)


On Sat, Jan 8, 2011 at 10:11 AM, Harri Pasanen <grego at mpaja.com> wrote:
> I wonder if pinch zoom is on the roadmap for webkit?
> Meanwhile I rolled my own simple implementation which is better than nothing,
> but not perfect.  In my code I'm scaling a pixmap for fluid motion, and at the
> end I call setZoomFactor.  The relevant code is visible here:
> http://pastebin.com/VzimAPD0
> It is usable in that it works fluidly and gives you a rough idea what the
> resulting zoom will be.  But pixel positions move around and the end result is
> rarely exact to the zoom preview.
> On Symbian3 the native browser's pinch zoom is much more faithful to pixel
> positions and sizing of the preview.  So that must be doing something more
> clever, any hints what?
> Better yet, perhaps this is already implemented and I just have to be patient
> and it will be delivered to my door...
> Harri
> http://mpaja.com/
> _______________________________________________
> webkit-qt mailing list
> webkit-qt at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-qt

Kenneth Rohde Christiansen
Senior Engineer
Application and Service Frameworks, Nokia Danmark A/S
Phone  +45 4093 0598 / E-mail kenneth.christiansen at gmail.com

http://codeposts.blogspot.com ﹆﹆﹆

More information about the webkit-qt mailing list