[webkit-qt] API for viewport meta tag support

Simon Hausmann simon.hausmann at nokia.com
Fri Jun 4 05:53:32 PDT 2010


Hi,

WebCore itself has support for Apple's viewport meta tag:

http://developer.apple.com/safari/library/documentation/appleapplications/reference/safarihtmlref/articles/metatags.html

which can look like this in HTML:

	<meta name = "viewport" content = "width = 320,
           initial-scale = 2.3, user-scalable = no">

The tag allows the web page to influence the sacl and geometry
of the viewport on mobile browsers. WebCore has support for
parsing all these attributes and passing them to the ChromeClient
layer as soon as they're available. It is then the job of the WebKit
API layer to propagate the information to the mobile browser
application.

Jesus has been working on that in bug

	https://bugs.webkit.org/show_bug.cgi?id=39902

and has come up with a nice API where QWebPage emits a signal
as soon as WebCore processes this tag:

 /*!
+    \since 4.7
+    \fn void QWebPage::viewportChangeRequested(const ViewportHints& hints)
+
+    This signal is emitted before any layout of the contents, giving you the viewport \a arguments
+    the web page would like you to use when laying out its contents, including elements fixed to the
+    viewport. This viewport might be larger that your actual viewport, meaning that a initialScale
+    should be applied. When no scale is given (-1.0), it is assumed that the contents should be scaled
+    such that the width of the scaled contents fits within the actual viewport.
+
+    The minimum and maximum allowed scale represents the min and max values that the page
+    allows for scaling, and thus, affects the ability to zoom in on the page.
+
+    Invalid values are supplied for the values not explicitly set by the web author; thus an
+    invalid viewport size, and values equal to -1.0 for scale factor and limits. The boolean
+    ViewportHints::isUserScalable is set to true.
+
+    Page authors can provide the supplied values by using the viewport meta tag. More information
+    about this can be found at \l{http://developer.apple.com/safari/library/documentation/appleapplications/reference/safariwebcontent/usingtheviewport/usingtheviewport.html}{Safari Reference Library: Using the 
Viewport Meta Tag}.
+
+    \sa QWebPage::ViewportHints, setPreferredContentsSize(), QGraphicsWebView::setScale()
+*/

In order to avoid having a signal in the API that has lots of arguments, the parameters are
instead collected in a structure:

+    struct ViewportHints {
+
+        ViewportHints()
+            : initialScale(-1.0)
+            , minAllowedScale(-1.0)
+            , maxAllowedScale(-1.0)
+            , isUserScalable(true)
+        {
+        }
+
+        QSize size;
+        qreal initialScale;
+        qreal minAllowedScale;
+        qreal maxAllowedScale;
+
+        bool isUserScalable;
+    };
+

What do you guys think about this API?

Please give feedback on https://bugs.webkit.org/show_bug.cgi?id=39902 :-)


Simon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.webkit.org/pipermail/webkit-qt/attachments/20100604/f33c1b75/attachment-0001.bin>


More information about the webkit-qt mailing list