Wednesday, June 23, 2010

QtWebKit goes Mobile

There is a lot of effort being put into QtWebKit in order to make it attractive on the mobile front.

Among a tons of bug fixes and good performance improvements there are also lots of new features being developed, mainly geared toward mobile deployment.

The goal with this tutorial is to help you understand some of these new features and how to make the best of them. Or said in other words; how to create a good mobile web view that can be used on touch devices.

First we should make it clear that QGraphicsWebView is the way forward, so if you want to target mobile devices, it is bye bye QWebView. Why is that? Well, the QWebView is based on the QWidget system, thus it cannot easily support rotation, overlays, hardware accelerated compositing and tiling. If you need a QWidget anyway, you can always construct a QGraphicsView (which is a QWidget) with a QGraphicsWebView inside. This is more or less what we will start with.

Let's start with the most simple QGraphicsWebView based "browser" ever:

Here we just bootstrap a QGraphicsView application and add a QGraphicsWebView to the scene.

It might seem a bit useless as you can only navigate through one website, but it serves well as a simple example. Notice that I'm disabling the scrollbars on the graphics view because QtWebKit handles scrolling and scrollbars automatically. This is due to scrolling optimizations and due to the fact that web authors can interact with the scrollbars for instance style them differently.

On touch-based mobile devices a feature known as tiling is often used. It is used due to the interaction model (touch) as well as a scrolling "optimization". With this optimization we will have to deal with scrolling ourselves and we thus will have to say good bye to the scrollbar styling. Not a big thing, as mobile browsers usually do not even show scrollbars, but use scroll indicators instead.

Tiling basically means that the contents of the viewport is separated into a grid of tiles, so that when you update some area, instead of just updating the area you actually update the whole tile. This gives a few advantages for scrolling as when you scroll you do not need to repaint the new visible area for each scroll step, as you update a row of tiles each time; tiles that are often only partly on the screen. This minimized all the paint calls that we have to do and makes it possible to make nicely kinetic scrolling a possibility.

Loading, layouting etc are blocking operations. Though barely noticeable on a Desktop machines, these operations can block for a long time on a mobile device, letting the user believe the application has become unresponsive and died. Scrolling which is done by using fingers will also stall and give a bad user experience.

One way to over come this issue, is to do all loading, layouting and painting (basically all non-UI related work) in another thread or process, and just blit the result from the web process/thread to the UI. When using tiles, you can blit any tile available when scrolling. When no tile is available you can show a checkerboard tile instead, not letting the scrolling wait for the tiles to be updated. This results in a responsive interface, with the only disadvantage that you from time to time might see checkerboard tiles.

Tiles also helps with zooming. Repainting at each zoom level change during a zoom animation is basically impossible on a mobile device (or desktop for that sake) and thus with tiling, you can stop the tiles from being updates and just scale the already existing tiles, and then at the end of the animation update tiles on top of the scaled ones.

For now we will ignore the blocking issue and concentrate on the tiling and the interaction model.

Resize to contents

When using tiling, we basically want the QGraphicsWebView to act as our contents, as it supports tiling a.o. things. In order for this we need to make it resize itself to the size of its contents. For this we will use QGraphicsWebView::resizesToContents.

From Qt 4.7 documentation: "If this property is set, the QGraphicsWebView will automatically change its size to match the size of the main frame contents. As a result the top level frame will never have scrollbars. It will also make CSS fixed positioning to behave like absolute positioning with elements positioned relative to the document instead of the viewport."

This setting, thus, removes the scrollbars for us on the main frame and makes our QGraphicsWebView resize itself to the size of its content.

Enabling it, is as easy as:

webview.setResizesToContents(true);

Qt 4.7 docs also says: "This property should be used in conjunction with the QWebPage::preferredContentsSize property. If not explicitly set, the preferredContentsSize is automatically set to a reasonable value."

If we are going to expand our mobile web view to the size of the contents of its contained page, then that is going to make the view a lot bigger that what can fit on the device's screen!

Using a view as the window to the contents

The idea is to have a custom widget which has a QGraphicsWebView as a class member. Remember that the QGraphicsWebView will be as big as its content's size, so this custom widget will serve as a window, as a viewport.

There is not much more to say here, and the following code snippet illustrates it well:

In order to properly handle mouse events you must install an event filter on web view or stack it behind its parent object (search for QGraphicsItem::ItemStacksBehindParent). By doing this the mouse events will reach a MobileWebView instance before they reach the member QGraphicsWebView.

Keep in mind that you'll need to add some logic in order to distinguish different mouse events and gestures like a single click, double click, click-and-pan, etc. That is left as an exercise to the reader.

Also keep in mind that as stated earlier, scrolling will have to be implemented manually, just as zoom etc.

Adjusting how contents is laid out

When testing the above on a device, you will notice that many pages do not layout very nicely. In particular the width is larger than the width of the device!

The way web contents is laid out, is that the first the viewport width is used for fitting the contents. If the contents doesn't fit due to non-flexible element with a width larger than the viewport width, the min width possible will be used. As most pages are written with a desktop browser in mind, that makes only very few sites fit into the width of a mobile device.

QtWebKit has a way to force a layout to a given width/height. What really matters here is the width. If you layout a size to a given width, it will get that width and images etc might get cut of. The width/height is also used for laying out fixed elements, but when we resize the QGraphicsWebView to the size of the contents, fixed elements will not be relative to the view, which is the behaviour found on most mobile browsers.

From Qt 4.7 documentation: "If this property is set to a valid size, it is used to lay out the page."

We saw that this property is automatically set to a reasonable value when using QGraphicsWebView::resizesToContents.

As you can imaging, laying out with a smaller viewport can cause pages to break, and as thus, a default value has been chosen so that it almost breaks no pages while still making the sites fit. This value is 960x800.

If the device have a bigger resolution, this value can be changed using:

You can play around with this and find your own magic number, but let's stick to this 960px wide for now.

The 'viewport' meta tag

As some sites do not work with 960 or want to have control on how the page is laid out, QtWebKit as well as Android, Firefox Mobile and the iPhone Safari supports a meta tag called viewport.

This one also deserves a whole blog post for itself. For now let's just say that this is a meta tag that Apple came up with to make a web page capable of "telling" the browser how it wants to be shown.

In QtWebKit trunk we already have support for this with a nice API. You must connect the signal from QWebPage::viewportChangeRequested(const ViewportHints& hints) to a slot of your mobile web view and use what is provided by QWebPage::ViewportHints to updated your viewport size, scale range, and so on.

This can be tricky and that's why I'm not going deeper on it right now. Since I know you are curious about it I'll leave you with one more exercise! So try to understand how the guys from MicroB and Firefox Mobile dealt with this:

Voila! Mind that if you are going to add animations to your zoom/scale or want to implement a fancy kinetic scrolling you might want to take a look at QGraphicsWebView::setTiledBackingStoreFrozen. With this you can avoid updates to your tiles during an animation, for instance.

Avoiding scrollable sub elements

One big issue with the above is that, iframes and sites using frames can contain scrollable sub elements. That doesn't work well with the touch interaction model, as you want a finger swipe to scroll the whole page and not end up just scrolling a sub frame. Most mobile browser work around this by enabling something called frame flattening.

The Power Balance bracelet is made of pure surgical grade silicone that is extremely durable. Its stretch feature optimizes users' comfort level. It comes equipped with two, visible power balance holograms and this sporty and stylish bracelet goes with everything.

Specification:

Silicone Power Balance Wristband Bracelet The band made of 100% silicone rubber With 2 visible hologram disks for balance power,waterproof.

We hear of the mbt shoes clearance masque no more.Some time elapsed, after the death of our author, before any of his later productions appeared : two small editions of his minor pieces were at length sent to the press in 1640, coach bags outlet and in the subsequent year a wretched reprint of the first folio, and a second volume of the same km-, containing his dramatic pieces from 1612, several masques, and all that could be found of his occasional poetry, coach outlet coupon were published together. Several of the comedies appear to have been taken from the prompter's book, and surreptitiously printed (but not published) during the author's life; how the rest were procured I know not. cheap coach purses Such of his dramas as were revived at the Restoration were printed separately ; and in 1692 the whole of his writings were again collected, and published in one huge folio volume. The demand for his works must have been considerable for those days, since in mbt trainers 1716 the booksellers were encouraged to prepare another edition, which they gave the world in six volumes 8ro. This publication was merely a reprint of the old copy, and with this, defective as it was, the town was content till the year 1756, cheap coach bags when a more complete edition, in seven volumes, 8vo, was published by the Rev. Peter Whalley, LL. B.Mr. Whalley had received an academical education, and he was competent, in some measure, to the undertaking. He did little, however, for the poet ; the form of five finger shoes the old editions was rigidly observed, and though a few notes were subjoined, they were seldom of material import, and never explanatory of the author's general views, though they occasionally touched on his language. It is not a little remarkable that this gentleman, who was master of the Grammar School 5 finger shoes of Christ's Hospital, and must naturally have been somewhat conTenant with the ancient writers, should not have ventured on one remark of a literary nature, every thing of this kind, which occurs in his edition, being, coach outlet store online as I discovered with some surprise, taken from Upton and others.Whether Whalley was diffident of himself, or the gentlemen volunteered their assistance, I have no means of knowing ; but he availed himself occasionally of the aid coach purses outlet of Sympson and Scward, (the editors of Beaumont and Fletcher,) who led him astray, and where he would have been simply wrong, if left to himself, rendered him absurd. In one pleasant way of making notes, and swelling the bulk of the book, they all agreed.

We thought we had kept it long " enough, and by use of the flood water relieved ourselves from a considerable The North Face Sale quantity of stink by that means."Bishop Stortford has hitherto escaped litigation, but the same witness informed us,—" We have been threatened by several parties. Our neighbours at Sawbridgeworth have told us that we " have been poisoning them. We have said that we are sorry for it, but we think that they contribute to the " nuisance to some extent themselves, and we have Skechers Shoes therefore not heeded what they had to say."Millers on the same stream are almost obliged to resort to similar practices by way of self-defence. Mr. Garratt, of Hunsdon Mill, who has been much troubled with accumulation of mud, says,—" I find that other people send the mud to me ; and I had a Discount G Star Sale large hoe constructed, and I put four horses to " it, and I sent the mud down again into the navigation. It is cheaper than throwing it out."The condition of the lower end of the valley, where the population is much denser, and adoption of the watercloset system is more general, is of course much worse. Various towns on the Lee, and local authorities on the outskirts of London, have been or are at litigation one with another. To preserve the purity of Edmonton Brook, Edmonton has obtained an injunction against Enfield, and is applying for an injunction against North Face Outlet the Trustees of Colney Hatch Lunatic Asylum. Tottenham last year instituted proceedings against Hornsey for fouling Moselle Stream, but although both the fact of the nuisance and the right of Tottenham to relief were equally undoubted, no relief could be given by the law, because there was no public body at Hornsey to be made amenable. The Lee Trustees a few years ago obtained an injunction against the Metropolitan Board of Works, and 820/. damages in respect of injury done to the Shape Ups Shoes navigation by discharge of sewage from storm-water outlets belonging to the Board. The Lee. Trustees alsorecently filed a bill against the authorities of Tottenham, to put an end to the nuisance from their sewage works, and especially to prevent the sewage of WoodGreen and West-Green, which are Shape Ups Boots districts within Tottenham parish, being added to the sewage of the rest of the parish, which is now discharged into the Lee.

We thought we had kept it long " enough, and by use of the flood water relieved ourselves from a considerable The North Face Sale quantity of stink by that means."Bishop Stortford has hitherto escaped litigation, but the same witness informed us,—" We have been threatened by several parties. Our neighbours at Sawbridgeworth have told us that we " have been poisoning them. We have said that we are sorry for it, but we think that they contribute to the " nuisance to some extent themselves, and we have Skechers Shoes therefore not heeded what they had to say."Millers on the same stream are almost obliged to resort to similar practices by way of self-defence. Mr. Garratt, of Hunsdon Mill, who has been much troubled with accumulation of mud, says,—" I find that other people send the mud to me ; and I had a Discount G Star Sale large hoe constructed, and I put four horses to " it, and I sent the mud down again into the navigation. It is cheaper than throwing it out."The condition of the lower end of the valley, where the population is much denser, and adoption of the watercloset system is more general, is of course much worse. Various towns on the Lee, and local authorities on the outskirts of London, have been or are at litigation one with another. To preserve the purity of Edmonton Brook, Edmonton has obtained an injunction against Enfield, and is applying for an injunction against North Face Outlet the Trustees of Colney Hatch Lunatic Asylum. Tottenham last year instituted proceedings against Hornsey for fouling Moselle Stream, but although both the fact of the nuisance and the right of Tottenham to relief were equally undoubted, no relief could be given by the law, because there was no public body at Hornsey to be made amenable. The Lee Trustees a few years ago obtained an injunction against the Metropolitan Board of Works, and 820/. damages in respect of injury done to the Shape Ups Shoes navigation by discharge of sewage from storm-water outlets belonging to the Board. The Lee. Trustees alsorecently filed a bill against the authorities of Tottenham, to put an end to the nuisance from their sewage works, and especially to prevent the sewage of WoodGreen and West-Green, which are Shape Ups Boots districts within Tottenham parish, being added to the sewage of the rest of the parish, which is now discharged into the Lee.

The louboutin heels is designed for the ladies. Since the pumps was born, the ladies life become colorful. The christian louboutin thong sandals are the god's masterwork. Who invited thechristian louboutin pumps? Seldom people knew, but I think every lady would be grateful for him. Among the countless pumps, the christian louboutin platforms is the most outstanding ones. The elegant pattern, the delicate style all mold the ladies perfect leg profile. Flowers in the spring of 2011 creeping, up from hair to clothes continue to footwear, have had a brilliant up. In such a glamor, spring and summer flowers now here. Romance is a woman's mood, exquisite flowers just right of expression in our gestures, the woman, how can we not love the romantic temperament so that they distributed the flowers do? 2011 flowers bloom will enjoy different poses!The christian louboutin wedges also can adds the hright of the ladies, it bring surprise to the short lady. Especially the red sole of the louboutin heels, magic and sexy, many ladies are crazy. The red sole, the first feature of the Christian Louboutin stroe.

Most women would love to own an authentic cheap christian louboutin shoes The problem comes when people try to match that goal up with finding a Christian Louboutin Outletthat fits their budget. We have heard stories that it is possible to find discounted designer shoes, but it is easy to get frustrated when the cheapest shoes you are able to find are priced well into the hundreds of dollars. Christian Louboutin DiscountLet's cut right to the chase. However desirable all but the wealthiest women may find designer label shoes, Louboutin Outletmost of us are going to have at best one or two cheap christian louboutin clearance shoes if we insist on buying new at retail.Christian Louboutin 2011Christian Louboutin Ankle Shoes if we want to have an assortment of such treasures, we're going to have to make our purchases of lower-priced, Christian Louboutin Heelsdare I say cheap shoes, while not sacrificing original designer heritage for them.Christian Louboutin Peep ToeOf course, when shopping for cheap cheap louis vuitton bags one can put oneself at the mercy of charlatans.Sad to say, there are those among us who have no qualms about passing off a counterfeit designer bag as the real deal, and perhaps having a good laugh at our expense.Recognizing that,Christian Louboutin Pumpsunless one has grown up in a family of purse collectors or had some kind of similar experience of being around genuine articles of quality, Christian Louboutin Sandalssome education is in order. Some people suggest going to christian louboutin outlet stores and examining the goods found there.Christian Louboutin Tall ShoesSuch a plan can be an advantage, Ghd Australia in the outlet store.Five Fingers ShoesHappy to see this article as it is just what I have looking for and I am looking forward to another great article from you. You may be interested in CHI usYour space is really pretty, have no interest in to my chi for sale space to share it? thank you Oh.Buy Nike Shoes

The Louboutin 2011 is planned using the ladies. offered the fact that pumps was born, the ladies lifestyle turn into colorful. The christian Louboutin 2011 Pumpswill be the god's masterwork. Who invited the Christian Louboutin Wedges ? Seldom people knew, but I think each and every and every lady will be grateful for him. between the countless pumps,the Christian Louboutin Shoescould be probably the most exceptional ones. The stylish pattern, the delicate design all mold the ladies perfect leg profile. Flowers inside the spring of 2011 creeping, up from frizzy hair to outfits hold on to footwear, have experienced a brilliant up. on this type of the glamor, spring and summer time flowers now here. Romance is really a woman's mood, exquisite flowers just appropriate of expression within our gestures, the woman, how can we not adore the romantic temperament to make certain which they distributed the flowers do? 2011 flowers bloom will get satisfaction from numerous poses! The Christian Louboutin New Sandalsalso can adds the hright in the ladies, it hold shock toward short lady. especially the red-colored lone in the louboutin heels, beauty and sexy, different ladies are crazy. The red-colored sole, andChristian Louboutin Mensis a very distinctive design, its design reflects its style. You put on it, that means you have its style.the earliest attribute in the Louboutin Shoes sale stroe.http://www.sale-louboutin-shoes.us

Hello, I'm having a bit of a problem with the webview control. In the QT designer, it works and I can see the webpage, etc. When I try to build the project in netbeans, it gives me an unfound library error.

uggs clearance In cold climate, Ugg boots help to maintain your ft warm. They're a needed fashion accessory currently, Uggs Outlet equally stylish and comfortable. The obvious way to get cheap Ugg boots at a superb price tag should be to research for seasonal gross sales. These could be at outlets or at online web sites ugg boots clearance.

Only the progress of your time can prove the fact that modifications exist in clothing, merely because clothes should adhere to the pace of tiffany set times, bags are no exception. since the major area of luxury products, Louis Vuitton bags continually deliver us the newest craze of coach online style world, now the brand new yr has just arrived; designers of LV have previously developed the brand new models, that will be the spring holiday assortment of converse shoes new Louis Vuitton bags 2011. New Louis Vuitton bags 2011 are complete of inhale of spring, while you see them; you may possibly really feel the fact that property from every sole corner is dynamic.

The best place to learn Chinese online is in China. However, we understand that it isn't always possible to move here to study Chinese language. The next best thing is to study with our experienced teachers in a virtual classroom. Online students enjoy the same excellent way of Mandarin Online Course and custom designed courseware that we provide for our face to face clients.

I really liked this part of the article, with a nice and interesting topics have helped a lot of people who do not challenge things people should know... you need more publicize this so many people who know about it are rare for people to know this, Success for you.

Excellent blog you have here but I was curious about if you knew of any community forums that cover the same topics talked about in this article? I’d really like to be a part of online community where I can get advice from other experienced individuals that share the same interest. If you have any suggestions, please let me know. Appreciate itsofttonice | canon support | drivers and software

Excellent blog you have here but I was curious about if you knew of any community forums that cover the same topics talked about in this article? I’d really like to be a part of online community where I can get advice from other experienced individuals that share the same interest. If you have any suggestions, please let me know. Appreciate itsoftonice | canon support | drivers and software-

Links

About Me

Kenneth is 30 year old, Danish, open source hacker currently involved with developing the next-generation products for the Nokia N810. Working at the Brazilian-based Nokia Technology Institute as a researcher, he has gained great knowledge in what is needed for the Linux-platform to mature in order to deliver products that can compete with products such as the iPhone.