<!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>[194487] 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/194487">194487</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2016-01-01 20:45:36 -0800 (Fri, 01 Jan 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix reload and programmatic scrolling in RTL documents
https://bugs.webkit.org/show_bug.cgi?id=152639

Reviewed by Zalan Bujtas.
Source/WebCore:

Reloading a left-scrolled RTL document would cause the content to appear
at an odd offset, and programmatic sideways scrolls in RTL documents also
jumped to the wrong location.

Fix by resolving offset/position confusion in ScrollableArea::scrollPositionChanged()
and the scrolling tree.

ScrollableArea::scrollPositionChanged() was erroneously passing a scrollPosition
to setScrollOffset().

ScrollingTreeFrameScrollingNode* were confused about offsets and positions. It
turns out that the layer position is just -scrollPosition, but minimumScrollPosition()
and maximumScrollPosition() need fixing to return positions, not offsets.

ScrollingTreeFrameScrollingNode::viewToContentsOffset() was also doing incorrect
math with scrollOrigin, which was detected by a failing test.

Add more logging to the Scrolling channel.

Tests: fast/scrolling/programmatic-document-rtl-scroll.html
       fast/scrolling/programmatic-document-rtl-scrollIntoView.html
       fast/scrolling/scroll-position-on-reload-rtl.html

* page/FrameView.cpp:
(WebCore::FrameView::requestScrollPositionUpdate):
* page/scrolling/ScrollingTree.cpp:
(WebCore::ScrollingTree::shouldHandleWheelEventSynchronously):
* page/scrolling/ScrollingTreeFrameScrollingNode.cpp:
(WebCore::ScrollingTreeFrameScrollingNode::scrollBy):
(WebCore::ScrollingTreeFrameScrollingNode::viewToContentsOffset):
* page/scrolling/ScrollingTreeFrameScrollingNode.h:
* page/scrolling/ios/ScrollingTreeFrameScrollingNodeIOS.mm:
(WebCore::ScrollingTreeFrameScrollingNodeIOS::scrollPosition):
(WebCore::ScrollingTreeFrameScrollingNodeIOS::setScrollLayerPosition):
(WebCore::ScrollingTreeFrameScrollingNodeIOS::updateChildNodesAfterScroll):
(WebCore::ScrollingTreeFrameScrollingNodeIOS::minimumScrollPosition):
(WebCore::ScrollingTreeFrameScrollingNodeIOS::maximumScrollPosition):
* page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:
(WebCore::ScrollingTreeFrameScrollingNodeMac::immediateScrollBy):
(WebCore::ScrollingTreeFrameScrollingNodeMac::scrollPosition):
(WebCore::ScrollingTreeFrameScrollingNodeMac::setScrollPosition):
(WebCore::ScrollingTreeFrameScrollingNodeMac::setScrollLayerPosition):
(WebCore::ScrollingTreeFrameScrollingNodeMac::minimumScrollPosition):
(WebCore::ScrollingTreeFrameScrollingNodeMac::maximumScrollPosition):
* platform/ScrollView.cpp:
(WebCore::ScrollView::setScrollOffset):
(WebCore::ScrollView::scrollTo):
(WebCore::ScrollView::setScrollPosition):
(WebCore::ScrollView::updateScrollbars):
* platform/ScrollView.h:
* platform/ScrollableArea.cpp:
(WebCore::ScrollableArea::scrollPositionChanged):
(WebCore::ScrollableArea::setScrollOffsetFromAnimation):
(WebCore::ScrollableArea::scrollPositionFromOffset):
(WebCore::ScrollableArea::scrollOffsetFromPosition):
* platform/ScrollableArea.h:
(WebCore::ScrollableArea::scrollPositionFromOffset):
(WebCore::ScrollableArea::scrollOffsetFromPosition):
* rendering/RenderListBox.cpp:
(WebCore::RenderListBox::setScrollOffset):
* rendering/RenderListBox.h:

Source/WebKit2:

Reloading a left-scrolled RTL document would cause the content to appear
at an odd offset, and programmatic sideways scrolls in RTL documents also
jumped to the wrong location.

Fix by resolving offset/position confusion in ScrollableArea::scrollPositionChanged()
and the scrolling tree.

ScrollableArea::scrollPositionChanged() was erroneously passing a scrollPosition
to setScrollOffset().

ScrollingTreeFrameScrollingNode* were confused about offsets and positions. It
turns out that the layer position is just -scrollPosition, but minimumScrollPosition()
and maximumScrollPosition() need fixing to return positions, not offsets.

ScrollingTreeFrameScrollingNode::viewToContentsOffset() was also doing incorrect
math with scrollOrigin, which was detected by a failing test.

Add more logging to the Scrolling channel.

* WebProcess/Plugins/PDF/DeprecatedPDFPlugin.h:
* WebProcess/Plugins/PDF/DeprecatedPDFPlugin.mm:
(WebKit::PDFPlugin::setScrollOffset):

LayoutTests:

New tests for programmatic scrolling (2 kinds!) in RTL documents, and
reloading a scrolled RTL document.

* fast/scrolling/programmatic-document-rtl-scroll-expected.html: Added.
* fast/scrolling/programmatic-document-rtl-scroll.html: Added.
* fast/scrolling/programmatic-document-rtl-scrollIntoView-expected.txt: Added.
* fast/scrolling/programmatic-document-rtl-scrollIntoView.html: Added.
* fast/scrolling/scroll-position-on-reload-rtl-expected.txt: Added.
* fast/scrolling/scroll-position-on-reload-rtl.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="#trunkSourceWebCorepageFrameViewcpp">trunk/Source/WebCore/page/FrameView.cpp</a></li>
<li><a href="#trunkSourceWebCorepagescrollingScrollingTreecpp">trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp</a></li>
<li><a href="#trunkSourceWebCorepagescrollingScrollingTreeFrameScrollingNodecpp">trunk/Source/WebCore/page/scrolling/ScrollingTreeFrameScrollingNode.cpp</a></li>
<li><a href="#trunkSourceWebCorepagescrollingScrollingTreeFrameScrollingNodeh">trunk/Source/WebCore/page/scrolling/ScrollingTreeFrameScrollingNode.h</a></li>
<li><a href="#trunkSourceWebCorepagescrollingiosScrollingTreeFrameScrollingNodeIOSmm">trunk/Source/WebCore/page/scrolling/ios/ScrollingTreeFrameScrollingNodeIOS.mm</a></li>
<li><a href="#trunkSourceWebCorepagescrollingmacScrollingTreeFrameScrollingNodeMacmm">trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformScrollViewcpp">trunk/Source/WebCore/platform/ScrollView.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformScrollViewh">trunk/Source/WebCore/platform/ScrollView.h</a></li>
<li><a href="#trunkSourceWebCoreplatformScrollableAreacpp">trunk/Source/WebCore/platform/ScrollableArea.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformScrollableAreah">trunk/Source/WebCore/platform/ScrollableArea.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderListBoxcpp">trunk/Source/WebCore/rendering/RenderListBox.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderListBoxh">trunk/Source/WebCore/rendering/RenderListBox.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessPluginsPDFDeprecatedPDFPluginh">trunk/Source/WebKit2/WebProcess/Plugins/PDF/DeprecatedPDFPlugin.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessPluginsPDFDeprecatedPDFPluginmm">trunk/Source/WebKit2/WebProcess/Plugins/PDF/DeprecatedPDFPlugin.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastscrollingprogrammaticdocumentrtlscrollexpectedhtml">trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scroll-expected.html</a></li>
<li><a href="#trunkLayoutTestsfastscrollingprogrammaticdocumentrtlscrollhtml">trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scroll.html</a></li>
<li><a href="#trunkLayoutTestsfastscrollingprogrammaticdocumentrtlscrollIntoViewexpectedtxt">trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scrollIntoView-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastscrollingprogrammaticdocumentrtlscrollIntoViewhtml">trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scrollIntoView.html</a></li>
<li><a href="#trunkLayoutTestsfastscrollingscrollpositiononreloadrtlexpectedtxt">trunk/LayoutTests/fast/scrolling/scroll-position-on-reload-rtl-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastscrollingscrollpositiononreloadrtlhtml">trunk/LayoutTests/fast/scrolling/scroll-position-on-reload-rtl.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/LayoutTests/ChangeLog        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -1,5 +1,22 @@
</span><span class="cx"> 2016-01-01  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Fix reload and programmatic scrolling in RTL documents
+        https://bugs.webkit.org/show_bug.cgi?id=152639
+
+        Reviewed by Zalan Bujtas.
+        
+        New tests for programmatic scrolling (2 kinds!) in RTL documents, and
+        reloading a scrolled RTL document.
+
+        * fast/scrolling/programmatic-document-rtl-scroll-expected.html: Added.
+        * fast/scrolling/programmatic-document-rtl-scroll.html: Added.
+        * fast/scrolling/programmatic-document-rtl-scrollIntoView-expected.txt: Added.
+        * fast/scrolling/programmatic-document-rtl-scrollIntoView.html: Added.
+        * fast/scrolling/scroll-position-on-reload-rtl-expected.txt: Added.
+        * fast/scrolling/scroll-position-on-reload-rtl.html: Added.
+
+2016-01-01  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
</ins><span class="cx">         REGRESSION (r194448): Scrolling overflow:scroll goes too far
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=152645
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsfastscrollingprogrammaticdocumentrtlscrollexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scroll-expected.html (0 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scroll-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scroll-expected.html        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -0,0 +1,45 @@
</span><ins>+&lt;html&gt;
+&lt;head&gt;
+    &lt;style&gt;
+        body {
+            margin: 0;
+        }
+        .wide {
+            width: 2000px;
+            height: 10px;
+            background-color: silver;
+        }
+        .origin {
+            position: absolute;
+            top: 0;
+            left: 1200px;
+            width: 10px;
+            height: 10px;
+            background-color: blue;
+        }
+        
+        #lefty {
+            position: absolute;
+            left: 1000px;
+            width: 100px;
+            height: 100px;
+            background-color: orange;
+        }
+    &lt;/style&gt;
+    &lt;script&gt;
+    function runTest()
+    {
+        document.scrollingElement.scrollLeft = 1000;
+    }
+    
+    window.addEventListener('load', runTest, false);
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;div class=&quot;wide&quot;&gt;&lt;/div&gt;
+    &lt;div class=&quot;origin&quot;&gt;&lt;/div&gt;
+    &lt;div id=&quot;lefty&quot;&gt;&lt;/div&gt;
+    &lt;div id=&quot;result&quot;&gt;
+    &lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastscrollingprogrammaticdocumentrtlscrollhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scroll.html (0 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scroll.html                                (rev 0)
+++ trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scroll.html        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -0,0 +1,45 @@
</span><ins>+&lt;html dir=&quot;rtl&quot;&gt;
+&lt;head&gt;
+    &lt;style&gt;
+        body {
+            margin: 0;
+        }
+        .wide {
+            width: 2000px;
+            height: 10px;
+            background-color: silver;
+        }
+        .origin {
+            position: absolute;
+            top: 0;
+            left: 0;
+            width: 10px;
+            height: 10px;
+            background-color: blue;
+        }
+        
+        #lefty {
+            position: absolute;
+            left: -200px;
+            width: 100px;
+            height: 100px;
+            background-color: orange;
+        }
+    &lt;/style&gt;
+    &lt;script&gt;
+    function runTest()
+    {
+        document.scrollingElement.scrollLeft = -200;
+    }
+    
+    window.addEventListener('load', runTest, false);
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;div class=&quot;wide&quot;&gt;&lt;/div&gt;
+    &lt;div class=&quot;origin&quot;&gt;&lt;/div&gt;
+    &lt;div id=&quot;lefty&quot;&gt;&lt;/div&gt;
+    &lt;div id=&quot;result&quot;&gt;
+    &lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastscrollingprogrammaticdocumentrtlscrollIntoViewexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scrollIntoView-expected.txt (0 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scrollIntoView-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scrollIntoView-expected.txt        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+document.scrollingElement.scrollLeft = -200
</ins></span></pre></div>
<a id="trunkLayoutTestsfastscrollingprogrammaticdocumentrtlscrollIntoViewhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scrollIntoView.html (0 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scrollIntoView.html                                (rev 0)
+++ trunk/LayoutTests/fast/scrolling/programmatic-document-rtl-scrollIntoView.html        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -0,0 +1,46 @@
</span><ins>+&lt;html dir=&quot;rtl&quot;&gt;
+&lt;head&gt;
+    &lt;style&gt;
+        .wide {
+            width: 2000px;
+            height: 10px;
+            background-color: silver;
+        }
+        .origin {
+            position: absolute;
+            top: 0;
+            left: 0;
+            width: 10px;
+            height: 10px;
+            background-color: blue;
+        }
+        
+        #lefty {
+            position: absolute;
+            left: -200px;
+            width: 100px;
+            height: 100px;
+            background-color: orange;
+        }
+    &lt;/style&gt;
+    &lt;script&gt;
+    if (window.testRunner)
+        testRunner.dumpAsText();
+
+    function runTest()
+    {
+        document.getElementById('lefty').scrollIntoView();
+        document.getElementById('result').textContent = 'document.scrollingElement.scrollLeft = ' + document.scrollingElement.scrollLeft;
+    }
+    
+    window.addEventListener('load', runTest, false);
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;div class=&quot;wide&quot;&gt;&lt;/div&gt;
+    &lt;div class=&quot;origin&quot;&gt;&lt;/div&gt;
+    &lt;div id=&quot;lefty&quot;&gt;&lt;/div&gt;
+    &lt;div id=&quot;result&quot;&gt;
+    &lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastscrollingscrollpositiononreloadrtlexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/scrolling/scroll-position-on-reload-rtl-expected.txt (0 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/scrolling/scroll-position-on-reload-rtl-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/scrolling/scroll-position-on-reload-rtl-expected.txt        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+PASS: scrollLeft after reload is -200
</ins></span></pre></div>
<a id="trunkLayoutTestsfastscrollingscrollpositiononreloadrtlhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/scrolling/scroll-position-on-reload-rtl.html (0 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/scrolling/scroll-position-on-reload-rtl.html                                (rev 0)
+++ trunk/LayoutTests/fast/scrolling/scroll-position-on-reload-rtl.html        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -0,0 +1,66 @@
</span><ins>+&lt;html dir=&quot;rtl&quot;&gt;
+&lt;head&gt;
+    &lt;style&gt;
+        .wide {
+            width: 2000px;
+            height: 10px;
+            background-color: silver;
+        }
+        .origin {
+            position: absolute;
+            top: 0;
+            left: 0;
+            width: 10px;
+            height: 10px;
+            background-color: blue;
+        }
+        
+        #lefty {
+            position: absolute;
+            left: -200px;
+            width: 100px;
+            height: 100px;
+            background-color: orange;
+        }
+    &lt;/style&gt;
+    &lt;script&gt;
+    var desiredScrollOffset = -200;
+    function runTest()
+    {
+        if (!window.sessionStorage)
+            return;
+
+        if (window.testRunner) {
+            testRunner.waitUntilDone();
+            testRunner.dumpAsText();
+        }
+
+        if (sessionStorage.testCompleted) {
+            window.setTimeout(function() {
+                var currentOffset = document.scrollingElement.scrollLeft;
+                if (currentOffset == desiredScrollOffset)
+                    document.getElementById('result').textContent = 'PASS: scrollLeft after reload is ' + desiredScrollOffset;
+                else
+                    document.getElementById('result').textContent = 'FAIL: scrollLeft after reload is ' + currentOffset + ', should be' + desiredScrollOffset;
+
+                delete sessionStorage.testCompleted;
+                if (window.testRunner)
+                    testRunner.notifyDone();
+            }, 0);
+        } else {
+            document.scrollingElement.scrollLeft = desiredScrollOffset;
+            sessionStorage.testCompleted = true;
+            document.location.reload(true);
+        }
+    }
+
+    window.addEventListener('load', runTest, false);
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;div class=&quot;wide&quot;&gt;&lt;/div&gt;
+    &lt;div class=&quot;origin&quot;&gt;&lt;/div&gt;
+    &lt;div id=&quot;lefty&quot;&gt;&lt;/div&gt;
+    &lt;div id=&quot;result&quot;&gt;&lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebCore/ChangeLog        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -1,5 +1,74 @@
</span><span class="cx"> 2016-01-01  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Fix reload and programmatic scrolling in RTL documents
+        https://bugs.webkit.org/show_bug.cgi?id=152639
+
+        Reviewed by Zalan Bujtas.
+        
+        Reloading a left-scrolled RTL document would cause the content to appear
+        at an odd offset, and programmatic sideways scrolls in RTL documents also
+        jumped to the wrong location.
+        
+        Fix by resolving offset/position confusion in ScrollableArea::scrollPositionChanged()
+        and the scrolling tree.
+        
+        ScrollableArea::scrollPositionChanged() was erroneously passing a scrollPosition
+        to setScrollOffset(). 
+        
+        ScrollingTreeFrameScrollingNode* were confused about offsets and positions. It
+        turns out that the layer position is just -scrollPosition, but minimumScrollPosition()
+        and maximumScrollPosition() need fixing to return positions, not offsets.
+        
+        ScrollingTreeFrameScrollingNode::viewToContentsOffset() was also doing incorrect
+        math with scrollOrigin, which was detected by a failing test.
+        
+        Add more logging to the Scrolling channel.
+
+        Tests: fast/scrolling/programmatic-document-rtl-scroll.html
+               fast/scrolling/programmatic-document-rtl-scrollIntoView.html
+               fast/scrolling/scroll-position-on-reload-rtl.html
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::requestScrollPositionUpdate):
+        * page/scrolling/ScrollingTree.cpp:
+        (WebCore::ScrollingTree::shouldHandleWheelEventSynchronously):
+        * page/scrolling/ScrollingTreeFrameScrollingNode.cpp:
+        (WebCore::ScrollingTreeFrameScrollingNode::scrollBy):
+        (WebCore::ScrollingTreeFrameScrollingNode::viewToContentsOffset):
+        * page/scrolling/ScrollingTreeFrameScrollingNode.h:
+        * page/scrolling/ios/ScrollingTreeFrameScrollingNodeIOS.mm:
+        (WebCore::ScrollingTreeFrameScrollingNodeIOS::scrollPosition):
+        (WebCore::ScrollingTreeFrameScrollingNodeIOS::setScrollLayerPosition):
+        (WebCore::ScrollingTreeFrameScrollingNodeIOS::updateChildNodesAfterScroll):
+        (WebCore::ScrollingTreeFrameScrollingNodeIOS::minimumScrollPosition):
+        (WebCore::ScrollingTreeFrameScrollingNodeIOS::maximumScrollPosition):
+        * page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::immediateScrollBy):
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::scrollPosition):
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::setScrollPosition):
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::setScrollLayerPosition):
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::minimumScrollPosition):
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::maximumScrollPosition):
+        * platform/ScrollView.cpp:
+        (WebCore::ScrollView::setScrollOffset):
+        (WebCore::ScrollView::scrollTo):
+        (WebCore::ScrollView::setScrollPosition):
+        (WebCore::ScrollView::updateScrollbars):
+        * platform/ScrollView.h:
+        * platform/ScrollableArea.cpp:
+        (WebCore::ScrollableArea::scrollPositionChanged):
+        (WebCore::ScrollableArea::setScrollOffsetFromAnimation):
+        (WebCore::ScrollableArea::scrollPositionFromOffset):
+        (WebCore::ScrollableArea::scrollOffsetFromPosition):
+        * platform/ScrollableArea.h:
+        (WebCore::ScrollableArea::scrollPositionFromOffset):
+        (WebCore::ScrollableArea::scrollOffsetFromPosition):
+        * rendering/RenderListBox.cpp:
+        (WebCore::RenderListBox::setScrollOffset):
+        * rendering/RenderListBox.h:
+
+2016-01-01  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
</ins><span class="cx">         REGRESSION (r194448): Scrolling overflow:scroll goes too far
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=152645
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorepageFrameViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FrameView.cpp (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FrameView.cpp        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebCore/page/FrameView.cpp        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -2353,6 +2353,8 @@
</span><span class="cx"> 
</span><span class="cx"> bool FrameView::requestScrollPositionUpdate(const ScrollPosition&amp; position)
</span><span class="cx"> {
</span><ins>+    LOG_WITH_STREAM(Scrolling, stream &lt;&lt; &quot;FrameView::requestScrollPositionUpdate &quot; &lt;&lt; position);
+
</ins><span class="cx"> #if ENABLE(ASYNC_SCROLLING)
</span><span class="cx">     if (TiledBacking* tiledBacking = this-&gt;tiledBacking())
</span><span class="cx">         tiledBacking-&gt;prepopulateRect(FloatRect(position, visibleContentRect().size()));
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingScrollingTreecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTree.cpp        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -28,12 +28,14 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ASYNC_SCROLLING)
</span><span class="cx"> 
</span><ins>+#include &quot;Logging.h&quot;
</ins><span class="cx"> #include &quot;PlatformWheelEvent.h&quot;
</span><span class="cx"> #include &quot;ScrollingStateTree.h&quot;
</span><span class="cx"> #include &quot;ScrollingTreeFrameScrollingNode.h&quot;
</span><span class="cx"> #include &quot;ScrollingTreeNode.h&quot;
</span><span class="cx"> #include &quot;ScrollingTreeOverflowScrollingNode.h&quot;
</span><span class="cx"> #include &quot;ScrollingTreeScrollingNode.h&quot;
</span><ins>+#include &quot;TextStream.h&quot;
</ins><span class="cx"> #include &lt;wtf/TemporaryChange.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -61,9 +63,11 @@
</span><span class="cx">     
</span><span class="cx">     if (!m_nonFastScrollableRegion.isEmpty() &amp;&amp; m_rootNode) {
</span><span class="cx">         ScrollingTreeFrameScrollingNode&amp; frameScrollingNode = downcast&lt;ScrollingTreeFrameScrollingNode&gt;(*m_rootNode);
</span><del>-        // FIXME: This is not correct for non-default scroll origins.
</del><span class="cx">         FloatPoint position = wheelEvent.position();
</span><span class="cx">         position.move(frameScrollingNode.viewToContentsOffset(m_mainFrameScrollPosition));
</span><ins>+
+        LOG_WITH_STREAM(Scrolling, stream &lt;&lt; &quot;ScrollingTree::shouldHandleWheelEventSynchronously: wheelEvent at &quot; &lt;&lt; wheelEvent.position() &lt;&lt; &quot; mapped to content point &quot; &lt;&lt; position &lt;&lt; &quot;, in non-fast region &quot; &lt;&lt; m_nonFastScrollableRegion.contains(roundedIntPoint(position)));
+
</ins><span class="cx">         if (m_nonFastScrollableRegion.contains(roundedIntPoint(position)))
</span><span class="cx">             return true;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingScrollingTreeFrameScrollingNodecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/ScrollingTreeFrameScrollingNode.cpp (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/ScrollingTreeFrameScrollingNode.cpp        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTreeFrameScrollingNode.cpp        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -70,9 +70,9 @@
</span><span class="cx">         m_fixedElementsLayoutRelativeToFrame = state.fixedElementsLayoutRelativeToFrame();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ScrollingTreeFrameScrollingNode::scrollBy(const FloatSize&amp; offset)
</del><ins>+void ScrollingTreeFrameScrollingNode::scrollBy(const FloatSize&amp; delta)
</ins><span class="cx"> {
</span><del>-    setScrollPosition(scrollPosition() + offset);
</del><ins>+    setScrollPosition(scrollPosition() + delta);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ScrollingTreeFrameScrollingNode::scrollByWithoutContentEdgeConstraints(const FloatSize&amp; offset)
</span><span class="lines">@@ -86,9 +86,9 @@
</span><span class="cx">     setScrollPositionWithoutContentEdgeConstraints(newScrollPosition);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-FloatSize ScrollingTreeFrameScrollingNode::viewToContentsOffset(const FloatPoint&amp; scrollOffset) const
</del><ins>+FloatSize ScrollingTreeFrameScrollingNode::viewToContentsOffset(const FloatPoint&amp; scrollPosition) const
</ins><span class="cx"> {
</span><del>-    return toFloatSize(scrollOffset) - toFloatSize(scrollOrigin()) - FloatSize(0, headerHeight() + topContentInset());
</del><ins>+    return toFloatSize(scrollPosition) - FloatSize(0, headerHeight() + topContentInset());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingScrollingTreeFrameScrollingNodeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/ScrollingTreeFrameScrollingNode.h (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/ScrollingTreeFrameScrollingNode.h        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTreeFrameScrollingNode.h        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -56,7 +56,7 @@
</span><span class="cx">     bool shouldUpdateScrollLayerPositionSynchronously() const { return m_synchronousScrollingReasons; }
</span><span class="cx">     bool fixedElementsLayoutRelativeToFrame() const { return m_fixedElementsLayoutRelativeToFrame; }
</span><span class="cx"> 
</span><del>-    FloatSize viewToContentsOffset(const FloatPoint&amp; scrollOffset) const;
</del><ins>+    FloatSize viewToContentsOffset(const FloatPoint&amp; scrollPosition) const;
</ins><span class="cx"> 
</span><span class="cx"> protected:
</span><span class="cx">     ScrollingTreeFrameScrollingNode(ScrollingTree&amp;, ScrollingNodeID);
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingiosScrollingTreeFrameScrollingNodeIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/ios/ScrollingTreeFrameScrollingNodeIOS.mm (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/ios/ScrollingTreeFrameScrollingNodeIOS.mm        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebCore/page/scrolling/ios/ScrollingTreeFrameScrollingNodeIOS.mm        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -102,8 +102,7 @@
</span><span class="cx">     if (shouldUpdateScrollLayerPositionSynchronously())
</span><span class="cx">         return m_probableMainThreadScrollPosition;
</span><span class="cx"> 
</span><del>-    CGPoint scrollLayerPosition = m_scrollLayer.get().position;
-    return IntPoint(-scrollLayerPosition.x + scrollOrigin().x(), -scrollLayerPosition.y + scrollOrigin().y());
</del><ins>+    return -m_scrollLayer.get().position;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ScrollingTreeFrameScrollingNodeIOS::setScrollPositionWithoutContentEdgeConstraints(const FloatPoint&amp; scrollPosition)
</span><span class="lines">@@ -121,7 +120,7 @@
</span><span class="cx"> void ScrollingTreeFrameScrollingNodeIOS::setScrollLayerPosition(const FloatPoint&amp; scrollPosition)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!shouldUpdateScrollLayerPositionSynchronously());
</span><del>-    [m_scrollLayer setPosition:CGPointMake(-scrollPosition.x() + scrollOrigin().x(), -scrollPosition.y() + scrollOrigin().y())];
</del><ins>+    [m_scrollLayer setPosition:-scrollPosition];
</ins><span class="cx"> 
</span><span class="cx">     updateChildNodesAfterScroll(scrollPosition);
</span><span class="cx"> }
</span><span class="lines">@@ -146,9 +145,8 @@
</span><span class="cx"> void ScrollingTreeFrameScrollingNodeIOS::updateChildNodesAfterScroll(const FloatPoint&amp; scrollPosition)
</span><span class="cx"> {
</span><span class="cx">     ScrollBehaviorForFixedElements behaviorForFixed = scrollBehaviorForFixedElements();
</span><del>-    FloatPoint scrollOffset = scrollPosition - toIntSize(scrollOrigin());
-    FloatRect viewportRect(FloatPoint(), scrollableAreaSize());
-    FloatPoint scrollPositionForFixedChildren = FrameView::scrollPositionForFixedPosition(enclosingLayoutRect(viewportRect), LayoutSize(totalContentsSize()), LayoutPoint(scrollOffset), scrollOrigin(), frameScaleFactor(), fixedElementsLayoutRelativeToFrame(), behaviorForFixed, headerHeight(), footerHeight());
</del><ins>+    FloatRect viewportRect(scrollPosition, scrollableAreaSize());
+    FloatPoint scrollPositionForFixedChildren = FrameView::scrollPositionForFixedPosition(enclosingLayoutRect(viewportRect), LayoutSize(totalContentsSize()), LayoutPoint(scrollPosition), scrollOrigin(), frameScaleFactor(), fixedElementsLayoutRelativeToFrame(), behaviorForFixed, headerHeight(), footerHeight());
</ins><span class="cx"> 
</span><span class="cx">     [m_counterScrollingLayer setPosition:scrollPositionForFixedChildren];
</span><span class="cx"> 
</span><span class="lines">@@ -158,7 +156,7 @@
</span><span class="cx">         // then we should recompute scrollPositionForFixedChildren for the banner with a scale factor of 1.
</span><span class="cx">         float horizontalScrollOffsetForBanner = scrollPositionForFixedChildren.x();
</span><span class="cx">         if (frameScaleFactor() != 1)
</span><del>-            horizontalScrollOffsetForBanner = FrameView::scrollPositionForFixedPosition(enclosingLayoutRect(viewportRect), LayoutSize(totalContentsSize()), LayoutPoint(scrollOffset), scrollOrigin(), 1, fixedElementsLayoutRelativeToFrame(), behaviorForFixed, headerHeight(), footerHeight()).x();
</del><ins>+            horizontalScrollOffsetForBanner = FrameView::scrollPositionForFixedPosition(enclosingLayoutRect(viewportRect), LayoutSize(totalContentsSize()), LayoutPoint(scrollPosition), scrollOrigin(), 1, fixedElementsLayoutRelativeToFrame(), behaviorForFixed, headerHeight(), footerHeight()).x();
</ins><span class="cx"> 
</span><span class="cx">         if (m_headerLayer)
</span><span class="cx">             [m_headerLayer setPosition:FloatPoint(horizontalScrollOffsetForBanner, 0)];
</span><span class="lines">@@ -175,7 +173,7 @@
</span><span class="cx">     if (!parent())
</span><span class="cx">         fixedPositionRect = scrollingTree().fixedPositionRect();
</span><span class="cx">     else
</span><del>-        fixedPositionRect = FloatRect(scrollOffset, scrollableAreaSize());
</del><ins>+        fixedPositionRect = FloatRect(scrollPosition, scrollableAreaSize());
</ins><span class="cx"> 
</span><span class="cx">     for (auto&amp; child : *m_children)
</span><span class="cx">         child-&gt;updateLayersAfterAncestorChange(*this, fixedPositionRect, FloatSize());
</span><span class="lines">@@ -183,7 +181,7 @@
</span><span class="cx"> 
</span><span class="cx"> FloatPoint ScrollingTreeFrameScrollingNodeIOS::minimumScrollPosition() const
</span><span class="cx"> {
</span><del>-    FloatPoint position;
</del><ins>+    FloatPoint position = ScrollableArea::scrollPositionFromOffset(FloatPoint(), toFloatSize(scrollOrigin()));
</ins><span class="cx">     
</span><span class="cx">     if (scrollingTree().rootNode() == this &amp;&amp; scrollingTree().scrollPinningBehavior() == PinToBottom)
</span><span class="cx">         position.setY(maximumScrollPosition().y());
</span><span class="lines">@@ -193,9 +191,7 @@
</span><span class="cx"> 
</span><span class="cx"> FloatPoint ScrollingTreeFrameScrollingNodeIOS::maximumScrollPosition() const
</span><span class="cx"> {
</span><del>-    FloatPoint position(totalContentsSizeForRubberBand().width() - scrollableAreaSize().width(),
-        totalContentsSizeForRubberBand().height() - scrollableAreaSize().height());
-
</del><ins>+    FloatPoint position = ScrollableArea::scrollPositionFromOffset(FloatPoint(totalContentsSizeForRubberBand() - scrollableAreaSize()), toFloatSize(scrollOrigin()));
</ins><span class="cx">     position = position.expandedTo(FloatPoint());
</span><span class="cx"> 
</span><span class="cx">     if (scrollingTree().rootNode() == this &amp;&amp; scrollingTree().scrollPinningBehavior() == PinToTop)
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingmacScrollingTreeFrameScrollingNodeMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -33,10 +33,12 @@
</span><span class="cx"> #import &quot;Logging.h&quot;
</span><span class="cx"> #import &quot;NSScrollerImpDetails.h&quot;
</span><span class="cx"> #import &quot;PlatformWheelEvent.h&quot;
</span><ins>+#import &quot;ScrollableArea.h&quot;
</ins><span class="cx"> #import &quot;ScrollingCoordinator.h&quot;
</span><span class="cx"> #import &quot;ScrollingTree.h&quot;
</span><span class="cx"> #import &quot;ScrollingStateTree.h&quot;
</span><span class="cx"> #import &quot;Settings.h&quot;
</span><ins>+#import &quot;TextStream.h&quot;
</ins><span class="cx"> #import &quot;TileController.h&quot;
</span><span class="cx"> #import &quot;WebLayer.h&quot;
</span><span class="cx"> 
</span><span class="lines">@@ -328,9 +330,9 @@
</span><span class="cx">     return roundedIntPoint(scrollPosition());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ScrollingTreeFrameScrollingNodeMac::immediateScrollBy(const FloatSize&amp; offset)
</del><ins>+void ScrollingTreeFrameScrollingNodeMac::immediateScrollBy(const FloatSize&amp; delta)
</ins><span class="cx"> {
</span><del>-    scrollBy(offset);
</del><ins>+    scrollBy(delta);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ScrollingTreeFrameScrollingNodeMac::immediateScrollByWithoutContentEdgeConstraints(const FloatSize&amp; offset)
</span><span class="lines">@@ -364,12 +366,13 @@
</span><span class="cx">     if (shouldUpdateScrollLayerPositionSynchronously())
</span><span class="cx">         return m_probableMainThreadScrollPosition;
</span><span class="cx"> 
</span><del>-    CGPoint scrollLayerPosition = m_scrollLayer.get().position;
-    return FloatPoint(-scrollLayerPosition.x + scrollOrigin().x(), -scrollLayerPosition.y + scrollOrigin().y());
</del><ins>+    return -m_scrollLayer.get().position;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ScrollingTreeFrameScrollingNodeMac::setScrollPosition(const FloatPoint&amp; scrollPosition)
</span><span class="cx"> {
</span><ins>+    LOG_WITH_STREAM(Scrolling, stream &lt;&lt; &quot;ScrollingTreeFrameScrollingNodeMac::setScrollPosition &quot; &lt;&lt; scrollPosition &lt;&lt; &quot; scrollPosition(): &quot; &lt;&lt; this-&gt;scrollPosition() &lt;&lt; &quot; min: &quot; &lt;&lt; minimumScrollPosition() &lt;&lt; &quot; max: &quot; &lt;&lt; maximumScrollPosition());
+
</ins><span class="cx">     // Scroll deltas can be non-integral with some input devices, so scrollPosition may not be integral.
</span><span class="cx">     // FIXME: when we support half-pixel scroll positions on Retina displays, this will need to round to half pixels.
</span><span class="cx">     FloatPoint roundedPosition(roundf(scrollPosition.x()), roundf(scrollPosition.y()));
</span><span class="lines">@@ -397,13 +400,13 @@
</span><span class="cx"> void ScrollingTreeFrameScrollingNodeMac::setScrollLayerPosition(const FloatPoint&amp; position)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!shouldUpdateScrollLayerPositionSynchronously());
</span><del>-    m_scrollLayer.get().position = CGPointMake(-position.x() + scrollOrigin().x(), -position.y() + scrollOrigin().y());
</del><span class="cx"> 
</span><ins>+    m_scrollLayer.get().position = -position;
+
</ins><span class="cx">     ScrollBehaviorForFixedElements behaviorForFixed = scrollBehaviorForFixedElements();
</span><del>-    LayoutPoint scrollOffset = LayoutPoint(position) - toLayoutSize(scrollOrigin());
-    FloatRect viewportRect(FloatPoint(), scrollableAreaSize());
</del><ins>+    FloatRect viewportRect(position, scrollableAreaSize());
</ins><span class="cx">     
</span><del>-    FloatPoint scrollPositionForFixedChildren = FrameView::scrollPositionForFixedPosition(enclosingLayoutRect(viewportRect), LayoutSize(totalContentsSize()), scrollOffset, scrollOrigin(), frameScaleFactor(),
</del><ins>+    FloatPoint scrollPositionForFixedChildren = FrameView::scrollPositionForFixedPosition(enclosingLayoutRect(viewportRect), LayoutSize(totalContentsSize()), LayoutPoint(position), scrollOrigin(), frameScaleFactor(),
</ins><span class="cx">         fixedElementsLayoutRelativeToFrame(), behaviorForFixed, headerHeight(), footerHeight());
</span><span class="cx">     
</span><span class="cx">     if (m_counterScrollingLayer)
</span><span class="lines">@@ -424,7 +427,7 @@
</span><span class="cx">         // then we should recompute scrollOffsetForFixedChildren for the banner with a scale factor of 1.
</span><span class="cx">         float horizontalScrollOffsetForBanner = scrollPositionForFixedChildren.x();
</span><span class="cx">         if (frameScaleFactor() != 1)
</span><del>-            horizontalScrollOffsetForBanner = FrameView::scrollPositionForFixedPosition(enclosingLayoutRect(viewportRect), LayoutSize(totalContentsSize()), scrollOffset, scrollOrigin(), 1, fixedElementsLayoutRelativeToFrame(), behaviorForFixed, headerHeight(), footerHeight()).x();
</del><ins>+            horizontalScrollOffsetForBanner = FrameView::scrollPositionForFixedPosition(enclosingLayoutRect(viewportRect), LayoutSize(totalContentsSize()), LayoutPoint(position), scrollOrigin(), 1, fixedElementsLayoutRelativeToFrame(), behaviorForFixed, headerHeight(), footerHeight()).x();
</ins><span class="cx"> 
</span><span class="cx">         if (m_headerLayer)
</span><span class="cx">             m_headerLayer.get().position = FloatPoint(horizontalScrollOffsetForBanner, FrameView::yPositionForHeaderLayer(position, topContentInset));
</span><span class="lines">@@ -472,7 +475,7 @@
</span><span class="cx"> 
</span><span class="cx"> FloatPoint ScrollingTreeFrameScrollingNodeMac::minimumScrollPosition() const
</span><span class="cx"> {
</span><del>-    FloatPoint position;
</del><ins>+    FloatPoint position = ScrollableArea::scrollPositionFromOffset(FloatPoint(), toFloatSize(scrollOrigin()));
</ins><span class="cx">     
</span><span class="cx">     if (scrollingTree().rootNode() == this &amp;&amp; scrollingTree().scrollPinningBehavior() == PinToBottom)
</span><span class="cx">         position.setY(maximumScrollPosition().y());
</span><span class="lines">@@ -482,7 +485,7 @@
</span><span class="cx"> 
</span><span class="cx"> FloatPoint ScrollingTreeFrameScrollingNodeMac::maximumScrollPosition() const
</span><span class="cx"> {
</span><del>-    FloatPoint position(totalContentsSizeForRubberBand() - scrollableAreaSize());
</del><ins>+    FloatPoint position = ScrollableArea::scrollPositionFromOffset(FloatPoint(totalContentsSizeForRubberBand() - scrollableAreaSize()), toFloatSize(scrollOrigin()));
</ins><span class="cx">     position = position.expandedTo(FloatPoint());
</span><span class="cx"> 
</span><span class="cx">     if (scrollingTree().rootNode() == this &amp;&amp; scrollingTree().scrollPinningBehavior() == PinToTop)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformScrollViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ScrollView.cpp (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ScrollView.cpp        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebCore/platform/ScrollView.cpp        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -429,8 +429,10 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ScrollView::setScrollOffset(const IntPoint&amp; offset)
</del><ins>+void ScrollView::setScrollOffset(const ScrollOffset&amp; offset)
</ins><span class="cx"> {
</span><ins>+    LOG_WITH_STREAM(Scrolling, stream &lt;&lt; &quot;ScrollView::setScrollOffset &quot; &lt;&lt; offset);
+
</ins><span class="cx">     IntPoint constrainedOffset = offset;
</span><span class="cx">     if (constrainsScrollingToContentEdge())
</span><span class="cx">         constrainedOffset = constrainedOffset.constrainedBetween(IntPoint(), maximumScrollOffset());
</span><span class="lines">@@ -471,6 +473,8 @@
</span><span class="cx"> 
</span><span class="cx"> void ScrollView::scrollTo(const ScrollPosition&amp; newPosition)
</span><span class="cx"> {
</span><ins>+    LOG_WITH_STREAM(Scrolling, stream &lt;&lt; &quot;ScrollView::scrollTo &quot; &lt;&lt; newPosition &lt;&lt; &quot; min: &quot; &lt;&lt; minimumScrollPosition() &lt;&lt; &quot; max: &quot; &lt;&lt; maximumScrollPosition());
+
</ins><span class="cx">     IntSize scrollDelta = newPosition - m_scrollPosition;
</span><span class="cx">     if (scrollDelta.isZero())
</span><span class="cx">         return;
</span><span class="lines">@@ -515,6 +519,8 @@
</span><span class="cx"> 
</span><span class="cx"> void ScrollView::setScrollPosition(const ScrollPosition&amp; scrollPosition)
</span><span class="cx"> {
</span><ins>+    LOG_WITH_STREAM(Scrolling, stream &lt;&lt; &quot;ScrollView::setScrollPosition &quot; &lt;&lt; scrollPosition);
+
</ins><span class="cx">     if (prohibitsScrolling())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="lines">@@ -568,6 +574,8 @@
</span><span class="cx"> 
</span><span class="cx"> void ScrollView::updateScrollbars(const ScrollPosition&amp; desiredPosition)
</span><span class="cx"> {
</span><ins>+    LOG_WITH_STREAM(Scrolling, stream &lt;&lt; &quot;ScrollView::updateScrollbars &quot; &lt;&lt; desiredPosition);
+
</ins><span class="cx">     if (m_inUpdateScrollbars || prohibitsScrolling() || platformWidget() || delegatesScrolling())
</span><span class="cx">         return;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformScrollViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ScrollView.h (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ScrollView.h        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebCore/platform/ScrollView.h        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -67,7 +67,7 @@
</span><span class="cx">     // ScrollableArea functions.
</span><span class="cx">     virtual int scrollSize(ScrollbarOrientation) const override;
</span><span class="cx">     virtual int scrollPosition(Scrollbar*) const override;
</span><del>-    WEBCORE_EXPORT virtual void setScrollOffset(const IntPoint&amp;) override;
</del><ins>+    WEBCORE_EXPORT virtual void setScrollOffset(const ScrollOffset&amp;) override;
</ins><span class="cx">     virtual bool isScrollCornerVisible() const override;
</span><span class="cx">     virtual void scrollbarStyleChanged(ScrollbarStyle, bool forceUpdate) override;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformScrollableAreacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ScrollableArea.cpp (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ScrollableArea.cpp        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebCore/platform/ScrollableArea.cpp        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -151,11 +151,11 @@
</span><span class="cx">     scrollAnimator().setCurrentPosition(position);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ScrollableArea::scrollPositionChanged(const IntPoint&amp; position)
</del><ins>+void ScrollableArea::scrollPositionChanged(const ScrollPosition&amp; position)
</ins><span class="cx"> {
</span><span class="cx">     IntPoint oldPosition = scrollPosition();
</span><span class="cx">     // Tell the derived class to scroll its contents.
</span><del>-    setScrollOffset(position);
</del><ins>+    setScrollOffset(scrollOffsetFromPosition(position));
</ins><span class="cx"> 
</span><span class="cx">     Scrollbar* verticalScrollbar = this-&gt;verticalScrollbar();
</span><span class="cx"> 
</span><span class="lines">@@ -207,17 +207,18 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> // NOTE: Only called from Internals for testing.
</span><del>-void ScrollableArea::setScrollOffsetFromInternals(const IntPoint&amp; offset)
</del><ins>+void ScrollableArea::setScrollOffsetFromInternals(const ScrollOffset&amp; offset)
</ins><span class="cx"> {
</span><span class="cx">     setScrollOffsetFromAnimation(offset);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ScrollableArea::setScrollOffsetFromAnimation(const IntPoint&amp; offset)
</del><ins>+void ScrollableArea::setScrollOffsetFromAnimation(const ScrollOffset&amp; offset)
</ins><span class="cx"> {
</span><del>-    if (requestScrollPositionUpdate(offset))
</del><ins>+    ScrollPosition position = scrollPositionFromOffset(offset);
+    if (requestScrollPositionUpdate(position))
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    scrollPositionChanged(offset);
</del><ins>+    scrollPositionChanged(position);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ScrollableArea::willStartLiveResize()
</span><span class="lines">@@ -549,12 +550,12 @@
</span><span class="cx"> 
</span><span class="cx"> ScrollPosition ScrollableArea::scrollPositionFromOffset(ScrollOffset offset) const
</span><span class="cx"> {
</span><del>-    return IntPoint(toIntSize(offset) - toIntSize(m_scrollOrigin));
</del><ins>+    return scrollPositionFromOffset(offset, toIntSize(m_scrollOrigin));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ScrollOffset ScrollableArea::scrollOffsetFromPosition(ScrollPosition position) const
</span><span class="cx"> {
</span><del>-    return IntPoint(toIntSize(position) + toIntSize(m_scrollOrigin));
</del><ins>+    return scrollOffsetFromPosition(position, toIntSize(m_scrollOrigin));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool ScrollableArea::scrolledToTop() const
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformScrollableAreah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ScrollableArea.h (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ScrollableArea.h        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebCore/platform/ScrollableArea.h        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -193,6 +193,18 @@
</span><span class="cx">     WEBCORE_EXPORT ScrollPosition scrollPositionFromOffset(ScrollOffset) const;
</span><span class="cx">     WEBCORE_EXPORT ScrollOffset scrollOffsetFromPosition(ScrollPosition) const;
</span><span class="cx"> 
</span><ins>+    template&lt;typename PositionType, typename SizeType&gt;
+    static PositionType scrollPositionFromOffset(PositionType offset, SizeType scrollOrigin)
+    {
+        return offset - scrollOrigin;
+    }
+
+    template&lt;typename PositionType, typename SizeType&gt;
+    static PositionType scrollOffsetFromPosition(PositionType position, SizeType scrollOrigin)
+    {
+        return position + scrollOrigin;
+    }
+
</ins><span class="cx">     WEBCORE_EXPORT virtual bool scrolledToTop() const;
</span><span class="cx">     WEBCORE_EXPORT virtual bool scrolledToBottom() const;
</span><span class="cx">     WEBCORE_EXPORT virtual bool scrolledToLeft() const;
</span><span class="lines">@@ -249,7 +261,7 @@
</span><span class="cx">     virtual bool scrollAnimatorEnabled() const { return false; }
</span><span class="cx"> 
</span><span class="cx">     // NOTE: Only called from Internals for testing.
</span><del>-    WEBCORE_EXPORT void setScrollOffsetFromInternals(const IntPoint&amp;);
</del><ins>+    WEBCORE_EXPORT void setScrollOffsetFromInternals(const ScrollOffset&amp;);
</ins><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT static LayoutPoint constrainScrollPositionForOverhang(const LayoutRect&amp; visibleContentRect, const LayoutSize&amp; totalContentsSize, const LayoutPoint&amp; scrollPosition, const LayoutPoint&amp; scrollOrigin, int headerHeight, int footetHeight);
</span><span class="cx">     LayoutPoint constrainScrollPositionForOverhang(const LayoutPoint&amp; scrollPosition);
</span><span class="lines">@@ -312,15 +324,15 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     WEBCORE_EXPORT virtual IntRect visibleContentRectInternal(VisibleContentRectIncludesScrollbars, VisibleContentRectBehavior) const;
</span><del>-    void scrollPositionChanged(const IntPoint&amp;);
</del><ins>+    void scrollPositionChanged(const ScrollPosition&amp;);
</ins><span class="cx">     
</span><span class="cx">     // NOTE: Only called from the ScrollAnimator.
</span><span class="cx">     friend class ScrollAnimator;
</span><del>-    void setScrollOffsetFromAnimation(const IntPoint&amp;);
</del><ins>+    void setScrollOffsetFromAnimation(const ScrollOffset&amp;);
</ins><span class="cx"> 
</span><span class="cx">     // This function should be overriden by subclasses to perform the actual
</span><span class="cx">     // scroll of the content.
</span><del>-    virtual void setScrollOffset(const IntPoint&amp;) = 0;
</del><ins>+    virtual void setScrollOffset(const ScrollOffset&amp;) = 0;
</ins><span class="cx"> 
</span><span class="cx">     mutable std::unique_ptr&lt;ScrollAnimator&gt; m_scrollAnimator;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderListBoxcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderListBox.cpp (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderListBox.cpp        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebCore/rendering/RenderListBox.cpp        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -608,7 +608,7 @@
</span><span class="cx">     return m_indexOffset;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RenderListBox::setScrollOffset(const IntPoint&amp; offset)
</del><ins>+void RenderListBox::setScrollOffset(const ScrollOffset&amp; offset)
</ins><span class="cx"> {
</span><span class="cx">     scrollTo(offset.y());
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderListBoxh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderListBox.h (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderListBox.h        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebCore/rendering/RenderListBox.h        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -111,7 +111,7 @@
</span><span class="cx">     // ScrollableArea interface.
</span><span class="cx">     virtual int scrollSize(ScrollbarOrientation) const override;
</span><span class="cx">     virtual int scrollPosition(Scrollbar*) const override;
</span><del>-    virtual void setScrollOffset(const IntPoint&amp;) override;
</del><ins>+    virtual void setScrollOffset(const ScrollOffset&amp;) override;
</ins><span class="cx">     virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&amp;) override;
</span><span class="cx">     virtual bool isActive() const override;
</span><span class="cx">     virtual bool isScrollCornerVisible() const override { return false; } // We don't support resize on list boxes yet. If we did these would have to change.
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebKit2/ChangeLog        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2016-01-01  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
+        Fix reload and programmatic scrolling in RTL documents
+        https://bugs.webkit.org/show_bug.cgi?id=152639
+
+        Reviewed by Zalan Bujtas.
+
+        Reloading a left-scrolled RTL document would cause the content to appear
+        at an odd offset, and programmatic sideways scrolls in RTL documents also
+        jumped to the wrong location.
+        
+        Fix by resolving offset/position confusion in ScrollableArea::scrollPositionChanged()
+        and the scrolling tree.
+        
+        ScrollableArea::scrollPositionChanged() was erroneously passing a scrollPosition
+        to setScrollOffset(). 
+        
+        ScrollingTreeFrameScrollingNode* were confused about offsets and positions. It
+        turns out that the layer position is just -scrollPosition, but minimumScrollPosition()
+        and maximumScrollPosition() need fixing to return positions, not offsets.
+        
+        ScrollingTreeFrameScrollingNode::viewToContentsOffset() was also doing incorrect
+        math with scrollOrigin, which was detected by a failing test.
+        
+        Add more logging to the Scrolling channel.
+
+        * WebProcess/Plugins/PDF/DeprecatedPDFPlugin.h:
+        * WebProcess/Plugins/PDF/DeprecatedPDFPlugin.mm:
+        (WebKit::PDFPlugin::setScrollOffset):
+
</ins><span class="cx"> 2016-01-01  Michael Catanzaro  &lt;mcatanzaro@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [SOUP] REGRESSION(r192761): Broke resource URIs for applications that use g_resource_load in a web extension
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessPluginsPDFDeprecatedPDFPluginh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/DeprecatedPDFPlugin.h (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/DeprecatedPDFPlugin.h        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/DeprecatedPDFPlugin.h        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -189,7 +189,7 @@
</span><span class="cx">     virtual bool isScrollableOrRubberbandable() override { return true; }
</span><span class="cx">     virtual bool hasScrollableOrRubberbandableAncestor() override { return true; }
</span><span class="cx">     virtual WebCore::IntRect scrollableAreaBoundingBox(bool* = nullptr) const override;
</span><del>-    virtual void setScrollOffset(const WebCore::IntPoint&amp;) override;
</del><ins>+    virtual void setScrollOffset(const WebCore::ScrollOffset&amp;) override;
</ins><span class="cx">     virtual void invalidateScrollbarRect(WebCore::Scrollbar*, const WebCore::IntRect&amp;) override;
</span><span class="cx">     virtual void invalidateScrollCornerRect(const WebCore::IntRect&amp;) override;
</span><span class="cx">     virtual WebCore::IntPoint lastKnownMousePosition() const override { return m_lastMousePositionInPluginCoordinates; }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessPluginsPDFDeprecatedPDFPluginmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Plugins/PDF/DeprecatedPDFPlugin.mm (194486 => 194487)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Plugins/PDF/DeprecatedPDFPlugin.mm        2016-01-02 04:44:16 UTC (rev 194486)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PDF/DeprecatedPDFPlugin.mm        2016-01-02 04:45:36 UTC (rev 194487)
</span><span class="lines">@@ -1538,7 +1538,7 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void PDFPlugin::setScrollOffset(const IntPoint&amp; offset)
</del><ins>+void PDFPlugin::setScrollOffset(const ScrollOffset&amp; offset)
</ins><span class="cx"> {
</span><span class="cx">     m_scrollOffset = IntSize(offset.x(), offset.y());
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>