<!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>[205505] 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/205505">205505</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2016-09-06 14:18:06 -0700 (Tue, 06 Sep 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Align element.scroll() / scrollTo() / scrollBy() with the CSSOM specification
https://bugs.webkit.org/show_bug.cgi?id=161610
Reviewed by Darin Adler, Chris Dumez.
Source/WebCore:
Implement Element.scroll(), scrollBy() and scrollTo() with x,y and ScrollToOptions
on Element, according to <https://drafts.csswg.org/cssom-view/#element-scrolling-members>
WebKit's behavior of treating scrolls on the body element in both quirks and strict mode
is preserved.
Tests: fast/dom/Element/scrolling-funtions-on-body-quirks.html
fast/dom/Element/scrolling-funtions-on-body.html
fast/dom/Element/scrolling-funtions-on-element.html
* dom/Element.cpp:
(WebCore::Element::scrollBy):
(WebCore::normalizeNonFiniteValue):
(WebCore::Element::scrollTo):
* dom/Element.h:
* dom/Element.idl:
* html/HTMLBodyElement.cpp:
(WebCore::HTMLBodyElement::scrollTo):
* html/HTMLBodyElement.h:
LayoutTests:
* fast/dom/Element/scrolling-funtions-on-body-expected.txt: Added.
* fast/dom/Element/scrolling-funtions-on-body-quirks-expected.txt: Added.
* fast/dom/Element/scrolling-funtions-on-body-quirks.html: Added.
* fast/dom/Element/scrolling-funtions-on-body.html: Added.
* fast/dom/Element/scrolling-funtions-on-element-expected.txt: Added.
* fast/dom/Element/scrolling-funtions-on-element.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="#trunkSourceWebCoredomElementcpp">trunk/Source/WebCore/dom/Element.cpp</a></li>
<li><a href="#trunkSourceWebCoredomElementh">trunk/Source/WebCore/dom/Element.h</a></li>
<li><a href="#trunkSourceWebCoredomElementidl">trunk/Source/WebCore/dom/Element.idl</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLBodyElementcpp">trunk/Source/WebCore/html/HTMLBodyElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLBodyElementh">trunk/Source/WebCore/html/HTMLBodyElement.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastdomElementscrollingfuntionsonbodyexpectedtxt">trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomElementscrollingfuntionsonbodyquirksexpectedtxt">trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-quirks-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomElementscrollingfuntionsonbodyquirkshtml">trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-quirks.html</a></li>
<li><a href="#trunkLayoutTestsfastdomElementscrollingfuntionsonbodyhtml">trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body.html</a></li>
<li><a href="#trunkLayoutTestsfastdomElementscrollingfuntionsonelementexpectedtxt">trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-element-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomElementscrollingfuntionsonelementhtml">trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-element.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (205504 => 205505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-09-06 21:13:25 UTC (rev 205504)
+++ trunk/LayoutTests/ChangeLog        2016-09-06 21:18:06 UTC (rev 205505)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2016-09-06 Simon Fraser <simon.fraser@apple.com>
+
+ Align element.scroll() / scrollTo() / scrollBy() with the CSSOM specification
+ https://bugs.webkit.org/show_bug.cgi?id=161610
+
+ Reviewed by Darin Adler, Chris Dumez.
+
+ * fast/dom/Element/scrolling-funtions-on-body-expected.txt: Added.
+ * fast/dom/Element/scrolling-funtions-on-body-quirks-expected.txt: Added.
+ * fast/dom/Element/scrolling-funtions-on-body-quirks.html: Added.
+ * fast/dom/Element/scrolling-funtions-on-body.html: Added.
+ * fast/dom/Element/scrolling-funtions-on-element-expected.txt: Added.
+ * fast/dom/Element/scrolling-funtions-on-element.html: Added.
+
</ins><span class="cx"> 2016-09-06 Ryan Haddad <ryanhaddad@apple.com>
</span><span class="cx">
</span><span class="cx"> Skip some asserting Fetch API tests.
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomElementscrollingfuntionsonbodyexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-expected.txt (0 => 205505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-expected.txt         (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-expected.txt        2016-09-06 21:18:06 UTC (rev 205505)
</span><span class="lines">@@ -0,0 +1,21 @@
</span><ins>+Tests scrollTo/By(x,y) and scrollTo/By(scrollOptions) on the body. WebKit always uses quirks mode for body scrolling behavior, so this scrolls the window.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS scroller.scrollLeft is 20
+PASS scroller.scrollTop is 500
+PASS window.scrollX is 20
+PASS window.scrollY is 500
+PASS scroller.scrollLeft is 70
+PASS scroller.scrollTop is 560
+PASS window.scrollX is 70
+PASS window.scrollY is 560
+PASS scroller.scrollLeft is 100
+PASS scroller.scrollTop is 400
+PASS window.scrollX is 100
+PASS window.scrollY is 400
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomElementscrollingfuntionsonbodyquirksexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-quirks-expected.txt (0 => 205505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-quirks-expected.txt         (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-quirks-expected.txt        2016-09-06 21:18:06 UTC (rev 205505)
</span><span class="lines">@@ -0,0 +1,21 @@
</span><ins>+Tests scrollTo/By(x,y) and scrollTo/By(scrollOptions) on the body in quirks mode.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS scroller.scrollLeft is 20
+PASS scroller.scrollTop is 500
+PASS window.scrollX is 20
+PASS window.scrollY is 500
+PASS scroller.scrollLeft is 70
+PASS scroller.scrollTop is 560
+PASS window.scrollX is 70
+PASS window.scrollY is 560
+PASS scroller.scrollLeft is 100
+PASS scroller.scrollTop is 400
+PASS window.scrollX is 100
+PASS window.scrollY is 400
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomElementscrollingfuntionsonbodyquirkshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-quirks.html (0 => 205505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-quirks.html         (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-quirks.html        2016-09-06 21:18:06 UTC (rev 205505)
</span><span class="lines">@@ -0,0 +1,48 @@
</span><ins>+<html>
+ <head>
+ <style>
+ div {
+ width: 9999px;
+ height: 9999px;
+ }
+ </style>
+ <script src="../../../resources/js-test-pre.js"></script>
+ <script>
+ var scroller;
+ function runTest() {
+ description('Tests scrollTo/By(x,y) and scrollTo/By(scrollOptions) on the body in quirks mode.');
+
+ scroller = document.body;
+ setTimeout(function() {
+ scroller.scrollTo(20, 500);
+ shouldBe("scroller.scrollLeft", "20");
+ shouldBe("scroller.scrollTop", "500");
+ shouldBe("window.scrollX", "20");
+ shouldBe("window.scrollY", "500");
+
+ scroller.scrollBy(50, 60);
+ shouldBe("scroller.scrollLeft", "70");
+ shouldBe("scroller.scrollTop", "560");
+ shouldBe("window.scrollX", "70");
+ shouldBe("window.scrollY", "560");
+
+ scroller.scrollTo({ 'left' : 100, 'top' : 400 });
+ shouldBe("scroller.scrollLeft", "100");
+ shouldBe("scroller.scrollTop", "400");
+ shouldBe("window.scrollX", "100");
+ shouldBe("window.scrollY", "400");
+
+ scroller.scrollTo(0, 0);
+
+ finishJSTest();
+ }, 0);
+ }
+ var jsTestIsAsync = true;
+ </script>
+ </head>
+ <body onload="runTest()">
+ <div>
+ </div>
+ <script src="../../../resources/js-test-post.js"></script>
+ </body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomElementscrollingfuntionsonbodyhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body.html (0 => 205505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body.html         (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body.html        2016-09-06 21:18:06 UTC (rev 205505)
</span><span class="lines">@@ -0,0 +1,49 @@
</span><ins>+<!DOCTYPE html>
+<html>
+ <head>
+ <style>
+ div {
+ width: 9999px;
+ height: 9999px;
+ }
+ </style>
+ <script src="../../../resources/js-test-pre.js"></script>
+ <script>
+ var scroller;
+ function runTest() {
+ description('Tests scrollTo/By(x,y) and scrollTo/By(scrollOptions) on the body. WebKit always uses quirks mode for body scrolling behavior, so this scrolls the window.');
+
+ scroller = document.body;
+ setTimeout(function() {
+ scroller.scrollTo(20, 500);
+ shouldBe("scroller.scrollLeft", "20");
+ shouldBe("scroller.scrollTop", "500");
+ shouldBe("window.scrollX", "20");
+ shouldBe("window.scrollY", "500");
+
+ scroller.scrollBy(50, 60);
+ shouldBe("scroller.scrollLeft", "70");
+ shouldBe("scroller.scrollTop", "560");
+ shouldBe("window.scrollX", "70");
+ shouldBe("window.scrollY", "560");
+
+ scroller.scrollTo({ 'left' : 100, 'top' : 400 });
+ shouldBe("scroller.scrollLeft", "100");
+ shouldBe("scroller.scrollTop", "400");
+ shouldBe("window.scrollX", "100");
+ shouldBe("window.scrollY", "400");
+
+ scroller.scrollTo(0, 0);
+
+ finishJSTest();
+ }, 0);
+ }
+ var jsTestIsAsync = true;
+ </script>
+ </head>
+ <body onload="runTest()">
+ <div>
+ </div>
+ <script src="../../../resources/js-test-post.js"></script>
+ </body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomElementscrollingfuntionsonelementexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-element-expected.txt (0 => 205505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-element-expected.txt         (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-element-expected.txt        2016-09-06 21:18:06 UTC (rev 205505)
</span><span class="lines">@@ -0,0 +1,41 @@
</span><ins>+Tests scrollTo/By(x,y) and scrollTo/By(scrollOptions) on Element
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS scroller.scrollLeft is 20
+PASS scroller.scrollTop is 500
+PASS scroller.scrollLeft is 70
+PASS scroller.scrollTop is 560
+PASS scroller.scrollLeft is 100
+PASS scroller.scrollTop is 400
+PASS scroller.scrollLeft is 120
+PASS scroller.scrollTop is 430
+PASS scroller.scrollLeft is 120
+PASS scroller.scrollTop is 700
+PASS scroller.scrollLeft is 300
+PASS scroller.scrollTop is 700
+PASS scroller.scrollLeft is 500
+PASS scroller.scrollTop is 700
+PASS scroller.scrollLeft is 500
+PASS scroller.scrollTop is 950
+PASS scroller.scrollLeft is 20
+PASS scroller.scrollTop is 25
+PASS scroller.scrollLeft is 30
+PASS scroller.scrollTop is 35
+PASS scroller.scrollLeft is 0
+PASS scroller.scrollTop is 0
+PASS scroller.scrollLeft is 10
+PASS scroller.scrollTop is 10
+PASS scroller.scrollLeft is 0
+PASS scroller.scrollTop is 0
+PASS scroller.scrollLeft is 0
+PASS scroller.scrollTop is 0
+PASS scroller.scrollLeft is 0
+PASS scroller.scrollTop is 0
+PASS scroller.scrollLeft is 100
+PASS scroller.scrollTop is 400
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomElementscrollingfuntionsonelementhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-element.html (0 => 205505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-element.html         (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-element.html        2016-09-06 21:18:06 UTC (rev 205505)
</span><span class="lines">@@ -0,0 +1,106 @@
</span><ins>+<!DOCTYPE html>
+<html>
+ <head>
+ <style>
+ #scroller {
+ height: 500px;
+ width:500px;
+ outline: 1px solid black;
+ overflow: auto;
+ }
+ .content {
+ width: 9999px;
+ height: 9999px;
+ }
+ </style>
+ <script src="../../../resources/js-test-pre.js"></script>
+ <script>
+ function runTest() {
+ description('Tests scrollTo/By(x,y) and scrollTo/By(scrollOptions) on Element');
+
+ var scroller = document.getElementById('scroller');
+ setTimeout(function() {
+ scroller.scrollTo(20, 500);
+ shouldBe("scroller.scrollLeft", "20");
+ shouldBe("scroller.scrollTop", "500");
+
+ scroller.scrollBy(50, 60);
+ shouldBe("scroller.scrollLeft", "70");
+ shouldBe("scroller.scrollTop", "560");
+
+ scroller.scrollTo({ 'left' : 100, 'top' : 400 });
+ shouldBe("scroller.scrollLeft", "100");
+ shouldBe("scroller.scrollTop", "400");
+
+ scroller.scrollBy({ 'left' : 20, 'top' : 30 });
+ shouldBe("scroller.scrollLeft", "120");
+ shouldBe("scroller.scrollTop", "430");
+
+ scroller.scrollTo({ 'top' : 700 });
+ shouldBe("scroller.scrollLeft", "120");
+ shouldBe("scroller.scrollTop", "700");
+
+ scroller.scrollTo({ 'left' : 300 });
+ shouldBe("scroller.scrollLeft", "300");
+ shouldBe("scroller.scrollTop", "700");
+
+ scroller.scrollBy({ 'left' : 200 });
+ shouldBe("scroller.scrollLeft", "500");
+ shouldBe("scroller.scrollTop", "700");
+
+ scroller.scrollBy({ 'top' : 250 });
+ shouldBe("scroller.scrollLeft", "500");
+ shouldBe("scroller.scrollTop", "950");
+
+ scroller.scrollTo(20.5, 25.5);
+ shouldBe("scroller.scrollLeft", "20");
+ shouldBe("scroller.scrollTop", "25");
+
+ scroller.scrollTo(30.99, 35.99);
+ shouldBe("scroller.scrollLeft", "30");
+ shouldBe("scroller.scrollTop", "35");
+
+ scroller.scrollTo(NaN, NaN);
+ shouldBe("scroller.scrollLeft", "0");
+ shouldBe("scroller.scrollTop", "0");
+
+ scroller.scrollTo(10, 10);
+ scroller.scrollBy(Infinity, Infinity);
+ shouldBe("scroller.scrollLeft", "10");
+ shouldBe("scroller.scrollTop", "10");
+
+ scroller.scrollTo(-100, -100);
+ shouldBe("scroller.scrollLeft", "0");
+ shouldBe("scroller.scrollTop", "0");
+
+ scroller.style.display = 'none';
+ scroller.scrollTo(100, 100);
+ shouldBe("scroller.scrollLeft", "0");
+ shouldBe("scroller.scrollTop", "0");
+
+ scroller.style.display = 'block';
+ shouldBe("scroller.scrollLeft", "0");
+ shouldBe("scroller.scrollTop", "0");
+
+ if (window.internals)
+ internals.setPageZoomFactor(1.5);
+
+ scroller.scrollTo({ 'left' : 100, 'top' : 400 });
+ shouldBe("scroller.scrollLeft", "100");
+ shouldBe("scroller.scrollTop", "400");
+
+ scroller.style.display = 'none';
+
+ finishJSTest();
+ }, 0);
+ }
+ var jsTestIsAsync = true;
+ </script>
+ </head>
+ <body onload="runTest()">
+ <div id="scroller">
+ <div class="content">Scrolling content</div>
+ </div>
+ <script src="../../../resources/js-test-post.js"></script>
+ </body>
+</html>
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (205504 => 205505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-09-06 21:13:25 UTC (rev 205504)
+++ trunk/Source/WebCore/ChangeLog        2016-09-06 21:18:06 UTC (rev 205505)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2016-09-06 Simon Fraser <simon.fraser@apple.com>
+
+ Align element.scroll() / scrollTo() / scrollBy() with the CSSOM specification
+ https://bugs.webkit.org/show_bug.cgi?id=161610
+
+ Reviewed by Darin Adler, Chris Dumez.
+
+ Implement Element.scroll(), scrollBy() and scrollTo() with x,y and ScrollToOptions
+ on Element, according to <https://drafts.csswg.org/cssom-view/#element-scrolling-members>
+
+ WebKit's behavior of treating scrolls on the body element in both quirks and strict mode
+ is preserved.
+
+ Tests: fast/dom/Element/scrolling-funtions-on-body-quirks.html
+ fast/dom/Element/scrolling-funtions-on-body.html
+ fast/dom/Element/scrolling-funtions-on-element.html
+
+ * dom/Element.cpp:
+ (WebCore::Element::scrollBy):
+ (WebCore::normalizeNonFiniteValue):
+ (WebCore::Element::scrollTo):
+ * dom/Element.h:
+ * dom/Element.idl:
+ * html/HTMLBodyElement.cpp:
+ (WebCore::HTMLBodyElement::scrollTo):
+ * html/HTMLBodyElement.h:
+
</ins><span class="cx"> 2016-09-06 Saam Barati <sbarati@apple.com>
</span><span class="cx">
</span><span class="cx"> Make JSMap and JSSet faster
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.cpp (205504 => 205505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.cpp        2016-09-06 21:13:25 UTC (rev 205504)
+++ trunk/Source/WebCore/dom/Element.cpp        2016-09-06 21:18:06 UTC (rev 205505)
</span><span class="lines">@@ -684,7 +684,50 @@
</span><span class="cx"> else
</span><span class="cx"> renderer()->scrollRectToVisible(SelectionRevealMode::Reveal, bounds, ScrollAlignment::alignToEdgeIfNotVisible, ScrollAlignment::alignToEdgeIfNotVisible);
</span><span class="cx"> }
</span><del>-
</del><ins>+
+void Element::scrollBy(const ScrollToOptions& options)
+{
+ return scrollBy(options.left.valueOr(0), options.top.valueOr(0));
+}
+
+static inline double normalizeNonFiniteValue(double f)
+{
+ return std::isfinite(f) ? f : 0;
+}
+
+void Element::scrollBy(double x, double y)
+{
+ scrollTo(scrollLeft() + normalizeNonFiniteValue(x), scrollTop() + normalizeNonFiniteValue(y));
+}
+
+void Element::scrollTo(const ScrollToOptions& options)
+{
+ // If the element is the root element and document is in quirks mode, terminate these steps.
+ // Note that WebKit always uses quirks mode document scrolling behavior. See Document::scrollingElement().
+ if (this == document().documentElement())
+ return;
+
+ document().updateLayoutIgnorePendingStylesheets();
+
+ // If the element does not have any associated CSS layout box, the element has no associated scrolling box,
+ // or the element has no overflow, terminate these steps.
+ RenderBox* renderer = renderBox();
+ if (!renderer || !renderer->hasOverflowClip())
+ return;
+
+ // Normalize non-finite values for left and top dictionary members of options, if present.
+ double x = options.left ? normalizeNonFiniteValue(options.left.value()) : adjustForAbsoluteZoom(renderer->scrollLeft(), *renderer);
+ double y = options.top ? normalizeNonFiniteValue(options.top.value()) : adjustForAbsoluteZoom(renderer->scrollTop(), *renderer);
+
+ renderer->setScrollLeft(clampToInteger(x * renderer->style().effectiveZoom()));
+ renderer->setScrollTop(clampToInteger(y * renderer->style().effectiveZoom()));
+}
+
+void Element::scrollTo(double x, double y)
+{
+ scrollTo({ x, y });
+}
+
</ins><span class="cx"> void Element::scrollByUnits(int units, ScrollGranularity granularity)
</span><span class="cx"> {
</span><span class="cx"> document().updateLayoutIgnorePendingStylesheets();
</span><span class="lines">@@ -826,7 +869,7 @@
</span><span class="cx"> {
</span><span class="cx"> document().updateLayoutIgnorePendingStylesheets();
</span><span class="cx">
</span><del>- if (RenderBox* renderer = renderBox()) {
</del><ins>+ if (auto* renderer = renderBox()) {
</ins><span class="cx"> LayoutUnit clientLeft = subpixelMetricsEnabled(renderer->document()) ? renderer->clientLeft() : LayoutUnit(roundToInt(renderer->clientLeft()));
</span><span class="cx"> return convertToNonSubpixelValueIfNeeded(adjustLayoutUnitForAbsoluteZoom(clientLeft, *renderer).toDouble(), renderer->document());
</span><span class="cx"> }
</span><span class="lines">@@ -837,7 +880,7 @@
</span><span class="cx"> {
</span><span class="cx"> document().updateLayoutIgnorePendingStylesheets();
</span><span class="cx">
</span><del>- if (RenderBox* renderer = renderBox()) {
</del><ins>+ if (auto* renderer = renderBox()) {
</ins><span class="cx"> LayoutUnit clientTop = subpixelMetricsEnabled(renderer->document()) ? renderer->clientTop() : LayoutUnit(roundToInt(renderer->clientTop()));
</span><span class="cx"> return convertToNonSubpixelValueIfNeeded(adjustLayoutUnitForAbsoluteZoom(clientTop, *renderer).toDouble(), renderer->document());
</span><span class="cx"> }
</span><span class="lines">@@ -850,6 +893,7 @@
</span><span class="cx">
</span><span class="cx"> if (!document().hasLivingRenderTree())
</span><span class="cx"> return 0;
</span><ins>+
</ins><span class="cx"> RenderView& renderView = *document().renderView();
</span><span class="cx">
</span><span class="cx"> // When in strict mode, clientWidth for the document element should return the width of the containing frame.
</span><span class="lines">@@ -870,6 +914,7 @@
</span><span class="cx"> document().updateLayoutIfDimensionsOutOfDate(*this, HeightDimensionsCheck);
</span><span class="cx"> if (!document().hasLivingRenderTree())
</span><span class="cx"> return 0;
</span><ins>+
</ins><span class="cx"> RenderView& renderView = *document().renderView();
</span><span class="cx">
</span><span class="cx"> // When in strict mode, clientHeight for the document element should return the height of the containing frame.
</span><span class="lines">@@ -889,8 +934,8 @@
</span><span class="cx"> {
</span><span class="cx"> document().updateLayoutIgnorePendingStylesheets();
</span><span class="cx">
</span><del>- if (RenderBox* rend = renderBox())
- return adjustForAbsoluteZoom(rend->scrollLeft(), *rend);
</del><ins>+ if (auto* renderer = renderBox())
+ return adjustForAbsoluteZoom(renderer->scrollLeft(), *renderer);
</ins><span class="cx"> return 0;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -898,8 +943,8 @@
</span><span class="cx"> {
</span><span class="cx"> document().updateLayoutIgnorePendingStylesheets();
</span><span class="cx">
</span><del>- if (RenderBox* rend = renderBox())
- return adjustForAbsoluteZoom(rend->scrollTop(), *rend);
</del><ins>+ if (RenderBox* renderer = renderBox())
+ return adjustForAbsoluteZoom(renderer->scrollTop(), *renderer);
</ins><span class="cx"> return 0;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -907,7 +952,7 @@
</span><span class="cx"> {
</span><span class="cx"> document().updateLayoutIgnorePendingStylesheets();
</span><span class="cx">
</span><del>- if (RenderBox* renderer = renderBox()) {
</del><ins>+ if (auto* renderer = renderBox()) {
</ins><span class="cx"> renderer->setScrollLeft(static_cast<int>(newLeft * renderer->style().effectiveZoom()));
</span><span class="cx"> if (auto* scrollableArea = renderer->layer())
</span><span class="cx"> scrollableArea->setScrolledProgrammatically(true);
</span><span class="lines">@@ -918,7 +963,7 @@
</span><span class="cx"> {
</span><span class="cx"> document().updateLayoutIgnorePendingStylesheets();
</span><span class="cx">
</span><del>- if (RenderBox* renderer = renderBox()) {
</del><ins>+ if (auto* renderer = renderBox()) {
</ins><span class="cx"> renderer->setScrollTop(static_cast<int>(newTop * renderer->style().effectiveZoom()));
</span><span class="cx"> if (auto* scrollableArea = renderer->layer())
</span><span class="cx"> scrollableArea->setScrolledProgrammatically(true);
</span><span class="lines">@@ -928,8 +973,8 @@
</span><span class="cx"> int Element::scrollWidth()
</span><span class="cx"> {
</span><span class="cx"> document().updateLayoutIfDimensionsOutOfDate(*this, WidthDimensionsCheck);
</span><del>- if (RenderBox* rend = renderBox())
- return adjustForAbsoluteZoom(rend->scrollWidth(), *rend);
</del><ins>+ if (auto* renderer = renderBox())
+ return adjustForAbsoluteZoom(renderer->scrollWidth(), *renderer);
</ins><span class="cx"> return 0;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -936,8 +981,8 @@
</span><span class="cx"> int Element::scrollHeight()
</span><span class="cx"> {
</span><span class="cx"> document().updateLayoutIfDimensionsOutOfDate(*this, HeightDimensionsCheck);
</span><del>- if (RenderBox* rend = renderBox())
- return adjustForAbsoluteZoom(rend->scrollHeight(), *rend);
</del><ins>+ if (auto* renderer = renderBox())
+ return adjustForAbsoluteZoom(renderer->scrollHeight(), *renderer);
</ins><span class="cx"> return 0;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.h (205504 => 205505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.h        2016-09-06 21:13:25 UTC (rev 205504)
+++ trunk/Source/WebCore/dom/Element.h        2016-09-06 21:18:06 UTC (rev 205505)
</span><span class="lines">@@ -136,6 +136,16 @@
</span><span class="cx"> WEBCORE_EXPORT void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
</span><span class="cx"> WEBCORE_EXPORT void scrollIntoViewIfNotVisible(bool centerIfNotVisible = true);
</span><span class="cx">
</span><ins>+ struct ScrollToOptions {
+ Optional<double> left;
+ Optional<double> top;
+ };
+
+ void scrollBy(const ScrollToOptions&);
+ void scrollBy(double x, double y);
+ virtual void scrollTo(const ScrollToOptions&);
+ void scrollTo(double x, double y);
+
</ins><span class="cx"> WEBCORE_EXPORT void scrollByLines(int lines);
</span><span class="cx"> WEBCORE_EXPORT void scrollByPages(int pages);
</span><span class="cx">
</span><span class="lines">@@ -157,6 +167,7 @@
</span><span class="cx"> WEBCORE_EXPORT double clientTop();
</span><span class="cx"> WEBCORE_EXPORT double clientWidth();
</span><span class="cx"> WEBCORE_EXPORT double clientHeight();
</span><ins>+
</ins><span class="cx"> virtual int scrollLeft();
</span><span class="cx"> virtual int scrollTop();
</span><span class="cx"> virtual void setScrollLeft(int);
</span></span></pre></div>
<a id="trunkSourceWebCoredomElementidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Element.idl (205504 => 205505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Element.idl        2016-09-06 21:13:25 UTC (rev 205504)
+++ trunk/Source/WebCore/dom/Element.idl        2016-09-06 21:18:06 UTC (rev 205505)
</span><span class="lines">@@ -71,8 +71,8 @@
</span><span class="cx"> readonly attribute double clientWidth;
</span><span class="cx"> readonly attribute double clientHeight;
</span><span class="cx">
</span><del>- attribute long scrollLeft;
- attribute long scrollTop;
</del><ins>+ attribute long scrollLeft; // FIXME: should be unrestricted double
+ attribute long scrollTop; // FIXME: should be unrestricted double
</ins><span class="cx"> readonly attribute long scrollWidth;
</span><span class="cx"> readonly attribute long scrollHeight;
</span><span class="cx">
</span><span class="lines">@@ -80,12 +80,22 @@
</span><span class="cx">
</span><span class="cx"> void scrollIntoView(optional boolean alignWithTop = true);
</span><span class="cx">
</span><del>- sequence<DOMString> getAttributeNames();
</del><ins>+ void scrollIntoViewIfNeeded(optional boolean centerIfNeeded = true);
</ins><span class="cx">
</span><del>- void scrollIntoViewIfNeeded(optional boolean centerIfNeeded = true);
</del><ins>+ [ImplementedAs=scrollTo] void scroll(optional ScrollToOptions options);
+ [ImplementedAs=scrollTo] void scroll(unrestricted double x, unrestricted double y);
+
+ void scrollTo(optional ScrollToOptions options);
+ void scrollTo(unrestricted double x, unrestricted double y);
+
+ void scrollBy(optional ScrollToOptions option);
+ void scrollBy(unrestricted double x, unrestricted double y);
+
</ins><span class="cx"> void scrollByLines(optional long lines = 0);
</span><span class="cx"> void scrollByPages(optional long pages = 0);
</span><span class="cx">
</span><ins>+ sequence<DOMString> getAttributeNames();
+
</ins><span class="cx"> HTMLCollection getElementsByClassName(DOMString name);
</span><span class="cx"> [TreatNullAs=EmptyString, SetterRaisesException] attribute DOMString innerHTML;
</span><span class="cx"> [TreatNullAs=EmptyString, SetterRaisesException] attribute DOMString outerHTML;
</span><span class="lines">@@ -178,6 +188,12 @@
</span><span class="cx"> required ShadowRootMode mode;
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+// FIXME: Support ScrollBehavior.
+dictionary ScrollToOptions {
+ unrestricted double left;
+ unrestricted double top;
+};
+
</ins><span class="cx"> Element implements Animatable;
</span><span class="cx"> Element implements ChildNode;
</span><span class="cx"> Element implements NonDocumentTypeChildNode;
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLBodyElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLBodyElement.cpp (205504 => 205505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLBodyElement.cpp        2016-09-06 21:13:25 UTC (rev 205504)
+++ trunk/Source/WebCore/html/HTMLBodyElement.cpp        2016-09-06 21:18:06 UTC (rev 205505)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #include "CSSImageValue.h"
</span><span class="cx"> #include "CSSParser.h"
</span><span class="cx"> #include "CSSValueKeywords.h"
</span><ins>+#include "DOMWindow.h"
</ins><span class="cx"> #include "EventNames.h"
</span><span class="cx"> #include "Frame.h"
</span><span class="cx"> #include "FrameView.h"
</span><span class="lines">@@ -294,6 +295,23 @@
</span><span class="cx"> return HTMLElement::setScrollTop(scrollTop);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void HTMLBodyElement::scrollTo(const ScrollToOptions& options)
+{
+ if (isFirstBodyElementOfDocument()) {
+ // If the element is the HTML body element, document is in quirks mode, and the element is not potentially scrollable,
+ // invoke scroll() on window with options as the only argument, and terminate these steps.
+ // Note that WebKit always uses quirks mode document scrolling behavior. See Document::scrollingElement().
+ // FIXME: Scrolling an independently scrollable body is broken: webkit.org/b/161612.
+ auto* window = document().domWindow();
+ if (!window)
+ return;
+
+ window->scrollTo({ options.left, options.top });
+ return;
+ }
+ return HTMLElement::scrollTo(options);
+}
+
</ins><span class="cx"> int HTMLBodyElement::scrollHeight()
</span><span class="cx"> {
</span><span class="cx"> if (isFirstBodyElementOfDocument()) {
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLBodyElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLBodyElement.h (205504 => 205505)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLBodyElement.h        2016-09-06 21:13:25 UTC (rev 205504)
+++ trunk/Source/WebCore/html/HTMLBodyElement.h        2016-09-06 21:18:06 UTC (rev 205505)
</span><span class="lines">@@ -56,6 +56,8 @@
</span><span class="cx">
</span><span class="cx"> int scrollTop() final;
</span><span class="cx"> void setScrollTop(int) final;
</span><ins>+
+ void scrollTo(const ScrollToOptions&) final;
</ins><span class="cx">
</span><span class="cx"> int scrollHeight() final;
</span><span class="cx"> int scrollWidth() final;
</span></span></pre>
</div>
</div>
</body>
</html>