[Qt][WK2] Fix scrolling in touch mode
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 May 2012 15:07:59 +0000 (15:07 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 May 2012 15:07:59 +0000 (15:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=75006

Patch by Allan Sandfeld Jensen <allan.jensen@nokia.com> on 2012-05-15
Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

* page/FrameView.cpp:
(WebCore::FrameView::setFixedVisibleContentRect):
    On changes to fixedVisibleContentRect update scroll-animators position, and
    recalculate page-step sizes in scrollbars.
* platform/ScrollView.cpp:
(WebCore::ScrollView::scrollTo):
    Forward scrolling-request to the host window.
(WebCore::ScrollView::updateScrollbars):
    Allow ScrollViews to have invisible scrollbars when scrolling is delegated.
* platform/ScrollView.h:
(ScrollView):

Source/WebKit2:

Only handle mouse-wheel events in WebCore to avoid double scrolling, and
scale pixels scrolled by wheel events according to viewport transformation.

* Shared/qt/WebEventFactoryQt.cpp:
(WebKit::WebEventFactory::createWebWheelEvent):
* UIProcess/qt/QtViewportInteractionEngine.cpp:
* UIProcess/qt/QtViewportInteractionEngine.h:
(QtViewportInteractionEngine):
* UIProcess/qt/QtWebPageEventHandler.cpp:
(QtWebPageEventHandler::handleWheelEvent):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@117069 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/page/FrameView.cpp
Source/WebCore/platform/ScrollView.cpp
Source/WebCore/platform/ScrollView.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/qt/WebEventFactoryQt.cpp
Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.cpp
Source/WebKit2/UIProcess/qt/QtViewportInteractionEngine.h
Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp

index f09c3bb..43139d2 100644 (file)
@@ -1,3 +1,22 @@
+2012-05-15  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
+
+        [Qt][WK2] Fix scrolling in touch mode
+        https://bugs.webkit.org/show_bug.cgi?id=75006
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::setFixedVisibleContentRect):
+            On changes to fixedVisibleContentRect update scroll-animators position, and
+            recalculate page-step sizes in scrollbars.
+        * platform/ScrollView.cpp:
+        (WebCore::ScrollView::scrollTo):
+            Forward scrolling-request to the host window.
+        (WebCore::ScrollView::updateScrollbars):
+            Allow ScrollViews to have invisible scrollbars when scrolling is delegated.
+        * platform/ScrollView.h:
+        (ScrollView):
+
 2012-05-15  Vsevolod Vlasov  <vsevik@chromium.org>
 
         Web Inspector: Refactor SnippetsModel: extract SnippetStorage, make SnippetScriptMapping delegate calls to ScriptSnippetModel and provide public interface on ScriptSnippetModel in terms of uiSourceCodes
index b8517bc..4cba9c6 100644 (file)
@@ -1722,11 +1722,13 @@ void FrameView::delegatesScrollingDidChange()
 
 void FrameView::setFixedVisibleContentRect(const IntRect& visibleContentRect)
 {
+    bool visibleContentSizeDidChange = false;
     if (visibleContentRect.size() != this->fixedVisibleContentRect().size()) {
         // When the viewport size changes or the content is scaled, we need to
         // reposition the fixed positioned elements.
         if (RenderView* root = rootRenderer(this))
             root->setFixedPositionedObjectsNeedLayout();
+        visibleContentSizeDidChange = true;
     }
 
     IntSize offset = scrollOffset();
@@ -1734,8 +1736,13 @@ void FrameView::setFixedVisibleContentRect(const IntRect& visibleContentRect)
     if (offset != scrollOffset()) {
         if (m_frame->page()->settings()->acceleratedCompositingForFixedPositionEnabled())
             updateFixedElementsAfterScrolling();
+        scrollAnimator()->setCurrentPosition(scrollPosition());
         scrollPositionChanged();
     }
+    if (visibleContentSizeDidChange) {
+        // Update the scroll-bars to calculate new page-step size.
+        updateScrollbars(scrollOffset());
+    }
     frame()->loader()->client()->didChangeScrollOffset();
 }
 
index b982d4d..a8fe5ab 100644 (file)
@@ -371,6 +371,12 @@ void ScrollView::scrollTo(const IntSize& newOffset)
         return;
 
     repaintFixedElementsAfterScrolling();
+#if USE(TILED_BACKING_STORE)
+    if (delegatesScrolling()) {
+        hostWindow()->delegatedScrollRequested(IntPoint(newOffset));
+        return;
+    }
+#endif
     scrollContents(scrollDelta);
     updateFixedElementsAfterScrolling();
 }
@@ -453,7 +459,7 @@ static const unsigned cMaxUpdateScrollbarsPass = 2;
 
 void ScrollView::updateScrollbars(const IntSize& desiredOffset)
 {
-    if (m_inUpdateScrollbars || prohibitsScrolling() || delegatesScrolling() || platformWidget())
+    if (m_inUpdateScrollbars || prohibitsScrolling() || platformWidget())
         return;
 
     // If we came in here with the view already needing a layout, then go ahead and do that
index ec03125..07ffb3f 100644 (file)
@@ -313,6 +313,9 @@ protected:
     virtual bool isVerticalDocument() const { return true; }
     virtual bool isFlippedDocument() const { return false; }
 
+    // Called to update the scrollbars to accurately reflect the state of the view.
+    void updateScrollbars(const IntSize& desiredOffset);
+
 private:
     RefPtr<Scrollbar> m_horizontalScrollbar;
     RefPtr<Scrollbar> m_verticalScrollbar;
@@ -355,8 +358,6 @@ private:
     void init();
     void destroy();
 
-    // Called to update the scrollbars to accurately reflect the state of the view.
-    void updateScrollbars(const IntSize& desiredOffset);
     IntRect rectToCopyOnScroll() const;
 
     // Called when the scroll position within this view changes.  FrameView overrides this to generate repaint invalidations.
index 2094976..3230964 100644 (file)
@@ -1,3 +1,21 @@
+2012-05-15  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
+
+        [Qt][WK2] Fix scrolling in touch mode
+        https://bugs.webkit.org/show_bug.cgi?id=75006
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Only handle mouse-wheel events in WebCore to avoid double scrolling, and
+        scale pixels scrolled by wheel events according to viewport transformation.
+
+        * Shared/qt/WebEventFactoryQt.cpp:
+        (WebKit::WebEventFactory::createWebWheelEvent):
+        * UIProcess/qt/QtViewportInteractionEngine.cpp:
+        * UIProcess/qt/QtViewportInteractionEngine.h:
+        (QtViewportInteractionEngine):
+        * UIProcess/qt/QtWebPageEventHandler.cpp:
+        (QtWebPageEventHandler::handleWheelEvent):
+
 2012-05-15  Kenneth Rohde Christiansen  <kenneth@webkit.org>
 
         [Qt] Add infra for testing double-tap to zoom functionality etc
index 3091d64..45fc34a 100644 (file)
 #include "config.h"
 #include "WebEventFactoryQt.h"
 #include <QKeyEvent>
+#include <QLineF>
 #include <QTransform>
-#include <WebCore/IntPoint.h>
 #include <WebCore/FloatPoint.h>
+#include <WebCore/FloatSize.h>
+#include <WebCore/IntPoint.h>
 #include <WebCore/PlatformKeyboardEvent.h>
 #include <wtf/ASCIICType.h>
 #include <wtf/CurrentTime.h>
@@ -149,7 +151,13 @@ WebWheelEvent WebEventFactory::createWebWheelEvent(QWheelEvent* e, const QTransf
     deltaX = wheelTicksX * wheelScrollLines * cDefaultQtScrollStep;
     deltaY = wheelTicksY * wheelScrollLines * cDefaultQtScrollStep;
 
-    return WebWheelEvent(WebEvent::Wheel, fromItemTransform.map(e->posF()).toPoint(), e->globalPosF().toPoint(), FloatSize(deltaX, deltaY), FloatSize(wheelTicksX, wheelTicksY), granularity, modifiers, timestamp);
+    // Transform the position and the pixel scrolling distance.
+    QLineF transformedScroll = fromItemTransform.map(QLineF(e->posF(), e->posF() + QPointF(deltaX, deltaY)));
+    IntPoint transformedPoint = transformedScroll.p1().toPoint();
+    IntPoint globalPoint = e->globalPosF().toPoint();
+    FloatSize transformedDelta(transformedScroll.dx(), transformedScroll.dy());
+    FloatSize wheelTicks(wheelTicksX, wheelTicksY);
+    return WebWheelEvent(WebEvent::Wheel, transformedPoint, globalPoint, transformedDelta, wheelTicks, granularity, modifiers, timestamp);
 }
 
 WebKeyboardEvent WebEventFactory::createWebKeyboardEvent(QKeyEvent* event)
index b8c85ef..eb3c5a8 100644 (file)
@@ -261,36 +261,6 @@ static inline QPointF boundPosition(const QPointF minPosition, const QPointF& po
                    qBound(minPosition.y(), position.y(), maxPosition.y()));
 }
 
-void QtViewportInteractionEngine::wheelEvent(QWheelEvent* ev)
-{
-    if (scrollAnimationActive() || scaleAnimationActive() || pinchGestureActive())
-        return; // Ignore.
-
-
-    // A normal scroll-tick should have a delta of 120 (1/8) degrees. Convert this to
-    // local standard scroll step of 3 lines of 20 pixels.
-    static const int cDefaultQtScrollStep = 20;
-    static const int wheelScrollLines = 3;
-    const int wheelTick = wheelScrollLines * cDefaultQtScrollStep;
-
-    int pixelDelta = ev->delta() * (wheelTick / 120.f);
-
-    QPointF newPosition = m_viewport->contentPos();
-
-    if (ev->orientation() == Qt::Horizontal)
-        newPosition.rx() -= pixelDelta;
-    else
-        newPosition.ry() -= pixelDelta;
-
-    QRectF endPosRange = computePosRangeForItemAtScale(m_content->contentsScale());
-
-    QPointF currentPosition = m_viewport->contentPos();
-    newPosition = boundPosition(endPosRange.topLeft(), newPosition, endPosRange.bottomRight());
-    m_viewport->setContentPos(newPosition);
-
-    emit contentViewportChanged(currentPosition - newPosition);
-}
-
 void QtViewportInteractionEngine::pagePositionRequest(const QPoint& pagePosition)
 {
     // Ignore the request if suspended. Can only happen due to delay in event delivery.
index 876ab69..accfc6a 100644 (file)
@@ -65,7 +65,6 @@ public:
     void setItemRectVisible(const QRectF&);
     bool animateItemRectVisible(const QRectF&);
 
-    void wheelEvent(QWheelEvent*);
     void pagePositionRequest(const QPoint& pos);
     void touchBegin();
     void touchEnd();
index bbfab1a..c1ebaac 100644 (file)
@@ -154,9 +154,6 @@ void QtWebPageEventHandler::handleWheelEvent(QWheelEvent* ev)
 {
     QTransform fromItemTransform = m_webPage->transformFromItem();
     m_webPageProxy->handleWheelEvent(NativeWebWheelEvent(ev, fromItemTransform));
-    // FIXME: Handle whether the page used the wheel event or not.
-    if (m_interactionEngine)
-        m_interactionEngine->wheelEvent(ev);
 }
 
 void QtWebPageEventHandler::handleHoverLeaveEvent(QHoverEvent* ev)