src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp
branchRCL_3
changeset 5 d3bac044e0f0
parent 3 41300fa6a67c
--- a/src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp	Fri Feb 19 23:40:16 2010 +0200
+++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebview.cpp	Fri Mar 12 15:46:37 2010 +0200
@@ -57,6 +57,106 @@
     view->setPage(0);
 }
 
+#ifdef Q_WS_MAEMO_5
+#include "qabstractkineticscroller.h"
+
+class QWebViewKineticScroller : public QAbstractKineticScroller {
+public:
+    QWebViewKineticScroller() : QAbstractKineticScroller() {}
+    // remember the frame where the button was pressed
+    bool eventFilter(QObject* o, QEvent* ev)
+    {
+        switch (ev->type()) {
+        case QEvent::MouseButtonPress: {
+            QWebFrame* hitFrame = scrollingFrameAt(static_cast<QMouseEvent*>(ev)->pos());
+            if (hitFrame)
+                m_frame = hitFrame;
+            break;
+        }
+        default:
+            break;
+        }
+        return QAbstractKineticScroller::eventFilter(o, ev);
+    }
+
+protected:
+    QWebFrame* currentFrame() const
+    {
+        if (!m_frame.isNull())
+            return m_frame.data();
+
+        QWebView* view = static_cast<QWebView*>(widget());
+        QWebFrame* frame = view->page()->mainFrame();
+        return frame;
+    }
+
+    // Returns the innermost frame at the given position that can scroll.
+    QWebFrame* scrollingFrameAt(const QPoint& pos) const
+    {
+        QWebView* view = static_cast<QWebView*>(widget());
+        QWebFrame* mainFrame = view->page()->mainFrame();
+        QWebFrame* hitFrame = mainFrame->hitTestContent(pos).frame();
+        QSize range = hitFrame->contentsSize() - hitFrame->geometry().size();
+
+        while (hitFrame && range.width() <= 1 && range.height() <= 1)
+            hitFrame = hitFrame->parentFrame();
+
+        return hitFrame;
+    }
+
+    void attachToWidget()
+    {
+        QWebView* view = static_cast<QWebView*>(widget());
+        QWebFrame* mainFrame = view->page()->mainFrame();
+        m_oldHorizontalScrollBarPolicy = mainFrame->scrollBarPolicy(Qt::Horizontal);
+        m_oldVerticalScrollBarPolicy = mainFrame->scrollBarPolicy(Qt::Vertical);
+        mainFrame->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
+        mainFrame->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
+        view->installEventFilter(this);
+    }
+
+    void removeFromWidget()
+    {
+        QWebView* view = static_cast<QWebView*>(widget());
+        view->removeEventFilter(this);
+        QWebFrame* mainFrame = view->page()->mainFrame();
+        mainFrame->setScrollBarPolicy(Qt::Vertical, m_oldVerticalScrollBarPolicy);
+        mainFrame->setScrollBarPolicy(Qt::Horizontal, m_oldHorizontalScrollBarPolicy);
+    }
+
+    QRect positionRange() const
+    {
+        QRect r;
+        QWebFrame* frame = currentFrame();
+        r.setSize(frame->contentsSize() - frame->geometry().size());
+        return r;
+    }
+
+    QPoint position() const
+    {
+        QWebFrame* frame = currentFrame();
+        return frame->scrollPosition();
+    }
+
+    QSize viewportSize() const
+    {
+        return static_cast<QWebView*>(widget())->page()->viewportSize();
+    }
+
+    void setPosition(const QPoint& point, const QPoint& /* overShootDelta */)
+    {
+        QWebFrame* frame = currentFrame();
+        frame->setScrollPosition(point);
+    }
+
+    QPointer<QWebFrame> m_frame;
+    Qt::ScrollBarPolicy m_oldVerticalScrollBarPolicy;
+    Qt::ScrollBarPolicy m_oldHorizontalScrollBarPolicy;
+};
+
+#endif // Q_WS_MAEMO_5
+
+
 /*!
     \class QWebView
     \since 4.4
@@ -153,6 +253,10 @@
     setAttribute(Qt::WA_InputMethodEnabled);
 #endif
 
+#if defined(Q_WS_MAEMO_5)
+    QAbstractKineticScroller* scroller = new QWebViewKineticScroller();
+    scroller->setWidget(this);
+#endif
     setAcceptDrops(true);
 
     setMouseTracking(true);