Divide gesture scroll delta by scale factor
authoraelias@chromium.org <aelias@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Jan 2013 01:39:04 +0000 (01:39 +0000)
committeraelias@chromium.org <aelias@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Jan 2013 01:39:04 +0000 (01:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=106263

Reviewed by Adam Barth.

Gesture scroll deltas were not being adjusted by the frame's scale
factors, resulting in overly fast main-thread scrolling when zoomed
in.

New test: fast/events/touch/gesture/touch-gesture-scroll-div-scaled.html

* page/EventHandler.cpp:
(WebCore::EventHandler::handleGestureScrollCore):

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

LayoutTests/fast/events/touch/gesture/touch-gesture-scroll-div-scaled-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/touch/gesture/touch-gesture-scroll-div-scaled.html [new file with mode: 0644]
LayoutTests/platform/chromium/fast/events/touch/gesture/touch-gesture-scroll-div-scaled-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/EventHandler.cpp

diff --git a/LayoutTests/fast/events/touch/gesture/touch-gesture-scroll-div-scaled-expected.txt b/LayoutTests/fast/events/touch/gesture/touch-gesture-scroll-div-scaled-expected.txt
new file mode 100644 (file)
index 0000000..734d7cd
--- /dev/null
@@ -0,0 +1,10 @@
+This tests gesture event scrolling of an overflow div with page scale.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+gesture events not implemented on this platform or gesture event scrolling of a document is broken
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/events/touch/gesture/touch-gesture-scroll-div-scaled.html b/LayoutTests/fast/events/touch/gesture/touch-gesture-scroll-div-scaled.html
new file mode 100644 (file)
index 0000000..fdb41d3
--- /dev/null
@@ -0,0 +1,131 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../../js/resources/js-test-pre.js"></script>
+<script src="resources/gesture-helpers.js"></script>
+<style type="text/css">
+#touchtarget {
+  width: 100px;
+  height: 100px;
+  position: relative;
+  background: white;
+}
+
+::-webkit-scrollbar {
+    width: 0px;
+    height: 0px;
+}
+
+#movingbox {
+  width: 100%;
+  height: 100%;
+  position: absolute;
+  word-wrap: break-word;
+  overflow-y: scroll;
+  overflow-x: scroll;
+  display: block;
+}
+
+#greenbox {
+  width: 100px;
+  height: 100px;
+  background: green;
+  padding: 0px;
+  margin: 0px;
+}
+
+#redbox {
+  width: 100px;
+  height: 100px;
+  background: red;
+  padding: 0px;
+  margin: 0px;
+}
+
+td {
+  padding: 0px;
+}
+</style>
+</head>
+<body style="margin:0" onload="runTest();">
+<div id="touchtarget">
+  <div id="movingbox">
+    <table border="0" cellspacing="0px" id="tablefoo">
+      <tr>
+        <td><div id="redbox"></div></td>
+        <td><div id="greenbox"></div></td>
+      </tr>
+      <tr>
+        <td><div id="greenbox"></div></td>
+        <td><div id="greenbox"></div></td>
+      </tr>
+    </table>
+  </div>
+</div>
+
+<p id="description"></p>
+<div id="console"></div>
+<script type="text/javascript">
+
+var movingdiv;
+var expectedGesturesTotal = 2;
+var gesturesOccurred = 0;
+var scrollAmountX = ['45', '45'];
+var scrollAmountY = ['0', '48'];
+var wheelEventsOccurred = 0;
+var expectedWheelEventsOccurred = ['1', '1'];
+var scrollEventsOccurred = 0;
+var expectedScrollEventsOccurred = '1';
+var scrolledElement = 'movingdiv'
+
+function firstGestureScroll()
+{
+    debug("first gesture");
+    eventSender.gestureScrollBegin(95, 12);
+    eventSender.gestureScrollUpdate(-90, 0);
+    eventSender.gestureScrollEnd(0, 0);
+
+    // Wait for layout.
+    checkScrollOffset();
+}
+
+ function secondGestureScroll()
+ {
+     debug("second gesture");
+     eventSender.gestureScrollBegin(12, 97);
+     eventSender.gestureScrollUpdate(0, -95);
+     eventSender.gestureScrollEnd(0, 0);
+
+     // Wait for layout.
+     checkScrollOffset();
+ }
+
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+function runTest()
+{
+    var scaleFactor = 2.0;
+    var scaleOffset = 0;
+    if (window.internals) {
+       window.internals.setPageScaleFactor(scaleFactor, scaleOffset, scaleOffset);
+    }
+
+    movingdiv = document.getElementById('movingbox');
+    movingdiv.addEventListener("scroll", recordScroll);
+    window.addEventListener("mousewheel", recordWheel);
+
+    if (window.eventSender) {
+        description('This tests gesture event scrolling of an overflow div with page scale.');
+
+        if (checkTestDependencies())
+            firstGestureScroll();
+        else
+            exitIfNecessary();
+    } else {
+        debug("This test requires DumpRenderTree.  Touch scroll the red rect to log.");
+    }
+}
+</script>
+</body>
+</html>
diff --git a/LayoutTests/platform/chromium/fast/events/touch/gesture/touch-gesture-scroll-div-scaled-expected.txt b/LayoutTests/platform/chromium/fast/events/touch/gesture/touch-gesture-scroll-div-scaled-expected.txt
new file mode 100644 (file)
index 0000000..d2f64f3
--- /dev/null
@@ -0,0 +1,21 @@
+This tests gesture event scrolling of an overflow div with page scale.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+first gesture
+wheel event 0+> [object HTMLDivElement]
+PASS movingdiv.scrollTop is 0
+PASS movingdiv.scrollLeft is 45
+PASS wheelEventsOccurred is 1
+second gesture
+wheel event 0+> [object HTMLDivElement]
+PASS movingdiv.scrollTop is 48
+PASS movingdiv.scrollLeft is 45
+PASS wheelEventsOccurred is 1
+scroll event 0+> [object HTMLDivElement]
+PASS scrollEventsOccurred is 1
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
index 93fe271..2ea1cc3 100644 (file)
@@ -1,3 +1,19 @@
+2013-01-07  Alexandre Elias  <aelias@chromium.org>
+
+        Divide gesture scroll delta by scale factor
+        https://bugs.webkit.org/show_bug.cgi?id=106263
+
+        Reviewed by Adam Barth.
+
+        Gesture scroll deltas were not being adjusted by the frame's scale
+        factors, resulting in overly fast main-thread scrolling when zoomed
+        in.
+
+        New test: fast/events/touch/gesture/touch-gesture-scroll-div-scaled.html
+
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::handleGestureScrollCore):
+
 2013-01-07  Adam Barth  <abarth@webkit.org>
 
         HTMLTreeBuilder should not depend on Frame
index b2c07bc..4c3b1f3 100644 (file)
@@ -2599,10 +2599,13 @@ bool EventHandler::isScrollbarHandlingGestures() const
 bool EventHandler::handleGestureScrollCore(const PlatformGestureEvent& gestureEvent, PlatformWheelEventGranularity granularity, bool latchedWheel)
 {
     const float tickDivisor = (float)WheelEvent::tickMultiplier;
+    const float scaleFactor = m_frame->pageZoomFactor() * m_frame->frameScaleFactor();
+    float scaledDeltaX = gestureEvent.deltaX() / scaleFactor;
+    float scaledDeltaY = gestureEvent.deltaY() / scaleFactor;
     IntPoint point(gestureEvent.position().x(), gestureEvent.position().y());
     IntPoint globalPoint(gestureEvent.globalPosition().x(), gestureEvent.globalPosition().y());
     PlatformWheelEvent syntheticWheelEvent(point, globalPoint,
-        gestureEvent.deltaX(), gestureEvent.deltaY(), gestureEvent.deltaX() / tickDivisor, gestureEvent.deltaY() / tickDivisor,
+        scaledDeltaX, scaledDeltaY, scaledDeltaX / tickDivisor, scaledDeltaY / tickDivisor,
         granularity,
         gestureEvent.shiftKey(), gestureEvent.ctrlKey(), gestureEvent.altKey(), gestureEvent.metaKey());
     syntheticWheelEvent.setUseLatchedEventNode(latchedWheel);