<!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>[244887] tags/Safari-608.1.20.1</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/244887">244887</a></dd>
<dt>Author</dt> <dd>alancoon@apple.com</dd>
<dt>Date</dt> <dd>2019-05-02 14:08:40 -0700 (Thu, 02 May 2019)</dd>
</dl>

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

    [iOS] Element::focus and Element::scrollIntoView do not clamp scroll positions
    https://bugs.webkit.org/show_bug.cgi?id=197211

    Reviewed by Simon Fraser.

    Source/WebCore:

    Fixed the bug that Element::focus and Element::scrollIntoView were not clamping scroll offsets,
    which causes scrollTop etc... to return a bogus negative scrolling offset.

    Unfortunately, we can't just use FrameView's ScrollableArea::constrainScrollPosition since
    scrollRectToVisible relies on the visible rect being expanded by the content insets in order to scroll to
    a position within the content insets of UIScrollView; e.g. revealing the top of the page as the center.
    We manually expand minimumScrollPosition() and maximumScrollPosition() by the content insets instead.

    Tests: fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html
           fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html
           fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html

    * rendering/RenderLayer.cpp:
    (WebCore::RenderLayer::scrollRectToVisible):

    LayoutTests:

    Added tests for scrolling via Element.prototype.focus and Element.prototype.scrollIntoView.

    * fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top-expected.txt: Added.
    * fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html: Added.
    * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top-expected.txt: Added.
    * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html: Added.
    * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top-expected.txt: Added.
    * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html: Added.
    * platform/ios-wk2/fast/dom/focus-contenteditable-expected.txt: Rebaselined the output now that the scroll position
    is properly clamped.
    * platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/elementFromPoint-expected.txt: Rebaselined as one
    more test case is passing.

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

<h3>Modified Paths</h3>
<ul>
<li><a href="#tagsSafari6081201LayoutTestsChangeLog">tags/Safari-608.1.20.1/LayoutTests/ChangeLog</a></li>
<li><a href="#tagsSafari6081201LayoutTestsplatformioswk2fastdomfocuscontenteditableexpectedtxt">tags/Safari-608.1.20.1/LayoutTests/platform/ios-wk2/fast/dom/focus-contenteditable-expected.txt</a></li>
<li><a href="#tagsSafari6081201LayoutTestsplatformioswk2importedw3cwebplatformtestscsscssomviewelementFromPointexpectedtxt">tags/Safari-608.1.20.1/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/elementFromPoint-expected.txt</a></li>
<li><a href="#tagsSafari6081201SourceWebCoreChangeLog">tags/Safari-608.1.20.1/Source/WebCore/ChangeLog</a></li>
<li><a href="#tagsSafari6081201SourceWebCorerenderingRenderLayercpp">tags/Safari-608.1.20.1/Source/WebCore/rendering/RenderLayer.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#tagsSafari6081201LayoutTestsfastscrollingiosprogrammaticscrollviafocusshouldclamptopexpectedtxt">tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top-expected.txt</a></li>
<li><a href="#tagsSafari6081201LayoutTestsfastscrollingiosprogrammaticscrollviafocusshouldclamptophtml">tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html</a></li>
<li><a href="#tagsSafari6081201LayoutTestsfastscrollingiosprogrammaticscrollviascrollIntoViewinsideiframeshouldclamptopexpectedtxt">tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top-expected.txt</a></li>
<li><a href="#tagsSafari6081201LayoutTestsfastscrollingiosprogrammaticscrollviascrollIntoViewinsideiframeshouldclamptophtml">tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html</a></li>
<li><a href="#tagsSafari6081201LayoutTestsfastscrollingiosprogrammaticscrollviascrollIntoViewshouldclamptopexpectedtxt">tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top-expected.txt</a></li>
<li><a href="#tagsSafari6081201LayoutTestsfastscrollingiosprogrammaticscrollviascrollIntoViewshouldclamptophtml">tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="tagsSafari6081201LayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: tags/Safari-608.1.20.1/LayoutTests/ChangeLog (244886 => 244887)</h4>
<pre class="diff"><span>
<span class="info">--- tags/Safari-608.1.20.1/LayoutTests/ChangeLog     2019-05-02 21:08:35 UTC (rev 244886)
+++ tags/Safari-608.1.20.1/LayoutTests/ChangeLog        2019-05-02 21:08:40 UTC (rev 244887)
</span><span class="lines">@@ -1,5 +1,69 @@
</span><span class="cx"> 2019-05-02  Alan Coon  <alancoon@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r244851. rdar://problem/49784711
+
+    [iOS] Element::focus and Element::scrollIntoView do not clamp scroll positions
+    https://bugs.webkit.org/show_bug.cgi?id=197211
+    
+    Reviewed by Simon Fraser.
+    
+    Source/WebCore:
+    
+    Fixed the bug that Element::focus and Element::scrollIntoView were not clamping scroll offsets,
+    which causes scrollTop etc... to return a bogus negative scrolling offset.
+    
+    Unfortunately, we can't just use FrameView's ScrollableArea::constrainScrollPosition since
+    scrollRectToVisible relies on the visible rect being expanded by the content insets in order to scroll to
+    a position within the content insets of UIScrollView; e.g. revealing the top of the page as the center.
+    We manually expand minimumScrollPosition() and maximumScrollPosition() by the content insets instead.
+    
+    Tests: fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html
+           fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html
+           fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html
+    
+    * rendering/RenderLayer.cpp:
+    (WebCore::RenderLayer::scrollRectToVisible):
+    
+    LayoutTests:
+    
+    Added tests for scrolling via Element.prototype.focus and Element.prototype.scrollIntoView.
+    
+    * fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top-expected.txt: Added.
+    * fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html: Added.
+    * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top-expected.txt: Added.
+    * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html: Added.
+    * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top-expected.txt: Added.
+    * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html: Added.
+    * platform/ios-wk2/fast/dom/focus-contenteditable-expected.txt: Rebaselined the output now that the scroll position
+    is properly clamped.
+    * platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/elementFromPoint-expected.txt: Rebaselined as one
+    more test case is passing.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244851 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-05-01  Ryosuke Niwa  <rniwa@webkit.org>
+
+            [iOS] Element::focus and Element::scrollIntoView do not clamp scroll positions
+            https://bugs.webkit.org/show_bug.cgi?id=197211
+
+            Reviewed by Simon Fraser.
+
+            Added tests for scrolling via Element.prototype.focus and Element.prototype.scrollIntoView.
+
+            * fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top-expected.txt: Added.
+            * fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html: Added.
+            * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top-expected.txt: Added.
+            * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html: Added.
+            * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top-expected.txt: Added.
+            * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html: Added.
+            * platform/ios-wk2/fast/dom/focus-contenteditable-expected.txt: Rebaselined the output now that the scroll position
+            is properly clamped.
+            * platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/elementFromPoint-expected.txt: Rebaselined as one
+            more test case is passing.
+
+2019-05-02  Alan Coon  <alancoon@apple.com>
+
</ins><span class="cx">         Cherry-pick r244849. rdar://problem/50063091
</span><span class="cx"> 
</span><span class="cx">     [iOS] Add a version of viewport shrink-to-fit heuristics that preserves page layout
</span></span></pre></div>
<a id="tagsSafari6081201LayoutTestsfastscrollingiosprogrammaticscrollviafocusshouldclamptopexpectedtxt"></a>
<div class="addfile"><h4>Added: tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top-expected.txt (0 => 244887)</h4>
<pre class="diff"><span>
<span class="info">--- tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top-expected.txt                                (rev 0)
+++ tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top-expected.txt   2019-05-02 21:08:40 UTC (rev 244887)
</span><span class="lines">@@ -0,0 +1,13 @@
</span><ins>+This tests programming scrolling via element.focus to an element position well above the viewport top
+WebKit should clamp the scroll top to 0px.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.documentElement.scrollTop is 0
+PASS visualViewport.pageTop is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+hi
+
</ins></span></pre></div>
<a id="tagsSafari6081201LayoutTestsfastscrollingiosprogrammaticscrollviafocusshouldclamptophtml"></a>
<div class="addfile"><h4>Added: tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html (0 => 244887)</h4>
<pre class="diff"><span>
<span class="info">--- tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html                                (rev 0)
+++ tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html   2019-05-02 21:08:40 UTC (rev 244887)
</span><span class="lines">@@ -0,0 +1,20 @@
</span><ins>+<!DOCTYPE html><!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<head>
+<meta name="viewport" content="width=device-width, initial-scale=1">
+</head>
+<body>
+<div style="position: absolute; top:-1000px;" id="hiddenEditor" contenteditable>hi<br></div>
+<script src="../../../resources/js-test.js"></script>
+<script>
+
+description(`This tests programming scrolling via element.focus to an element position well above the viewport top<br>
+WebKit should clamp the scroll top to 0px.`);
+
+hiddenEditor.focus();
+shouldBe('document.documentElement.scrollTop', '0');
+shouldBe('visualViewport.pageTop', '0');
+
+</script>
+</body>
+</html>
</ins></span></pre></div>
<a id="tagsSafari6081201LayoutTestsfastscrollingiosprogrammaticscrollviascrollIntoViewinsideiframeshouldclamptopexpectedtxt"></a>
<div class="addfile"><h4>Added: tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top-expected.txt (0 => 244887)</h4>
<pre class="diff"><span>
<span class="info">--- tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top-expected.txt                         (rev 0)
+++ tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top-expected.txt    2019-05-02 21:08:40 UTC (rev 244887)
</span><span class="lines">@@ -0,0 +1,15 @@
</span><ins>+This tests programming scrolling via element.scrollIntoView to an element inside an iframe position well above the viewport top
+WebKit should clamp the scroll top to 0px.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.documentElement.scrollTop is 0
+PASS visualViewport.pageTop is 0
+PASS iframe.contentDocument.documentElement.scrollTop is 0
+PASS iframe.contentWindow.visualViewport.pageTop > 900 is true
+PASS iframe.contentWindow.visualViewport.pageTop is target.offsetTop + target.offsetHeight - iframe.clientHeight
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="tagsSafari6081201LayoutTestsfastscrollingiosprogrammaticscrollviascrollIntoViewinsideiframeshouldclamptophtml"></a>
<div class="addfile"><h4>Added: tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html (0 => 244887)</h4>
<pre class="diff"><span>
<span class="info">--- tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html                         (rev 0)
+++ tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html    2019-05-02 21:08:40 UTC (rev 244887)
</span><span class="lines">@@ -0,0 +1,33 @@
</span><ins>+<!DOCTYPE html><!-- webkit-test-runner [ useFlexibleViewport=true internal:AsyncFrameScrollingEnabled=true ] -->
+<html>
+<head>
+<meta name="viewport" content="width=device-width, initial-scale=1">
+</head>
+<body>
+<script src="../../../resources/js-test.js"></script>
+<script>
+
+if (window.internals)
+    internals.settings.setAsyncFrameScrollingEnabled(true);
+
+description(`This tests programming scrolling via element.scrollIntoView to an element inside an iframe position well above the viewport top<br>
+WebKit should clamp the scroll top to 0px.`);
+
+const iframe = document.createElement('iframe');
+document.body.append(iframe);
+iframe.style.position = 'absolute';
+iframe.style.top = '-1000px';
+iframe.style.height = '1050px';
+iframe.contentDocument.body.innerHTML = '<div id="target" style="position: absolute; top:2000px; height: 20px;">some content</div>';
+const target = iframe.contentWindow.target;
+
+target.scrollIntoView({block: 'end'});
+shouldBe('document.documentElement.scrollTop', '0');
+shouldBe('visualViewport.pageTop', '0');
+shouldBe('iframe.contentDocument.documentElement.scrollTop', '0');
+shouldBeTrue('iframe.contentWindow.visualViewport.pageTop > 900');
+shouldBe('iframe.contentWindow.visualViewport.pageTop', 'target.offsetTop + target.offsetHeight - iframe.clientHeight');
+
+</script>
+</body>
+</html>
</ins></span></pre></div>
<a id="tagsSafari6081201LayoutTestsfastscrollingiosprogrammaticscrollviascrollIntoViewshouldclamptopexpectedtxt"></a>
<div class="addfile"><h4>Added: tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top-expected.txt (0 => 244887)</h4>
<pre class="diff"><span>
<span class="info">--- tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top-expected.txt                               (rev 0)
+++ tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top-expected.txt  2019-05-02 21:08:40 UTC (rev 244887)
</span><span class="lines">@@ -0,0 +1,12 @@
</span><ins>+This tests programming scrolling via element.scrollIntoView to an element position well above the viewport top
+WebKit should clamp the scroll top to 0px.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.documentElement.scrollTop is 0
+PASS visualViewport.pageTop is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+some content
</ins></span></pre></div>
<a id="tagsSafari6081201LayoutTestsfastscrollingiosprogrammaticscrollviascrollIntoViewshouldclamptophtml"></a>
<div class="addfile"><h4>Added: tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html (0 => 244887)</h4>
<pre class="diff"><span>
<span class="info">--- tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html                               (rev 0)
+++ tags/Safari-608.1.20.1/LayoutTests/fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html  2019-05-02 21:08:40 UTC (rev 244887)
</span><span class="lines">@@ -0,0 +1,20 @@
</span><ins>+<!DOCTYPE html><!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<head>
+<meta name="viewport" content="width=device-width, initial-scale=1">
+</head>
+<body>
+<div id="target" style="position: absolute; top:-1000px;">some content</div>
+<script src="../../../resources/js-test.js"></script>
+<script>
+
+description(`This tests programming scrolling via element.scrollIntoView to an element position well above the viewport top<br>
+WebKit should clamp the scroll top to 0px.`);
+
+target.scrollIntoView();
+shouldBe('document.documentElement.scrollTop', '0');
+shouldBe('visualViewport.pageTop', '0');
+
+</script>
+</body>
+</html>
</ins></span></pre></div>
<a id="tagsSafari6081201LayoutTestsplatformioswk2fastdomfocuscontenteditableexpectedtxt"></a>
<div class="modfile"><h4>Modified: tags/Safari-608.1.20.1/LayoutTests/platform/ios-wk2/fast/dom/focus-contenteditable-expected.txt (244886 => 244887)</h4>
<pre class="diff"><span>
<span class="info">--- tags/Safari-608.1.20.1/LayoutTests/platform/ios-wk2/fast/dom/focus-contenteditable-expected.txt  2019-05-02 21:08:35 UTC (rev 244886)
+++ tags/Safari-608.1.20.1/LayoutTests/platform/ios-wk2/fast/dom/focus-contenteditable-expected.txt     2019-05-02 21:08:40 UTC (rev 244887)
</span><span class="lines">@@ -18,4 +18,4 @@
</span><span class="cx">           text run at (0,0) width 78: "Test Passed."
</span><span class="cx">       RenderBlock {DIV} at (0,886) size 784x0
</span><span class="cx"> caret: position 0 of child 0 {#text} of child 5 {DIV} of body
</span><del>-scrolled to 0,561
</del><ins>+scrolled to 0,282
</ins></span></pre></div>
<a id="tagsSafari6081201LayoutTestsplatformioswk2importedw3cwebplatformtestscsscssomviewelementFromPointexpectedtxt"></a>
<div class="modfile"><h4>Modified: tags/Safari-608.1.20.1/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/elementFromPoint-expected.txt (244886 => 244887)</h4>
<pre class="diff"><span>
<span class="info">--- tags/Safari-608.1.20.1/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/elementFromPoint-expected.txt 2019-05-02 21:08:35 UTC (rev 244886)
+++ tags/Safari-608.1.20.1/LayoutTests/platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/elementFromPoint-expected.txt    2019-05-02 21:08:40 UTC (rev 244887)
</span><span class="lines">@@ -17,5 +17,5 @@
</span><span class="cx"> PASS No viewport available 
</span><span class="cx"> FAIL Image Maps assert_equals: Should have returned the area element expected Element node <area id="rectG" shape="rect" coords="0,0,90,100" href="#... but got Element node <html><head><title>cssom-view - elementFromPoint</title>
</span><span class="cx"> ...
</span><del>-FAIL Fieldsets assert_equals: The fieldset should not cover up the div it doesn't even overlap expected Element node <div id="fieldset-div" class="size" style="position: abso... but got null
</del><ins>+PASS Fieldsets 
</ins><span class="cx"> 
</span></span></pre></div>
<a id="tagsSafari6081201SourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: tags/Safari-608.1.20.1/Source/WebCore/ChangeLog (244886 => 244887)</h4>
<pre class="diff"><span>
<span class="info">--- tags/Safari-608.1.20.1/Source/WebCore/ChangeLog  2019-05-02 21:08:35 UTC (rev 244886)
+++ tags/Safari-608.1.20.1/Source/WebCore/ChangeLog     2019-05-02 21:08:40 UTC (rev 244887)
</span><span class="lines">@@ -1,5 +1,71 @@
</span><span class="cx"> 2019-05-02  Alan Coon  <alancoon@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r244851. rdar://problem/49784711
+
+    [iOS] Element::focus and Element::scrollIntoView do not clamp scroll positions
+    https://bugs.webkit.org/show_bug.cgi?id=197211
+    
+    Reviewed by Simon Fraser.
+    
+    Source/WebCore:
+    
+    Fixed the bug that Element::focus and Element::scrollIntoView were not clamping scroll offsets,
+    which causes scrollTop etc... to return a bogus negative scrolling offset.
+    
+    Unfortunately, we can't just use FrameView's ScrollableArea::constrainScrollPosition since
+    scrollRectToVisible relies on the visible rect being expanded by the content insets in order to scroll to
+    a position within the content insets of UIScrollView; e.g. revealing the top of the page as the center.
+    We manually expand minimumScrollPosition() and maximumScrollPosition() by the content insets instead.
+    
+    Tests: fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html
+           fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html
+           fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html
+    
+    * rendering/RenderLayer.cpp:
+    (WebCore::RenderLayer::scrollRectToVisible):
+    
+    LayoutTests:
+    
+    Added tests for scrolling via Element.prototype.focus and Element.prototype.scrollIntoView.
+    
+    * fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top-expected.txt: Added.
+    * fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html: Added.
+    * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top-expected.txt: Added.
+    * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html: Added.
+    * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top-expected.txt: Added.
+    * fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html: Added.
+    * platform/ios-wk2/fast/dom/focus-contenteditable-expected.txt: Rebaselined the output now that the scroll position
+    is properly clamped.
+    * platform/ios-wk2/imported/w3c/web-platform-tests/css/cssom-view/elementFromPoint-expected.txt: Rebaselined as one
+    more test case is passing.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244851 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-05-01  Ryosuke Niwa  <rniwa@webkit.org>
+
+            [iOS] Element::focus and Element::scrollIntoView do not clamp scroll positions
+            https://bugs.webkit.org/show_bug.cgi?id=197211
+
+            Reviewed by Simon Fraser.
+
+            Fixed the bug that Element::focus and Element::scrollIntoView were not clamping scroll offsets,
+            which causes scrollTop etc... to return a bogus negative scrolling offset.
+
+            Unfortunately, we can't just use FrameView's ScrollableArea::constrainScrollPosition since
+            scrollRectToVisible relies on the visible rect being expanded by the content insets in order to scroll to
+            a position within the content insets of UIScrollView; e.g. revealing the top of the page as the center.
+            We manually expand minimumScrollPosition() and maximumScrollPosition() by the content insets instead.
+
+            Tests: fast/scrolling/ios/programmatic-scroll-via-focus-should-clamp-top.html
+                   fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-inside-iframe-should-clamp-top.html
+                   fast/scrolling/ios/programmatic-scroll-via-scrollIntoView-should-clamp-top.html
+
+            * rendering/RenderLayer.cpp:
+            (WebCore::RenderLayer::scrollRectToVisible):
+
+2019-05-02  Alan Coon  <alancoon@apple.com>
+
</ins><span class="cx">         Cherry-pick r244849. rdar://problem/50063091
</span><span class="cx"> 
</span><span class="cx">     [iOS] Add a version of viewport shrink-to-fit heuristics that preserves page layout
</span></span></pre></div>
<a id="tagsSafari6081201SourceWebCorerenderingRenderLayercpp"></a>
<div class="modfile"><h4>Modified: tags/Safari-608.1.20.1/Source/WebCore/rendering/RenderLayer.cpp (244886 => 244887)</h4>
<pre class="diff"><span>
<span class="info">--- tags/Safari-608.1.20.1/Source/WebCore/rendering/RenderLayer.cpp  2019-05-02 21:08:35 UTC (rev 244886)
+++ tags/Safari-608.1.20.1/Source/WebCore/rendering/RenderLayer.cpp     2019-05-02 21:08:40 UTC (rev 244887)
</span><span class="lines">@@ -2586,10 +2586,19 @@
</span><span class="cx">             if (options.revealMode == SelectionRevealMode::RevealUpToMainFrame && frameView.frame().isMainFrame())
</span><span class="cx">                 return;
</span><span class="cx"> 
</span><ins>+            auto minScrollPosition = frameView.minimumScrollPosition();
+            auto maxScrollPosition = frameView.maximumScrollPosition();
+
</ins><span class="cx"> #if !PLATFORM(IOS_FAMILY)
</span><span class="cx">             LayoutRect viewRect = frameView.visibleContentRect();
</span><span class="cx"> #else
</span><ins>+            // FIXME: ContentInsets should be taken care of in UI process side.
+            // To do that, getRectToExpose needs to return the additional scrolling to do beyond content rect.
</ins><span class="cx">             LayoutRect viewRect = frameView.visualViewportRectExpandedByContentInsets();
</span><ins>+
+            auto contentInsets = page().contentInsets();
+            minScrollPosition.move(-contentInsets.left(), -contentInsets.top());
+            maxScrollPosition.move(contentInsets.right(), contentInsets.bottom());
</ins><span class="cx"> #endif
</span><span class="cx">             // Move the target rect into "scrollView contents" coordinates.
</span><span class="cx">             LayoutRect targetRect = absoluteRect;
</span><span class="lines">@@ -2596,8 +2605,8 @@
</span><span class="cx">             targetRect.move(0, frameView.headerHeight());
</span><span class="cx"> 
</span><span class="cx">             LayoutRect revealRect = getRectToExpose(viewRect, targetRect, insideFixed, options.alignX, options.alignY);
</span><del>-            
-            frameView.setScrollPosition(roundedIntPoint(revealRect.location()));
</del><ins>+            ScrollOffset clampedScrollPosition = roundedIntPoint(revealRect.location()).constrainedBetween(minScrollPosition, maxScrollPosition);
+            frameView.setScrollPosition(clampedScrollPosition);
</ins><span class="cx"> 
</span><span class="cx">             // This is the outermost view of a web page, so after scrolling this view we
</span><span class="cx">             // scroll its container by calling Page::scrollRectIntoView.
</span></span></pre>
</div>
</div>

</body>
</html>