Index: trunk/demos/embedded/anomaly/anomaly.pro
===================================================================
--- trunk/demos/embedded/anomaly/anomaly.pro	(revision 561)
+++ trunk/demos/embedded/anomaly/anomaly.pro	(revision 651)
@@ -9,5 +9,6 @@
     src/flickcharm.h \
     src/ZoomStrip.h \
-    src/ControlStrip.h
+    src/ControlStrip.h \
+    src/webview.h
 SOURCES += src/Main.cpp \
     src/BrowserWindow.cpp \
@@ -19,5 +20,6 @@
     src/flickcharm.cpp \
     src/ZoomStrip.cpp \
-    src/ControlStrip.cpp
+    src/ControlStrip.cpp \
+    src/webview.cpp
 RESOURCES += src/anomaly.qrc
 
Index: trunk/demos/embedded/anomaly/src/AddressBar.cpp
===================================================================
--- trunk/demos/embedded/anomaly/src/AddressBar.cpp	(revision 561)
+++ trunk/demos/embedded/anomaly/src/AddressBar.cpp	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/AddressBar.h
===================================================================
--- trunk/demos/embedded/anomaly/src/AddressBar.h	(revision 561)
+++ trunk/demos/embedded/anomaly/src/AddressBar.h	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/BookmarksView.cpp
===================================================================
--- trunk/demos/embedded/anomaly/src/BookmarksView.cpp	(revision 561)
+++ trunk/demos/embedded/anomaly/src/BookmarksView.cpp	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/BookmarksView.h
===================================================================
--- trunk/demos/embedded/anomaly/src/BookmarksView.h	(revision 561)
+++ trunk/demos/embedded/anomaly/src/BookmarksView.h	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/BrowserView.cpp
===================================================================
--- trunk/demos/embedded/anomaly/src/BrowserView.cpp	(revision 561)
+++ trunk/demos/embedded/anomaly/src/BrowserView.cpp	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -49,4 +49,5 @@
 #include "TitleBar.h"
 #include "flickcharm.h"
+#include "webview.h"
 #include "ZoomStrip.h"
 
@@ -63,5 +64,5 @@
 {
     m_titleBar = new TitleBar(this);
-    m_webView = new QWebView(this);
+    m_webView = new WebView(this);
     m_zoomStrip = new ZoomStrip(this);
     m_controlStrip = new ControlStrip(this);
@@ -96,5 +97,5 @@
     connect(m_webView, SIGNAL(urlChanged(QUrl)), SLOT(updateTitleBar()));
 
-    m_webView->setHtml("Will try to load page soon!");
+    m_webView->setHtml("about:blank");
     m_webView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
     m_webView->setFocus();
Index: trunk/demos/embedded/anomaly/src/BrowserView.h
===================================================================
--- trunk/demos/embedded/anomaly/src/BrowserView.h	(revision 561)
+++ trunk/demos/embedded/anomaly/src/BrowserView.h	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -50,4 +50,5 @@
 class TitleBar;
 class ControlStrip;
+class WebView;
 class ZoomStrip;
 
@@ -82,5 +83,5 @@
 private:
     TitleBar *m_titleBar;
-    QWebView *m_webView;
+    WebView *m_webView;
     ZoomStrip *m_zoomStrip;
     ControlStrip *m_controlStrip;
@@ -91,2 +92,3 @@
 
 #endif // BROWSERVIEW_H
+
Index: trunk/demos/embedded/anomaly/src/BrowserWindow.cpp
===================================================================
--- trunk/demos/embedded/anomaly/src/BrowserWindow.cpp	(revision 561)
+++ trunk/demos/embedded/anomaly/src/BrowserWindow.cpp	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/BrowserWindow.h
===================================================================
--- trunk/demos/embedded/anomaly/src/BrowserWindow.h	(revision 561)
+++ trunk/demos/embedded/anomaly/src/BrowserWindow.h	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/ControlStrip.cpp
===================================================================
--- trunk/demos/embedded/anomaly/src/ControlStrip.cpp	(revision 561)
+++ trunk/demos/embedded/anomaly/src/ControlStrip.cpp	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/ControlStrip.h
===================================================================
--- trunk/demos/embedded/anomaly/src/ControlStrip.h	(revision 561)
+++ trunk/demos/embedded/anomaly/src/ControlStrip.h	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/HomeView.cpp
===================================================================
--- trunk/demos/embedded/anomaly/src/HomeView.cpp	(revision 561)
+++ trunk/demos/embedded/anomaly/src/HomeView.cpp	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/HomeView.h
===================================================================
--- trunk/demos/embedded/anomaly/src/HomeView.h	(revision 561)
+++ trunk/demos/embedded/anomaly/src/HomeView.h	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/Main.cpp
===================================================================
--- trunk/demos/embedded/anomaly/src/Main.cpp	(revision 561)
+++ trunk/demos/embedded/anomaly/src/Main.cpp	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/TitleBar.cpp
===================================================================
--- trunk/demos/embedded/anomaly/src/TitleBar.cpp	(revision 561)
+++ trunk/demos/embedded/anomaly/src/TitleBar.cpp	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/TitleBar.h
===================================================================
--- trunk/demos/embedded/anomaly/src/TitleBar.h	(revision 561)
+++ trunk/demos/embedded/anomaly/src/TitleBar.h	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/ZoomStrip.cpp
===================================================================
--- trunk/demos/embedded/anomaly/src/ZoomStrip.cpp	(revision 561)
+++ trunk/demos/embedded/anomaly/src/ZoomStrip.cpp	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/ZoomStrip.h
===================================================================
--- trunk/demos/embedded/anomaly/src/ZoomStrip.h	(revision 561)
+++ trunk/demos/embedded/anomaly/src/ZoomStrip.h	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/flickcharm.cpp
===================================================================
--- trunk/demos/embedded/anomaly/src/flickcharm.cpp	(revision 561)
+++ trunk/demos/embedded/anomaly/src/flickcharm.cpp	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
@@ -50,4 +50,5 @@
 #include <QMouseEvent>
 #include <QScrollBar>
+#include <QTime>
 #include <QWebFrame>
 #include <QWebView>
@@ -55,13 +56,104 @@
 #include <QDebug>
 
+const int fingerAccuracyThreshold = 3;
+
 struct FlickData {
-    typedef enum { Steady, Pressed, ManualScroll, AutoScroll, Stop } State;
+    typedef enum {
+        Steady, // Interaction without scrolling
+        ManualScroll, // Scrolling manually with the finger on the screen
+        AutoScroll, // Scrolling automatically
+        AutoScrollAcceleration // Scrolling automatically but a finger is on the screen
+    } State;
     State state;
     QWidget *widget;
     QPoint pressPos;
-    QPoint offset;
-    QPoint dragPos;
+    QPoint lastPos;
     QPoint speed;
+    QTime speedTimer;
     QList<QEvent*> ignored;
+    QTime accelerationTimer;
+    bool lastPosValid:1;
+    bool waitingAcceleration:1;
+
+    FlickData()
+        : lastPosValid(false)
+        , waitingAcceleration(false)
+    {}
+
+    void resetSpeed()
+    {
+        speed = QPoint();
+        lastPosValid = false;
+    }
+    void updateSpeed(const QPoint &newPosition)
+    {
+        if (lastPosValid) {
+            const int timeElapsed = speedTimer.elapsed();
+            if (timeElapsed) {
+                const QPoint newPixelDiff = (newPosition - lastPos);
+                const QPoint pixelsPerSecond = newPixelDiff * (1000 / timeElapsed);
+                // fingers are inacurates, we ignore small changes to avoid stopping the autoscroll because
+                // of a small horizontal offset when scrolling vertically
+                const int newSpeedY = (qAbs(pixelsPerSecond.y()) > fingerAccuracyThreshold) ? pixelsPerSecond.y() : 0;
+                const int newSpeedX = (qAbs(pixelsPerSecond.x()) > fingerAccuracyThreshold) ? pixelsPerSecond.x() : 0;
+                if (state == AutoScrollAcceleration) {
+                    const int max = 4000; // px by seconds
+                    const int oldSpeedY = speed.y();
+                    const int oldSpeedX = speed.x();
+                    if ((oldSpeedY <= 0 && newSpeedY <= 0) ||  (oldSpeedY >= 0 && newSpeedY >= 0)
+                        && (oldSpeedX <= 0 && newSpeedX <= 0) ||  (oldSpeedX >= 0 && newSpeedX >= 0)) {
+                        speed.setY(qBound(-max, (oldSpeedY + (newSpeedY / 4)), max));
+                        speed.setX(qBound(-max, (oldSpeedX + (newSpeedX / 4)), max));
+                    } else {
+                        speed = QPoint();
+                    }
+                } else {
+                    const int max = 2500; // px by seconds
+                    // we average the speed to avoid strange effects with the last delta
+                    if (!speed.isNull()) {
+                        speed.setX(qBound(-max, (speed.x() / 4) + (newSpeedX * 3 / 4), max));
+                        speed.setY(qBound(-max, (speed.y() / 4) + (newSpeedY * 3 / 4), max));
+                    } else {
+                        speed = QPoint(newSpeedX, newSpeedY);
+                    }
+                }
+            }
+        } else {
+            lastPosValid = true;
+        }
+        speedTimer.start();
+        lastPos = newPosition;
+    }
+
+    // scroll by dx, dy
+    // return true if the widget was scrolled
+    bool scrollWidget(const int dx, const int dy)
+    {
+        QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(widget);
+        if (scrollArea) {
+            const int x = scrollArea->horizontalScrollBar()->value();
+            const int y = scrollArea->verticalScrollBar()->value();
+            scrollArea->horizontalScrollBar()->setValue(x - dx);
+            scrollArea->verticalScrollBar()->setValue(y - dy);
+            return (scrollArea->horizontalScrollBar()->value() != x
+                    || scrollArea->verticalScrollBar()->value() != y);
+        }
+
+        QWebView *webView = qobject_cast<QWebView*>(widget);
+        if (webView) {
+            QWebFrame *frame = webView->page()->mainFrame();
+            const QPoint position = frame->scrollPosition();
+            frame->setScrollPosition(position - QPoint(dx, dy));
+            return frame->scrollPosition() != position;
+        }
+        return false;
+    }
+
+    bool scrollTo(const QPoint &newPosition)
+    {
+        const QPoint delta = newPosition - lastPos;
+        updateSpeed(newPosition);
+        return scrollWidget(delta.x(), delta.y());
+    }
 };
 
@@ -71,4 +163,11 @@
     QHash<QWidget*, FlickData*> flickData;
     QBasicTimer ticker;
+    QTime timeCounter;
+    void startTicker(QObject *object)
+    {
+        if (!ticker.isActive())
+            ticker.start(15, object);
+        timeCounter.start();
+    }
 };
 
@@ -149,47 +248,15 @@
 }
 
-static QPoint scrollOffset(QWidget *widget)
-{
-    int x = 0, y = 0;
-
-    QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(widget);
-    if (scrollArea) {
-        x = scrollArea->horizontalScrollBar()->value();
-        y = scrollArea->verticalScrollBar()->value();
-    }
-
-    QWebView *webView = qobject_cast<QWebView*>(widget);
-    if (webView) {
-        QWebFrame *frame = webView->page()->mainFrame();
-        x = frame->evaluateJavaScript("window.scrollX").toInt();
-        y = frame->evaluateJavaScript("window.scrollY").toInt();
-    }
-
+static QPoint deaccelerate(const QPoint &speed, const int deltatime)
+{
+    const int deltaSpeed = deltatime;
+
+    int x = speed.x();
+    int y = speed.y();
+    x = (x == 0) ? x : (x > 0) ? qMax(0, x - deltaSpeed) : qMin(0, x + deltaSpeed);
+    y = (y == 0) ? y : (y > 0) ? qMax(0, y - deltaSpeed) : qMin(0, y + deltaSpeed);
     return QPoint(x, y);
 }
 
-static void setScrollOffset(QWidget *widget, const QPoint &p)
-{
-    QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(widget);
-    if (scrollArea) {
-        scrollArea->horizontalScrollBar()->setValue(p.x());
-        scrollArea->verticalScrollBar()->setValue(p.y());
-    }
-
-    QWebView *webView = qobject_cast<QWebView*>(widget);
-    QWebFrame *frame = webView ? webView->page()->mainFrame() : 0;
-    if (frame)
-        frame->evaluateJavaScript(QString("window.scrollTo(%1,%2);").arg(p.x()).arg(p.y()));
-}
-
-static QPoint deaccelerate(const QPoint &speed, int a = 1, int max = 64)
-{
-    int x = qBound(-max, speed.x(), max);
-    int y = qBound(-max, speed.y(), max);
-    x = (x == 0) ? x : (x > 0) ? qMax(0, x - a) : qMin(0, x + a);
-    y = (y == 0) ? y : (y > 0) ? qMax(0, y - a) : qMin(0, y + a);
-    return QPoint(x, y);
-}
-
 bool FlickCharm::eventFilter(QObject *object, QEvent *event)
 {
@@ -197,20 +264,22 @@
         return false;
 
-    QEvent::Type type = event->type();
-    if (type != QEvent::MouseButtonPress &&
-            type != QEvent::MouseButtonRelease &&
-            type != QEvent::MouseMove)
-        return false;
-
-    QMouseEvent *mouseEvent = 0;
-    switch (event->type()) {
-        case QEvent::MouseButtonPress:
-        case QEvent::MouseButtonRelease:
-        case QEvent::MouseMove:
-            mouseEvent = static_cast<QMouseEvent*>(event);
-            break;
-    }
-
-    if (!mouseEvent || mouseEvent->modifiers() != Qt::NoModifier)
+    const QEvent::Type type = event->type();
+
+    switch (type) {
+    case QEvent::MouseButtonPress:
+    case QEvent::MouseMove:
+    case QEvent::MouseButtonRelease:
+        break;
+    case QEvent::MouseButtonDblClick: // skip double click
+        return true;
+    default:
+        return false;
+    }
+
+    QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
+    if (type == QEvent::MouseMove && mouseEvent->buttons() != Qt::LeftButton)
+        return false;
+
+    if (mouseEvent->modifiers() != Qt::NoModifier)
         return false;
 
@@ -220,26 +289,20 @@
         return false;
 
+    const QPoint mousePos = mouseEvent->pos();
     bool consumed = false;
     switch (data->state) {
 
     case FlickData::Steady:
-        if (mouseEvent->type() == QEvent::MouseButtonPress)
-            if (mouseEvent->buttons() == Qt::LeftButton) {
-                consumed = true;
-                data->state = FlickData::Pressed;
-                data->pressPos = mouseEvent->pos();
-                data->offset = scrollOffset(data->widget);
-            }
-        break;
-
-    case FlickData::Pressed:
-        if (mouseEvent->type() == QEvent::MouseButtonRelease) {
-            consumed = true;
-            data->state = FlickData::Steady;
-
+        if (type == QEvent::MouseButtonPress) {
+            consumed = true;
+            data->pressPos = mousePos;
+        } else if (type == QEvent::MouseButtonRelease) {
+            consumed = true;
             QMouseEvent *event1 = new QMouseEvent(QEvent::MouseButtonPress,
                                                   data->pressPos, Qt::LeftButton,
                                                   Qt::LeftButton, Qt::NoModifier);
-            QMouseEvent *event2 = new QMouseEvent(*mouseEvent);
+            QMouseEvent *event2 = new QMouseEvent(QEvent::MouseButtonRelease,
+                                                  data->pressPos, Qt::LeftButton,
+                                                  Qt::LeftButton, Qt::NoModifier);
 
             data->ignored << event1;
@@ -247,60 +310,60 @@
             QApplication::postEvent(object, event1);
             QApplication::postEvent(object, event2);
-        }
-        if (mouseEvent->type() == QEvent::MouseMove) {
-            consumed = true;
-            data->state = FlickData::ManualScroll;
-            data->dragPos = QCursor::pos();
-            if (!d->ticker.isActive())
-                d->ticker.start(20, this);
+        } else if (type == QEvent::MouseMove) {
+            consumed = true;
+            data->scrollTo(mousePos);
+
+            const QPoint delta = mousePos - data->pressPos;
+            if (delta.x() > fingerAccuracyThreshold || delta.y() > fingerAccuracyThreshold)
+                data->state = FlickData::ManualScroll;
         }
         break;
 
     case FlickData::ManualScroll:
-        if (mouseEvent->type() == QEvent::MouseMove) {
-            consumed = true;
-            QPoint delta = mouseEvent->pos() - data->pressPos;
-            setScrollOffset(data->widget, data->offset - delta);
-        }
-        if (mouseEvent->type() == QEvent::MouseButtonRelease) {
+        if (type == QEvent::MouseMove) {
+            consumed = true;
+            data->scrollTo(mousePos);
+        } else if (type == QEvent::MouseButtonRelease) {
             consumed = true;
             data->state = FlickData::AutoScroll;
+            data->lastPosValid = false;
+            d->startTicker(this);
         }
         break;
 
     case FlickData::AutoScroll:
-        if (mouseEvent->type() == QEvent::MouseButtonPress) {
-            consumed = true;
-            data->state = FlickData::Stop;
-            data->speed = QPoint(0, 0);
-            data->pressPos = mouseEvent->pos();
-            data->offset = scrollOffset(data->widget);
-        }
-        if (mouseEvent->type() == QEvent::MouseButtonRelease) {
+        if (type == QEvent::MouseButtonPress) {
+            consumed = true;
+            data->state = FlickData::AutoScrollAcceleration;
+            data->waitingAcceleration = true;
+            data->accelerationTimer.start();
+            data->updateSpeed(mousePos);
+            data->pressPos = mousePos;
+        } else if (type == QEvent::MouseButtonRelease) {
             consumed = true;
             data->state = FlickData::Steady;
-            data->speed = QPoint(0, 0);
-        }
-        break;
-
-    case FlickData::Stop:
-        if (mouseEvent->type() == QEvent::MouseButtonRelease) {
-            consumed = true;
-            data->state = FlickData::Steady;
-        }
-        if (mouseEvent->type() == QEvent::MouseMove) {
-            consumed = true;
-            data->state = FlickData::ManualScroll;
-            data->dragPos = QCursor::pos();
-            if (!d->ticker.isActive())
-                d->ticker.start(20, this);
-        }
-        break;
-
+            data->resetSpeed();
+        }
+        break;
+
+    case FlickData::AutoScrollAcceleration:
+        if (type == QEvent::MouseMove) {
+            consumed = true;
+            data->updateSpeed(mousePos);
+            data->accelerationTimer.start();
+            if (data->speed.isNull())
+                data->state = FlickData::ManualScroll;
+        } else if (type == QEvent::MouseButtonRelease) {
+            consumed = true;
+            data->state = FlickData::AutoScroll;
+            data->waitingAcceleration = false;
+            data->lastPosValid = false;
+        }
+        break;
     default:
         break;
     }
-
-    return consumed;
+    data->lastPos = mousePos;
+    return true;
 }
 
@@ -312,18 +375,20 @@
         item.next();
         FlickData *data = item.value();
-
-        if (data->state == FlickData::ManualScroll) {
-            count++;
-            data->speed = QCursor::pos() - data->dragPos;
-            data->dragPos = QCursor::pos();
-        }
-
-        if (data->state == FlickData::AutoScroll) {
-            count++;
-            data->speed = deaccelerate(data->speed);
-            QPoint p = scrollOffset(data->widget);
-            setScrollOffset(data->widget, p - data->speed);
-            if (data->speed == QPoint(0, 0))
+        if (data->state == FlickData::AutoScrollAcceleration
+            && data->waitingAcceleration
+            && data->accelerationTimer.elapsed() > 40) {
+            data->state = FlickData::ManualScroll;
+            data->resetSpeed();
+        }
+        if (data->state == FlickData::AutoScroll || data->state == FlickData::AutoScrollAcceleration) {
+            const int timeElapsed = d->timeCounter.elapsed();
+            const QPoint delta = (data->speed) * timeElapsed / 1000;
+            bool hasScrolled = data->scrollWidget(delta.x(), delta.y());
+
+            if (data->speed.isNull() || !hasScrolled)
                 data->state = FlickData::Steady;
+            else
+                count++;
+            data->speed = deaccelerate(data->speed, timeElapsed);
         }
     }
@@ -331,4 +396,6 @@
     if (!count)
         d->ticker.stop();
+    else
+        d->timeCounter.start();
 
     QObject::timerEvent(event);
Index: trunk/demos/embedded/anomaly/src/flickcharm.h
===================================================================
--- trunk/demos/embedded/anomaly/src/flickcharm.h	(revision 561)
+++ trunk/demos/embedded/anomaly/src/flickcharm.h	(revision 651)
@@ -1,5 +1,5 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
Index: trunk/demos/embedded/anomaly/src/webview.cpp
===================================================================
--- trunk/demos/embedded/anomaly/src/webview.cpp	(revision 651)
+++ trunk/demos/embedded/anomaly/src/webview.cpp	(revision 651)
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demos of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "webview.h"
+
+#include <QPaintEvent>
+#include <QWebFrame>
+
+WebView::WebView(QWidget *parent)
+    : QWebView(parent)
+    , inLoading(false)
+{
+    connect(this, SIGNAL(loadStarted()), this, SLOT(newPageLoading()));
+    connect(this, SIGNAL(loadFinished(bool)), this, SLOT(pageLoaded(bool)));
+    page()->setPreferredContentsSize(QSize(1024, 768));
+}
+
+void WebView::paintEvent(QPaintEvent *event)
+{
+    if (inLoading && loadingTime.elapsed() < 750) {
+        QPainter painter(this);
+        painter.setBrush(Qt::white);
+        painter.setPen(Qt::NoPen);
+        foreach (const QRect &rect, event->region().rects()) {
+            painter.drawRect(rect);
+        }
+    } else {
+        QWebView::paintEvent(event);
+    }
+}
+
+void WebView::newPageLoading()
+{
+    inLoading = true;
+    loadingTime.start();
+}
+
+void WebView::pageLoaded(bool)
+{
+    inLoading = false;
+    update();
+}
Index: trunk/demos/embedded/anomaly/src/webview.h
===================================================================
--- trunk/demos/embedded/anomaly/src/webview.h	(revision 651)
+++ trunk/demos/embedded/anomaly/src/webview.h	(revision 651)
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the demos of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial Usage
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef WEBVIEW_H
+#define WEBVIEW_H
+
+#include <QWebView>
+#include <QTime>
+
+class WebView : public QWebView
+{
+    Q_OBJECT
+public:
+    WebView(QWidget *parent = 0);
+
+protected:
+    void paintEvent(QPaintEvent *event);
+
+private slots:
+    void newPageLoading();
+    void pageLoaded(bool ok);
+
+private:
+    QTime loadingTime;
+    bool inLoading;
+};
+
+#endif // WEBVIEW_H
