<!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>[266306] branches/safari-610.1.28.1-branch</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/266306">266306</a></dd>
<dt>Author</dt> <dd>alancoon@apple.com</dd>
<dt>Date</dt> <dd>2020-08-28 15:58:04 -0700 (Fri, 28 Aug 2020)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/266262">r266262</a>. rdar://problem/67963578

    Scrolling on select element doesn't work after scrolling the page
    https://bugs.webkit.org/show_bug.cgi?id=215900
    Source/WebCore:

    <rdar://problem/67766032>

    Reviewed by Tim Horton.

    The scrolling thread could use a node that was latched some time ago; we need to
    check the freshness of the latched node before using it.

    Test: fast/scrolling/latching/latching-stuck-to-main-page.html

    * page/scrolling/ScrollingTreeLatchingController.cpp:
    (WebCore::ScrollingTreeLatchingController::receivedWheelEvent):
    (WebCore::ScrollingTreeLatchingController::latchedNodeForEvent const):
    (WebCore::ScrollingTreeLatchingController::latchedNodeIsRelevant const):
    * page/scrolling/ScrollingTreeLatchingController.h:

    LayoutTests:

    Reviewed by Tim Horton.

    * fast/scrolling/latching/latching-stuck-to-main-page-expected.txt: Added.
    * fast/scrolling/latching/latching-stuck-to-main-page.html: Added.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266262 268f45cc-cd09-0410-ab3c-d52691b4dbfc</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari6101281branchLayoutTestsChangeLog">branches/safari-610.1.28.1-branch/LayoutTests/ChangeLog</a></li>
<li><a href="#branchessafari6101281branchSourceWebCoreChangeLog">branches/safari-610.1.28.1-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari6101281branchSourceWebCorepagescrollingScrollingTreeLatchingControllercpp">branches/safari-610.1.28.1-branch/Source/WebCore/page/scrolling/ScrollingTreeLatchingController.cpp</a></li>
<li><a href="#branchessafari6101281branchSourceWebCorepagescrollingScrollingTreeLatchingControllerh">branches/safari-610.1.28.1-branch/Source/WebCore/page/scrolling/ScrollingTreeLatchingController.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari6101281branchLayoutTestsfastscrollinglatchinglatchingstucktomainpageexpectedtxt">branches/safari-610.1.28.1-branch/LayoutTests/fast/scrolling/latching/latching-stuck-to-main-page-expected.txt</a></li>
<li><a href="#branchessafari6101281branchLayoutTestsfastscrollinglatchinglatchingstucktomainpagehtml">branches/safari-610.1.28.1-branch/LayoutTests/fast/scrolling/latching/latching-stuck-to-main-page.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari6101281branchLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-610.1.28.1-branch/LayoutTests/ChangeLog (266305 => 266306)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-610.1.28.1-branch/LayoutTests/ChangeLog  2020-08-28 22:58:01 UTC (rev 266305)
+++ branches/safari-610.1.28.1-branch/LayoutTests/ChangeLog     2020-08-28 22:58:04 UTC (rev 266306)
</span><span class="lines">@@ -1,5 +1,48 @@
</span><span class="cx"> 2020-08-28  Russell Epstein  <repstein@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r266262. rdar://problem/67963578
+
+    Scrolling on select element doesn't work after scrolling the page
+    https://bugs.webkit.org/show_bug.cgi?id=215900
+    Source/WebCore:
+    
+    <rdar://problem/67766032>
+    
+    Reviewed by Tim Horton.
+    
+    The scrolling thread could use a node that was latched some time ago; we need to
+    check the freshness of the latched node before using it.
+    
+    Test: fast/scrolling/latching/latching-stuck-to-main-page.html
+    
+    * page/scrolling/ScrollingTreeLatchingController.cpp:
+    (WebCore::ScrollingTreeLatchingController::receivedWheelEvent):
+    (WebCore::ScrollingTreeLatchingController::latchedNodeForEvent const):
+    (WebCore::ScrollingTreeLatchingController::latchedNodeIsRelevant const):
+    * page/scrolling/ScrollingTreeLatchingController.h:
+    
+    LayoutTests:
+    
+    Reviewed by Tim Horton.
+    
+    * fast/scrolling/latching/latching-stuck-to-main-page-expected.txt: Added.
+    * fast/scrolling/latching/latching-stuck-to-main-page.html: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266262 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-08-27  Simon Fraser  <simon.fraser@apple.com>
+
+            Scrolling on select element doesn't work after scrolling the page
+            https://bugs.webkit.org/show_bug.cgi?id=215900
+
+            Reviewed by Tim Horton.
+
+            * fast/scrolling/latching/latching-stuck-to-main-page-expected.txt: Added.
+            * fast/scrolling/latching/latching-stuck-to-main-page.html: Added.
+
+2020-08-28  Russell Epstein  <repstein@apple.com>
+
</ins><span class="cx">         Cherry-pick r266248. rdar://problem/67963534
</span><span class="cx"> 
</span><span class="cx">     Occasional crashes when restoring replaced text under Editor::changeBackToReplacedString
</span></span></pre></div>
<a id="branchessafari6101281branchLayoutTestsfastscrollinglatchinglatchingstucktomainpageexpectedtxt"></a>
<div class="addfile"><h4>Added: branches/safari-610.1.28.1-branch/LayoutTests/fast/scrolling/latching/latching-stuck-to-main-page-expected.txt (0 => 266306)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-610.1.28.1-branch/LayoutTests/fast/scrolling/latching/latching-stuck-to-main-page-expected.txt                           (rev 0)
+++ branches/safari-610.1.28.1-branch/LayoutTests/fast/scrolling/latching/latching-stuck-to-main-page-expected.txt      2020-08-28 22:58:04 UTC (rev 266306)
</span><span class="lines">@@ -0,0 +1,21 @@
</span><ins>+
+Tests that scrolling doesn't get wrongly latched to the main page.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Checking wheel event over the select
+PASS selectScrollCount > 0 is true
+PASS pageScrollCount == 0 is true
+Triggering main page latch; scrolling down
+Triggering main page latch; scrolling up
+PASS selectScrollCount == 0 is true
+PASS pageScrollCount > 0 is true
+PASS document.scrollingElement.scrollTop == 0 is true
+Checking wheel event over the select again
+PASS selectScrollCount > 0 is true
+PASS pageScrollCount == 0 is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="branchessafari6101281branchLayoutTestsfastscrollinglatchinglatchingstucktomainpagehtml"></a>
<div class="addfile"><h4>Added: branches/safari-610.1.28.1-branch/LayoutTests/fast/scrolling/latching/latching-stuck-to-main-page.html (0 => 266306)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-610.1.28.1-branch/LayoutTests/fast/scrolling/latching/latching-stuck-to-main-page.html                           (rev 0)
+++ branches/safari-610.1.28.1-branch/LayoutTests/fast/scrolling/latching/latching-stuck-to-main-page.html      2020-08-28 22:58:04 UTC (rev 266306)
</span><span class="lines">@@ -0,0 +1,111 @@
</span><ins>+<!DOCTYPE html> <!-- webkit-test-runner [ internal:AsyncOverflowScrollingEnabled=true ] -->
+<html>
+<head>
+<style>
+    body {
+        height: 2000px;
+    }
+    select {
+        margin-top: 100px;
+        font-size: 12pt;
+    }
+</style>
+<script src="../../../resources/js-test-pre.js"></script>
+<script src="../../../resources/ui-helper.js"></script>
+<script>
+    jsTestIsAsync = true;
+
+    let selectScrollCount = 0;
+    let pageScrollCount = 0; 
+
+    async function scrollTest()
+    {
+        let select = document.getElementsByTagName('select')[0];
+        select.addEventListener('scroll', () => {
+            ++selectScrollCount;
+        });
+        
+        window.addEventListener('scroll', () => {
+            ++pageScrollCount;
+        });
+
+        debug('Checking wheel event over the select');
+        await UIHelper.mouseWheelScrollAt(50, 200);
+        
+        shouldBeTrue('selectScrollCount > 0');
+        shouldBeTrue('pageScrollCount == 0');
+        
+        selectScrollCount = 0;
+
+        debug('Triggering main page latch; scrolling down');
+        await UIHelper.mouseWheelScrollAt(400, 200);
+
+        await UIHelper.animationFrame();
+
+        debug('Triggering main page latch; scrolling up');
+
+        eventSender.mouseMoveTo(400, 200);
+        eventSender.monitorWheelEvents({ resetLatching: false });
+        eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 2, 'began', 'none');
+        eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 11, 'changed', 'none');
+        eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, 'ended', 'none');
+        await UIHelper.waitForScrollCompletion();
+
+        shouldBeTrue('selectScrollCount == 0');
+        shouldBeTrue('pageScrollCount > 0');
+
+        shouldBeTrue('document.scrollingElement.scrollTop == 0');
+        
+        // Stupid hack to reset the select back to the top (webkit.org/b/215898).
+        pageScrollCount = 0;
+        select.style.display = 'none';
+        document.body.offsetWidth;
+        select.style.display = 'inline';
+
+        // Delay for longer than resetLatchedStateTimeout.
+        await UIHelper.delayFor(150);
+
+        debug('Checking wheel event over the select again');
+        eventSender.mouseMoveTo(50, 200);
+        eventSender.monitorWheelEvents({ resetLatching: false });
+        eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -1, 'began', 'none');
+        eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -5, 'changed', 'none');
+        eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, 'ended', 'none');
+        await UIHelper.waitForScrollCompletion();
+
+        shouldBeTrue('selectScrollCount > 0');
+        shouldBeTrue('pageScrollCount == 0');
+
+        finishJSTest();
+    }
+
+    window.addEventListener('load', () => {
+        description("Tests that scrolling doesn't get wrongly latched to the main page.");
+        setTimeout(scrollTest, 0);
+    }, false);
+</script>
+</head>
+<body>
+    <select size="10">
+        <option>first first first</option>
+        <option>two two two two</option>
+        <option>one one one one</option>
+        <option>two two two two</option>
+        <option>one one one one</option>
+        <option>two two two two</option>
+        <option>one one one one</option>
+        <option>two two two two</option>        
+        <option>one one one one</option>
+        <option>two two two two</option>
+        <option>one one one one</option>
+        <option>two two two two</option>
+        <option>one one one one</option>
+        <option>two two two two</option>
+        <option>one one one one</option>
+        <option>two two two two</option>        
+        <option>last last last</option>        
+    </select>
+    <div id="console"></div>
+<script src="../../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="branchessafari6101281branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-610.1.28.1-branch/Source/WebCore/ChangeLog (266305 => 266306)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-610.1.28.1-branch/Source/WebCore/ChangeLog       2020-08-28 22:58:01 UTC (rev 266305)
+++ branches/safari-610.1.28.1-branch/Source/WebCore/ChangeLog  2020-08-28 22:58:04 UTC (rev 266306)
</span><span class="lines">@@ -1,5 +1,57 @@
</span><span class="cx"> 2020-08-28  Russell Epstein  <repstein@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r266262. rdar://problem/67963578
+
+    Scrolling on select element doesn't work after scrolling the page
+    https://bugs.webkit.org/show_bug.cgi?id=215900
+    Source/WebCore:
+    
+    <rdar://problem/67766032>
+    
+    Reviewed by Tim Horton.
+    
+    The scrolling thread could use a node that was latched some time ago; we need to
+    check the freshness of the latched node before using it.
+    
+    Test: fast/scrolling/latching/latching-stuck-to-main-page.html
+    
+    * page/scrolling/ScrollingTreeLatchingController.cpp:
+    (WebCore::ScrollingTreeLatchingController::receivedWheelEvent):
+    (WebCore::ScrollingTreeLatchingController::latchedNodeForEvent const):
+    (WebCore::ScrollingTreeLatchingController::latchedNodeIsRelevant const):
+    * page/scrolling/ScrollingTreeLatchingController.h:
+    
+    LayoutTests:
+    
+    Reviewed by Tim Horton.
+    
+    * fast/scrolling/latching/latching-stuck-to-main-page-expected.txt: Added.
+    * fast/scrolling/latching/latching-stuck-to-main-page.html: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266262 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-08-27  Simon Fraser  <simon.fraser@apple.com>
+
+            Scrolling on select element doesn't work after scrolling the page
+            https://bugs.webkit.org/show_bug.cgi?id=215900
+            <rdar://problem/67766032>
+
+            Reviewed by Tim Horton.
+
+            The scrolling thread could use a node that was latched some time ago; we need to
+            check the freshness of the latched node before using it.
+
+            Test: fast/scrolling/latching/latching-stuck-to-main-page.html
+
+            * page/scrolling/ScrollingTreeLatchingController.cpp:
+            (WebCore::ScrollingTreeLatchingController::receivedWheelEvent):
+            (WebCore::ScrollingTreeLatchingController::latchedNodeForEvent const):
+            (WebCore::ScrollingTreeLatchingController::latchedNodeIsRelevant const):
+            * page/scrolling/ScrollingTreeLatchingController.h:
+
+2020-08-28  Russell Epstein  <repstein@apple.com>
+
</ins><span class="cx">         Cherry-pick r266248. rdar://problem/67963534
</span><span class="cx"> 
</span><span class="cx">     Occasional crashes when restoring replaced text under Editor::changeBackToReplacedString
</span></span></pre></div>
<a id="branchessafari6101281branchSourceWebCorepagescrollingScrollingTreeLatchingControllercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-610.1.28.1-branch/Source/WebCore/page/scrolling/ScrollingTreeLatchingController.cpp (266305 => 266306)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-610.1.28.1-branch/Source/WebCore/page/scrolling/ScrollingTreeLatchingController.cpp      2020-08-28 22:58:01 UTC (rev 266305)
+++ branches/safari-610.1.28.1-branch/Source/WebCore/page/scrolling/ScrollingTreeLatchingController.cpp 2020-08-28 22:58:04 UTC (rev 266306)
</span><span class="lines">@@ -47,14 +47,9 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     LockHolder locker(m_latchedNodeMutex);
</span><del>-    if (wheelEvent.shouldConsiderLatching()) {
-        if (m_latchedNodeID) {
-            auto secondsSinceLastInteraction = MonotonicTime::now() - m_lastLatchedNodeInterationTime;
-            if (secondsSinceLastInteraction > resetLatchedStateTimeout) {
-                LOG_WITH_STREAM(ScrollLatching, stream << "ScrollingTreeLatchingController " << this << " receivedWheelEvent - " << secondsSinceLastInteraction.milliseconds() << "ms since last event, clearing latched node");
-                m_latchedNodeID.reset();
-            }
-        }
</del><ins>+    if (wheelEvent.shouldConsiderLatching() && m_latchedNodeID && !latchedNodeIsRelevant()) {
+        LOG_WITH_STREAM(ScrollLatching, stream << "ScrollingTreeLatchingController " << this << " receivedWheelEvent - " << (MonotonicTime::now() - m_lastLatchedNodeInterationTime).milliseconds() << "ms since last event, clearing latched node");
+        m_latchedNodeID.reset();
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -66,7 +61,7 @@
</span><span class="cx">     LockHolder locker(m_latchedNodeMutex);
</span><span class="cx"> 
</span><span class="cx">     // If we have a latched node, use it.
</span><del>-    if (wheelEvent.useLatchedEventElement() && m_latchedNodeID) {
</del><ins>+    if (wheelEvent.useLatchedEventElement() && m_latchedNodeID && latchedNodeIsRelevant()) {
</ins><span class="cx">         LOG_WITH_STREAM(ScrollLatching, stream << "ScrollingTreeLatchingController " << this << " latchedNodeForEvent: returning " << m_latchedNodeID);
</span><span class="cx">         return m_latchedNodeID.value();
</span><span class="cx">     }
</span><span class="lines">@@ -114,6 +109,12 @@
</span><span class="cx">     m_latchedNodeID.reset();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-};
</del><ins>+bool ScrollingTreeLatchingController::latchedNodeIsRelevant() const
+{
+    auto secondsSinceLastInteraction = MonotonicTime::now() - m_lastLatchedNodeInterationTime;
+    return secondsSinceLastInteraction < resetLatchedStateTimeout;
+}
</ins><span class="cx"> 
</span><ins>+} // namespace WebCore
+
</ins><span class="cx"> #endif // ENABLE(ASYNC_SCROLLING)
</span></span></pre></div>
<a id="branchessafari6101281branchSourceWebCorepagescrollingScrollingTreeLatchingControllerh"></a>
<div class="modfile"><h4>Modified: branches/safari-610.1.28.1-branch/Source/WebCore/page/scrolling/ScrollingTreeLatchingController.h (266305 => 266306)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-610.1.28.1-branch/Source/WebCore/page/scrolling/ScrollingTreeLatchingController.h        2020-08-28 22:58:01 UTC (rev 266305)
+++ branches/safari-610.1.28.1-branch/Source/WebCore/page/scrolling/ScrollingTreeLatchingController.h   2020-08-28 22:58:04 UTC (rev 266306)
</span><span class="lines">@@ -51,6 +51,8 @@
</span><span class="cx">     void clearLatchedNode();
</span><span class="cx"> 
</span><span class="cx"> private:
</span><ins>+    bool latchedNodeIsRelevant() const;
+
</ins><span class="cx">     mutable Lock m_latchedNodeMutex;
</span><span class="cx">     Markable<ScrollingNodeID, IntegralMarkableTraits<ScrollingNodeID, 0>> m_latchedNodeID;
</span><span class="cx">     MonotonicTime m_lastLatchedNodeInterationTime;
</span></span></pre>
</div>
</div>

</body>
</html>