<!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>[208409] 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/208409">208409</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2016-11-04 17:41:50 -0700 (Fri, 04 Nov 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Layout viewport wrong with RTL documents
https://bugs.webkit.org/show_bug.cgi?id=164434

Reviewed by Tim Horton.

Source/WebCore:

The layoutViewportRect was computed incorrectly in RTL documents, because
FrameView::unscaledMaximumScrollPosition() was wrong; it erroneously mapped
what it thought was a scrollOffset to a scrollPosition.

Unscaled scroll positions are in the same coordinate space as unscaledDocumentRect,
so we should not call scrollPositionFromOffset() in FrameView::unscaledMaximumScrollPosition().

Changed FrameView::unscaledMinimumScrollPosition() to also just grab the location of
unscaledDocumentRect, for symmetry.

Finally fixed the tiled scrolling indicator's viewport rect for zoomed RTL documents
by using the unscaled scroll origin.

Tests: fast/visual-viewport/rtl-nonzoomed-rects.html
       fast/visual-viewport/rtl-zoomed-rects.html

* page/FrameView.cpp:
(WebCore::FrameView::setLayoutViewportOrigin):
(WebCore::FrameView::unscaledScrollOrigin):
(WebCore::FrameView::unscaledMinimumScrollPosition):
(WebCore::FrameView::unscaledMaximumScrollPosition):
* page/FrameView.h:

LayoutTests:

* fast/visual-viewport/rtl-nonzoomed-rects-expected.txt: Added.
* fast/visual-viewport/rtl-nonzoomed-rects.html: Added.
* fast/visual-viewport/rtl-zoomed-rects-expected.txt: Added.
* fast/visual-viewport/rtl-zoomed-rects.html: Added.
* platform/ios-simulator/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt: Added.
* platform/ios-simulator/fast/visual-viewport/rtl-zoomed-rects-expected.txt: Added.
* platform/mac-wk1/fast/visual-viewport/rtl-zoomed-rects-expected.txt: Added. WK1 and RTL are weird.</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="#trunkSourceWebCorepageFrameViewh">trunk/Source/WebCore/page/FrameView.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastvisualviewportrtlnonzoomedrectsexpectedtxt">trunk/LayoutTests/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastvisualviewportrtlnonzoomedrectshtml">trunk/LayoutTests/fast/visual-viewport/rtl-nonzoomed-rects.html</a></li>
<li><a href="#trunkLayoutTestsfastvisualviewportrtlzoomedrectsexpectedtxt">trunk/LayoutTests/fast/visual-viewport/rtl-zoomed-rects-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastvisualviewportrtlzoomedrectshtml">trunk/LayoutTests/fast/visual-viewport/rtl-zoomed-rects.html</a></li>
<li><a href="#trunkLayoutTestsplatformiossimulatorfastvisualviewportrtlnonzoomedrectsexpectedtxt">trunk/LayoutTests/platform/ios-simulator/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt</a></li>
<li><a href="#trunkLayoutTestsplatformiossimulatorfastvisualviewportrtlzoomedrectsexpectedtxt">trunk/LayoutTests/platform/ios-simulator/fast/visual-viewport/rtl-zoomed-rects-expected.txt</a></li>
<li>trunk/LayoutTests/platform/mac-wk1/fast/visual-viewport/</li>
<li><a href="#trunkLayoutTestsplatformmacwk1fastvisualviewportrtlzoomedrectsexpectedtxt">trunk/LayoutTests/platform/mac-wk1/fast/visual-viewport/rtl-zoomed-rects-expected.txt</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (208408 => 208409)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-11-05 00:03:32 UTC (rev 208408)
+++ trunk/LayoutTests/ChangeLog        2016-11-05 00:41:50 UTC (rev 208409)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2016-11-04  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
+        Layout viewport wrong with RTL documents
+        https://bugs.webkit.org/show_bug.cgi?id=164434
+
+        Reviewed by Tim Horton.
+
+        * fast/visual-viewport/rtl-nonzoomed-rects-expected.txt: Added.
+        * fast/visual-viewport/rtl-nonzoomed-rects.html: Added.
+        * fast/visual-viewport/rtl-zoomed-rects-expected.txt: Added.
+        * fast/visual-viewport/rtl-zoomed-rects.html: Added.
+        * platform/ios-simulator/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt: Added.
+        * platform/ios-simulator/fast/visual-viewport/rtl-zoomed-rects-expected.txt: Added.
+        * platform/mac-wk1/fast/visual-viewport/rtl-zoomed-rects-expected.txt: Added. WK1 and RTL are weird.
+
</ins><span class="cx"> 2016-11-04  Wenson Hsieh  &lt;wenson_hsieh@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Safari does not emit composition end if blurred for dead key / Japanese IME
</span></span></pre></div>
<a id="trunkLayoutTestsfastvisualviewportrtlnonzoomedrectsexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt (0 => 208409)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt        2016-11-05 00:41:50 UTC (rev 208409)
</span><span class="lines">@@ -0,0 +1,23 @@
</span><ins>+This test scrolls the page and checks that the layout and visual viewports respond as expected.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:0,&quot;right&quot;:785,&quot;bottom&quot;:585,&quot;left&quot;:0,&quot;width&quot;:785,&quot;height&quot;:585}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:0,&quot;right&quot;:785,&quot;bottom&quot;:585,&quot;left&quot;:0,&quot;width&quot;:785,&quot;height&quot;:585}
+
+Scrolled to -475, 525
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:525,&quot;right&quot;:310,&quot;bottom&quot;:1110,&quot;left&quot;:-475,&quot;width&quot;:785,&quot;height&quot;:585}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:525,&quot;right&quot;:310,&quot;bottom&quot;:1110,&quot;left&quot;:-475,&quot;width&quot;:785,&quot;height&quot;:585}
+
+Scrolled to -100, 776
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:776,&quot;right&quot;:685,&quot;bottom&quot;:1361,&quot;left&quot;:-100,&quot;width&quot;:785,&quot;height&quot;:585}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:776,&quot;right&quot;:685,&quot;bottom&quot;:1361,&quot;left&quot;:-100,&quot;width&quot;:785,&quot;height&quot;:585}
+
+Scrolled to -50, 300
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:300,&quot;right&quot;:735,&quot;bottom&quot;:885,&quot;left&quot;:-50,&quot;width&quot;:785,&quot;height&quot;:585}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:300,&quot;right&quot;:735,&quot;bottom&quot;:885,&quot;left&quot;:-50,&quot;width&quot;:785,&quot;height&quot;:585}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastvisualviewportrtlnonzoomedrectshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/visual-viewport/rtl-nonzoomed-rects.html (0 => 208409)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/visual-viewport/rtl-nonzoomed-rects.html                                (rev 0)
+++ trunk/LayoutTests/fast/visual-viewport/rtl-nonzoomed-rects.html        2016-11-05 00:41:50 UTC (rev 208409)
</span><span class="lines">@@ -0,0 +1,61 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+
+&lt;html dir=&quot;rtl&quot;&gt;
+&lt;head&gt;
+    &lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+    &lt;style&gt;
+        body {
+            height: 2000px;
+            width: 2000px;
+        }
+    &lt;/style&gt;
+    &lt;script&gt;
+        description(&quot;This test scrolls the page and checks that the layout and visual viewports respond as expected.&quot;);
+
+        if (window.internals)
+            internals.settings.setVisualViewportEnabled(true);
+
+        window.jsTestIsAsync = true;
+
+        function doTest()
+        {
+            // Zooming may scroll the view away from the origin.
+            window.scrollTo(0, 0);
+
+            // Don't use shouldBeEqualToString() to avoid showing failures when correct output differs between platforms. 
+            evalAndLogResult(&quot;JSON.stringify(internals.layoutViewportRect())&quot;);
+            evalAndLogResult(&quot;JSON.stringify(internals.visualViewportRect())&quot;);
+
+            debug('');
+            window.scrollTo(-475, 525);
+            debug('Scrolled to ' + window.scrollX + ', ' + window.scrollY);
+
+            evalAndLogResult(&quot;JSON.stringify(internals.layoutViewportRect())&quot;);
+            evalAndLogResult(&quot;JSON.stringify(internals.visualViewportRect())&quot;);
+
+            debug('');
+            window.scrollTo(-100, 776);
+            debug('Scrolled to ' + window.scrollX + ', ' + window.scrollY);
+
+            evalAndLogResult(&quot;JSON.stringify(internals.layoutViewportRect())&quot;);
+            evalAndLogResult(&quot;JSON.stringify(internals.visualViewportRect())&quot;);
+
+            debug('');
+            window.scrollTo(-50, 300);
+            debug('Scrolled to ' + window.scrollX + ', ' + window.scrollY);
+
+            evalAndLogResult(&quot;JSON.stringify(internals.layoutViewportRect())&quot;);
+            evalAndLogResult(&quot;JSON.stringify(internals.visualViewportRect())&quot;);
+
+            window.scrollTo(0, 0);
+
+            finishJSTest();
+        }
+        
+        window.addEventListener('load', doTest, false);
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastvisualviewportrtlzoomedrectsexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/visual-viewport/rtl-zoomed-rects-expected.txt (0 => 208409)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/visual-viewport/rtl-zoomed-rects-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/visual-viewport/rtl-zoomed-rects-expected.txt        2016-11-05 00:41:50 UTC (rev 208409)
</span><span class="lines">@@ -0,0 +1,23 @@
</span><ins>+This test zooms and scrolls the page and checks that the layout and visual viewports respond as expected.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:0,&quot;right&quot;:785,&quot;bottom&quot;:585,&quot;left&quot;:0,&quot;width&quot;:785,&quot;height&quot;:585}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:0,&quot;right&quot;:392.5,&quot;bottom&quot;:292.5,&quot;left&quot;:0,&quot;width&quot;:392.5,&quot;height&quot;:292.5}
+
+Scrolled to -475, 525
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:232.5,&quot;right&quot;:310,&quot;bottom&quot;:817.5,&quot;left&quot;:-475,&quot;width&quot;:785,&quot;height&quot;:585}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:525,&quot;right&quot;:-82.5,&quot;bottom&quot;:817.5,&quot;left&quot;:-475,&quot;width&quot;:392.5,&quot;height&quot;:292.5}
+
+Scrolled to -100, 776
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:483.5,&quot;right&quot;:310,&quot;bottom&quot;:1068.5,&quot;left&quot;:-475,&quot;width&quot;:785,&quot;height&quot;:585}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:776,&quot;right&quot;:292.5,&quot;bottom&quot;:1068.5,&quot;left&quot;:-100,&quot;width&quot;:392.5,&quot;height&quot;:292.5}
+
+Scrolled to -50, 300
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:300,&quot;right&quot;:342.5,&quot;bottom&quot;:885,&quot;left&quot;:-442.5,&quot;width&quot;:785,&quot;height&quot;:585}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:300,&quot;right&quot;:342.5,&quot;bottom&quot;:592.5,&quot;left&quot;:-50,&quot;width&quot;:392.5,&quot;height&quot;:292.5}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastvisualviewportrtlzoomedrectshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/visual-viewport/rtl-zoomed-rects.html (0 => 208409)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/visual-viewport/rtl-zoomed-rects.html                                (rev 0)
+++ trunk/LayoutTests/fast/visual-viewport/rtl-zoomed-rects.html        2016-11-05 00:41:50 UTC (rev 208409)
</span><span class="lines">@@ -0,0 +1,78 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+
+&lt;html dir=&quot;rtl&quot;&gt;
+&lt;head&gt;
+    &lt;style&gt;
+        body {
+            height: 2000px;
+            width: 2000px;
+        }
+    &lt;/style&gt;
+    &lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+    &lt;script&gt;
+        description(&quot;This test zooms and scrolls the page and checks that the layout and visual viewports respond as expected.&quot;);
+
+        if (window.internals)
+            internals.settings.setVisualViewportEnabled(true);
+
+        window.jsTestIsAsync = true;
+
+        function doAfterZooming()
+        {
+            window.scrollTo(0, 0);
+
+            evalAndLogResult(&quot;JSON.stringify(internals.layoutViewportRect())&quot;);
+            evalAndLogResult(&quot;JSON.stringify(internals.visualViewportRect())&quot;);
+
+            debug('');
+            window.scrollTo(-475, 525);
+            debug('Scrolled to ' + window.scrollX + ', ' + window.scrollY);
+
+            evalAndLogResult(&quot;JSON.stringify(internals.layoutViewportRect())&quot;);
+            evalAndLogResult(&quot;JSON.stringify(internals.visualViewportRect())&quot;);
+
+            debug('');
+            window.scrollTo(-100, 776);
+            debug('Scrolled to ' + window.scrollX + ', ' + window.scrollY);
+
+            evalAndLogResult(&quot;JSON.stringify(internals.layoutViewportRect())&quot;);
+            evalAndLogResult(&quot;JSON.stringify(internals.visualViewportRect())&quot;);
+
+            debug('');
+            window.scrollTo(-50, 300);
+            debug('Scrolled to ' + window.scrollX + ', ' + window.scrollY);
+
+            evalAndLogResult(&quot;JSON.stringify(internals.layoutViewportRect())&quot;);
+            evalAndLogResult(&quot;JSON.stringify(internals.visualViewportRect())&quot;);
+
+            window.scrollTo(0, 0);
+
+            finishJSTest();
+        }
+        
+        function getUIScript()
+        {
+            return `(function() {
+                uiController.zoomToScale(2, function() {
+                    uiController.uiScriptComplete(uiController.zoomScale);
+                });
+            })();`;
+        }
+
+        function doTest()
+        {
+            if (!window.testRunner)
+                return;
+
+            testRunner.runUIScript(getUIScript(), function(zoomScale) {
+                doAfterZooming();
+            });
+        }
+        
+        window.addEventListener('load', doTest, false);
+    &lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformiossimulatorfastvisualviewportrtlnonzoomedrectsexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/platform/ios-simulator/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt (0 => 208409)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/ios-simulator/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt                                (rev 0)
+++ trunk/LayoutTests/platform/ios-simulator/fast/visual-viewport/rtl-nonzoomed-rects-expected.txt        2016-11-05 00:41:50 UTC (rev 208409)
</span><span class="lines">@@ -0,0 +1,23 @@
</span><ins>+This test scrolls the page and checks that the layout and visual viewports respond as expected.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:0,&quot;right&quot;:800,&quot;bottom&quot;:600,&quot;left&quot;:0,&quot;width&quot;:800,&quot;height&quot;:600}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:0,&quot;right&quot;:800,&quot;bottom&quot;:600,&quot;left&quot;:0,&quot;width&quot;:800,&quot;height&quot;:600}
+
+Scrolled to -475, 525
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:525,&quot;right&quot;:325,&quot;bottom&quot;:1125,&quot;left&quot;:-475,&quot;width&quot;:800,&quot;height&quot;:600}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:525,&quot;right&quot;:325,&quot;bottom&quot;:1125,&quot;left&quot;:-475,&quot;width&quot;:800,&quot;height&quot;:600}
+
+Scrolled to -100, 776
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:776,&quot;right&quot;:700,&quot;bottom&quot;:1376,&quot;left&quot;:-100,&quot;width&quot;:800,&quot;height&quot;:600}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:776,&quot;right&quot;:700,&quot;bottom&quot;:1376,&quot;left&quot;:-100,&quot;width&quot;:800,&quot;height&quot;:600}
+
+Scrolled to -50, 300
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:300,&quot;right&quot;:750,&quot;bottom&quot;:900,&quot;left&quot;:-50,&quot;width&quot;:800,&quot;height&quot;:600}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:300,&quot;right&quot;:750,&quot;bottom&quot;:900,&quot;left&quot;:-50,&quot;width&quot;:800,&quot;height&quot;:600}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformiossimulatorfastvisualviewportrtlzoomedrectsexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/platform/ios-simulator/fast/visual-viewport/rtl-zoomed-rects-expected.txt (0 => 208409)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/ios-simulator/fast/visual-viewport/rtl-zoomed-rects-expected.txt                                (rev 0)
+++ trunk/LayoutTests/platform/ios-simulator/fast/visual-viewport/rtl-zoomed-rects-expected.txt        2016-11-05 00:41:50 UTC (rev 208409)
</span><span class="lines">@@ -0,0 +1,23 @@
</span><ins>+This test zooms and scrolls the page and checks that the layout and visual viewports respond as expected.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:0,&quot;right&quot;:800,&quot;bottom&quot;:600,&quot;left&quot;:0,&quot;width&quot;:800,&quot;height&quot;:600}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:0,&quot;right&quot;:400,&quot;bottom&quot;:300,&quot;left&quot;:0,&quot;width&quot;:400,&quot;height&quot;:300}
+
+Scrolled to -475, 525
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:225,&quot;right&quot;:325,&quot;bottom&quot;:825,&quot;left&quot;:-475,&quot;width&quot;:800,&quot;height&quot;:600}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:525,&quot;right&quot;:-75,&quot;bottom&quot;:825,&quot;left&quot;:-475,&quot;width&quot;:400,&quot;height&quot;:300}
+
+Scrolled to -100, 776
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:476,&quot;right&quot;:325,&quot;bottom&quot;:1076,&quot;left&quot;:-475,&quot;width&quot;:800,&quot;height&quot;:600}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:776,&quot;right&quot;:300,&quot;bottom&quot;:1076,&quot;left&quot;:-100,&quot;width&quot;:400,&quot;height&quot;:300}
+
+Scrolled to -50, 300
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:300,&quot;right&quot;:350,&quot;bottom&quot;:900,&quot;left&quot;:-450,&quot;width&quot;:800,&quot;height&quot;:600}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:300,&quot;right&quot;:350,&quot;bottom&quot;:600,&quot;left&quot;:-50,&quot;width&quot;:400,&quot;height&quot;:300}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk1fastvisualviewportrtlzoomedrectsexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/platform/mac-wk1/fast/visual-viewport/rtl-zoomed-rects-expected.txt (0 => 208409)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk1/fast/visual-viewport/rtl-zoomed-rects-expected.txt                                (rev 0)
+++ trunk/LayoutTests/platform/mac-wk1/fast/visual-viewport/rtl-zoomed-rects-expected.txt        2016-11-05 00:41:50 UTC (rev 208409)
</span><span class="lines">@@ -0,0 +1,23 @@
</span><ins>+This test zooms and scrolls the page and checks that the layout and visual viewports respond as expected.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:0,&quot;right&quot;:392.5,&quot;bottom&quot;:585,&quot;left&quot;:-392.5,&quot;width&quot;:785,&quot;height&quot;:585}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:0,&quot;right&quot;:392.5,&quot;bottom&quot;:292.5,&quot;left&quot;:0,&quot;width&quot;:392.5,&quot;height&quot;:292.5}
+
+Scrolled to -475, 525
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:232.5,&quot;right&quot;:310,&quot;bottom&quot;:817.5,&quot;left&quot;:-475,&quot;width&quot;:785,&quot;height&quot;:585}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:525,&quot;right&quot;:-82.5,&quot;bottom&quot;:817.5,&quot;left&quot;:-475,&quot;width&quot;:392.5,&quot;height&quot;:292.5}
+
+Scrolled to -100, 776
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:483.5,&quot;right&quot;:310,&quot;bottom&quot;:1068.5,&quot;left&quot;:-475,&quot;width&quot;:785,&quot;height&quot;:585}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:776,&quot;right&quot;:292.5,&quot;bottom&quot;:1068.5,&quot;left&quot;:-100,&quot;width&quot;:392.5,&quot;height&quot;:292.5}
+
+Scrolled to -50, 300
+JSON.stringify(internals.layoutViewportRect()) is {&quot;top&quot;:300,&quot;right&quot;:342.5,&quot;bottom&quot;:885,&quot;left&quot;:-442.5,&quot;width&quot;:785,&quot;height&quot;:585}
+JSON.stringify(internals.visualViewportRect()) is {&quot;top&quot;:300,&quot;right&quot;:342.5,&quot;bottom&quot;:592.5,&quot;left&quot;:-50,&quot;width&quot;:392.5,&quot;height&quot;:292.5}
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (208408 => 208409)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-11-05 00:03:32 UTC (rev 208408)
+++ trunk/Source/WebCore/ChangeLog        2016-11-05 00:41:50 UTC (rev 208409)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2016-11-04  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
+        Layout viewport wrong with RTL documents
+        https://bugs.webkit.org/show_bug.cgi?id=164434
+
+        Reviewed by Tim Horton.
+
+        The layoutViewportRect was computed incorrectly in RTL documents, because 
+        FrameView::unscaledMaximumScrollPosition() was wrong; it erroneously mapped
+        what it thought was a scrollOffset to a scrollPosition.
+
+        Unscaled scroll positions are in the same coordinate space as unscaledDocumentRect,
+        so we should not call scrollPositionFromOffset() in FrameView::unscaledMaximumScrollPosition().
+
+        Changed FrameView::unscaledMinimumScrollPosition() to also just grab the location of
+        unscaledDocumentRect, for symmetry.
+
+        Finally fixed the tiled scrolling indicator's viewport rect for zoomed RTL documents
+        by using the unscaled scroll origin.
+
+        Tests: fast/visual-viewport/rtl-nonzoomed-rects.html
+               fast/visual-viewport/rtl-zoomed-rects.html
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::setLayoutViewportOrigin):
+        (WebCore::FrameView::unscaledScrollOrigin):
+        (WebCore::FrameView::unscaledMinimumScrollPosition):
+        (WebCore::FrameView::unscaledMaximumScrollPosition):
+        * page/FrameView.h:
+
</ins><span class="cx"> 2016-11-04  Sam Weinig  &lt;sam@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         [WebIDL] Add support for modern callback syntax
</span></span></pre></div>
<a id="trunkSourceWebCorepageFrameViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FrameView.cpp (208408 => 208409)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FrameView.cpp        2016-11-05 00:03:32 UTC (rev 208408)
+++ trunk/Source/WebCore/page/FrameView.cpp        2016-11-05 00:41:50 UTC (rev 208409)
</span><span class="lines">@@ -1821,8 +1821,11 @@
</span><span class="cx">     m_layoutViewportOrigin = origin;
</span><span class="cx">     setViewportConstrainedObjectsNeedLayout();
</span><span class="cx">     
</span><del>-    if (TiledBacking* tiledBacking = this-&gt;tiledBacking())
-        tiledBacking-&gt;setLayoutViewportRect(FloatRect(layoutViewportRect()));
</del><ins>+    if (TiledBacking* tiledBacking = this-&gt;tiledBacking()) {
+        FloatRect layoutViewport = layoutViewportRect();
+        layoutViewport.moveBy(unscaledScrollOrigin()); // tiledBacking deals in top-left relative coordinates.
+        tiledBacking-&gt;setLayoutViewportRect(layoutViewport);
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void FrameView::updateLayoutViewport()
</span><span class="lines">@@ -1854,6 +1857,14 @@
</span><span class="cx">     return unscaledMaximumScrollPosition();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+IntPoint FrameView::unscaledScrollOrigin() const
+{
+    if (RenderView* renderView = this-&gt;renderView())
+        return -renderView-&gt;unscaledDocumentRect().location(); // Akin to code in adjustViewSize().
+
+    return { };
+}
+
</ins><span class="cx"> // Size of initial containing block, anchored at scroll position, in document coordinates (unchanged by scale factor).
</span><span class="cx"> LayoutRect FrameView::layoutViewportRect() const
</span><span class="cx"> {
</span><span class="lines">@@ -2038,16 +2049,14 @@
</span><span class="cx"> {
</span><span class="cx">     if (RenderView* renderView = this-&gt;renderView()) {
</span><span class="cx">         IntRect unscaledDocumentRect = renderView-&gt;unscaledDocumentRect();
</span><ins>+        ScrollPosition minimumPosition = unscaledDocumentRect.location() - visibleSize();
</ins><span class="cx"> 
</span><del>-        IntPoint unscaledScrollOrigin = -unscaledDocumentRect.location();
-        ScrollPosition minimumPosition = scrollPositionFromOffset(ScrollOffset(), toIntSize(unscaledScrollOrigin));
-
</del><span class="cx">         if (frame().isMainFrame() &amp;&amp; m_scrollPinningBehavior == PinToBottom)
</span><span class="cx">             minimumPosition.setY(unscaledMaximumScrollPosition().y());
</span><span class="cx"> 
</span><span class="cx">         return minimumPosition;
</span><span class="cx">     }
</span><del>-    
</del><ins>+
</ins><span class="cx">     return minimumScrollPosition();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -2056,11 +2065,7 @@
</span><span class="cx">     if (RenderView* renderView = this-&gt;renderView()) {
</span><span class="cx">         IntRect unscaledDocumentRect = renderView-&gt;unscaledDocumentRect();
</span><span class="cx">         unscaledDocumentRect.expand(0, headerHeight() + footerHeight());
</span><del>-        
-        // Max scroll position is size - visible - scrollOrigin, which is max - visible.
-        ScrollOffset maximumOffset = unscaledDocumentRect.maxXMaxYCorner() - visibleSize();
-        IntPoint unscaledScrollOrigin = -unscaledDocumentRect.location();
-        ScrollPosition maximumPosition = scrollPositionFromOffset(maximumOffset, toIntSize(unscaledScrollOrigin));
</del><ins>+        ScrollPosition maximumPosition = unscaledDocumentRect.maxXMaxYCorner() - visibleSize();
</ins><span class="cx"> 
</span><span class="cx">         if (frame().isMainFrame() &amp;&amp; m_scrollPinningBehavior == PinToTop)
</span><span class="cx">             maximumPosition.setY(unscaledMinimumScrollPosition().y());
</span></span></pre></div>
<a id="trunkSourceWebCorepageFrameViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FrameView.h (208408 => 208409)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FrameView.h        2016-11-05 00:03:32 UTC (rev 208408)
+++ trunk/Source/WebCore/page/FrameView.h        2016-11-05 00:41:50 UTC (rev 208409)
</span><span class="lines">@@ -250,6 +250,8 @@
</span><span class="cx">     ScrollPosition unscaledMinimumScrollPosition() const;
</span><span class="cx">     ScrollPosition unscaledMaximumScrollPosition() const;
</span><span class="cx"> 
</span><ins>+    IntPoint unscaledScrollOrigin() const;
+
</ins><span class="cx">     void setLayoutViewportOrigin(LayoutPoint);
</span><span class="cx">     LayoutPoint layoutViewportOrigin() const { return m_layoutViewportOrigin; }
</span><span class="cx">     
</span></span></pre>
</div>
</div>

</body>
</html>