<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[186160] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/186160">186160</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-06-30 18:51:16 -0700 (Tue, 30 Jun 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>scroll-snap-points do not work very well with mechanical scroll wheel events
https://bugs.webkit.org/show_bug.cgi?id=142501
&lt;rdar://problem/20093511&gt;

Patch by Wenson Hsieh &lt;whsieh@berkeley.edu&gt; on 2015-06-30
Reviewed by Brent Fulgham.

Source/WebCore:

Stateless scroll events generated by scrolling with a mechanical mouse wheel now trigger scroll
snapping after a fixed delay.

Test: platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html

* platform/cocoa/ScrollController.h: Added member to track stateless scrolling.
* platform/cocoa/ScrollController.mm: Added constant for delay for stateless scroll snapping.
(WebCore::ScrollController::processWheelEventForScrollSnapOnAxis): Triggers timer upon stateless scroll events.
(WebCore::ScrollController::horizontalScrollSnapTimerFired): Timer now handles stateless scrolling updates.
(WebCore::ScrollController::verticalScrollSnapTimerFired): See above.
(WebCore::ScrollController::beginScrollSnapAnimation): Handles stateless scroll snapping.

LayoutTests:

* platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless-expected.txt: Added.
* platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformcocoaScrollControllerh">trunk/Source/WebCore/platform/cocoa/ScrollController.h</a></li>
<li><a href="#trunkSourceWebCoreplatformcocoaScrollControllermm">trunk/Source/WebCore/platform/cocoa/ScrollController.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsplatformmacwk2tileddrawingscrollingscrollsnapscrollsnapmandatoryoverflowstatelessexpectedtxt">trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless-expected.txt</a></li>
<li><a href="#trunkLayoutTestsplatformmacwk2tileddrawingscrollingscrollsnapscrollsnapmandatoryoverflowstatelesshtml">trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (186159 => 186160)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-07-01 01:46:52 UTC (rev 186159)
+++ trunk/LayoutTests/ChangeLog        2015-07-01 01:51:16 UTC (rev 186160)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2015-06-30  Wenson Hsieh  &lt;whsieh@berkeley.edu&gt;
+
+        scroll-snap-points do not work very well with mechanical scroll wheel events
+        https://bugs.webkit.org/show_bug.cgi?id=142501
+        &lt;rdar://problem/20093511&gt;
+
+        Reviewed by Brent Fulgham.
+
+        * platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless-expected.txt: Added.
+        * platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html: Added.
+
</ins><span class="cx"> 2015-06-30  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rebaseline editing/style/unbold-in-bold.html on WK2.
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk2tileddrawingscrollingscrollsnapscrollsnapmandatoryoverflowstatelessexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless-expected.txt (0 => 186160)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless-expected.txt                                (rev 0)
+++ trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless-expected.txt        2015-07-01 01:51:16 UTC (rev 186160)
</span><span class="lines">@@ -0,0 +1,9 @@
</span><ins>+Tests that the scroll-snap feature works properly in overflow regions when using a mechanical mouse wheel.
+ PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS div honored snap points.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk2tileddrawingscrollingscrollsnapscrollsnapmandatoryoverflowstatelesshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html (0 => 186160)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html                                (rev 0)
+++ trunk/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html        2015-07-01 01:51:16 UTC (rev 186160)
</span><span class="lines">@@ -0,0 +1,107 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+    &lt;head&gt;
+        &lt;style&gt;
+            .gallery {
+                width: 400px;
+                height: 400px;
+                display: inline-block;
+                overflow-x: hidden;
+                overflow-y: auto;
+                -webkit-scroll-snap-points-y: repeat(400px);
+                -webkit-scroll-snap-type: mandatory;
+            }
+            .colorBox {
+                height: 400px;
+                width: 400px;
+            }
+            #item0, #item2 { background-color: red; }
+            #item1 { background-color: green; }
+        &lt;/style&gt;
+        &lt;script src=&quot;../../../../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+        &lt;script&gt;
+        function finishTest()
+        {
+            finishJSTest();
+            testRunner.notifyDone();
+        }
+
+        function locationInWindowCoordinates(element)
+        {
+            var position = {};
+            position.x = element.offsetLeft;
+            position.y = element.offsetTop;
+
+            while (element.offsetParent) {
+                position.x = position.x + element.offsetParent.offsetLeft;
+                position.y = position.y + element.offsetParent.offsetTop;
+                if (element == document.getElementsByTagName(&quot;body&quot;)[0])
+                    break;
+
+                element = element.offsetParent;
+            }
+
+            return position;
+        }
+
+        function scrollSnapTest()
+        {
+            var divTarget = document.getElementById(&quot;target&quot;);
+            var windowPosition = locationInWindowCoordinates(divTarget);
+
+            var startPosX = windowPosition.x + 0.5 * divTarget.clientWidth;
+            var startPosY = windowPosition.y + 0.5 * divTarget.clientHeight;
+            eventSender.mouseMoveTo(startPosX, startPosY);
+            // Each unit of stateless scroll is scaled by 10 pixels.
+            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -10, &quot;none&quot;, &quot;none&quot;, false);
+            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -10, &quot;none&quot;, &quot;none&quot;, false);
+            eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -10, &quot;none&quot;, &quot;none&quot;, false);
+            // Wait for the snapping to finish.
+            setTimeout(function() {
+                if (divTarget.scrollTop != 400)
+                    testFailed(&quot;div did not snap to the green region. Expected 400, but got &quot; + divTarget.scrollTop + &quot;.&quot;);
+                else
+                    testPassed(&quot;div honored snap points.&quot;);
+
+                finishTest();
+            }, 2000);
+        }
+
+
+        function onLoad()
+        {
+            if (window.eventSender) {
+                window.jsTestIsAsync = true;
+                testRunner.dumpAsText();
+                testRunner.waitUntilDone();
+
+                eventSender.monitorWheelEvents();
+                setTimeout(scrollSnapTest, 0);
+            } else {
+                var messageLocationH = document.getElementById(&quot;item0&quot;);
+                var message = document.createElement(&quot;div&quot;);
+                message.innerHTML = &quot;This test is better run under DumpRenderTree. To manually&lt;br/&gt;&quot;
+                    + &quot;test it, place the mouse pointer inside the red region at the&lt;br/&gt;&quot;
+                    + &quot;top of the page, and then, using a mechanical mouse wheel,&lt;br/&gt;&quot;
+                    + &quot;scroll so that the green region takes up more of the&lt;br/&gt;&quot;
+                    + &quot;container than the surrounding red regions. After a brief&lt;br/&gt;&quot;
+                    + &quot;pause, the target should scroll so that the green region is&lt;br/&gt;&quot;
+                    + &quot;fully visible, and no red is visible.&quot;;
+                messageLocationH.appendChild(message);
+            }
+        }
+        &lt;/script&gt;
+    &lt;/head&gt;
+    &lt;body onload=&quot;onLoad();&quot;&gt;
+        &lt;div style=&quot;position: relative; width: 400px&quot;&gt;
+            &lt;div&gt;Tests that the scroll-snap feature works properly in overflow regions when using a mechanical mouse wheel.&lt;/div&gt;
+            &lt;div class=&quot;gallery&quot; id=&quot;target&quot;&gt;
+                &lt;div id=&quot;item0&quot; class=&quot;colorBox&quot;&gt;&lt;/div&gt;
+                &lt;div id=&quot;item1&quot; class=&quot;colorBox&quot;&gt;&lt;/div&gt;
+                &lt;div id=&quot;item2&quot; class=&quot;colorBox&quot;&gt;&lt;/div&gt;
+            &lt;/div&gt;
+            &lt;div id=&quot;console&quot;&gt;&lt;/div&gt;
+        &lt;/div&gt;
+        &lt;script src=&quot;../../../../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+    &lt;/body&gt;
+&lt;/html&gt;
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (186159 => 186160)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-07-01 01:46:52 UTC (rev 186159)
+++ trunk/Source/WebCore/ChangeLog        2015-07-01 01:51:16 UTC (rev 186160)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2015-06-30  Wenson Hsieh  &lt;whsieh@berkeley.edu&gt;
+
+        scroll-snap-points do not work very well with mechanical scroll wheel events
+        https://bugs.webkit.org/show_bug.cgi?id=142501
+        &lt;rdar://problem/20093511&gt;
+
+        Reviewed by Brent Fulgham.
+
+        Stateless scroll events generated by scrolling with a mechanical mouse wheel now trigger scroll
+        snapping after a fixed delay.
+
+        Test: platform/mac-wk2/tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html
+
+        * platform/cocoa/ScrollController.h: Added member to track stateless scrolling.
+        * platform/cocoa/ScrollController.mm: Added constant for delay for stateless scroll snapping.
+        (WebCore::ScrollController::processWheelEventForScrollSnapOnAxis): Triggers timer upon stateless scroll events.
+        (WebCore::ScrollController::horizontalScrollSnapTimerFired): Timer now handles stateless scrolling updates.
+        (WebCore::ScrollController::verticalScrollSnapTimerFired): See above.
+        (WebCore::ScrollController::beginScrollSnapAnimation): Handles stateless scroll snapping.
+
</ins><span class="cx"> 2015-06-30  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Try to fix Gtk and EFL builds.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformcocoaScrollControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/cocoa/ScrollController.h (186159 => 186160)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cocoa/ScrollController.h        2015-07-01 01:46:52 UTC (rev 186159)
+++ trunk/Source/WebCore/platform/cocoa/ScrollController.h        2015-07-01 01:51:16 UTC (rev 186160)
</span><span class="lines">@@ -188,6 +188,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(CSS_SCROLL_SNAP)
</span><ins>+    bool m_expectingStatelessScrollSnap { false };
</ins><span class="cx">     std::unique_ptr&lt;ScrollSnapAnimatorState&gt; m_horizontalScrollSnapState;
</span><span class="cx">     std::unique_ptr&lt;ScrollSnapAnimatorState&gt; m_verticalScrollSnapState;
</span><span class="cx"> #if PLATFORM(MAC)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformcocoaScrollControllermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/cocoa/ScrollController.mm (186159 => 186160)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/cocoa/ScrollController.mm        2015-07-01 01:46:52 UTC (rev 186159)
+++ trunk/Source/WebCore/platform/cocoa/ScrollController.mm        2015-07-01 01:51:16 UTC (rev 186160)
</span><span class="lines">@@ -86,6 +86,8 @@
</span><span class="cx"> 
</span><span class="cx"> static const float maxTargetWheelDelta = 7;
</span><span class="cx"> static const float minTargetWheelDelta = 3.5;
</span><ins>+
+static const double statelessScrollSnapDelay = 0.5;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="lines">@@ -583,6 +585,11 @@
</span><span class="cx">         endScrollSnapAnimation(axis, ScrollSnapState::UserInteraction);
</span><span class="cx">         snapState.clearInitialWheelDeltaWindow();
</span><span class="cx">         snapState.m_shouldOverrideWheelEvent = false;
</span><ins>+        m_expectingStatelessScrollSnap = true;
+        if (axis == ScrollEventAxis::Vertical)
+            m_verticalScrollSnapTimer.startOneShot(statelessScrollSnapDelay);
+        else
+            m_horizontalScrollSnapTimer.startOneShot(statelessScrollSnapDelay);
</ins><span class="cx">         break;
</span><span class="cx"> 
</span><span class="cx">     case WheelEventStatus::Unknown:
</span><span class="lines">@@ -668,12 +675,18 @@
</span><span class="cx"> 
</span><span class="cx"> void ScrollController::horizontalScrollSnapTimerFired()
</span><span class="cx"> {
</span><del>-    scrollSnapAnimationUpdate(ScrollEventAxis::Horizontal);
</del><ins>+    if (m_expectingStatelessScrollSnap)
+        beginScrollSnapAnimation(ScrollEventAxis::Horizontal, ScrollSnapState::Snapping);
+    else
+        scrollSnapAnimationUpdate(ScrollEventAxis::Horizontal);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ScrollController::verticalScrollSnapTimerFired()
</span><span class="cx"> {
</span><del>-    scrollSnapAnimationUpdate(ScrollEventAxis::Vertical);
</del><ins>+    if (m_expectingStatelessScrollSnap)
+        beginScrollSnapAnimation(ScrollEventAxis::Vertical, ScrollSnapState::Snapping);
+    else
+        scrollSnapAnimationUpdate(ScrollEventAxis::Vertical);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ScrollController::scrollSnapAnimationUpdate(ScrollEventAxis axis)
</span><span class="lines">@@ -768,7 +781,10 @@
</span><span class="cx"> void ScrollController::beginScrollSnapAnimation(ScrollEventAxis axis, ScrollSnapState newState)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(newState == ScrollSnapState::Gliding || newState == ScrollSnapState::Snapping);
</span><del>-    
</del><ins>+    if (m_expectingStatelessScrollSnap) {
+        m_expectingStatelessScrollSnap = false;
+        stopScrollSnapTimer(axis);
+    }
</ins><span class="cx">     ScrollSnapAnimatorState&amp; snapState = scrollSnapPointState(axis);
</span><span class="cx"> 
</span><span class="cx">     LayoutUnit offset = m_client.scrollOffsetOnAxis(axis);
</span></span></pre>
</div>
</div>

</body>
</html>